Skip to content

Commit

Permalink
#350: Further changes to CMake files (checkpoint->magistrate)
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Jun 24, 2024
1 parent b476f45 commit 1c39c47
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 56 deletions.
60 changes: 35 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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()

Expand All @@ -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)
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion cmake/checkpointConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()
55 changes: 26 additions & 29 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -18,7 +18,7 @@ file(GLOB TOP_HEADERS "checkpoint/*.h")

install(
FILES ${TOP_HEADERS}
DESTINATION ${CHECKPOINT_INSTALL_DESTINATION}
DESTINATION ${MAGISTRATE_INSTALL_DESTINATION}
)

file(
Expand Down Expand Up @@ -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(
Expand All @@ -131,36 +128,36 @@ install(
)

target_include_directories(
${CHECKPOINT_LIBRARY} PUBLIC
${MAGISTRATE_LIBRARY} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)

target_include_directories(
${CHECKPOINT_LIBRARY} PUBLIC
${MAGISTRATE_LIBRARY} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)

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::
COMPONENT runtime
)

export(
TARGETS ${CHECKPOINT_LIBRARY}
TARGETS ${MAGISTRATE_LIBRARY}
FILE "checkpointTargets.cmake"
NAMESPACE vt::lib::
)
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit 1c39c47

Please sign in to comment.