2012-04-04 22:12:04 +00:00
|
|
|
# CMake build for CompilerRT.
|
|
|
|
#
|
|
|
|
# An important constraint of the build is that it only produces libraries
|
|
|
|
# based on the ability of the host toolchain to target various platforms.
|
|
|
|
|
2017-06-16 21:14:45 +00:00
|
|
|
cmake_minimum_required(VERSION 3.4.3)
|
|
|
|
|
2014-02-19 07:49:16 +00:00
|
|
|
# Check if compiler-rt is built as a standalone project.
|
2016-08-19 06:46:00 +00:00
|
|
|
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD)
|
2015-07-28 16:52:42 +00:00
|
|
|
project(CompilerRT C CXX ASM)
|
2014-02-19 07:49:16 +00:00
|
|
|
set(COMPILER_RT_STANDALONE_BUILD TRUE)
|
2018-06-27 12:56:34 +00:00
|
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
2014-02-19 07:49:16 +00:00
|
|
|
endif()
|
|
|
|
|
[CMake] Support platform building builtins without a full toolchain
Summary:
This patch adds support for building lib/builtins without a fully functioning toolchain. It allows you to bootstrap a cross-compiler, which previously couldn't be done with CMake.
This patch contains the following specific changes:
* Split builtin-specific code out of config-ix.cmake into builtin-config-ix.cmake
* Split some common CMake functionality needed by both builtins and sanitizers into base-config-ix.cmake
* Made lib/builtins/CMakeLists.txt able to be a top-level CMake configuration
I have tested this on Darwin targeting embedded Darwin, and on FreeBSD x86_64 targeting FreeBSD AArch64.
This patch depends on http://reviews.llvm.org/D19692, and is the last part of http://reviews.llvm.org/D16653.
Reviewers: samsonov, iains, jroelofs
Subscribers: compnerd, aemerson, tberghammer, danalbert, srhines, emaste, llvm-commits
Differential Revision: http://reviews.llvm.org/D19742
llvm-svn: 268977
2016-05-09 21:45:52 +00:00
|
|
|
# Add path for custom compiler-rt modules.
|
|
|
|
list(INSERT CMAKE_MODULE_PATH 0
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
|
|
|
|
)
|
|
|
|
|
2017-07-28 00:50:56 +00:00
|
|
|
if(CMAKE_CONFIGURATION_TYPES)
|
|
|
|
set(CMAKE_CFG_RESOLVED_INTDIR "${CMAKE_CFG_INTDIR}/")
|
|
|
|
else()
|
|
|
|
set(CMAKE_CFG_RESOLVED_INTDIR "")
|
|
|
|
endif()
|
|
|
|
|
[CMake] Support platform building builtins without a full toolchain
Summary:
This patch adds support for building lib/builtins without a fully functioning toolchain. It allows you to bootstrap a cross-compiler, which previously couldn't be done with CMake.
This patch contains the following specific changes:
* Split builtin-specific code out of config-ix.cmake into builtin-config-ix.cmake
* Split some common CMake functionality needed by both builtins and sanitizers into base-config-ix.cmake
* Made lib/builtins/CMakeLists.txt able to be a top-level CMake configuration
I have tested this on Darwin targeting embedded Darwin, and on FreeBSD x86_64 targeting FreeBSD AArch64.
This patch depends on http://reviews.llvm.org/D19692, and is the last part of http://reviews.llvm.org/D16653.
Reviewers: samsonov, iains, jroelofs
Subscribers: compnerd, aemerson, tberghammer, danalbert, srhines, emaste, llvm-commits
Differential Revision: http://reviews.llvm.org/D19742
llvm-svn: 268977
2016-05-09 21:45:52 +00:00
|
|
|
include(base-config-ix)
|
2016-08-02 05:51:05 +00:00
|
|
|
include(CompilerRTUtils)
|
2013-10-01 12:52:15 +00:00
|
|
|
|
2015-09-14 19:59:24 +00:00
|
|
|
option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
|
|
|
|
mark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
|
|
|
|
option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON)
|
|
|
|
mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS)
|
2016-08-08 03:58:57 +00:00
|
|
|
option(COMPILER_RT_BUILD_XRAY "Build xray" ON)
|
2016-07-21 07:39:55 +00:00
|
|
|
mark_as_advanced(COMPILER_RT_BUILD_XRAY)
|
2017-08-21 23:25:50 +00:00
|
|
|
option(COMPILER_RT_BUILD_LIBFUZZER "Build libFuzzer" ON)
|
|
|
|
mark_as_advanced(COMPILER_RT_BUILD_LIBFUZZER)
|
2017-10-02 05:03:55 +00:00
|
|
|
option(COMPILER_RT_BUILD_PROFILE "Build profile runtime" ON)
|
|
|
|
mark_as_advanced(COMPILER_RT_BUILD_PROFILE)
|
2017-08-03 00:58:45 +00:00
|
|
|
option(COMPILER_RT_BUILD_XRAY_NO_PREINIT "Build xray with no preinit patching" OFF)
|
|
|
|
mark_as_advanced(COMPILER_RT_BUILD_XRAY_NO_PREINIT)
|
2015-09-14 19:59:24 +00:00
|
|
|
|
2017-11-13 14:02:27 +00:00
|
|
|
set(COMPILER_RT_ASAN_SHADOW_SCALE ""
|
|
|
|
CACHE STRING "Override the shadow scale to be used in ASan runtime")
|
|
|
|
|
|
|
|
if (NOT COMPILER_RT_ASAN_SHADOW_SCALE STREQUAL "")
|
|
|
|
# Check that the shadow scale value is valid.
|
|
|
|
if (NOT (COMPILER_RT_ASAN_SHADOW_SCALE GREATER -1 AND
|
|
|
|
COMPILER_RT_ASAN_SHADOW_SCALE LESS 8))
|
|
|
|
message(FATAL_ERROR "
|
|
|
|
Invalid ASan Shadow Scale '${COMPILER_RT_ASAN_SHADOW_SCALE}'.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(COMPILER_RT_ASAN_SHADOW_SCALE_LLVM_FLAG
|
|
|
|
-mllvm -asan-mapping-scale=${COMPILER_RT_ASAN_SHADOW_SCALE})
|
|
|
|
set(COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION
|
|
|
|
ASAN_SHADOW_SCALE=${COMPILER_RT_ASAN_SHADOW_SCALE})
|
|
|
|
set(COMPILER_RT_ASAN_SHADOW_SCALE_FLAG
|
|
|
|
-D${COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION})
|
|
|
|
endif()
|
|
|
|
|
[hwasan] Add a (almost) no-interceptor mode.
Summary:
The idea behind this change is to allow sanitization of libc. We are prototyping on Bionic,
but the tool interface will be general enough (or at least generalizable) to support any other libc.
When libc depends on libclang_rt.hwasan, the latter can not interpose libc functions.
In fact, majority of interceptors become unnecessary when libc code is instrumented.
This change gets rid of most hwasan interceptors and provides interface for libc to notify
hwasan about thread creation and destruction events. Some interceptors (pthread_create)
are kept under #ifdef to enable testing with uninstrumented libc. They are expressed in
terms of the new libc interface.
The new cmake switch, COMPILER_RT_HWASAN_WITH_INTERCEPTORS, ON by default, builds testing
version of the library with the aforementioned pthread_create interceptor.
With the OFF setting, the library becomes more of a libc plugin.
Reviewers: vitalybuka, kcc, jfb
Subscribers: srhines, kubamracek, mgorny, jfb, llvm-commits
Differential Revision: https://reviews.llvm.org/D50922
llvm-svn: 340216
2018-08-20 21:49:15 +00:00
|
|
|
set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS ON CACHE BOOLEAN
|
|
|
|
"Enable libc interceptors in HWASan (testing mode)")
|
|
|
|
|
2017-05-10 15:34:25 +00:00
|
|
|
set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOLEAN
|
|
|
|
"Build for a bare-metal target.")
|
|
|
|
|
[CMake] Support platform building builtins without a full toolchain
Summary:
This patch adds support for building lib/builtins without a fully functioning toolchain. It allows you to bootstrap a cross-compiler, which previously couldn't be done with CMake.
This patch contains the following specific changes:
* Split builtin-specific code out of config-ix.cmake into builtin-config-ix.cmake
* Split some common CMake functionality needed by both builtins and sanitizers into base-config-ix.cmake
* Made lib/builtins/CMakeLists.txt able to be a top-level CMake configuration
I have tested this on Darwin targeting embedded Darwin, and on FreeBSD x86_64 targeting FreeBSD AArch64.
This patch depends on http://reviews.llvm.org/D19692, and is the last part of http://reviews.llvm.org/D16653.
Reviewers: samsonov, iains, jroelofs
Subscribers: compnerd, aemerson, tberghammer, danalbert, srhines, emaste, llvm-commits
Differential Revision: http://reviews.llvm.org/D19742
llvm-svn: 268977
2016-05-09 21:45:52 +00:00
|
|
|
if (COMPILER_RT_STANDALONE_BUILD)
|
2016-08-02 05:51:05 +00:00
|
|
|
load_llvm_config()
|
2018-06-27 12:56:34 +00:00
|
|
|
if (TARGET intrinsics_gen)
|
|
|
|
# Loading the llvm config causes this target to be imported so place it
|
|
|
|
# under the appropriate folder in an IDE.
|
|
|
|
set_target_properties(intrinsics_gen PROPERTIES FOLDER "Compiler-RT Misc")
|
|
|
|
endif()
|
2014-02-19 10:04:29 +00:00
|
|
|
|
|
|
|
# Find Python interpreter.
|
|
|
|
set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5)
|
|
|
|
include(FindPythonInterp)
|
|
|
|
if(NOT PYTHONINTERP_FOUND)
|
|
|
|
message(FATAL_ERROR "
|
|
|
|
Unable to find Python interpreter required testing. Please install Python
|
|
|
|
or specify the PYTHON_EXECUTABLE CMake variable.")
|
|
|
|
endif()
|
|
|
|
|
2018-09-17 23:25:36 +00:00
|
|
|
# Ensure that fat libraries are built correctly on Darwin
|
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
|
|
|
if(NOT CMAKE_LIBTOOL)
|
|
|
|
find_program(CMAKE_XCRUN
|
|
|
|
NAMES
|
|
|
|
xcrun)
|
|
|
|
if(CMAKE_XCRUN)
|
|
|
|
execute_process(COMMAND
|
|
|
|
${CMAKE_XCRUN} -find libtool
|
|
|
|
OUTPUT_VARIABLE
|
|
|
|
CMAKE_LIBTOOL
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT CMAKE_LIBTOOL OR NOT EXISTS CMAKE_LIBTOOL)
|
|
|
|
find_program(CMAKE_LIBTOOL
|
|
|
|
NAMES
|
|
|
|
libtool)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
|
|
|
|
|
|
|
|
if(CMAKE_LIBTOOL)
|
|
|
|
set(CMAKE_LIBTOOL ${CMAKE_LIBTOOL} CACHE PATH "libtool executable")
|
|
|
|
message(STATUS "Found libtool - ${CMAKE_LIBTOOL}")
|
|
|
|
|
|
|
|
execute_process(COMMAND
|
|
|
|
${CMAKE_LIBTOOL} -V
|
|
|
|
OUTPUT_VARIABLE
|
|
|
|
LIBTOOL_V_OUTPUT
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
if("${LIBTOOL_V_OUTPUT}" MATCHES ".*cctools-([0-9]+).*")
|
|
|
|
string(REGEX REPLACE ".*cctools-([0-9]+).*" "\\1" LIBTOOL_VERSION ${LIBTOOL_V_OUTPUT})
|
|
|
|
if(NOT LIBTOOL_VERSION VERSION_LESS "862")
|
|
|
|
set(LIBTOOL_NO_WARNING_FLAG "-no_warning_for_no_symbols")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
foreach(lang ${languages})
|
|
|
|
set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "\"${CMAKE_LIBTOOL}\" -static ${LIBTOOL_NO_WARNING_FLAG} -o <TARGET> <LINK_FLAGS> <OBJECTS>")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Workaround SIP :-(
|
|
|
|
if(DYLD_LIBRARY_PATH)
|
|
|
|
set(dyld_envar "DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}")
|
|
|
|
foreach(lang ${languages})
|
|
|
|
foreach(cmd ${CMAKE_${lang}_CREATE_STATIC_LIBRARY})
|
|
|
|
list(APPEND CMAKE_${lang}_CREATE_STATIC_LIBRARY_NEW "${dyld_envar} ${cmd}")
|
|
|
|
endforeach()
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2014-02-19 10:04:29 +00:00
|
|
|
# Define default arguments to lit.
|
|
|
|
set(LIT_ARGS_DEFAULT "-sv")
|
|
|
|
if (MSVC OR XCODE)
|
|
|
|
set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
|
|
|
|
endif()
|
|
|
|
set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
|
2017-09-15 22:10:46 +00:00
|
|
|
set(LLVM_LIT_OUTPUT_DIR "${COMPILER_RT_EXEC_OUTPUT_DIR}")
|
2014-02-19 07:49:16 +00:00
|
|
|
endif()
|
|
|
|
|
2016-08-02 05:51:05 +00:00
|
|
|
construct_compiler_rt_default_triple()
|
2018-08-14 18:01:19 +00:00
|
|
|
if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*hf$")
|
2017-09-19 17:54:11 +00:00
|
|
|
if (${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "^arm")
|
|
|
|
set(COMPILER_RT_DEFAULT_TARGET_ARCH "armhf")
|
|
|
|
endif()
|
|
|
|
endif()
|
2018-08-14 18:01:19 +00:00
|
|
|
if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*android.*")
|
2016-06-27 22:52:05 +00:00
|
|
|
set(ANDROID 1)
|
|
|
|
endif()
|
2017-09-16 05:13:56 +00:00
|
|
|
pythonize_bool(ANDROID)
|
2012-12-19 12:33:39 +00:00
|
|
|
|
2019-02-05 05:10:19 +00:00
|
|
|
set(ANDROID_NDK_VERSION 18
|
|
|
|
CACHE STRING "Set this to the Android NDK version that you are using")
|
|
|
|
|
2012-12-19 12:33:39 +00:00
|
|
|
set(COMPILER_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
2013-06-06 12:35:48 +00:00
|
|
|
set(COMPILER_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
2012-12-19 12:33:39 +00:00
|
|
|
|
2018-06-28 03:11:52 +00:00
|
|
|
pythonize_bool(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
|
|
|
|
|
2014-05-13 14:25:49 +00:00
|
|
|
# We support running instrumented tests when we're not cross compiling
|
|
|
|
# and target a UNIX-like system or Windows.
|
|
|
|
# We can run tests on Android even when we are cross-compiling.
|
2015-07-17 16:23:05 +00:00
|
|
|
if(("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND (UNIX OR WIN32)) OR ANDROID
|
2014-05-14 00:36:15 +00:00
|
|
|
OR COMPILER_RT_EMULATOR)
|
2013-04-01 04:13:03 +00:00
|
|
|
option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" ON)
|
2012-12-27 13:19:23 +00:00
|
|
|
else()
|
2013-04-01 04:13:03 +00:00
|
|
|
option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" OFF)
|
2012-12-27 13:19:23 +00:00
|
|
|
endif()
|
2013-04-01 04:13:03 +00:00
|
|
|
|
2013-10-25 23:03:34 +00:00
|
|
|
option(COMPILER_RT_DEBUG "Build runtimes with full debug info" OFF)
|
2015-12-03 20:08:22 +00:00
|
|
|
option(COMPILER_RT_EXTERNALIZE_DEBUGINFO
|
|
|
|
"Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
|
2013-10-25 23:03:34 +00:00
|
|
|
# COMPILER_RT_DEBUG_PYBOOL is used by lit.common.configured.in.
|
|
|
|
pythonize_bool(COMPILER_RT_DEBUG)
|
|
|
|
|
2019-03-06 19:25:09 +00:00
|
|
|
option(COMPILER_RT_INTERCEPT_LIBDISPATCH
|
2019-03-15 17:52:27 +00:00
|
|
|
"Support interception of libdispatch (GCD). Requires '-fblocks'" OFF)
|
2019-04-04 00:28:09 +00:00
|
|
|
option(COMPILER_RT_LIBDISPATCH_INSTALL_PREFIX
|
|
|
|
"Specify if libdispatch is installed in a non-default path" "")
|
2019-04-02 20:04:32 +00:00
|
|
|
if (COMPILER_RT_INTERCEPT_LIBDISPATCH AND NOT APPLE)
|
2019-03-15 17:52:27 +00:00
|
|
|
set(COMPILER_RT_INTERCEPT_LIBDISPATCH_CFLAGS -fblocks)
|
|
|
|
set(COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS)
|
2019-04-04 00:28:09 +00:00
|
|
|
if (COMPILER_RT_LIBDISPATCH_INSTALL_PREFIX)
|
2019-03-15 17:52:27 +00:00
|
|
|
list(APPEND COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS
|
2019-04-04 00:28:09 +00:00
|
|
|
-L${COMPILER_RT_LIBDISPATCH_INSTALL_PREFIX}/lib
|
|
|
|
-Wl,-rpath=${COMPILER_RT_LIBDISPATCH_INSTALL_PREFIX}/lib)
|
2019-03-15 17:52:27 +00:00
|
|
|
endif()
|
|
|
|
list(APPEND COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS -lBlocksRuntime -ldispatch)
|
|
|
|
endif()
|
2019-03-06 19:25:09 +00:00
|
|
|
if (APPLE) # Always enable on Apple platforms.
|
|
|
|
set(COMPILER_RT_INTERCEPT_LIBDISPATCH ON)
|
|
|
|
endif()
|
2019-03-07 18:15:23 +00:00
|
|
|
pythonize_bool(COMPILER_RT_INTERCEPT_LIBDISPATCH)
|
2019-03-06 19:25:09 +00:00
|
|
|
|
2017-07-07 22:40:13 +00:00
|
|
|
if(APPLE AND SANITIZER_MIN_OSX_VERSION AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9")
|
2016-08-22 18:31:37 +00:00
|
|
|
# Mac OS X prior to 10.9 had problems with exporting symbols from
|
|
|
|
# libc++/libc++abi.
|
2017-09-15 20:24:12 +00:00
|
|
|
set(cxxabi_supported OFF)
|
2016-08-22 18:31:37 +00:00
|
|
|
else()
|
2017-09-15 20:24:12 +00:00
|
|
|
set(cxxabi_supported ON)
|
2016-08-22 18:31:37 +00:00
|
|
|
endif()
|
|
|
|
|
2018-05-18 18:44:37 +00:00
|
|
|
option(SANITIZER_ALLOW_CXXABI "Allow use of C++ ABI details in ubsan" ON)
|
2017-09-15 20:24:12 +00:00
|
|
|
|
|
|
|
set(SANITIZE_CAN_USE_CXXABI OFF)
|
|
|
|
if (cxxabi_supported AND SANITIZER_ALLOW_CXXABI)
|
|
|
|
set(SANITIZER_CAN_USE_CXXABI ON)
|
|
|
|
endif()
|
2016-08-22 18:31:37 +00:00
|
|
|
pythonize_bool(SANITIZER_CAN_USE_CXXABI)
|
|
|
|
|
2019-02-16 08:34:26 +00:00
|
|
|
macro(handle_default_cxx_lib var)
|
|
|
|
if (${var} STREQUAL "default")
|
|
|
|
if (APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
|
|
|
set(${var}_LIBNAME "libc++")
|
|
|
|
set(${var}_SYSTEM 1)
|
|
|
|
elseif (FUCHSIA)
|
|
|
|
set(${var}_LIBNAME "libc++")
|
|
|
|
set(${var}_INTREE 1)
|
|
|
|
else()
|
|
|
|
set(${var}_LIBNAME "libstdc++")
|
|
|
|
set(${var}_SYSTEM 1)
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
set(${var}_LIBNAME "${${var}}")
|
|
|
|
set(${var}_SYSTEM 1)
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
# This is either directly the C++ ABI library or the full C++ library
|
|
|
|
# which pulls in the ABI transitively.
|
2017-07-28 03:39:39 +00:00
|
|
|
set(SANITIZER_CXX_ABI "default" CACHE STRING
|
|
|
|
"Specify C++ ABI library to use.")
|
2019-02-16 08:34:26 +00:00
|
|
|
set(CXXABIS none default libstdc++ libc++ libcxxabi)
|
2017-07-28 03:39:39 +00:00
|
|
|
set_property(CACHE SANITIZER_CXX_ABI PROPERTY STRINGS ;${CXXABIS})
|
2019-02-16 08:34:26 +00:00
|
|
|
handle_default_cxx_lib(SANITIZER_CXX_ABI)
|
2017-07-28 03:39:39 +00:00
|
|
|
|
2019-02-16 08:34:26 +00:00
|
|
|
# This needs to be a full C++ library for linking gtest and unit tests.
|
|
|
|
set(SANITIZER_TEST_CXX "default" CACHE STRING
|
|
|
|
"Specify C++ library to use for tests.")
|
|
|
|
set(CXXLIBS none default libstdc++ libc++)
|
|
|
|
set_property(CACHE SANITIZER_TEST_CXX PROPERTY STRINGS ;${CXXLIBS})
|
|
|
|
handle_default_cxx_lib(SANITIZER_TEST_CXX)
|
2017-07-28 03:39:39 +00:00
|
|
|
|
2019-01-31 03:38:43 +00:00
|
|
|
set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER OFF)
|
|
|
|
if (FUCHSIA)
|
|
|
|
set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER ON)
|
|
|
|
elseif (DEFINED LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_SHARED)
|
|
|
|
set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
option(SANITIZER_USE_STATIC_LLVM_UNWINDER
|
|
|
|
"Use static LLVM unwinder." ${DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER})
|
|
|
|
|
|
|
|
set(DEFAULT_SANITIZER_USE_STATIC_CXX_ABI OFF)
|
|
|
|
if (DEFINED LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_SHARED)
|
|
|
|
set(DEFAULT_SANITIZER_USE_STATIC_CXX_ABI ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
option(SANITIZER_USE_STATIC_CXX_ABI
|
|
|
|
"Use static libc++abi." ${DEFAULT_SANITIZER_USE_STATIC_CXX_ABI})
|
|
|
|
|
2018-07-15 03:05:20 +00:00
|
|
|
set(DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY OFF)
|
|
|
|
if (FUCHSIA)
|
|
|
|
set(DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY ON)
|
2018-05-22 22:58:48 +00:00
|
|
|
endif()
|
2017-07-28 03:39:38 +00:00
|
|
|
|
2018-07-15 03:05:20 +00:00
|
|
|
option(COMPILER_RT_USE_BUILTINS_LIBRARY
|
|
|
|
"Use compiler-rt builtins instead of libgcc" ${DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY})
|
|
|
|
|
2018-05-22 18:33:27 +00:00
|
|
|
include(config-ix)
|
|
|
|
|
2014-02-18 07:26:58 +00:00
|
|
|
#================================
|
|
|
|
# Setup Compiler Flags
|
|
|
|
#================================
|
2015-01-14 15:55:17 +00:00
|
|
|
|
2014-03-13 11:31:10 +00:00
|
|
|
if(MSVC)
|
2016-06-17 17:48:52 +00:00
|
|
|
# Override any existing /W flags with /W4. This is what LLVM does. Failing to
|
|
|
|
# remove other /W[0-4] flags will result in a warning about overriding a
|
|
|
|
# previous flag.
|
|
|
|
if (COMPILER_RT_HAS_W4_FLAG)
|
|
|
|
string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
|
|
|
string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
|
|
append_string_if(COMPILER_RT_HAS_W4_FLAG /W4 CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
|
|
|
endif()
|
2014-03-13 11:31:10 +00:00
|
|
|
else()
|
|
|
|
append_string_if(COMPILER_RT_HAS_WALL_FLAG -Wall CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
|
|
|
endif()
|
2014-02-24 11:22:39 +00:00
|
|
|
if(COMPILER_RT_ENABLE_WERROR)
|
2014-03-13 11:31:10 +00:00
|
|
|
append_string_if(COMPILER_RT_HAS_WERROR_FLAG -Werror CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
|
|
|
append_string_if(COMPILER_RT_HAS_WX_FLAG /WX CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
2014-02-24 11:22:39 +00:00
|
|
|
endif()
|
|
|
|
|
2014-03-18 12:49:22 +00:00
|
|
|
append_string_if(COMPILER_RT_HAS_STD_CXX11_FLAG -std=c++11 CMAKE_CXX_FLAGS)
|
|
|
|
|
2014-02-26 21:54:39 +00:00
|
|
|
# Emulate C99 and C++11's __func__ for MSVC prior to 2013 CTP.
|
2014-02-27 06:52:41 +00:00
|
|
|
if(NOT COMPILER_RT_HAS_FUNC_SYMBOL)
|
2014-02-27 07:03:32 +00:00
|
|
|
add_definitions(-D__func__=__FUNCTION__)
|
2014-02-26 21:54:39 +00:00
|
|
|
endif()
|
|
|
|
|
2014-02-18 07:26:58 +00:00
|
|
|
# Provide some common commmandline flags for Sanitizer runtimes.
|
2016-09-08 15:57:22 +00:00
|
|
|
if(NOT WIN32)
|
|
|
|
append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC SANITIZER_COMMON_CFLAGS)
|
|
|
|
endif()
|
2014-10-15 22:47:54 +00:00
|
|
|
append_list_if(COMPILER_RT_HAS_FNO_BUILTIN_FLAG -fno-builtin SANITIZER_COMMON_CFLAGS)
|
|
|
|
append_list_if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions SANITIZER_COMMON_CFLAGS)
|
2017-03-27 17:14:48 +00:00
|
|
|
if(NOT COMPILER_RT_DEBUG AND NOT APPLE)
|
2016-05-22 19:59:06 +00:00
|
|
|
append_list_if(COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG -fomit-frame-pointer SANITIZER_COMMON_CFLAGS)
|
|
|
|
endif()
|
2014-10-15 22:47:54 +00:00
|
|
|
append_list_if(COMPILER_RT_HAS_FUNWIND_TABLES_FLAG -funwind-tables SANITIZER_COMMON_CFLAGS)
|
|
|
|
append_list_if(COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG -fno-stack-protector SANITIZER_COMMON_CFLAGS)
|
2015-06-15 21:08:47 +00:00
|
|
|
append_list_if(COMPILER_RT_HAS_FNO_SANITIZE_SAFE_STACK_FLAG -fno-sanitize=safe-stack SANITIZER_COMMON_CFLAGS)
|
2014-10-15 22:47:54 +00:00
|
|
|
append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SANITIZER_COMMON_CFLAGS)
|
2017-11-28 23:41:42 +00:00
|
|
|
if(NOT COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG)
|
|
|
|
append_list_if(COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG -fvisibility-inlines-hidden SANITIZER_COMMON_CFLAGS)
|
|
|
|
endif()
|
2015-01-15 16:31:22 +00:00
|
|
|
append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS)
|
2014-02-18 07:26:58 +00:00
|
|
|
|
2017-01-30 22:31:49 +00:00
|
|
|
# The following is a workaround for powerpc64le. This is the only architecture
|
|
|
|
# that requires -fno-function-sections to work properly. If lacking, the ASan
|
|
|
|
# Linux test function-sections-are-bad.cc fails with the following error:
|
|
|
|
# 'undefined symbol: __sanitizer_unaligned_load32'.
|
|
|
|
if(DEFINED TARGET_powerpc64le_CFLAGS)
|
|
|
|
append_list_if(COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG -fno-function-sections TARGET_powerpc64le_CFLAGS)
|
|
|
|
endif()
|
|
|
|
|
2014-02-28 08:04:30 +00:00
|
|
|
if(MSVC)
|
2015-07-08 22:10:34 +00:00
|
|
|
# Replace the /M[DT][d] flags with /MT, and strip any definitions of _DEBUG,
|
|
|
|
# which cause definition mismatches at link time.
|
2014-08-12 09:44:56 +00:00
|
|
|
# FIXME: In fact, sanitizers should support both /MT and /MD, see PR20214.
|
2014-02-28 08:04:30 +00:00
|
|
|
if(COMPILER_RT_HAS_MT_FLAG)
|
2014-10-23 20:24:00 +00:00
|
|
|
foreach(flag_var
|
2016-02-20 12:56:04 +00:00
|
|
|
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
|
|
|
|
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
|
2014-10-23 20:24:00 +00:00
|
|
|
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
|
|
|
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
2015-07-08 22:10:34 +00:00
|
|
|
string(REGEX REPLACE "/M[DT]d" "/MT" ${flag_var} "${${flag_var}}")
|
|
|
|
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
|
|
|
|
string(REGEX REPLACE "/D_DEBUG" "" ${flag_var} "${${flag_var}}")
|
2014-10-23 20:24:00 +00:00
|
|
|
endforeach()
|
2014-02-28 08:04:30 +00:00
|
|
|
endif()
|
2014-10-15 22:47:54 +00:00
|
|
|
append_list_if(COMPILER_RT_HAS_Oy_FLAG /Oy- SANITIZER_COMMON_CFLAGS)
|
|
|
|
append_list_if(COMPILER_RT_HAS_GS_FLAG /GS- SANITIZER_COMMON_CFLAGS)
|
2016-03-21 20:08:59 +00:00
|
|
|
# VS 2015 (version 1900) added support for thread safe static initialization.
|
|
|
|
# However, ASan interceptors run before CRT initialization, which causes the
|
|
|
|
# new thread safe code to crash. Disable this feature for now.
|
2016-07-21 20:03:37 +00:00
|
|
|
if (MSVC_VERSION GREATER 1899 OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
2016-03-21 20:08:59 +00:00
|
|
|
list(APPEND SANITIZER_COMMON_CFLAGS /Zc:threadSafeInit-)
|
|
|
|
endif()
|
2014-02-28 08:04:30 +00:00
|
|
|
endif()
|
2014-02-18 07:26:58 +00:00
|
|
|
|
2015-01-06 20:25:34 +00:00
|
|
|
append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 SANITIZER_COMMON_CFLAGS)
|
2015-01-03 04:29:12 +00:00
|
|
|
|
2017-07-15 00:30:46 +00:00
|
|
|
# If we're using MSVC,
|
2014-03-13 13:37:07 +00:00
|
|
|
# always respect the optimization flags set by CMAKE_BUILD_TYPE instead.
|
2017-07-15 00:30:46 +00:00
|
|
|
if (NOT MSVC)
|
|
|
|
|
2017-09-15 22:10:46 +00:00
|
|
|
# Build with optimization, unless we're in debug mode.
|
2017-07-15 00:30:46 +00:00
|
|
|
if(COMPILER_RT_DEBUG)
|
|
|
|
list(APPEND SANITIZER_COMMON_CFLAGS -O0)
|
|
|
|
else()
|
|
|
|
list(APPEND SANITIZER_COMMON_CFLAGS -O3)
|
|
|
|
endif()
|
2012-11-08 14:49:28 +00:00
|
|
|
endif()
|
2014-02-18 07:26:58 +00:00
|
|
|
|
2015-01-03 04:29:12 +00:00
|
|
|
# Determine if we should restrict stack frame sizes.
|
2015-04-10 09:45:22 +00:00
|
|
|
# Stack frames on PowerPC and Mips and in debug biuld can be much larger than
|
2015-01-03 04:29:12 +00:00
|
|
|
# anticipated.
|
|
|
|
# FIXME: Fix all sanitizers and add -Wframe-larger-than to
|
|
|
|
# SANITIZER_COMMON_FLAGS
|
|
|
|
if(COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG AND NOT COMPILER_RT_DEBUG
|
2015-09-08 23:13:47 +00:00
|
|
|
AND NOT ${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "powerpc|mips")
|
2015-01-03 04:29:12 +00:00
|
|
|
set(SANITIZER_LIMIT_FRAME_SIZE TRUE)
|
|
|
|
else()
|
|
|
|
set(SANITIZER_LIMIT_FRAME_SIZE FALSE)
|
|
|
|
endif()
|
|
|
|
|
2018-05-09 21:24:06 +00:00
|
|
|
if(FUCHSIA OR UNIX)
|
|
|
|
set(SANITIZER_USE_SYMBOLS TRUE)
|
|
|
|
else()
|
|
|
|
set(SANITIZER_USE_SYMBOLS FALSE)
|
|
|
|
endif()
|
|
|
|
|
2014-02-18 07:26:58 +00:00
|
|
|
# Build sanitizer runtimes with debug info.
|
2018-04-26 20:34:19 +00:00
|
|
|
if(MSVC)
|
2016-08-02 01:02:46 +00:00
|
|
|
# Use /Z7 instead of /Zi for the asan runtime. This avoids the LNK4099
|
|
|
|
# warning from the MS linker complaining that it can't find the 'vc140.pdb'
|
|
|
|
# file used by our object library compilations.
|
|
|
|
list(APPEND SANITIZER_COMMON_CFLAGS /Z7)
|
2019-03-01 22:30:17 +00:00
|
|
|
foreach(var_to_update
|
|
|
|
CMAKE_CXX_FLAGS
|
|
|
|
CMAKE_CXX_FLAGS_DEBUG
|
|
|
|
CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
|
|
|
string(REGEX REPLACE "(^| )/Z[i7I]($| )" " /Z7 "
|
|
|
|
"${var_to_update}" "${${var_to_update}}")
|
|
|
|
endforeach()
|
2018-04-26 20:34:19 +00:00
|
|
|
elseif(COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG AND NOT COMPILER_RT_DEBUG)
|
|
|
|
list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only)
|
|
|
|
elseif(COMPILER_RT_HAS_G_FLAG)
|
|
|
|
list(APPEND SANITIZER_COMMON_CFLAGS -g)
|
2013-03-25 10:31:49 +00:00
|
|
|
endif()
|
2014-02-18 07:26:58 +00:00
|
|
|
|
2016-10-08 09:01:27 +00:00
|
|
|
if(LLVM_ENABLE_MODULES)
|
|
|
|
# Sanitizers cannot be built with -fmodules. The interceptors intentionally
|
|
|
|
# don't include system headers, which is incompatible with modules.
|
|
|
|
list(APPEND SANITIZER_COMMON_CFLAGS -fno-modules)
|
|
|
|
endif()
|
|
|
|
|
2014-02-18 07:26:58 +00:00
|
|
|
# Turn off several warnings.
|
2014-11-13 21:19:53 +00:00
|
|
|
append_list_if(COMPILER_RT_HAS_WGNU_FLAG -Wno-gnu SANITIZER_COMMON_CFLAGS)
|
|
|
|
append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros SANITIZER_COMMON_CFLAGS)
|
|
|
|
append_list_if(COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG -Wno-c99-extensions SANITIZER_COMMON_CFLAGS)
|
|
|
|
append_list_if(COMPILER_RT_HAS_WNON_VIRTUAL_DTOR_FLAG -Wno-non-virtual-dtor SANITIZER_COMMON_CFLAGS)
|
2014-10-23 20:39:58 +00:00
|
|
|
append_list_if(COMPILER_RT_HAS_WD4146_FLAG /wd4146 SANITIZER_COMMON_CFLAGS)
|
|
|
|
append_list_if(COMPILER_RT_HAS_WD4291_FLAG /wd4291 SANITIZER_COMMON_CFLAGS)
|
2014-10-15 22:47:54 +00:00
|
|
|
append_list_if(COMPILER_RT_HAS_WD4391_FLAG /wd4391 SANITIZER_COMMON_CFLAGS)
|
|
|
|
append_list_if(COMPILER_RT_HAS_WD4722_FLAG /wd4722 SANITIZER_COMMON_CFLAGS)
|
2014-10-23 20:39:58 +00:00
|
|
|
append_list_if(COMPILER_RT_HAS_WD4800_FLAG /wd4800 SANITIZER_COMMON_CFLAGS)
|
2012-08-29 00:13:11 +00:00
|
|
|
|
2018-09-26 06:53:01 +00:00
|
|
|
append_list_if(MINGW -fms-extensions SANITIZER_COMMON_CFLAGS)
|
|
|
|
|
2017-07-28 03:39:38 +00:00
|
|
|
# Set common link flags.
|
|
|
|
append_list_if(COMPILER_RT_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs SANITIZER_COMMON_LINK_FLAGS)
|
2019-03-01 01:45:01 +00:00
|
|
|
append_list_if(COMPILER_RT_HAS_Z_TEXT -Wl,-z,text SANITIZER_COMMON_LINK_FLAGS)
|
2017-07-28 03:39:38 +00:00
|
|
|
|
2018-07-15 03:05:20 +00:00
|
|
|
if (COMPILER_RT_USE_BUILTINS_LIBRARY)
|
2017-07-28 03:39:38 +00:00
|
|
|
list(APPEND SANITIZER_COMMON_LINK_LIBS ${COMPILER_RT_BUILTINS_LIBRARY})
|
2018-10-29 22:16:56 +00:00
|
|
|
string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
|
2017-07-28 03:39:38 +00:00
|
|
|
else()
|
2017-07-31 22:46:43 +00:00
|
|
|
if (ANDROID)
|
|
|
|
append_list_if(COMPILER_RT_HAS_GCC_LIB gcc SANITIZER_COMMON_LINK_LIBS)
|
|
|
|
else()
|
|
|
|
append_list_if(COMPILER_RT_HAS_GCC_S_LIB gcc_s SANITIZER_COMMON_LINK_LIBS)
|
|
|
|
endif()
|
2017-07-28 03:39:38 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
append_list_if(COMPILER_RT_HAS_LIBC c SANITIZER_COMMON_LINK_LIBS)
|
|
|
|
|
2017-08-01 22:22:25 +00:00
|
|
|
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
|
|
|
|
list(APPEND SANITIZER_COMMON_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro)
|
2017-09-13 01:18:15 +00:00
|
|
|
list(APPEND SANITIZER_COMMON_LINK_LIBS zircon)
|
2017-08-01 22:22:25 +00:00
|
|
|
endif()
|
|
|
|
|
2019-02-16 08:34:26 +00:00
|
|
|
macro(append_libcxx_libs var)
|
|
|
|
if (${var}_INTREE)
|
2019-01-31 03:38:43 +00:00
|
|
|
if (SANITIZER_USE_STATIC_LLVM_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND))
|
2019-02-16 08:34:26 +00:00
|
|
|
list(APPEND ${var}_LIBRARIES unwind_static)
|
2019-01-31 03:38:43 +00:00
|
|
|
elseif (TARGET unwind_shared OR HAVE_LIBUNWIND)
|
2019-02-16 08:34:26 +00:00
|
|
|
list(APPEND ${var}_LIBRARIES unwind_shared)
|
2018-05-22 18:33:27 +00:00
|
|
|
endif()
|
2019-01-31 03:38:43 +00:00
|
|
|
|
|
|
|
if (SANITIZER_USE_STATIC_CXX_ABI AND (TARGET cxxabi_static OR HAVE_LIBCXXABI))
|
2019-02-16 08:34:26 +00:00
|
|
|
list(APPEND ${var}_LIBRARIES cxxabi_static)
|
2019-01-31 03:38:43 +00:00
|
|
|
elseif (TARGET cxxabi_shared OR HAVE_LIBCXXABI)
|
2019-02-16 08:34:26 +00:00
|
|
|
list(APPEND ${var}_LIBRARIES cxxabi_shared)
|
2018-05-22 18:33:27 +00:00
|
|
|
endif()
|
|
|
|
else()
|
2019-02-16 08:34:26 +00:00
|
|
|
append_list_if(COMPILER_RT_HAS_LIBCXX c++ ${var}_LIBRARIES)
|
2018-05-22 18:33:27 +00:00
|
|
|
endif()
|
2019-02-16 08:34:26 +00:00
|
|
|
endmacro()
|
|
|
|
|
|
|
|
if (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libc++")
|
|
|
|
append_libcxx_libs(SANITIZER_CXX_ABI)
|
Add libcxxabi option back for sanitizer use.
Summary:
A prior refactoring accidentally dropped the case for using libc++abi as
the out-of-tree C++ runtime library for sanitizers. This patch restores
that functionality, which is used by Android, which can't depend on the
full libc++ for these libraries.
Reviewers: phosek, EricWF
Reviewed By: phosek
Subscribers: meikeb, kongyi, chh, mgorny, delcypher, llvm-commits, #sanitizers, pirama
Differential Revision: https://reviews.llvm.org/D49157
llvm-svn: 336749
2018-07-11 00:50:03 +00:00
|
|
|
elseif (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libcxxabi")
|
2019-02-16 08:34:26 +00:00
|
|
|
list(APPEND SANITIZER_CXX_ABI_LIBRARIES "c++abi")
|
2018-05-22 18:33:27 +00:00
|
|
|
elseif (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libstdc++")
|
2019-02-16 08:34:26 +00:00
|
|
|
append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_CXX_ABI_LIBRARIES)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libc++")
|
|
|
|
append_libcxx_libs(SANITIZER_TEST_CXX)
|
|
|
|
elseif (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libstdc++")
|
|
|
|
append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_TEST_CXX_LIBRARIES)
|
2018-05-22 18:33:27 +00:00
|
|
|
endif()
|
|
|
|
|
2016-06-17 18:30:37 +00:00
|
|
|
# Warnings to turn off for all libraries, not just sanitizers.
|
|
|
|
append_string_if(COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG -Wno-unused-parameter CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
|
|
|
|
2017-01-04 21:40:00 +00:00
|
|
|
if (CMAKE_LINKER MATCHES "link.exe$")
|
|
|
|
# Silence MSVC linker warnings caused by empty object files. The
|
|
|
|
# sanitizer libraries intentionally use ifdefs that result in empty
|
|
|
|
# files, rather than skipping these files in the build system.
|
|
|
|
# Ideally, we would pass this flag only for the libraries that need
|
|
|
|
# it, but CMake doesn't seem to have a way to set linker flags for
|
|
|
|
# individual static libraries, so we enable the suppression flag for
|
|
|
|
# the whole compiler-rt project.
|
2018-03-19 18:22:35 +00:00
|
|
|
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /IGNORE:4221")
|
2017-01-04 21:40:00 +00:00
|
|
|
endif()
|
|
|
|
|
2013-04-11 15:49:52 +00:00
|
|
|
add_subdirectory(include)
|
|
|
|
|
2019-01-14 20:33:30 +00:00
|
|
|
option(COMPILER_RT_USE_LIBCXX
|
|
|
|
"Enable compiler-rt to use libc++ from the source tree" ON)
|
|
|
|
if(COMPILER_RT_USE_LIBCXX)
|
|
|
|
foreach(path IN ITEMS ${LLVM_MAIN_SRC_DIR}/projects/libcxx
|
|
|
|
${LLVM_MAIN_SRC_DIR}/runtimes/libcxx
|
|
|
|
${LLVM_MAIN_SRC_DIR}/../libcxx
|
|
|
|
${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR})
|
|
|
|
if(IS_DIRECTORY ${path})
|
|
|
|
set(COMPILER_RT_LIBCXX_PATH ${path})
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-02-17 12:16:20 +00:00
|
|
|
foreach(path IN ITEMS ${LLVM_MAIN_SRC_DIR}/projects/libcxxabi
|
|
|
|
${LLVM_MAIN_SRC_DIR}/runtimes/libcxxabi
|
|
|
|
${LLVM_MAIN_SRC_DIR}/../libcxxabi
|
|
|
|
${LLVM_EXTERNAL_LIBCXXABI_SOURCE_DIR})
|
|
|
|
if(IS_DIRECTORY ${path})
|
|
|
|
set(COMPILER_RT_LIBCXXABI_PATH ${path})
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-01-14 20:33:30 +00:00
|
|
|
endif()
|
2014-02-14 13:02:58 +00:00
|
|
|
|
2017-09-13 20:49:25 +00:00
|
|
|
set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/tools/lld)
|
|
|
|
if(EXISTS ${COMPILER_RT_LLD_PATH}/ AND LLVM_TOOL_LLD_BUILD)
|
|
|
|
set(COMPILER_RT_HAS_LLD TRUE)
|
|
|
|
else()
|
|
|
|
set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/../lld)
|
|
|
|
if(EXISTS ${COMPILER_RT_LLD_PATH}/ AND LLVM_TOOL_LLD_BUILD)
|
|
|
|
set(COMPILER_RT_HAS_LLD TRUE)
|
|
|
|
else()
|
|
|
|
set(COMPILER_RT_HAS_LLD FALSE)
|
|
|
|
endif()
|
2015-08-11 00:33:07 +00:00
|
|
|
endif()
|
2017-03-25 00:42:25 +00:00
|
|
|
pythonize_bool(COMPILER_RT_HAS_LLD)
|
2015-08-11 00:33:07 +00:00
|
|
|
|
2012-04-04 22:12:04 +00:00
|
|
|
add_subdirectory(lib)
|
|
|
|
|
2014-02-19 11:18:47 +00:00
|
|
|
if(COMPILER_RT_INCLUDE_TESTS)
|
2014-02-14 11:00:07 +00:00
|
|
|
add_subdirectory(unittests)
|
2015-09-14 19:54:12 +00:00
|
|
|
add_subdirectory(test)
|
2017-09-15 22:10:46 +00:00
|
|
|
if (COMPILER_RT_STANDALONE_BUILD)
|
|
|
|
# If we have a valid source tree, generate llvm-lit into the bin directory.
|
|
|
|
# The user can still choose to have the check targets *use* a different lit
|
|
|
|
# by specifying -DLLVM_EXTERNAL_LIT, but we generate it regardless.
|
|
|
|
if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
|
|
|
|
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)
|
|
|
|
elseif(NOT EXISTS ${LLVM_EXTERNAL_LIT})
|
|
|
|
message(WARNING "Could not find LLVM source directory and LLVM_EXTERNAL_LIT does not"
|
|
|
|
"point to a valid file. You will not be able to run tests.")
|
|
|
|
endif()
|
|
|
|
endif()
|
2012-04-04 22:12:04 +00:00
|
|
|
endif()
|