Skip to content

Commit

Permalink
Re-enable Sanitizers. (#1061)
Browse files Browse the repository at this point in the history
Implement the CMake code to run sanitizers.
  • Loading branch information
1uc authored Dec 2, 2024
1 parent 46ec4c5 commit 66ce7a5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ install(FILES

if(HIGHFIVE_EXAMPLES OR HIGHFIVE_UNIT_TESTS)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/HighFiveWarnings.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/HighFiveFlags.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/HighFiveOptionalDependencies.cmake)
endif()

Expand Down
30 changes: 30 additions & 0 deletions cmake/HighFiveFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
if(TARGET HighFiveFlags)
# Allow multiple `include(HighFiveWarnings)`, which would
# attempt to redefine `HighFiveWarnings` and fail without
# this check.
return()
endif()

add_library(HighFiveFlags INTERFACE)

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(HIGHFIVE_MAX_ERRORS)
target_compile_options(HighFiveFlags
INTERFACE
-fmax-errors=${HIGHFIVE_MAX_ERRORS}
)
endif()
endif()

if(HIGHFIVE_GLIBCXX_ASSERTIONS)
target_compile_definitions(HighFiveFlags INTERFACE -D_GLIBCXX_ASSERTIONS)
endif()

if(HIGHFIVE_HAS_FRIEND_DECLARATIONS)
target_compile_definitions(HighFiveFlags INTERFACE -DHIGHFIVE_HAS_FRIEND_DECLARATIONS=1)
endif()

if(HIGHFIVE_SANITIZER)
target_compile_options(HighFiveFlags INTERFACE -fsanitize=${HIGHFIVE_SANITIZER})
target_link_options(HighFiveFlags INTERFACE -fsanitize=${HIGHFIVE_SANITIZER})
endif()
9 changes: 0 additions & 9 deletions cmake/HighFiveWarnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ if(TARGET HighFiveWarnings)
endif()

add_library(HighFiveWarnings INTERFACE)
add_library(HighFiveFlags INTERFACE)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang"
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"
Expand Down Expand Up @@ -48,11 +47,3 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
endif()
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(HIGHFIVE_MAX_ERRORS)
target_compile_options(HighFiveFlags
INTERFACE
-fmax-errors=${HIGHFIVE_MAX_ERRORS}
)
endif()
endif()
18 changes: 9 additions & 9 deletions src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,36 @@ function(compile_example example_source)
string(REPLACE ".cpp" "_bin" example_name ${example_filename})

add_executable(${example_name} ${example_source})
target_link_libraries(${example_name} PUBLIC HighFive HighFiveWarnings HighFiveFlags)
if(${ARGC} EQUAL 2)
target_link_libraries(${example_name} PUBLIC ${ARGV1})
target_link_libraries(${example_name} PUBLIC HighFive HighFiveWarnings)
if(${ARGC} GREATER_EQUAL 2)
target_link_libraries(${example_name} PUBLIC ${ARGV1} ${ARGV2} ${ARGV3} ${ARGV4})
endif()
endfunction()


foreach(example_source ${core_examples})
compile_example(${example_source})
compile_example(${example_source} HighFiveFlags)
endforeach()

foreach(example_source ${easy_examples})
compile_example(${example_source} HighFiveOptionalDependencies)
compile_example(${example_source} HighFiveFlags HighFiveOptionalDependencies)
endforeach()

if(HIGHFIVE_TEST_SPAN)
foreach(example_source ${span_examples})
compile_example(${example_source})
compile_example(${example_source} HighFiveFlags)
endforeach()
endif()

if(HIGHFIVE_TEST_BOOST)
foreach(example_source ${boost_examples})
compile_example(${example_source} HighFiveBoostDependency)
compile_example(${example_source} HighFiveFlags HighFiveBoostDependency)
endforeach()
endif()

if(HIGHFIVE_TEST_EIGEN)
foreach(example_source ${eigen_examples})
compile_example(${example_source} HighFiveEigenDependency)
compile_example(${example_source} HighFiveFlags HighFiveEigenDependency)
endforeach()
endif()

Expand All @@ -105,7 +105,7 @@ if(${HDF5_HL_FOUND})
target_link_libraries(HighFiveHlHdf5Dependency ${HDF5_HL_LIBRARIES})

foreach(example_source ${hl_hdf5_examples})
compile_examples(${example_source} HighFiveHlHdf5Dependency)
compile_examples(${example_source} HighFiveFlags HighFiveHlHdf5Dependency)
endforeach()
endif()

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if(HDF5_IS_PARALLEL)

## parallel MPI tests
add_executable(tests_parallel_bin ${tests_parallel_src})
target_link_libraries(tests_parallel_bin HighFive HighFiveWarnings HighFiveFlags Catch2::Catch2)
target_link_libraries(tests_parallel_bin HighFive HighFiveWarnings Catch2::Catch2)
target_link_libraries(tests_parallel_bin HighFiveOptionalDependencies)

# We need to patch in a call to `mpirun` or equivalent when using
Expand Down

0 comments on commit 66ce7a5

Please sign in to comment.