diff options
author | Ankit Meel <ankitm> | 2020-09-15 23:46:15 +0300 |
---|---|---|
committer | Ankit Meel <ankitjmeel@gmail.com> | 2020-09-15 23:48:59 +0300 |
commit | a4c5811e21271d0f26e0534f25800059c198982d (patch) | |
tree | 9fb5129ac931636fc98c2cfd30b7a70a7e08aa96 /CMakeLists.txt | |
parent | 84032fd1108b29d270e51d890f0303f78b6962c2 (diff) |
ASan/macOS: fix incomplete C/CXX compiler flags.
While testing for {rB40dcf686f04f}, compiler flags got mixed up and
non-working ASan configuration was committed.
Platform file, which is `include`d after the `CMAKE_C_FLAGS_DEBUG` etc.,
are set, overwrites those flags instead of appending to them. To fix this,
`PLATFORM_CFLAGS` is used to pass the `-fsanitize=*` flags to the C/C++
compiler.
Tested on fresh build using both Xcode and Ninja, with & without ccache.
Also silence a clang warning for multi-config generators:
the object size sanitizer has no effect at -O0, but is explicitly
enabled: -fsanitize=object-size [-Winvalid-command-line-argument]
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D8879
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fc454a639c..c9a020ebbc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -522,7 +522,8 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") set(_asan_defaults "${_asan_defaults}") elseif(APPLE) # AppleClang doesn't support all sanitizers, but leak gives error. - if(CMAKE_BUILD_TYPE MATCHES "Debug") + # Build type is not known for multi-config generator, so don't add object-size sanitizer. + if(CMAKE_BUILD_TYPE MATCHES "Debug" OR GENERATOR_IS_MULTI_CONFIG) # Silence the warning that object-size is not effective in -O0. set(_asan_defaults "${_asan_defaults}") else() @@ -553,9 +554,11 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") ) string(STRIP "${CLANG_LIB_DIR}" CLANG_LIB_DIR) find_library( - COMPILER_ASAN_LIBRARY NAMES libclang_rt.asan_osx_dynamic.dylib + COMPILER_ASAN_LIBRARY + NAMES + libclang_rt.asan_osx_dynamic.dylib PATHS - "${CLANG_LIB_DIR}/darwin/" + "${CLANG_LIB_DIR}/darwin/" ) unset(CLANG_LIB_DIR) else() @@ -858,6 +861,9 @@ if(NOT CMAKE_BUILD_TYPE MATCHES "Release") set(COMPILER_ASAN_LINKER_FLAGS "/FUNCTIONPADMIN:6") endif() if(APPLE) + # COMPILER_ASAN_CFLAGS and COMPILER_ASAN_CXXFLAGS are the same as of + # now, so use either for PLATFORM_CFLAGS. + set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} ${COMPILER_ASAN_CFLAGS}") set(COMPILER_ASAN_LINKER_FLAGS "-fno-omit-frame-pointer -fsanitize=address") endif(APPLE) if(COMPILER_ASAN_LIBRARY) |