From 81e73705d428a2e8cb582eca00e208e7d0de318a Mon Sep 17 00:00:00 2001 From: Matthew Whitlock Date: Mon, 8 May 2023 13:37:08 -0700 Subject: [PATCH] Revert to BUILD_TESTING; make inc fix optionally transitive --- CMakeLists.txt | 58 +++++++------------- cmake/fenixConfig.cmake.in | 13 +++++ cmake/systemMPIOverride.cmake | 51 +++++++++++++++++ examples/01_hello_world/fenix/CMakeLists.txt | 2 +- examples/02_send_recv/fenix/CMakeLists.txt | 2 +- examples/05_subset_create/CMakeLists.txt | 2 +- examples/06_subset_createv/CMakeLists.txt | 2 +- fenixConfig.cmake.in | 5 -- src/CMakeLists.txt | 2 +- 9 files changed, 89 insertions(+), 48 deletions(-) create mode 100644 cmake/fenixConfig.cmake.in create mode 100644 cmake/systemMPIOverride.cmake delete mode 100644 fenixConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index dd0e3f7..7b8b20c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,57 +15,34 @@ project(Fenix C) set(FENIX_VERSION_MAJOR 1) set(FENIX_VERSION_MINOR 0) -option(FENIX_EXAMPLES "Builds example programs from the examples directory" OFF) -option(FENIX_TESTS "Builds tests and test modes of files" OFF) +option(BUILD_EXAMPLES "Builds example programs from the examples directory" OFF) +option(BUILD_TESTING "Builds tests and test modes of files" ON) + #Solves an issue with some system environments putting their MPI headers before #the headers CMake includes. Forces non-system MPI headers when incorrect headers #detected in include path. -option(FENIX_SYSTEM_INC_FIX "Attempts to force overriding any system MPI headers" ON) - +option(FENIX_SYSTEM_INC_FIX "Attempts to force overriding any system MPI headers" ON) +option(FENIX_PROPAGATE_INC_FIX "Attempt overriding system MPI headers in linking projects" ON) find_package(MPI REQUIRED) -#If we're using mpicc, we don't need to worry about the includes. -if("${CMAKE_C_COMPILER}" MATCHES ".*/?mpicc") - set(FENIX_SYSTEM_INC_FIX OFF) -endif() - if(${FENIX_SYSTEM_INC_FIX}) - include(CheckIncludeFile) - set(CMAKE_REQUIRED_QUIET ON) - check_include_file("mpi.h" MPI_HEADER_CRASH) - set(CMAKE_REQUIRED_QUIET OFF) - - if(${MPI_HEADER_CRASH}) - message(WARNING "Detected system MPI headers, attempting to force use of ${MPI_C_INCLUDE_DIRS}. Set SYSTEM_INC_FIX=OFF to stop this behavior.") - - if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.25") - set_target_properties(MPI::MPI_C PROPERTIES SYSTEM "FALSE") - else() - foreach(MPI_DIR ${MPI_C_INCLUDE_DIRS}) - if(NOT ("${CMAKE_C_FLAGS}" MATCHES ".* -I${MPI_DIR}.*")) - message(STATUS ${MPI_DIR}) - set(CMAKE_C_FLAGS " -I${MPI_DIR} ${CMAKE_C_FLAGS}" CACHE INTERNAL "Flags to append to build commands for C.") - endif() - endforeach() - set_target_properties(MPI::MPI_C PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") - endif() - endif() - -endif() #SYSTEM_INC_FIX + include(cmake/systemMPIOverride.cmake) +endif() add_subdirectory(src) + include(CTest) list(APPEND MPIEXEC_PREFLAGS "--with-ft;mpi") -if(FENIX_EXAMPLES) +if(BUILD_EXAMPLES) add_subdirectory(examples) endif() -if(FENIX_TESTS) +if(BUILD_TESTING) add_subdirectory(test) endif() @@ -75,17 +52,22 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/fenix-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/fenix-config.h @ONLY ) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/systemMPIOverride.cmake + ${CMAKE_CURRENT_BINARY_DIR}/cmake/systemMPIOverride.cmake COPYONLY +) + include(CMakePackageConfigHelpers) -configure_package_config_file(fenixConfig.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/fenixConfig.cmake +configure_package_config_file(cmake/fenixConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/cmake/fenixConfig.cmake INSTALL_DESTINATION cmake) -write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/fenixConfigVersion.cmake +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/cmake/fenixConfigVersion.cmake VERSION "${FENIX_VERSION_MAJOR}.${FENIX_VERSION_MINOR}" COMPATIBILITY SameMajorVersion) install( FILES - ${CMAKE_CURRENT_BINARY_DIR}/fenixConfig.cmake - ${CMAKE_CURRENT_BINARY_DIR}/fenixConfigVersion.cmake + ${CMAKE_CURRENT_BINARY_DIR}/cmake/fenixConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/cmake/systemMPIOverride.cmake DESTINATION cmake ) diff --git a/cmake/fenixConfig.cmake.in b/cmake/fenixConfig.cmake.in new file mode 100644 index 0000000..464e150 --- /dev/null +++ b/cmake/fenixConfig.cmake.in @@ -0,0 +1,13 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +include("${CMAKE_CURRENT_LIST_DIR}/fenixTargets.cmake") + +set(FENIX_SYSTEM_INC_FIX @FENIX_SYSTEM_INC_FIX@) +if(${FENIX_SYSTEM_INC_FIX}) + option(FENIX_PROPAGATE_INC_FIX "Attempt overriding system MPI headers in linking projects" @FENIX_PROPAGATE_INC_FIX@) + if(${FENIX_PROPAGATE_INC_FIX}) + include("${CMAKE_CURRENT_LIST_DIR}/systemMPIOverride.cmake") + endif() +endif() diff --git a/cmake/systemMPIOverride.cmake b/cmake/systemMPIOverride.cmake new file mode 100644 index 0000000..95b2619 --- /dev/null +++ b/cmake/systemMPIOverride.cmake @@ -0,0 +1,51 @@ +#If we're using mpicc, we don't need to worry about the includes. +if("${CMAKE_C_COMPILER}" MATCHES ".*/?mpic") + return() +endif() + +include(CheckIncludeFile) +set(CMAKE_REQUIRED_QUIET ON) +check_include_file("mpi.h" MPI_HEADER_CLASH) +set(CMAKE_REQUIRED_QUIET OFF) + +if(${MPI_HEADER_CLASH}) + if(TARGET fenix) + message(WARNING "Fenix detected system MPI headers, attempting to force use of ${MPI_C_INCLUDE_DIRS}. Disable FENIX_PROPAGATE_INC_FIX to stop this behavior.") + else() + message(WARNING "Detected system MPI headers, attempting to force use of ${MPI_C_INCLUDE_DIRS}. Disable FENIX_SYSTEM_INC_FIX to stop this behavior.") + endif() + + if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.25") + + if(TARGET MPI::MPI_C) + set_target_properties(MPI::MPI_C PROPERTIES SYSTEM "FALSE") + endif() + if(TARGET MPI::MPI_CXX) + set_target_properties(MPI::MPI_CXX PROPERTIES SYSTEM "FALSE") + endif() + + else() + + if(TARGET MPI::MPI_C) + set_property(DIRECTORY ${CMAKE_SOURCE_DIR} APPEND PROPERTY INCLUDE_DIRECTORIES "${MPI_C_INCLUDE_DIRS}") + endif() + if(TARGET MPI::MPI_CXX) + set_property(DIRECTORY ${CMAKE_SOURCE_DIR} APPEND PROPERTY INCLUDE_DIRECTORIES "${MPI_CXX_INCLUDE_DIRS}") + endif() + + if(TARGET fenix) + get_target_property(FENIX_INCLUDES fenix INTERFACE_INCLUDE_DIRECTORIES) + list(REMOVE_ITEM FENIX_INCLUDES ${MPI_C_INCLUDE_DIRS}) + list(REMOVE_ITEM FENIX_INCLUDES ${MPI_CXX_INCLUDE_DIRS}) + set_target_properties(fenix PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FENIX_INCLUDES}") + endif() + + if(TARGET MPI::MPI_C) + set_target_properties(MPI::MPI_C PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + endif() + if(TARGET MPI::MPI_CXX) + set_target_properties(MPI::MPI_CXX PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + endif() + + endif() +endif() diff --git a/examples/01_hello_world/fenix/CMakeLists.txt b/examples/01_hello_world/fenix/CMakeLists.txt index a474f82..6a344f4 100644 --- a/examples/01_hello_world/fenix/CMakeLists.txt +++ b/examples/01_hello_world/fenix/CMakeLists.txt @@ -11,7 +11,7 @@ add_executable(fenix_hello_world fenix_hello_world.c) target_link_libraries(fenix_hello_world fenix ${MPI_C_LIBRARIES}) -if(FENIX_TESTS) +if(BUILD_TESTING) add_test(NAME hello_world COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 3 ${MPIEXEC_PREFLAGS} fenix_hello_world ${MPIEXEC_POSTFLAGS} "1") endif() diff --git a/examples/02_send_recv/fenix/CMakeLists.txt b/examples/02_send_recv/fenix/CMakeLists.txt index 0c81d03..bf40679 100644 --- a/examples/02_send_recv/fenix/CMakeLists.txt +++ b/examples/02_send_recv/fenix/CMakeLists.txt @@ -11,7 +11,7 @@ add_executable(fenix_ring fenix_ring.c) target_link_libraries(fenix_ring fenix ${MPI_C_LIBRARIES} m ) -if(FENIX_TESTS) +if(BUILD_TESTING) add_test(NAME ring COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 5 ${MPIEXEC_PREFLAGS} fenix_ring ${MPIEXEC_POSTFLAGS} 1 2) set_tests_properties(ring PROPERTIES diff --git a/examples/05_subset_create/CMakeLists.txt b/examples/05_subset_create/CMakeLists.txt index fccb552..7f1efcd 100644 --- a/examples/05_subset_create/CMakeLists.txt +++ b/examples/05_subset_create/CMakeLists.txt @@ -11,7 +11,7 @@ add_executable(subset_create subset_create.c) target_link_libraries(subset_create fenix ${MPI_C_LIBRARIES}) -if(FENIX_TESTS) +if(BUILD_TESTING) add_test(NAME subset_create COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 5 ${MPIEXEC_PREFLAGS} subset_create ${MPIEXEC_POSTFLAGS} 1) set_tests_properties(subset_create PROPERTIES diff --git a/examples/06_subset_createv/CMakeLists.txt b/examples/06_subset_createv/CMakeLists.txt index 6a7b356..c242648 100644 --- a/examples/06_subset_createv/CMakeLists.txt +++ b/examples/06_subset_createv/CMakeLists.txt @@ -11,7 +11,7 @@ add_executable(subset_createv subset_createv.c) target_link_libraries(subset_createv fenix ${MPI_C_LIBRARIES}) -if(FENIX_TESTS) +if(BUILD_TESTING) add_test(NAME subset_createv COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 5 ${MPIEXEC_PREFLAGS} subset_createv ${MPIEXEC_POSTFLAGS} 1) set_tests_properties(subset_createv PROPERTIES diff --git a/fenixConfig.cmake.in b/fenixConfig.cmake.in deleted file mode 100644 index 6f59550..0000000 --- a/fenixConfig.cmake.in +++ /dev/null @@ -1,5 +0,0 @@ -@PACKAGE_INIT@ - -include(CMakeFindDependencyMacro) - -include("${CMAKE_CURRENT_LIST_DIR}/fenixTargets.cmake") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 096b76a..7c823fd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,7 +33,7 @@ globals.c add_library( fenix STATIC ${Fenix_SOURCES}) -target_link_libraries(fenix MPI::MPI_C) +target_link_libraries(fenix PUBLIC MPI::MPI_C) target_include_directories(fenix PUBLIC