Skip to content

Commit

Permalink
Revert to BUILD_TESTING; make inc fix optionally transitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew-Whitlock committed May 8, 2023
1 parent 490ce70 commit 81e7370
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 48 deletions.
58 changes: 20 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
)
13 changes: 13 additions & 0 deletions cmake/fenixConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -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()
51 changes: 51 additions & 0 deletions cmake/systemMPIOverride.cmake
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion examples/01_hello_world/fenix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion examples/02_send_recv/fenix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/05_subset_create/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/06_subset_createv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions fenixConfig.cmake.in

This file was deleted.

2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 81e7370

Please sign in to comment.