Commit bda1948a authored by Praetorius, Simon's avatar Praetorius, Simon

several corrections in the cmake files, e.g. test_compile_features and blas-lapack

parent b8063b9f
......@@ -2,12 +2,9 @@ set(CMAKE_LEGACY_CYGWIN_WIN32 0)
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(AMDiS)
if (USE_NEW_CMAKE AND ${CMAKE_VERSION} VERSION_GREATER "3.2")
# Experimental implementation of new CMakeLists.txt
# Can be selected by calling cmake -DUSE_NEW_CMAKE=ON .
# Use only if you know what you are doing :-)
include(${AMDiS_SOURCE_DIR}/cmake3/CMakeLists.txt)
if (${CMAKE_VERSION} VERSION_GREATER "3.2")
include(${AMDiS_SOURCE_DIR}/cmake3/CMakeLists.txt)
else ()
# By defualt the classical CMakeLists file ist used
include(${AMDiS_SOURCE_DIR}/cmake/CMakeLists.txt)
# Fallback to classical CMakeLists file
include(${AMDiS_SOURCE_DIR}/cmake/CMakeLists.txt)
endif ()
#thats bad because it affects each target
# globally add compile options and include directories
add_definitions(${AMDIS_COMPILEFLAGS})
include_directories(${AMDIS_INCLUDE_DIRS})
......@@ -30,12 +30,12 @@ set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
# #message("svn-rev: ${svn_info_WC_REVISION}")
# set(AMDIS_SUB_MINOR "${svn_info_WC_REVISION}")
# endif()
set(CurrentRevision "0.9")
set(CurrentRevision "1.1")
if(NOT AMDIS_MAJOR)
set(AMDIS_MAJOR "0")
set(AMDIS_MAJOR "1")
endif()
if(NOT AMDIS_MINOR)
set(AMDIS_MINOR "9")
set(AMDIS_MINOR "1")
endif()
list(APPEND COMPILEFLAGS "-DAMDIS_VERSION=${CurrentRevision}")
......
# enable the c++11 features. From cmake version 3.0 this is simply done by setting
# the cxx_standard variables. For older cmake version the compile-flags must be added manually.
include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles)
include(CheckIncludeFileCXX)
if (ENABLE_CXX11)
list(APPEND COMPILEFLAGS "-DHAS_CXX11=1")
if (${CMAKE_VERSION} VERSION_GREATER "3.0")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") # cmake can not detect intel compile features
set(REQUIRED_CXX_FEATURES "cxx_alias_templates" "cxx_auto_type" "cxx_lambdas" "cxx_override" "cxx_range_for" "cxx_static_assert" "cxx_variadic_templates")
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
if (NOT COMPILER_SUPPORTS_CXX11)
set(CMAKE_REQUIRED_FLAGS "-std=c++11")
check_cxx_source_compiles("int main(){decltype(1) vec[]={1,2,3}; for(auto&& x:vec);}" CXX_COMPILES_WITH_CXX11)
set(CMAKE_REQUIRED_FLAGS "")
endif ()
if (COMPILER_SUPPORTS_CXX11 OR CXX_COMPILES_WITH_CXX11)
add_definitions("-std=c++11")
else ()
check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if (NOT COMPILER_SUPPORTS_CXX0X)
set(CMAKE_REQUIRED_FLAGS "-std=c++0x")
check_cxx_source_compiles("int main(){decltype(1) vec[]={1,2,3}; for(auto&& x:vec);}" CXX_COMPILES_WITH_CXX0X)
set(CMAKE_REQUIRED_FLAGS "")
endif ()
if (COMPILER_SUPPORTS_CXX0X OR CXX_COMPILES_WITH_CXX0X)
add_definitions("-std=c++0x")
else ()
check_cxx_source_compiles("int main(){decltype(1) vec[]={1,2,3}; for(auto&& x:vec);}" CXX11_COMPILES)
check_include_file_cxx("array" CXX11_INCLUDES)
if (CXX11_COMPILES AND CXX11_INCLUDES)
set(${RESULT_VAR} true CACHE BOOL "Enable C++11 compiler features")
else ()
message (FATAL_ERROR "Compiler does not support C++11.")
endif ()
endif ()
endif ()
add_library(test_compiler_features cmake/dummy.cc)
foreach(feature ${REQUIRED_CXX_FEATURES})
target_compile_features(test_compiler_features PUBLIC ${feature})
endforeach(feature)
endif ()
else()
if (CMAKE_COMPILER_IS_GNUCXX)
set(GXX_MIN_VER "4.8")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS GXX_MIN_VER)
message (FATAL_ERROR "For C++11-Features the G++ Compiler must be at least version $GXX_MIN_VER")
endif ()
list(APPEND COMPILEFLAGS "-std=gnu++11")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CLANG_MIN_VER "3.0")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS CLANG_MIN_VER)
message (FATAL_ERROR "For C++11-Features the Clang Compiler must be at least version $CLANG_MIN_VER")
endif ()
list(APPEND COMPILEFLAGS "-std=c++11")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(INTEL_MIN_VER "12.1")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS INTEL_MIN_VER)
message (FATAL_ERROR "For C++11-Features the Intel C++ Compiler must be at least version $INTEL_MIN_VER")
endif ()
list(APPEND COMPILEFLAGS "-std=c++11")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(MSVC_MIN_VER "12.0")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS MSVC_MIN_VER)
message (FATAL_ERROR "For C++11-Features the MSVC C++ Compiler must be at least version $MSVC_MIN_VER")
endif ()
endif ()
endif()
list(APPEND COMPILEFLAGS "-DHAS_CXX11=1")
else ()
list(APPEND COMPILEFLAGS "-DHAS_CXX11=0")
list(APPEND COMPILEFLAGS "-DHAS_CXX11=0")
endif (ENABLE_CXX11)
......@@ -103,21 +103,39 @@ if (AMDIS_HAS_PARALLEL_DOMAIN)
HAVE_PARALLEL_DOMAIN_AMDIS=1)
find_package(MPI REQUIRED)
if (MPI_FOUND)
target_include_directories(amdis_base INTERFACE ${MPI_INCLUDE_PATH})
target_compile_options(amdis_base INTERFACE ${MPI_COMPILE_FLAGS})
target_link_libraries(amdis_base INTERFACE ${MPI_LIBRARIES})
endif (MPI_FOUND)
target_include_directories(amdis_base INTERFACE ${MPI_CXX_INCLUDE_PATH})
target_compile_options(amdis_base INTERFACE ${MPI_CXX_COMPILE_FLAGS})
string(STRIP " ${MPI_CXX_LINK_FLAGS} " MPI_CXX_LINK_FLAGS_)
target_link_libraries(amdis_base INTERFACE ${MPI_CXX_LINK_FLAGS_} ${MPI_CXX_LIBRARIES})
set(PETSC_EXECUTABLE_RUNS ON)
set(AMDIS_PETSC_DIR @PETSC_DIR@)
include(find_petsc)
if (PETSc_FOUND)
target_include_directories(amdis_base INTERFACE ${PETSC_INCLUDES})
find_library(BLAS_LIB
NAMES blas fblas openblas
HINTS ${BLAS_DIR}/lib ${PETSC_LIB_DIR} ${PETSC_DIR}/lib /usr/lib/openblas-base /usr/lib/atlas-base)
if (BLAS_LIB)
set(BLAS_LIBRARIES ${BLAS_LIB})
else ()
find_package(BLAS REQUIRED)
endif ()
find_library(LAPACK_LIB
NAMES lapack flapack
HINTS ${LAPACK_DIR}/lib ${PETSC_LIB_DIR} ${PETSC_DIR}/lib)
if (LAPACK_LIB)
set(LAPACK_LIBRARIES ${LAPACK_LIB})
else ()
find_package(LAPACK REQUIRED)
endif ()
target_link_libraries(amdis_base INTERFACE
${PETSC_LIBRARY_SYS}
${PETSC_LIBRARIES}
blas lapack)
${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
target_compile_definitions(amdis_base INTERFACE
HAVE_PARALLEL_PETSC=1)
else()
......@@ -198,4 +216,12 @@ if (AMDIS_NEED_ZOLTAN)
endif()
endif ()
set(AMDIS_LIBRARIES AMDiS)
# Extract some variables from INTERFACE target AMDiS
get_target_property(AMDIS_INCLUDE_DIRS AMDiS INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(AMDIS_LIBRARIES AMDiS INTERFACE_LINK_LIBRARIES)
get_target_property(AMDIS_COMPILEFLAGS AMDiS INTERFACE_COMPILE_OPTIONS)
get_target_property(_DEFINITIONS AMDiS INTERFACE_COMPILE_DEFINITIONS)
foreach(defn ${_DEFINITIONS})
list(APPEND AMDIS_COMPILEFLAGS "-D${defn}")
endforeach(s)
message(STATUS "To compile your program with AMDiS simply add the target 'AMDiS' to the target_link_libraries(...) command")
\ No newline at end of file
# globally add compile options and include directories
add_definitions(${AMDIS_COMPILEFLAGS})
include_directories(${AMDIS_INCLUDE_DIRS})
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(AMDiS VERSION 0.9 LANGUAGES CXX)
message(WARNING "This is an experimental CMakeLists.txt file.")
project(AMDiS VERSION 1.1 LANGUAGES CXX)
set(BASE_DIR ${AMDiS_SOURCE_DIR})
set(SOURCE_DIR ${BASE_DIR}/src)
......@@ -32,14 +30,9 @@ option(BUILD_SHARED_LIBS "Build all libraries as shared or static, default: shar
mark_as_advanced(BUILD_SHARED_LIBS)
if (MSVC)
# if (${CMAKE_VERSION} VERSION_LESS "3.4")
set(BUILD_SHARED_LIBS false)
mark_as_advanced(BUILD_SHARED_LIBS)
message(WARNING "Currently we can only build static libraries with Visual Studio")
# elseif (BUILD_SHARED_LIBS)
# set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS true)
# set(MSVC_SHARED_LIBS true)
# endif ()
set(BUILD_SHARED_LIBS false)
mark_as_advanced(BUILD_SHARED_LIBS)
message(WARNING "Currently we can only build static libraries with Visual Studio")
endif (MSVC)
# ------------------------------------------------------------------------------
......@@ -54,17 +47,9 @@ target_compile_definitions(amdis_base INTERFACE
$<$<NOT:$<CONFIG:Release>>:DEBUG=1>)
include(test_compile_features)
test_compile_features(ENABLE_CXX11 amdis_base INTERFACE
cxx_alias_templates
cxx_auto_type
cxx_lambdas
cxx_override
cxx_range_for
cxx_static_assert
cxx_variadic_templates)
target_enable_cxx11(ENABLE_CXX11 amdis_base INTERFACE)
if (ENABLE_CXX11)
# set(CMAKE_CXX_STANDARD 11)
# set(CMAKE_CXX_STANDARD_REQUIRED ON)
target_compile_definitions(amdis_base INTERFACE HAS_CXX11=1)
else ()
target_compile_definitions(amdis_base INTERFACE HAS_CXX11=0)
......@@ -245,7 +230,7 @@ if (MSVC)
endif (MSVC)
target_link_libraries(amdis AMDiS::base muparser
$<$<CONFIG:Debug>:amdis_debug>)
$<$<NOT:$<CONFIG:Release>>:amdis_debug>)
# specify how to install this target:
# -----------------------------------
......@@ -271,4 +256,3 @@ configure_file(${BASE_DIR}/cmake3/AMDISConfig.cmake.in
install(FILES ${AMDiS_BINARY_DIR}/AMDISConfig.cmake DESTINATION share/amdis/)
install(FILES ${BASE_DIR}/cmake3/AMDISUse.cmake DESTINATION share/amdis/)
install(FILES ${BASE_DIR}/cmake3/test_compile_features.cmake DESTINATION share/amdis/)
install(FILES ${BASE_DIR}/cmake3/dummy.cc DESTINATION share/amdis/)
......@@ -31,12 +31,13 @@ if (ENABLE_PARALLEL_DOMAIN)
# MPI is required
find_package(MPI REQUIRED)
if (MPI_FOUND)
target_include_directories(amdis_parallel INTERFACE
${MPI_INCLUDE_PATH})
target_compile_options(amdis_parallel INTERFACE
${MPI_COMPILE_FLAGS})
endif (MPI_FOUND)
target_include_directories(amdis_parallel INTERFACE
${MPI_CXX_INCLUDE_PATH})
target_compile_options(amdis_parallel INTERFACE
${MPI_CXX_COMPILE_FLAGS})
string(STRIP " ${MPI_CXX_LINK_FLAGS} " MPI_CXX_LINK_FLAGS_)
target_link_libraries(amdis_parallel INTERFACE
${MPI_CXX_LINK_FLAGS_} ${MPI_CXX_LIBRARIES})
# PETSc library is required
set(PETSC_EXECUTABLE_RUNS ON)
......@@ -47,7 +48,7 @@ if (ENABLE_PARALLEL_DOMAIN)
${PETSC_DIR}/${PETSC_ARCH}/include)
# parmetis is required
find_file(PARMETIS_HEADER_FILE "parmetis.h" HINTS ${PETSC_DIR}/include )
find_file(PARMETIS_HEADER_FILE "parmetis.h" HINTS ${PETSC_DIR}/include ${PARMETIS_DIR}/include )
if (PARMETIS_HEADER_FILE)
get_filename_component(PARMETIS_INCLUDE_PATH "${PARMETIS_HEADER_FILE}" PATH CACHE)
target_include_directories(amdis_parallel INTERFACE ${PARMETIS_INCLUDE_PATH})
......@@ -57,10 +58,10 @@ if (ENABLE_PARALLEL_DOMAIN)
# add support for the zoltan library
if (ENABLE_ZOLTAN)
find_file(ZOLTAN_HEADER_FILE "zoltan_cpp.h" HINTS ${PETSC_DIR}/include)
find_file(ZOLTAN_HEADER_FILE "zoltan_cpp.h" HINTS ${ZOLTAN_DIR}/include ${PETSC_DIR}/include)
if (ZOLTAN_HEADER_FILE)
get_filename_component(ZOLTAN_HEADER_DIR "${ZOLTAN_HEADER_FILE}" PATH CACHE)
target_include_directories(amdis_parallel PRIINTERFACEVATE ${ZOLTAN_HEADER_DIR})
target_include_directories(amdis_parallel INTERFACE ${ZOLTAN_HEADER_DIR})
else()
message(FATAL_ERROR "Could not find Zoltan include file 'zoltan_cpp.h'!")
endif(ZOLTAN_HEADER_FILE)
......
......@@ -7,17 +7,9 @@ else ()
endif (IS_AMDISCONFIG)
include(test_compile_features)
test_compile_features(MTL_ENABLE_CXX11 mtl4 INTERFACE
cxx_rvalue_references
cxx_auto_type
cxx_range_for
cxx_generalized_initializers
cxx_static_assert
cxx_defaulted_functions)
target_enable_cxx11(MTL_ENABLE_CXX11 mtl4 INTERFACE)
if (MTL_ENABLE_CXX11)
# set(CMAKE_CXX_STANDARD 11)
# set(CMAKE_CXX_STANDARD_REQUIRED ON)
set (CXX_ELEVEN_FEATURE_LIST "MOVE" "AUTO" "RANGEDFOR" "INITLIST" "STATICASSERT" "DEFAULTIMPL")
foreach (feature ${CXX_ELEVEN_FEATURE_LIST})
target_compile_definitions(mtl4 INTERFACE MTL_WITH_${feature})
......
......@@ -47,7 +47,7 @@ if (PETSC_DIR)
endif (PETSC_DIR)
find_path (PETSC_DIR include/petsc.h
HINTS ${AMDIS_PETSC_DIR} $ENV{HOME}/petsc ENV PETSC_DIR
HINTS ${AMDIS_PETSC_DIR} $ENV{HOME}/petsc /usr/lib/petsc ENV PETSC_DIR
DOC "PETSc Directory")
if (PETSC_DIR AND NOT PETSC_ARCH)
......
......@@ -87,5 +87,7 @@ if (ENABLE_UMFPACK OR AMDIS_NEED_UMFPACK)
HAVE_UMFPACK=1
MTL_HAS_UMFPACK=1)
install(FILES ${BASE_DIR}/cmake3/find_umfpack.cmake DESTINATION share/amdis/)
if (NOT IS_AMDISCONFIG)
install(FILES ${BASE_DIR}/cmake3/find_umfpack.cmake DESTINATION share/amdis/)
endif ()
endif (ENABLE_UMFPACK OR AMDIS_NEED_UMFPACK)
\ No newline at end of file
......@@ -17,8 +17,7 @@ add_library(muparser
target_include_directories(muparser PUBLIC ${MUPARSER_INCLUDE_DIR})
if (ENABLE_CXX11)
set_property(TARGET muparser PROPERTY CXX_STANDARD 11)
set_property(TARGET muparser PROPERTY CXX_STANDARD_REQUIRED ON)
target_enable_cxx11(MUPARSER_ENABLE_CXX11 muparser PRIVATE)
target_compile_definitions(muparser PRIVATE HAS_CXX11=1)
endif (ENABLE_CXX11)
......@@ -29,4 +28,4 @@ file(GLOB MUPARSER_HEADERS "${MUPARSER_SOURCE_DIR}/include/*.h")
install(FILES ${MUPARSER_HEADERS}
DESTINATION include/amdis/muparser)
install(TARGETS muparser
DESTINATION lib/amdis/ )
\ No newline at end of file
DESTINATION lib/amdis/ )
include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles)
include(CheckIncludeFileCXX)
macro(test_compile_features RESULT_VAR TARGET SCOPE) # feature1 feature2 feature3 ...)
set(_FEATURES "")
foreach(FEATURE ${ARGN})
set(_FEATURES "${_FEATURES} ${FEATURE}")
endforeach()
set(_DIR ${CMAKE_BINARY_DIR}/test_cxx11)
macro(target_enable_cxx11 RESULT_VAR _TARGET_ _SCOPE_)
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
# test only of variable RESULT_VAR not yet set manually or by a
# previous call to this macro
if (NOT DEFINED ${RESULT_VAR})
if (EXISTS "${BASE_DIR}/cmake3/dummy.cc")
set(DUMMY_FILE ${BASE_DIR}/cmake3/dummy.cc)
else ()
set(DUMMY_FILE ${AMDIS_DIR}/dummy.cc)
endif ()
if (NOT COMPILER_SUPPORTS_CXX11)
set(CMAKE_REQUIRED_FLAGS "-std=c++11")
check_cxx_source_compiles("int main(){decltype(1) vec[]={1,2,3}; for(auto&& x:vec);}" CXX_COMPILES_WITH_CXX11)
set(CMAKE_REQUIRED_FLAGS "")
endif ()
message(STATUS "Test for cxx11 features for target ${TARGET}")
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${_DIR})
file(WRITE ${_DIR}/CMakeLists.txt "
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(TestCxx LANGUAGES CXX)
add_library(test_cxx ${DUMMY_FILE})
target_compile_features(test_cxx PRIVATE ${_FEATURES})")
execute_process(COMMAND ${CMAKE_COMMAND} ${_DIR}
WORKING_DIRECTORY ${_DIR}
RESULT_VARIABLE _ERR_CODE OUTPUT_QUIET)
if (COMPILER_SUPPORTS_CXX11 OR CXX_COMPILES_WITH_CXX11)
target_compile_options(${_TARGET_} ${_SCOPE_} "-std=c++11")
set(${RESULT_VAR} true CACHE BOOL "Enable C++11 compiler features")
else ()
check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if (NOT COMPILER_SUPPORTS_CXX0X)
set(CMAKE_REQUIRED_FLAGS "-std=c++0x")
check_cxx_source_compiles("int main(){decltype(1) vec[]={1,2,3}; for(auto&& x:vec);}" CXX_COMPILES_WITH_CXX0X)
set(CMAKE_REQUIRED_FLAGS "")
endif ()
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory ${_DIR})
elseif (${RESULT_VAR})
set(_ERR_CODE "0")
if (COMPILER_SUPPORTS_CXX0X OR CXX_COMPILES_WITH_CXX0X)
target_compile_options(${_TARGET_} ${_SCOPE_} "-std=c++0x")
set(${RESULT_VAR} true CACHE BOOL "Enable C++11 compiler features")
else ()
set(_ERR_CODE "1")
endif ()
check_cxx_source_compiles("int main(){decltype(1) vec[]={1,2,3}; for(auto&& x:vec);}" CXX11_COMPILES)
check_include_file_cxx("array" CXX11_INCLUDES)
if ("${_ERR_CODE}" STREQUAL "0")
if (CXX11_COMPILES AND CXX11_INCLUDES)
set(${RESULT_VAR} true CACHE BOOL "Enable C++11 compiler features")
target_compile_features(${TARGET} ${SCOPE} ${ARGN})
else ()
else ()
set(${RESULT_VAR} false CACHE BOOL "Enable C++11 compiler features")
endif ()
endif ()
mark_as_advanced(${RESULT_VAR})
unset(_ERR_CODE)
unset(_DIR)
unset(_FEATURES)
endmacro(test_compile_features)
\ No newline at end of file
endif ()
endmacro(target_enable_cxx11)
......@@ -52,13 +52,6 @@ typedef __declspec(align(CACHE_LINE)) size_t aligned_size_t;
#define ALWAYS_INLINE __forceinline
#define OPENMODE std::ios::open_mode
// C++11 features
// --------------
// #if __cplusplus > 199711L
// #ifndef HAS_CXX11
// #define HAS_CXX11 1
// #endif
#if MSC_VERSION >= 1800 && !defined(HAS_VARIADIC_TEMPLATES)
#define HAS_VARIADIC_TEMPLATES 1
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment