diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c2568530326423935f990fcf4be7975a1a05927..068d95f00be44f8e9c5efd6beeb85d695dd8f961 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,8 +16,8 @@ set(DUNE_COMMON_VERSION_MAJOR "${DUNE_VERSION_MAJOR}") set(DUNE_COMMON_VERSION_MINOR "${DUNE_VERSION_MINOR}") set(DUNE_COMMON_VERSION_REVISION "${DUNE_VERSION_REVISION}") -message("DUNE_USE_ONLY_STATIC_LIB ${DUNE_USE_ONLY_STATIC_LIB}") - +option("DUNE_USE_ONLY_STATIC_LIBS" "If set to ON, we will force static linkage everywhere") +message("DUNE_USE_ONLY_STATIC_LIBS ${DUNE_USE_ONLY_STATIC_LIBS}") if(DUNE_USE_ONLY_STATIC_LIBS) # Use only static libraries. # We do this by overriding the library suffixes. @@ -37,7 +37,7 @@ include(DuneStreams) dune_set_minimal_debug_level() # include dune-common and current directory to include pathtest -include_directories("${CMAKE_SOURCE_DIR}" ".") +include_directories("${CMAKE_SOURCE_DIR}") link_directories("${CMAKE_SOURCE_DIR}/lib") # set required compiler flags for C++11 (former C++0x) @@ -52,13 +52,8 @@ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -DHAVE_MEMORY=${HAVE_MEMORY}") # search for packages find_package(PkgConfig) -find_package(MPI) -if(MPI_FOUND) -set(HAVE_MPI MPI_CXX_FOUND) -add_definitions("${MPI_CXX_COMPILE_FLAGS}") - #add_definitions("-DENABLE_MPI=1") -include_directories(${MPI_CXX_INCLUDE_PATH}) -endif(MPI_FOUND) + +include(DUNEMPI) find_package(Boost) set(HAVE_BOOST BOOST_FOUND) @@ -70,6 +65,7 @@ set(HAVE_LAPACK LAPACK_FOUND) # make calling fortran routines from C/C++ possible include(FortranCInterface) +FortranCInterface_VERIFY(CXX) FortranCInterface_HEADER(FC.h MACRO_NAMESPACE "FC_") # actually write the config.h file to disk diff --git a/cmake/modules/DUNEMPI.cmake b/cmake/modules/DUNEMPI.cmake new file mode 100644 index 0000000000000000000000000000000000000000..aac9e090b8a3fffa29a084088dda1534cd6720c7 --- /dev/null +++ b/cmake/modules/DUNEMPI.cmake @@ -0,0 +1,40 @@ +find_package(MPI) +find_package(Threads) + +if(MPI_FOUND) + set(HAVE_MPI MPI_CXX_FOUND) + # We do not support the CXX bindings of MPI + set(MPI_DUNE_COMPILE_FLAGS ${MPI_C_COMPILE_FLAGS} CACHE STRING + "Compile flags used by DUNE when compiling MPI programs") + set(MPI_DUNE_INCLUDE_PATH ${MPI_C_INCLUDE_PATH} CACHE STRING + "Include path used by DUNE when compiling MPI programs") + # There seems to be no target specific include path, use the global one. + include_directories(${MPI_DUNE_INCLUDE_PATH}) + set(MPI_DUNE_LINK_FLAGS ${MPI_C_LINK_FLAG} CACHE STRING + "Link flags used by DUNE when compiling MPI programs") + set(MPI_DUNE_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ${MPI_C_LIBRARIES} CACHE STRING + "Libraries used by DUNE when linking MPI programs") + + # Check whether the MPI-2 standard is supported + include(CMakePushCheckState) + include(CheckFunctionExists) + cmake_push_check_state() + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES};${MPI_DUNE_LIBRARIES}) + set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} "-DENABLE_MPI=1 -DMPICH_SKIP_MPICXX -DMPIPP_H") + set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${MPI_DUNE_INCLUDE_PATH}) + check_function_exists(MPI_Finalized MPI_2) + cmake_pop_check_state() +endif(MPI_FOUND) + +# A macro that adds the MPI flags for the compilation +function(add_DUNE_MPI_flags _target) + if(MPI_FOUND) + target_link_libraries(${_target} ${MPI_DUNE_LIBRARIES}) + # The definitions are a hack as we do not seem to know which MPI implementation was + # found. + SET_TARGET_PROPERTIES(${_target} PROPERTIES COMPILE_FLAGS ${MPI_DUNE_COMPILE_FLAGS} + "-DENABLE_MPI=1 -DMPICH_SKIP_MPICXX -DMPIPP_H") + SET_TARGET_PROPERTIES(${_target} PROPERTIES LINK_FLAGS ${MPI_DUNE_LINK_FLAGS} "") + #SET_TARGET_PROPERTIES(indicestest PROPERTIES INCLUDE_PATH ${MPI_CC_INCLUDE_PATH}) + endif(MPI_FOUND) +endfunction() diff --git a/config.h.cmake b/config.h.cmake index 75dd481a31f197387a5a7bb245730cd9159102db..72c9e4aefd557f4d36c4e2af0d07e430485c371a 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -57,7 +57,9 @@ /* Define to 1 if you have the <malloc.h> header file. */ // Not used! #cmakedefine01 HAVE_MALLOC_H -#cmakedefine01 HAVE_MPI +#cmakedefine HAVE_MPI ENABLE_MPI +/* Define to 1 if the MPI2 Standard is supported */ +#cmakedefine01 MPI_2 #cmakedefine01 HAVE_BOOST diff --git a/dune/common/parallel/test/CMakeLists.txt b/dune/common/parallel/test/CMakeLists.txt index 18abc7bcfa629f9a5ac45d9d8d6854c13dc85f24..6a26c93bb0da1519e80e4ca42f5bd535ecbb9c06 100644 --- a/dune/common/parallel/test/CMakeLists.txt +++ b/dune/common/parallel/test/CMakeLists.txt @@ -4,28 +4,22 @@ set(MPITESTPROGS indicestest indexsettest syncertest selectiontest) # but just build them on demand add_dependencies(build_tests ${MPITESTPROGS}) add_executable("indexsettest" indexsettest.cc) -target_link_libraries("indexsettest" "dunecommon") +target_link_libraries("indexsettest" "dunecommon" ${CMAKE_THREAD_LIBS_INIT} ${}) +include(DUNEMPI) add_executable("indicestest" indicestest.cc) target_link_libraries("indicestest" "dunecommon") -if(MPI_FOUND) - target_link_libraries(indicestest ${MPI_CXX_LIBRARIES}) -endif(MPI_FOUND) +add_DUNE_MPI_flags(indicestest) add_executable("selectiontest" selectiontest.cc) target_link_libraries("selectiontest" "dunecommon") -if(MPI_FOUND) - target_link_libraries(selectiontest ${MPI_CXX_LIBRARIES}) -endif(MPI_FOUND) +add_DUNE_MPI_flags(selectiontest) -#add_executable("syncertest" syncertest.cc) -#if(MPI_FOUND) -# target_link_libraries(syncertest ${MPI_CXX_LIBRARIES}) -#endif(MPI_FOUND) +add_executable("syncertest" syncertest.cc) +target_link_libraries("syncertest" "dunecommon") +add_DUNE_MPI_flags(syncertest) add_test(indexsettest indexsettest) add_test(selectiontest selectiontest) -if(MPI_CXX_FOUND) - add_test(indicestest indicestest) - #add_test(syncertest syncertest) -endif(MPI_CXX_FOUND) +add_test(indicestest indicestest) +add_test(syncertest syncertest) diff --git a/dune/common/test/CMakeLists.txt b/dune/common/test/CMakeLists.txt index 899f56448137a36eb5a156b900a994cd3ab3c265..8b80a35ee3ebd4687b33f64b862399cc433a30c9 100644 --- a/dune/common/test/CMakeLists.txt +++ b/dune/common/test/CMakeLists.txt @@ -94,25 +94,21 @@ add_executable("iteratorfacadetest" iteratorfacadetest.cc) add_executable("lrutest" lrutest.cc) add_executable("mpiguardtest" mpiguardtest.cc) target_link_libraries("mpiguardtest" "dunecommon") -if(MPI_FOUND) - target_link_libraries(mpiguardtest ${MPI_CXX_LIBRARIES}) -endif(MPI_FOUND) +add_DUNE_MPI_flags(mpiguardtest) + add_executable("mpicollectivecommunication" mpicollectivecommunication.cc) target_link_libraries(mpicollectivecommunication "dunecommon") -if(MPI_FOUND) - target_link_libraries(mpicollectivecommunication ${MPI_CXX_LIBRARIES}) -endif(MPI_FOUND) +add_DUNE_MPI_flags(mpicollectivecommunication) + add_executable("mpihelpertest" mpihelpertest.cc) target_link_libraries(mpihelpertest "dunecommon") -if(MPI_FOUND) - target_link_libraries(mpihelpertest ${MPI_CXX_LIBRARIES}) -endif(MPI_FOUND) +add_DUNE_MPI_flags(mpihelpertest) + add_executable("mpihelpertest2" mpihelpertest.cc) target_link_libraries(mpihelpertest2 "dunecommon") -if(MPI_FOUND) - target_link_libraries(mpihelpertest2 ${MPI_CXX_LIBRARIES}) -endif(MPI_FOUND) +add_DUNE_MPI_flags(mpihelpertest2) set_target_properties(mpihelpertest2 PROPERTIES COMPILE_FLAGS "-DMPIHELPER_PREINITIALIZE") + add_executable("nullptr_test" nullptr-test.cc nullptr-test2.cc) target_link_libraries(nullptr_test "dunecommon") add_executable("nullptr_test_fail" EXCLUDE_FROM_ALL nullptr-test.cc) @@ -204,9 +200,7 @@ add_test(gcdlcmtest gcdlcmtest) add_test(iteratorfacadetest iteratorfacadetest) add_test(iteratorfacadetest2 iteratorfacadetest2) add_test(lrutest lrutest) -if(MPI_CXX_FOUND) - add_test(mpicollectivecommunication mpicollectivecommunication) -endif(MPI_CXX_FOUND) +add_test(mpicollectivecommunication mpicollectivecommunication) add_test(mpiguardtest mpiguardtest) add_test(mpihelpertest mpihelpertest) add_test(mpihelpertest2 mpihelpertest2)