Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 66ce7a5

Browse files
authored
Re-enable Sanitizers. (#1061)
Implement the CMake code to run sanitizers.
1 parent 46ec4c5 commit 66ce7a5

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ install(FILES
156156

157157
if(HIGHFIVE_EXAMPLES OR HIGHFIVE_UNIT_TESTS)
158158
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/HighFiveWarnings.cmake)
159+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/HighFiveFlags.cmake)
159160
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/HighFiveOptionalDependencies.cmake)
160161
endif()
161162

cmake/HighFiveFlags.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
if(TARGET HighFiveFlags)
2+
# Allow multiple `include(HighFiveWarnings)`, which would
3+
# attempt to redefine `HighFiveWarnings` and fail without
4+
# this check.
5+
return()
6+
endif()
7+
8+
add_library(HighFiveFlags INTERFACE)
9+
10+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
11+
if(HIGHFIVE_MAX_ERRORS)
12+
target_compile_options(HighFiveFlags
13+
INTERFACE
14+
-fmax-errors=${HIGHFIVE_MAX_ERRORS}
15+
)
16+
endif()
17+
endif()
18+
19+
if(HIGHFIVE_GLIBCXX_ASSERTIONS)
20+
target_compile_definitions(HighFiveFlags INTERFACE -D_GLIBCXX_ASSERTIONS)
21+
endif()
22+
23+
if(HIGHFIVE_HAS_FRIEND_DECLARATIONS)
24+
target_compile_definitions(HighFiveFlags INTERFACE -DHIGHFIVE_HAS_FRIEND_DECLARATIONS=1)
25+
endif()
26+
27+
if(HIGHFIVE_SANITIZER)
28+
target_compile_options(HighFiveFlags INTERFACE -fsanitize=${HIGHFIVE_SANITIZER})
29+
target_link_options(HighFiveFlags INTERFACE -fsanitize=${HIGHFIVE_SANITIZER})
30+
endif()

cmake/HighFiveWarnings.cmake

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ if(TARGET HighFiveWarnings)
66
endif()
77

88
add_library(HighFiveWarnings INTERFACE)
9-
add_library(HighFiveFlags INTERFACE)
109

1110
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang"
1211
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"
@@ -48,11 +47,3 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
4847
endif()
4948
endif()
5049

51-
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
52-
if(HIGHFIVE_MAX_ERRORS)
53-
target_compile_options(HighFiveFlags
54-
INTERFACE
55-
-fmax-errors=${HIGHFIVE_MAX_ERRORS}
56-
)
57-
endif()
58-
endif()

src/examples/CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,36 +59,36 @@ function(compile_example example_source)
5959
string(REPLACE ".cpp" "_bin" example_name ${example_filename})
6060

6161
add_executable(${example_name} ${example_source})
62-
target_link_libraries(${example_name} PUBLIC HighFive HighFiveWarnings HighFiveFlags)
63-
if(${ARGC} EQUAL 2)
64-
target_link_libraries(${example_name} PUBLIC ${ARGV1})
62+
target_link_libraries(${example_name} PUBLIC HighFive HighFiveWarnings)
63+
if(${ARGC} GREATER_EQUAL 2)
64+
target_link_libraries(${example_name} PUBLIC ${ARGV1} ${ARGV2} ${ARGV3} ${ARGV4})
6565
endif()
6666
endfunction()
6767

6868

6969
foreach(example_source ${core_examples})
70-
compile_example(${example_source})
70+
compile_example(${example_source} HighFiveFlags)
7171
endforeach()
7272

7373
foreach(example_source ${easy_examples})
74-
compile_example(${example_source} HighFiveOptionalDependencies)
74+
compile_example(${example_source} HighFiveFlags HighFiveOptionalDependencies)
7575
endforeach()
7676

7777
if(HIGHFIVE_TEST_SPAN)
7878
foreach(example_source ${span_examples})
79-
compile_example(${example_source})
79+
compile_example(${example_source} HighFiveFlags)
8080
endforeach()
8181
endif()
8282

8383
if(HIGHFIVE_TEST_BOOST)
8484
foreach(example_source ${boost_examples})
85-
compile_example(${example_source} HighFiveBoostDependency)
85+
compile_example(${example_source} HighFiveFlags HighFiveBoostDependency)
8686
endforeach()
8787
endif()
8888

8989
if(HIGHFIVE_TEST_EIGEN)
9090
foreach(example_source ${eigen_examples})
91-
compile_example(${example_source} HighFiveEigenDependency)
91+
compile_example(${example_source} HighFiveFlags HighFiveEigenDependency)
9292
endforeach()
9393
endif()
9494

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

107107
foreach(example_source ${hl_hdf5_examples})
108-
compile_examples(${example_source} HighFiveHlHdf5Dependency)
108+
compile_examples(${example_source} HighFiveFlags HighFiveHlHdf5Dependency)
109109
endforeach()
110110
endif()
111111

tests/unit/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if(HDF5_IS_PARALLEL)
1919

2020
## parallel MPI tests
2121
add_executable(tests_parallel_bin ${tests_parallel_src})
22-
target_link_libraries(tests_parallel_bin HighFive HighFiveWarnings HighFiveFlags Catch2::Catch2)
22+
target_link_libraries(tests_parallel_bin HighFive HighFiveWarnings Catch2::Catch2)
2323
target_link_libraries(tests_parallel_bin HighFiveOptionalDependencies)
2424

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

0 commit comments

Comments
 (0)