Skip to content

Commit 7449d46

Browse files
committed
cmake: add support for sanitizers
problem: using address or other sanitizers is currently very manual and error prone solution: add support into the build system to select appropriate sanitizers and link them in. This uses an external project which has been pulled in as a git subtree (NOT a submodule, it's a single squashed out commit that pulls in the directory).
1 parent 7fff2f1 commit 7449d46

File tree

8 files changed

+14
-3
lines changed

8 files changed

+14
-3
lines changed

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ if("${isSystemDir}" STREQUAL "-1")
3636
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
3737
endif("${isSystemDir}" STREQUAL "-1")
3838

39-
4039
# Setting the include directory for the application to find config.h
4140
include_directories( ${CMAKE_BINARY_DIR} )
4241
# Since we have created a config.h add a global define for it
@@ -46,11 +45,12 @@ add_definitions( "-DPACKAGE_VERSION=\"${FLUX_SCHED_VER}\"" )
4645
# We build a lot of shared libs, build them all with PIC
4746
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
4847

49-
# variable to store paths to add to module path for tests
50-
5148
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
49+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/sanitizers-cmake/cmake)
5250
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX})
5351

52+
include(FindSanitizers)
53+
5454
# external dependencies
5555
find_package(PkgConfig REQUIRED)
5656
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
@@ -147,6 +147,7 @@ function(flux_add_plugin TargetName PluginType)
147147
)
148148
target_link_options(${TargetName} PRIVATE
149149
"LINKER:--version-script=${CMAKE_SOURCE_DIR}/flux-plugin.map" ${LinkerOpts})
150+
add_sanitizers(${TargetName})
150151
target_link_libraries(${TargetName} PRIVATE flux::core)
151152
if (NOT ARG_NOINSTALL)
152153
install(TARGETS ${TargetName}

resource/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ target_link_libraries(resource PUBLIC
8787
jobspec_conv
8888
Boost::filesystem
8989
)
90+
add_sanitizers(resource)
9091

9192
add_subdirectory(modules)
9293
add_subdirectory(reapi)

resource/libjobspec/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_library ( jobspec_conv STATIC
99
${CMAKE_CURRENT_SOURCE_DIR}/rank_constraint.cpp
1010
${CMAKE_CURRENT_SOURCE_DIR}/rank_constraint.hpp
1111
)
12+
add_sanitizers(jobspec_conv)
1213
target_link_libraries(jobspec_conv PUBLIC flux::hostlist flux::idset
1314
flux::core yaml-cpp PkgConfig::JANSSON
1415
PkgConfig::UUID

resource/planner/c++/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_library(planner_cxx STATIC
88
./planner_internal_tree.hpp
99
./scheduled_point_tree.hpp
1010
)
11+
add_sanitizers(planner_cxx)
1112
target_link_libraries(planner_cxx yggdrasil)
1213

1314

resource/planner/c/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_library(planner STATIC
44
./planner.h
55
./planner_multi.h
66
)
7+
add_sanitizers(planner)
78
target_include_directories(planner PUBLIC ./)
89
target_link_libraries(planner PUBLIC planner_cxx)
910

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
add_executable(planner_test01 planner_test01.cpp)
2+
add_sanitizers(planner_test01)
23
target_link_libraries(planner_test01 planner libtap)
34
flux_add_test(NAME planner_test01 COMMAND planner_test01)
45
set_property(TEST planner_test01 PROPERTY ENVIRONMENT "TESTRESRC_INPUT_FILE=$(CMAKE_SOURCE_DIR)/conf/hype.lua")
56

67
add_executable(planner_test02 planner_test02.cpp)
8+
add_sanitizers(planner_test02)
79
target_link_libraries(planner_test02 planner libtap)
810
flux_add_test(NAME planner_test02 COMMAND planner_test02)
911
set_property(TEST planner_test02 PROPERTY ENVIRONMENT "TESTRESRC_INPUT_FILE=$(CMAKE_SOURCE_DIR)/conf/hype.lua")

resource/policies/base/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ add_executable(matcher_util_api_test
44
target_link_libraries(matcher_util_api_test PRIVATE libtap resource
55
PkgConfig::JANSSON
66
)
7+
add_sanitizers(matcher_util_api_test)
78
flux_add_test(NAME matcher_util_api_test COMMAND matcher_util_api_test)

resource/utilities/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_executable(grug2dot
22
grug2dot.cpp
33
)
4+
add_sanitizers(grug2dot)
45
target_link_libraries(grug2dot
56
resource
67
Boost::headers
@@ -11,6 +12,7 @@ add_executable(resource-query
1112
command.cpp
1213
command.hpp
1314
)
15+
add_sanitizers(resource-query)
1416
target_link_libraries(resource-query
1517
resource
1618
PkgConfig::LIBEDIT
@@ -23,6 +25,7 @@ add_executable(rq2
2325
rq2.cpp
2426
rq2.hpp
2527
)
28+
add_sanitizers(rq2)
2629
target_link_libraries(rq2
2730
resource
2831
PkgConfig::LIBEDIT

0 commit comments

Comments
 (0)