diff options
author | Patrick Steinhardt <ps@pks.im> | 2018-07-19 15:13:40 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2018-08-03 09:50:35 +0200 |
commit | 186a7ba5d71c38e96af07ec9b8dfa29661fabb5a (patch) | |
tree | a60db273f13ae68876383dfdf6078619cd7467cc /CMakeLists.txt | |
parent | 07cf8b38dbad7de3f0a5da053726d8e697a65d0d (diff) | |
download | libgit2-186a7ba5d71c38e96af07ec9b8dfa29661fabb5a.tar.gz |
cmake: error out if required C flags are not supported
We do want to notify users compiling our source code early on if they
try to use C flags which aren't supported. Add a new macro `AddCFlag`,
which results in a fatal error in case the flag is not supported, and
use it for our fuzzing flags.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b976c568f..71a79c9a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -250,20 +250,25 @@ ELSE() ENDIF() IF(NOT USE_SANITIZER STREQUAL "OFF") - SET(CMAKE_C_FLAGS "-fsanitize=${USE_SANITIZER} ${CMAKE_C_FLAGS}") - SET(CMAKE_C_FLAGS "-fno-omit-frame-pointer ${CMAKE_C_FLAGS}") - SET(CMAKE_C_FLAGS "-fno-optimize-sibling-calls ${CMAKE_C_FLAGS}") + # Workaround to force linking against -lasan + SET(CMAKE_REQUIRED_FLAGS "-fsanitize=${USE_SANITIZER}") + ADD_C_FLAG(-fsanitize=${USE_SANITIZER}) + UNSET(CMAKE_REQUIRED_FLAGS) + ADD_C_FLAG(-fno-omit-frame-pointer) + ADD_C_FLAG(-fno-optimize-sibling-calls) ENDIF() IF(USE_COVERAGE) - SET(CMAKE_C_FLAGS "-fcoverage-mapping ${CMAKE_C_FLAGS}") - SET(CMAKE_C_FLAGS "-fprofile-instr-generate ${CMAKE_C_FLAGS}") + ADD_C_FLAG(-fcoverage-mapping) + ADD_C_FLAG(-fprofile-instr-generate) ENDIF() IF(BUILD_FUZZERS AND NOT USE_STANDALONE_FUZZERS) # The actual sanitizer link target will be added when linking the fuzz # targets. - SET(CMAKE_C_FLAGS "-fsanitize=fuzzer-no-link ${CMAKE_C_FLAGS}") + SET(CMAKE_REQUIRED_FLAGS "-fsanitize=fuzzer-no-link") + ADD_C_FLAG(-fsanitize=fuzzer-no-link) + UNSET(CMAKE_REQUIRED_FLAGS) ENDIF () ADD_SUBDIRECTORY(src) |