-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add options for enabling sanitisers (#119)
Partially replaces #68 #68 had extra intrusive options for valgrind which this leaves out. #68 is left open in case we need those in the future
- Loading branch information
1 parent
f56d4eb
commit 4640ec3
Showing
4 changed files
with
82 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Default not to run the clang-tidy checks, default to whatever our CI_BUILD is | ||
option(ENABLE_CLANG_TIDY "Enable building with clang-tidy checks.") | ||
if(ENABLE_CLANG_TIDY) | ||
# Search for clang-tidy-15 first as this is the version installed in CI | ||
find_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy-15 clang-tidy) | ||
if(NOT CLANG_TIDY_EXECUTABLE) | ||
message(FATAL_ERROR "clang-tidy-15 not found.") | ||
endif() | ||
|
||
# Report clang-tidy executable details | ||
execute_process(COMMAND "${CLANG_TIDY_EXECUTABLE}" "--version" OUTPUT_VARIABLE CLANG_TIDY_VERSION) | ||
string(REGEX REPLACE ".*LLVM version ([0-9.]*).*" "\\1" CLANG_TIDY_VERSION "${CLANG_TIDY_VERSION}") | ||
message(STATUS "Found clang-tidy: ${CLANG_TIDY_EXECUTABLE} ${CLANG_TIDY_VERSION}") | ||
|
||
# Build clang-tidy command line | ||
set(CLANG_TIDY_ARGS "${CLANG_TIDY_EXECUTABLE}" "--use-color" "--config-file=${PROJECT_SOURCE_DIR}/.clang-tidy") | ||
if(CI_BUILD) | ||
set(CLANG_TIDY_ARGS "${CLANG_TIDY_EXECUTABLE}" "-warnings-as-errors=*") | ||
endif(CI_BUILD) | ||
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_ARGS}" "--extra-arg=-std=c++14") | ||
set(CMAKE_C_CLANG_TIDY "${CLANG_TIDY_ARGS}" "--extra-arg=-std=c99") | ||
endif(ENABLE_CLANG_TIDY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Make the compiler display colours always (even when we build with ninja) | ||
if(CMAKE_CXX_COMPILER_ID MATCHES GNU) | ||
add_compile_options(-fdiagnostics-color=always) | ||
endif() | ||
if(CMAKE_CXX_COMPILER_ID MATCHES Clang) | ||
add_compile_options(-fcolor-diagnostics) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
############################################################################### | ||
### Options for enabling different sanitisers. ### | ||
### ### | ||
### User beware: ### | ||
### Not all sanitisers can be enabled at the same time. ### | ||
############################################################################### | ||
option(USE_ASAN "Enable address sanitization" OFF) | ||
if(USE_ASAN) | ||
add_compile_options(-fsanitize=address -fno-omit-frame-pointer -U_FORTIFY_SOURCE -fno-common) | ||
add_link_options(-fsanitize=address) | ||
link_libraries(asan) | ||
endif(USE_ASAN) | ||
|
||
option(USE_LSAN "Enable leak sanitization" OFF) | ||
if(USE_LSAN) | ||
add_compile_options(-fsanitize=leak -fno-omit-frame-pointer -U_FORTIFY_SOURCE -fno-common) | ||
add_link_options(-fsanitize=leak) | ||
link_libraries(lsan) | ||
endif(USE_LSAN) | ||
|
||
option(USE_TSAN "Enable thread sanitization" OFF) | ||
if(USE_TSAN) | ||
add_compile_options(-fsanitize=thread -fno-omit-frame-pointer -U_FORTIFY_SOURCE -fno-common) | ||
add_link_options(-fsanitize=thread) | ||
link_libraries(tsan) | ||
endif(USE_TSAN) | ||
|
||
option(USE_UBSAN "Enable undefined behaviour sanitization" OFF) | ||
if(USE_UBSAN) | ||
add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer -U_FORTIFY_SOURCE -fno-common) | ||
add_link_options(-fsanitize=undefined) | ||
link_libraries(ubsan) | ||
endif(USE_UBSAN) | ||
|
||
# Option for enabling code profiling. Disabled by default | ||
option(ENABLE_PROFILING "Compile with profiling support enabled." OFF) | ||
if(ENABLE_PROFILING) | ||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") | ||
message( | ||
WARNING | ||
"Profiling is enabled but no debugging symbols will be kept in the compiled binaries. This may cause fine-grained profilling data to be lost." | ||
) | ||
endif() | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg -fprofile-arcs") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg -fprofile-arcs") | ||
set(CMAKE_LINKER "${CMAKE_LINKER_FLAGS} -pg -fprofile-arcs") | ||
endif(ENABLE_PROFILING) |