From 1c39c47c1ecf6a9bef3842d97473ea70ef3c419a Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Thu, 20 Jun 2024 16:04:48 +0200 Subject: [PATCH] #350: Further changes to CMake files (checkpoint->magistrate) --- CMakeLists.txt | 60 +++++++++++++++++++-------------- cmake/checkpointConfig.cmake.in | 2 +- src/CMakeLists.txt | 55 ++++++++++++++---------------- tests/CMakeLists.txt | 2 +- 4 files changed, 63 insertions(+), 56 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d87f07b7..490f18cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,24 +74,34 @@ if (${magistrate_doxygen_enabled}) endif() # Optionally enable address sanitizer library in build +list(APPEND asan_ubsan_supported_compilers "AppleClang" "Clang" "GNU") + if (magistrate_asan_enabled) - set( - CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -fsanitize=address" - ) - message(STATUS "Building with address sanitizer enabled") + if(CMAKE_CXX_COMPILER_ID IN_LIST asan_ubsan_supported_compilers) + set( + CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} -fsanitize=address" + ) + message(STATUS "Building with address sanitizer enabled") + else() + message(SEND_ERROR "Cannot use ASan without clang or gcc") + endif() endif() if (magistrate_ubsan_enabled) - set( - CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -fsanitize=undefined" - ) - message(STATUS "Building with undefined behavior sanitizer enabled") + if(CMAKE_CXX_COMPILER_ID IN_LIST asan_ubsan_supported_compilers) + set( + CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} -fsanitize=undefined" + ) + message(STATUS "Building with undefined behavior sanitizer enabled") + else() + message(SEND_ERROR "Cannot use UBSan without clang or gcc") + endif() endif() -set(CHECKPOINT_LIBRARY checkpoint CACHE INTERNAL "" FORCE ) -set(MAGISTRATE_LIBRARY_NS vt::lib::checkpoint "" CACHE INTERNAL "" FORCE ) +set(MAGISTRATE_LIBRARY checkpoint CACHE INTERNAL "" FORCE ) +set(MAGISTRATE_LIBRARY_NS vt::lib::magistrate "" CACHE INTERNAL "" FORCE ) set(CMAKE_CXX_EXTENSIONS OFF) @@ -107,9 +117,9 @@ if (NOT kokkos_DISABLE) kokkos "${kokkos_DIR}/" Kokkos "CMake/Kokkos/" "cmake/Kokkos/" ) # Used to properly setup transitive dependency in checkpointConfig.cmake.in - set(CHECKPOINT_HAS_KOKKOS_LIBRARY 1) + set(MAGISTRATE_HAS_KOKKOS_LIBRARY 1) else() - set(CHECKPOINT_HAS_KOKKOS_LIBRARY 0) + set(MAGISTRATE_HAS_KOKKOS_LIBRARY 0) endif() endif() @@ -123,34 +133,34 @@ if (NOT kokkos_kernels_DISABLE) "CMake/KokkosKernels/" "cmake/KokkosKernels/" ) # Used to properly setup transitive dependency in checkpointConfig.cmake.in - set(CHECKPOINT_HAS_KOKKOS_KERNELS_LIBRARY 1) + set(MAGISTRATE_HAS_KOKKOS_KERNELS_LIBRARY 1) else() - set(CHECKPOINT_HAS_KOKKOS_KERNELS_LIBRARY 0) + set(MAGISTRATE_HAS_KOKKOS_KERNELS_LIBRARY 0) endif() endif() get_directory_property(hasParent PARENT_DIRECTORY) if(hasParent) - message(STATUS "Checkpoint: building as a sub-directory") + message(STATUS "Magistrate: building as a sub-directory") else() - message(STATUS "Checkpoint: building as top-level") + message(STATUS "Magistrate: building as top-level") endif() -# If checkpoint build tests require the GTest package +# If magistrate build tests require the GTest package if (${magistrate_tests_enabled}) if(NOT hasParent) find_package(GTest REQUIRED) - set(CHECKPOINT_HAS_GTEST TRUE) + set(MAGISTRATE_HAS_GTEST TRUE) else() if (NOT DISABLE_TPL_GTEST) - set(CHECKPOINT_HAS_GTEST TRUE) + set(MAGISTRATE_HAS_GTEST TRUE) else() - set(CHECKPOINT_HAS_GTEST FALSE) + set(MAGISTRATE_HAS_GTEST FALSE) endif() endif() else() - set(CHECKPOINT_HAS_GTEST FALSE) + set(MAGISTRATE_HAS_GTEST FALSE) endif() set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) @@ -162,10 +172,10 @@ enable_testing() add_subdirectory(src) -add_custom_target(checkpoint_examples) +add_custom_target(magistrate_examples) add_subdirectory(examples) -add_custom_target(checkpoint_tests) +add_custom_target(magistrate_tests) add_subdirectory(tests) configure_file( diff --git a/cmake/checkpointConfig.cmake.in b/cmake/checkpointConfig.cmake.in index 6ff50af6..0de44ce6 100644 --- a/cmake/checkpointConfig.cmake.in +++ b/cmake/checkpointConfig.cmake.in @@ -5,7 +5,7 @@ include(${SELF_DIR}/checkpointTargets.cmake) include(CMakeFindDependencyMacro) -if (@CHECKPOINT_HAS_KOKKOS_LIBRARY@) +if (@MAGISTRATE_HAS_KOKKOS_LIBRARY@) set (kokkos_DIR @kokkos_DIR@) find_dependency(kokkos REQUIRED HINTS @kokkos_DIR@ NAMES Kokkos) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dc8ddaf7..fe18dec8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,13 +3,13 @@ set( traits container serializers traits buffer dispatch ) -set(CHECKPOINT_INSTALL_DESTINATION "include/checkpoint") -set(CHECKPOINT_EXTERNAL_DESTINATION "include") +set(MAGISTRATE_INSTALL_DESTINATION "include/checkpoint") +set(MAGISTRATE_EXTERNAL_DESTINATION "include") foreach(DIR ${TOP_LEVEL_SUBDIRS}) install( DIRECTORY "checkpoint/${DIR}" - DESTINATION ${CHECKPOINT_INSTALL_DESTINATION} + DESTINATION ${MAGISTRATE_INSTALL_DESTINATION} FILES_MATCHING PATTERN "*.h" ) endforeach() @@ -18,7 +18,7 @@ file(GLOB TOP_HEADERS "checkpoint/*.h") install( FILES ${TOP_HEADERS} - DESTINATION ${CHECKPOINT_INSTALL_DESTINATION} + DESTINATION ${MAGISTRATE_INSTALL_DESTINATION} ) file( @@ -67,57 +67,54 @@ foreach(SUB_DIR ${TOP_LEVEL_SUBDIRS}) endforeach() add_library( - ${CHECKPOINT_LIBRARY} + ${MAGISTRATE_LIBRARY} ${HEADER_FILES} ${SOURCE_FILES} ) -add_library(${MAGISTRATE_LIBRARY_NS} ALIAS ${CHECKPOINT_LIBRARY}) +add_library(${MAGISTRATE_LIBRARY_NS} ALIAS ${MAGISTRATE_LIBRARY}) -target_compile_features(${CHECKPOINT_LIBRARY} PUBLIC cxx_std_17) +target_compile_features(${MAGISTRATE_LIBRARY} PUBLIC cxx_std_17) include(CMakePrintHelpers) if (${kokkos_DIR_FOUND}) if (KokkosKernels_DIR_FOUND) - message(STATUS "Checkpoint: Kokkos kernels enabled") + message(STATUS "Magistrate: Kokkos kernels enabled") set(KERNELS 1) # Kokkos Kernels historically installed its EXPORT targets in the Kokkos:: namespace, and several # downstream packages import it as such, so it's not readily changed. # Meanwhile, Trilinos installs it under the more consistent KokkosKernels:: namespace. # Account for both possible routes of acquiring Kokkos Kernels here if(TARGET KokkosKernels::kokkoskernels) - target_link_libraries(${CHECKPOINT_LIBRARY} PUBLIC KokkosKernels::kokkoskernels) + target_link_libraries(${MAGISTRATE_LIBRARY} PUBLIC KokkosKernels::kokkoskernels) else() - target_link_libraries(${CHECKPOINT_LIBRARY} PUBLIC Kokkos::kokkoskernels) + target_link_libraries(${MAGISTRATE_LIBRARY} PUBLIC Kokkos::kokkoskernels) endif() else() - message(STATUS "Checkpoint: Kokkos kernels disabled") + message(STATUS "Magistrate: Kokkos kernels disabled") set(KERNELS 0) endif() target_compile_definitions( - ${CHECKPOINT_LIBRARY} PUBLIC + ${MAGISTRATE_LIBRARY} PUBLIC MAGISTRATE_KOKKOS_ENABLED=1 MAGISTRATE_KOKKOS_KERNELS_ENABLED=${KERNELS} ) - message(STATUS "Checkpoint: Kokkos enabled") - target_link_libraries(${CHECKPOINT_LIBRARY} PUBLIC Kokkos::kokkos) + message(STATUS "Magistrate: Kokkos enabled") + target_link_libraries(${MAGISTRATE_LIBRARY} PUBLIC Kokkos::kokkos) endif() -target_link_libraries(${CHECKPOINT_LIBRARY} PUBLIC ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(${MAGISTRATE_LIBRARY} PUBLIC ${CMAKE_THREAD_LIBS_INIT}) if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - message(STATUS "Checkpoint: enabling code coverage generation") + message(STATUS "Magistrate: enabling code coverage generation") # Add required flags (GCC & LLVM/Clang) target_compile_options( - ${CHECKPOINT_LIBRARY} PUBLIC + ${MAGISTRATE_LIBRARY} PUBLIC -O0 # no optimization -g # generate debug info --coverage # sets all required flags ) - if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) - target_link_options(${CHECKPOINT_LIBRARY} INTERFACE --coverage) - else() - target_link_libraries(${CHECKPOINT_LIBRARY} INTERFACE --coverage) - endif() + + target_link_options(${MAGISTRATE_LIBRARY} INTERFACE --coverage) endif() configure_file( @@ -131,28 +128,28 @@ install( ) target_include_directories( - ${CHECKPOINT_LIBRARY} PUBLIC + ${MAGISTRATE_LIBRARY} PUBLIC $ $ ) target_include_directories( - ${CHECKPOINT_LIBRARY} PUBLIC + ${MAGISTRATE_LIBRARY} PUBLIC $ $ ) install( - TARGETS ${CHECKPOINT_LIBRARY} - EXPORT ${CHECKPOINT_LIBRARY} + TARGETS ${MAGISTRATE_LIBRARY} + EXPORT ${MAGISTRATE_LIBRARY} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin - INCLUDES DESTINATION ${CHECKPOINT_EXTERNAL_DESTINATION} + INCLUDES DESTINATION ${MAGISTRATE_EXTERNAL_DESTINATION} ) install( - EXPORT ${CHECKPOINT_LIBRARY} + EXPORT ${MAGISTRATE_LIBRARY} DESTINATION cmake FILE "checkpointTargets.cmake" NAMESPACE vt::lib:: @@ -160,7 +157,7 @@ install( ) export( - TARGETS ${CHECKPOINT_LIBRARY} + TARGETS ${MAGISTRATE_LIBRARY} FILE "checkpointTargets.cmake" NAMESPACE vt::lib:: ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 77f02963..0c53ef3a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,7 +29,7 @@ macro(magistrate_link_target target has_mpi) target_include_directories(${target} PUBLIC ${PROJECT_TEST_UNIT_DIR}) target_link_libraries(${target} PRIVATE GTest::gtest GTest::gtest_main) target_link_libraries(${target} PRIVATE Threads::Threads) - target_link_libraries(${target} PUBLIC ${CHECKPOINT_LIBRARY}) + target_link_libraries(${target} PUBLIC ${MAGISTRATE_LIBRARY}) if (${has_mpi}) target_link_libraries(${target} PUBLIC ${MPI_LIBRARIES})