cmake-scripts icon indicating copy to clipboard operation
cmake-scripts copied to clipboard

Sanitizer compilation test fails with Xcode generator.

Open jdumas opened this issue 1 year ago • 0 comments

Hi. Running CMake with the Xcode generator seems to fails the compilation for Address sanitizer on macOS:

❯ cmake .. -G "Xcode" -DUSE_SANITIZER=Address
-- The C compiler identification is AppleClang 13.1.6.13160021
-- The CXX compiler identification is AppleClang 13.1.6.13160021
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode13.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode13.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Testing with Address sanitizer
CMake Error at /Users/jedumas/external/git/cmake-scripts/sanitizers.cmake:77 (message):
  Address sanitizer not available for
  /Applications/Xcode13.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
Call Stack (most recent call first):
  CMakeLists.txt:10 (include)


-- Configuring incomplete, errors occurred!

Furthermore it looks like the -fsanitize=address flag should also be passed to linker options. I would generally recommend setting global options via add_compile_options() and add_link_options() rather than mucking around with CMAKE_CXX_FLAGS or CMAKE_EXE_LINKER_FLAGS directly though, but that's probably a separate issue.

jdumas avatar Apr 15 '24 15:04 jdumas