From 2dd469e18ca4921d1bf26b55e70a90225b114561 Mon Sep 17 00:00:00 2001 From: Ruslan Baratov Date: Wed, 28 Sep 2016 13:52:57 +0300 Subject: [PATCH] Add 'osx-10-11-sanitize-address' (Xcode) toolchain --- bin/detail/toolchain_table.py | 1 + flags/sanitize_address.cmake | 35 ++++++++++++++++++++++++++++++++ osx-10-11-sanitize-address.cmake | 30 +++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 osx-10-11-sanitize-address.cmake diff --git a/bin/detail/toolchain_table.py b/bin/detail/toolchain_table.py index 7c69d375..339d013e 100644 --- a/bin/detail/toolchain_table.py +++ b/bin/detail/toolchain_table.py @@ -292,6 +292,7 @@ def verify(self): Toolchain('osx-10-11', 'Xcode', osx_version='10.11'), Toolchain('osx-10-10-dep-10-7', 'Xcode', osx_version='10.10'), Toolchain('osx-10-10-dep-10-9-make', 'Unix Makefiles'), + Toolchain('osx-10-11-sanitize-address', 'Xcode', osx_version='10.11'), Toolchain('linux-gcc-x64', 'Unix Makefiles'), ] diff --git a/flags/sanitize_address.cmake b/flags/sanitize_address.cmake index b6e08d96..8cf38dc7 100644 --- a/flags/sanitize_address.cmake +++ b/flags/sanitize_address.cmake @@ -8,6 +8,7 @@ else() endif() include(polly_add_cache_flag) +include(polly_fatal_error) polly_add_cache_flag(CMAKE_CXX_FLAGS "-fsanitize=address") polly_add_cache_flag(CMAKE_CXX_FLAGS "-g") @@ -32,3 +33,37 @@ set( "C compiler flags" FORCE ) + +if(XCODE) + polly_add_cache_flag(CMAKE_C_FLAGS "-D_LIBCPP_HAS_NO_ASAN") + polly_add_cache_flag(CMAKE_CXX_FLAGS "-D_LIBCPP_HAS_NO_ASAN") + + string(COMPARE EQUAL "${CMAKE_XCODE_ATTRIBUTE_CC}" "" _is_empty) + if(_is_empty) + polly_fatal_error("CMAKE_XCODE_ATTRIBUTE_CC is empty") + endif() + + get_filename_component(_xcode_root "${CMAKE_XCODE_ATTRIBUTE_CC}" DIRECTORY) + + set(_xcode_asan_lib_name "libclang_rt.asan_osx_dynamic") + set( + _xcode_asan_pattern + "${_xcode_root}/../lib/clang/*/lib/darwin/${_xcode_asan_lib_name}.dylib" + ) + + file(GLOB _xcode_asan_lib "${_xcode_asan_pattern}") + list(LENGTH _xcode_asan_lib _xcode_asan_lib_length) + if(_xcode_asan_lib_length EQUAL 1) + get_filename_component(_xcode_asan_lib "${_xcode_asan_lib}" ABSOLUTE) + get_filename_component(_xcode_asan_lib_dir "${_xcode_asan_lib}" DIRECTORY) + polly_status_debug("Using ASAN library:\n") + polly_status_debug(" * ${_xcode_asan_lib}") + elseif(_xcode_asan_lib_length EQUAL 0) + polly_fatal_error("File not found by pattern: ${_xcode_asan_pattern}") + else() + polly_fatal_error("Unexpected: '${_xcode_asan_lib}'") + endif() + + polly_add_cache_flag(CMAKE_EXE_LINKER_FLAGS "${_xcode_asan_lib}") + polly_add_cache_flag(CMAKE_SHARED_LINKER_FLAGS "${_xcode_asan_lib}") +endif() diff --git a/osx-10-11-sanitize-address.cmake b/osx-10-11-sanitize-address.cmake new file mode 100644 index 00000000..bd2fab04 --- /dev/null +++ b/osx-10-11-sanitize-address.cmake @@ -0,0 +1,30 @@ +# Copyright (c) 2016, Ruslan Baratov +# All rights reserved. + +if(DEFINED POLLY_OSX_10_11_SANITIZE_ADDRESS_CMAKE_) + return() +else() + set(POLLY_OSX_10_11_SANITIZE_ADDRESS_CMAKE_ 1) +endif() + +include("${CMAKE_CURRENT_LIST_DIR}/utilities/polly_init.cmake") + +set(OSX_SDK_VERSION "10.11") +set(POLLY_XCODE_COMPILER "clang") +polly_init( + "Xcode (OS X ${OSX_SDK_VERSION}) / \ +${POLLY_XCODE_COMPILER} / \ +LLVM Standard C++ Library (libc++) / Clang address sanitizer / c++11 support" + "Xcode" +) + +include("${CMAKE_CURRENT_LIST_DIR}/utilities/polly_common.cmake") + +include("${CMAKE_CURRENT_LIST_DIR}/compiler/xcode.cmake") + +set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "OS X Deployment target" FORCE) + +include("${CMAKE_CURRENT_LIST_DIR}/library/std/libcxx.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/flags/cxx11.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/os/osx.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/flags/sanitize_address.cmake")