forked from OSchip/llvm-project
[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
This commit is contained in:
parent
78db5a9dca
commit
c49e5e336b
|
@ -46,51 +46,20 @@ else()
|
|||
endif()
|
||||
endif()
|
||||
|
||||
# Top level target used to build all compiler-rt libraries.
|
||||
add_custom_target(compiler-rt ALL)
|
||||
# Add path for custom compiler-rt modules.
|
||||
list(INSERT CMAKE_MODULE_PATH 0
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
|
||||
)
|
||||
|
||||
include(base-config-ix)
|
||||
|
||||
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)
|
||||
|
||||
if (NOT COMPILER_RT_STANDALONE_BUILD)
|
||||
# Compute the Clang version from the LLVM version.
|
||||
# FIXME: We should be able to reuse CLANG_VERSION variable calculated
|
||||
# in Clang cmake files, instead of copying the rules here.
|
||||
string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
|
||||
${PACKAGE_VERSION})
|
||||
# Setup the paths where compiler-rt runtimes and headers should be stored.
|
||||
set(COMPILER_RT_OUTPUT_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION})
|
||||
set(COMPILER_RT_EXEC_OUTPUT_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
|
||||
set(COMPILER_RT_INSTALL_PATH lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION})
|
||||
option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests."
|
||||
${LLVM_INCLUDE_TESTS})
|
||||
option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered"
|
||||
${LLVM_ENABLE_WERROR})
|
||||
# Use just-built Clang to compile/link tests on all platforms, except for
|
||||
# Windows where we need to use clang-cl instead.
|
||||
if(NOT MSVC)
|
||||
set(COMPILER_RT_TEST_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
|
||||
set(COMPILER_RT_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
|
||||
else()
|
||||
set(COMPILER_RT_TEST_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe)
|
||||
set(COMPILER_RT_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
|
||||
endif()
|
||||
else()
|
||||
# Take output dir and install path from the user.
|
||||
set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH
|
||||
"Path where built compiler-rt libraries should be stored.")
|
||||
set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH
|
||||
"Path where built compiler-rt executables should be stored.")
|
||||
set(COMPILER_RT_INSTALL_PATH ${CMAKE_INSTALL_PREFIX} CACHE PATH
|
||||
"Path where built compiler-rt libraries should be installed.")
|
||||
option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests." OFF)
|
||||
option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered" OFF)
|
||||
# Use a host compiler to compile/link tests.
|
||||
set(COMPILER_RT_TEST_COMPILER ${CMAKE_C_COMPILER} CACHE PATH "Compiler to use for testing")
|
||||
set(COMPILER_RT_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE PATH "C++ Compiler to use for testing")
|
||||
|
||||
if (COMPILER_RT_STANDALONE_BUILD)
|
||||
if (NOT LLVM_CONFIG_PATH)
|
||||
find_program(LLVM_CONFIG_PATH "llvm-config"
|
||||
DOC "Path to llvm-config binary")
|
||||
|
@ -138,14 +107,6 @@ else()
|
|||
set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
|
||||
endif()
|
||||
|
||||
if("${COMPILER_RT_TEST_COMPILER}" MATCHES "clang[+]*$")
|
||||
set(COMPILER_RT_TEST_COMPILER_ID Clang)
|
||||
elseif("${COMPILER_RT_TEST_COMPILER}" MATCHES "clang.*.exe$")
|
||||
set(COMPILER_RT_TEST_COMPILER_ID Clang)
|
||||
else()
|
||||
set(COMPILER_RT_TEST_COMPILER_ID GNU)
|
||||
endif()
|
||||
|
||||
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${TARGET_TRIPLE} CACHE STRING
|
||||
"Default triple for which compiler-rt runtimes will be built.")
|
||||
if(DEFINED COMPILER_RT_TEST_TARGET_TRIPLE)
|
||||
|
@ -165,23 +126,6 @@ if(NOT COMPILER_RT_DEFAULT_TARGET_TRIPLE STREQUAL TARGET_TRIPLE)
|
|||
else()
|
||||
set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE FALSE)
|
||||
endif()
|
||||
|
||||
if ("${COMPILER_RT_DEFAULT_TARGET_ABI}" STREQUAL "androideabi")
|
||||
set(ANDROID 1)
|
||||
endif()
|
||||
|
||||
string(TOLOWER ${CMAKE_SYSTEM_NAME} COMPILER_RT_OS_DIR)
|
||||
set(COMPILER_RT_LIBRARY_OUTPUT_DIR
|
||||
${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR})
|
||||
set(COMPILER_RT_LIBRARY_INSTALL_DIR
|
||||
${COMPILER_RT_INSTALL_PATH}/lib/${COMPILER_RT_OS_DIR})
|
||||
|
||||
# Add path for custom compiler-rt modules.
|
||||
set(CMAKE_MODULE_PATH
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
|
||||
${CMAKE_MODULE_PATH}
|
||||
)
|
||||
include(CompilerRTUtils)
|
||||
|
||||
set(COMPILER_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
@ -206,8 +150,6 @@ pythonize_bool(COMPILER_RT_DEBUG)
|
|||
#================================
|
||||
# Setup Compiler Flags
|
||||
#================================
|
||||
include(CheckIncludeFile)
|
||||
check_include_file(unwind.h HAVE_UNWIND_H)
|
||||
|
||||
include(config-ix)
|
||||
|
||||
|
|
|
@ -0,0 +1,162 @@
|
|||
# The CompilerRT build system requires CMake version 2.8.8 or higher in order
|
||||
# to use its support for building convenience "libraries" as a collection of
|
||||
# .o files. This is particularly useful in producing larger, more complex
|
||||
# runtime libraries.
|
||||
|
||||
include(CheckIncludeFile)
|
||||
check_include_file(unwind.h HAVE_UNWIND_H)
|
||||
|
||||
# Top level target used to build all compiler-rt libraries.
|
||||
add_custom_target(compiler-rt ALL)
|
||||
|
||||
if (NOT COMPILER_RT_STANDALONE_BUILD)
|
||||
# Compute the Clang version from the LLVM version.
|
||||
# FIXME: We should be able to reuse CLANG_VERSION variable calculated
|
||||
# in Clang cmake files, instead of copying the rules here.
|
||||
string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
|
||||
${PACKAGE_VERSION})
|
||||
# Setup the paths where compiler-rt runtimes and headers should be stored.
|
||||
set(COMPILER_RT_OUTPUT_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION})
|
||||
set(COMPILER_RT_EXEC_OUTPUT_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
|
||||
set(COMPILER_RT_INSTALL_PATH lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION})
|
||||
option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests."
|
||||
${LLVM_INCLUDE_TESTS})
|
||||
option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered"
|
||||
${LLVM_ENABLE_WERROR})
|
||||
# Use just-built Clang to compile/link tests on all platforms, except for
|
||||
# Windows where we need to use clang-cl instead.
|
||||
if(NOT MSVC)
|
||||
set(COMPILER_RT_TEST_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
|
||||
set(COMPILER_RT_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
|
||||
else()
|
||||
set(COMPILER_RT_TEST_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe)
|
||||
set(COMPILER_RT_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
|
||||
endif()
|
||||
else()
|
||||
# Take output dir and install path from the user.
|
||||
set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH
|
||||
"Path where built compiler-rt libraries should be stored.")
|
||||
set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH
|
||||
"Path where built compiler-rt executables should be stored.")
|
||||
set(COMPILER_RT_INSTALL_PATH ${CMAKE_INSTALL_PREFIX} CACHE PATH
|
||||
"Path where built compiler-rt libraries should be installed.")
|
||||
option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests." OFF)
|
||||
option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered" OFF)
|
||||
# Use a host compiler to compile/link tests.
|
||||
set(COMPILER_RT_TEST_COMPILER ${CMAKE_C_COMPILER} CACHE PATH "Compiler to use for testing")
|
||||
set(COMPILER_RT_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE PATH "C++ Compiler to use for testing")
|
||||
endif()
|
||||
|
||||
if("${COMPILER_RT_TEST_COMPILER}" MATCHES "clang[+]*$")
|
||||
set(COMPILER_RT_TEST_COMPILER_ID Clang)
|
||||
elseif("${COMPILER_RT_TEST_COMPILER}" MATCHES "clang.*.exe$")
|
||||
set(COMPILER_RT_TEST_COMPILER_ID Clang)
|
||||
else()
|
||||
set(COMPILER_RT_TEST_COMPILER_ID GNU)
|
||||
endif()
|
||||
|
||||
if ("${COMPILER_RT_DEFAULT_TARGET_ABI}" STREQUAL "androideabi")
|
||||
set(ANDROID 1)
|
||||
endif()
|
||||
|
||||
string(TOLOWER ${CMAKE_SYSTEM_NAME} COMPILER_RT_OS_DIR)
|
||||
set(COMPILER_RT_LIBRARY_OUTPUT_DIR
|
||||
${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR})
|
||||
set(COMPILER_RT_LIBRARY_INSTALL_DIR
|
||||
${COMPILER_RT_INSTALL_PATH}/lib/${COMPILER_RT_OS_DIR})
|
||||
|
||||
if(APPLE)
|
||||
# On Darwin if /usr/include doesn't exist, the user probably has Xcode but not
|
||||
# the command line tools. If this is the case, we need to find the OS X
|
||||
# sysroot to pass to clang.
|
||||
if(NOT EXISTS /usr/include)
|
||||
execute_process(COMMAND xcodebuild -version -sdk macosx Path
|
||||
OUTPUT_VARIABLE OSX_SYSROOT
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
set(OSX_SYSROOT_FLAG "-isysroot${OSX_SYSROOT}")
|
||||
endif()
|
||||
|
||||
option(COMPILER_RT_ENABLE_IOS "Enable building for iOS" Off)
|
||||
option(COMPILER_RT_ENABLE_WATCHOS "Enable building for watchOS - Experimental" Off)
|
||||
option(COMPILER_RT_ENABLE_TVOS "Enable building for tvOS - Experimental" Off)
|
||||
endif()
|
||||
|
||||
macro(test_targets)
|
||||
# Find and run MSVC (not clang-cl) and get its version. This will tell clang-cl
|
||||
# what version of MSVC to pretend to be so that the STL works.
|
||||
set(MSVC_VERSION_FLAG "")
|
||||
if (MSVC)
|
||||
# Find and run MSVC (not clang-cl) and get its version. This will tell
|
||||
# clang-cl what version of MSVC to pretend to be so that the STL works.
|
||||
execute_process(COMMAND "$ENV{VSINSTALLDIR}/VC/bin/cl.exe"
|
||||
OUTPUT_QUIET
|
||||
ERROR_VARIABLE MSVC_COMPAT_VERSION
|
||||
)
|
||||
string(REGEX REPLACE "^.*Compiler Version ([0-9.]+) for .*$" "\\1"
|
||||
MSVC_COMPAT_VERSION "${MSVC_COMPAT_VERSION}")
|
||||
if (MSVC_COMPAT_VERSION MATCHES "^[0-9].+$")
|
||||
set(MSVC_VERSION_FLAG "-fms-compatibility-version=${MSVC_COMPAT_VERSION}")
|
||||
# Add this flag into the host build if this is clang-cl.
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
append("${MSVC_VERSION_FLAG}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Generate the COMPILER_RT_SUPPORTED_ARCH list.
|
||||
if(ANDROID)
|
||||
# Examine compiler output to determine target architecture.
|
||||
detect_target_arch()
|
||||
set(COMPILER_RT_OS_SUFFIX "-android")
|
||||
elseif(NOT APPLE) # Supported archs for Apple platforms are generated later
|
||||
if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "i[2-6]86|x86|amd64")
|
||||
if(NOT MSVC)
|
||||
test_target_arch(x86_64 "" "-m64")
|
||||
# FIXME: We build runtimes for both i686 and i386, as "clang -m32" may
|
||||
# target different variant than "$CMAKE_C_COMPILER -m32". This part should
|
||||
# be gone after we resolve PR14109.
|
||||
test_target_arch(i686 __i686__ "-m32")
|
||||
test_target_arch(i386 __i386__ "-m32")
|
||||
else()
|
||||
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
test_target_arch(i386 "" "${MSVC_VERSION_FLAG}")
|
||||
else()
|
||||
test_target_arch(x86_64 "" "${MSVC_VERSION_FLAG}")
|
||||
endif()
|
||||
endif()
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc")
|
||||
TEST_BIG_ENDIAN(HOST_IS_BIG_ENDIAN)
|
||||
if(HOST_IS_BIG_ENDIAN)
|
||||
test_target_arch(powerpc64 "" "-m64")
|
||||
else()
|
||||
test_target_arch(powerpc64le "" "-m64")
|
||||
endif()
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
|
||||
test_target_arch(s390x "" "")
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mipsel|mips64el")
|
||||
# Gcc doesn't accept -m32/-m64 so we do the next best thing and use
|
||||
# -mips32r2/-mips64r2. We don't use -mips1/-mips3 because we want to match
|
||||
# clang's default CPU's. In the 64-bit case, we must also specify the ABI
|
||||
# since the default ABI differs between gcc and clang.
|
||||
# FIXME: Ideally, we would build the N32 library too.
|
||||
test_target_arch(mipsel "" "-mips32r2" "--target=mipsel-linux-gnu")
|
||||
test_target_arch(mips64el "" "-mips64r2" "--target=mips64el-linux-gnu" "-mabi=n64")
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mips")
|
||||
test_target_arch(mips "" "-mips32r2" "--target=mips-linux-gnu")
|
||||
test_target_arch(mips64 "" "-mips64r2" "--target=mips64-linux-gnu" "-mabi=n64")
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "arm")
|
||||
test_target_arch(arm "" "-march=armv7-a" "-mfloat-abi=soft")
|
||||
test_target_arch(armhf "" "-march=armv7-a" "-mfloat-abi=hard")
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch32")
|
||||
test_target_arch(aarch32 "" "-march=armv8-a")
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch64")
|
||||
test_target_arch(aarch64 "" "-march=armv8-a")
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "wasm32")
|
||||
test_target_arch(wasm32 "" "--target=wasm32-unknown-unknown")
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "wasm64")
|
||||
test_target_arch(wasm64 "" "--target=wasm64-unknown-unknown")
|
||||
endif()
|
||||
set(COMPILER_RT_OS_SUFFIX "")
|
||||
endif()
|
||||
endmacro()
|
|
@ -0,0 +1,169 @@
|
|||
include(BuiltinTests)
|
||||
|
||||
# Make all the tests only check the compiler
|
||||
set(TEST_COMPILE_ONLY On)
|
||||
|
||||
builtin_check_c_compiler_flag(-fPIC COMPILER_RT_HAS_FPIC_FLAG)
|
||||
builtin_check_c_compiler_flag(-fPIE COMPILER_RT_HAS_FPIE_FLAG)
|
||||
builtin_check_c_compiler_flag(-fno-builtin COMPILER_RT_HAS_FNO_BUILTIN_FLAG)
|
||||
builtin_check_c_compiler_flag(-std=c99 COMPILER_RT_HAS_STD_C99_FLAG)
|
||||
builtin_check_c_compiler_flag(-fvisibility=hidden COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG)
|
||||
builtin_check_c_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG)
|
||||
builtin_check_c_compiler_flag(-ffreestanding COMPILER_RT_HAS_FREESTANDING_FLAG)
|
||||
builtin_check_c_compiler_flag(-mfloat-abi=soft COMPILER_RT_HAS_FLOAT_ABI_SOFT_FLAG)
|
||||
builtin_check_c_compiler_flag(-mfloat-abi=hard COMPILER_RT_HAS_FLOAT_ABI_HARD_FLAG)
|
||||
builtin_check_c_compiler_flag(-static COMPILER_RT_HAS_STATIC_FLAG)
|
||||
|
||||
set(ARM64 aarch64)
|
||||
set(ARM32 arm armhf)
|
||||
set(X86 i386 i686)
|
||||
set(X86_64 x86_64)
|
||||
set(MIPS32 mips mipsel)
|
||||
set(MIPS64 mips64 mips64el)
|
||||
set(PPC64 powerpc64 powerpc64le)
|
||||
set(WASM32 wasm32)
|
||||
set(WASM64 wasm64)
|
||||
|
||||
if(APPLE)
|
||||
set(ARM64 arm64)
|
||||
set(ARM32 armv7 armv7k armv7s)
|
||||
set(X86_64 x86_64 x86_64h)
|
||||
endif()
|
||||
|
||||
set(ALL_BUILTIN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
|
||||
${MIPS32} ${MIPS64} ${WASM32} ${WASM64})
|
||||
|
||||
include(CompilerRTUtils)
|
||||
include(CompilerRTDarwinUtils)
|
||||
|
||||
if(APPLE)
|
||||
|
||||
find_darwin_sdk_dir(DARWIN_osx_SYSROOT macosx)
|
||||
find_darwin_sdk_dir(DARWIN_iossim_SYSROOT iphonesimulator)
|
||||
find_darwin_sdk_dir(DARWIN_ios_SYSROOT iphoneos)
|
||||
find_darwin_sdk_dir(DARWIN_watchossim_SYSROOT watchsimulator)
|
||||
find_darwin_sdk_dir(DARWIN_watchos_SYSROOT watchos)
|
||||
find_darwin_sdk_dir(DARWIN_tvossim_SYSROOT appletvsimulator)
|
||||
find_darwin_sdk_dir(DARWIN_tvos_SYSROOT appletvos)
|
||||
|
||||
set(DARWIN_EMBEDDED_PLATFORMS)
|
||||
set(DARWIN_osx_BUILTIN_MIN_VER 10.5)
|
||||
set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
|
||||
-mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
|
||||
|
||||
if(COMPILER_RT_ENABLE_IOS)
|
||||
list(APPEND DARWIN_EMBEDDED_PLATFORMS ios)
|
||||
set(DARWIN_ios_MIN_VER_FLAG -miphoneos-version-min)
|
||||
set(DARWIN_ios_BUILTIN_MIN_VER 6.0)
|
||||
set(DARWIN_ios_BUILTIN_MIN_VER_FLAG
|
||||
${DARWIN_ios_MIN_VER_FLAG}=${DARWIN_ios_BUILTIN_MIN_VER})
|
||||
endif()
|
||||
if(COMPILER_RT_ENABLE_WATCHOS)
|
||||
list(APPEND DARWIN_EMBEDDED_PLATFORMS watchos)
|
||||
set(DARWIN_watchos_MIN_VER_FLAG -mwatchos-version-min)
|
||||
set(DARWIN_watchos_BUILTIN_MIN_VER 2.0)
|
||||
set(DARWIN_watchos_BUILTIN_MIN_VER_FLAG
|
||||
${DARWIN_watchos_MIN_VER_FLAG}=${DARWIN_watchos_BUILTIN_MIN_VER})
|
||||
endif()
|
||||
if(COMPILER_RT_ENABLE_TVOS)
|
||||
list(APPEND DARWIN_EMBEDDED_PLATFORMS tvos)
|
||||
set(DARWIN_tvos_MIN_VER_FLAG -mtvos-version-min)
|
||||
set(DARWIN_tvos_BUILTIN_MIN_VER 9.0)
|
||||
set(DARWIN_tvos_BUILTIN_MIN_VER_FLAG
|
||||
${DARWIN_tvos_MIN_VER_FLAG}=${DARWIN_tvos_BUILTIN_MIN_VER})
|
||||
endif()
|
||||
|
||||
set(BUILTIN_SUPPORTED_OS osx)
|
||||
|
||||
# We're setting the flag manually for each target OS
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "")
|
||||
|
||||
if(NOT DARWIN_osx_ARCHS)
|
||||
set(DARWIN_osx_ARCHS i386 x86_64 x86_64h)
|
||||
endif()
|
||||
|
||||
set(DARWIN_sim_ARCHS i386 x86_64)
|
||||
set(DARWIN_device_ARCHS armv7 armv7s armv7k arm64)
|
||||
|
||||
message(STATUS "OSX supported arches: ${DARWIN_osx_ARCHS}")
|
||||
foreach(arch ${DARWIN_osx_ARCHS})
|
||||
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
|
||||
set(CAN_TARGET_${arch} 1)
|
||||
endforeach()
|
||||
|
||||
# Need to build a 10.4 compatible libclang_rt
|
||||
set(DARWIN_10.4_SYSROOT ${DARWIN_osx_SYSROOT})
|
||||
set(DARWIN_10.4_BUILTIN_MIN_VER 10.4)
|
||||
set(DARWIN_10.4_BUILTIN_MIN_VER_FLAG
|
||||
-mmacosx-version-min=${DARWIN_10.4_BUILTIN_MIN_VER})
|
||||
set(DARWIN_10.4_SKIP_CC_KEXT On)
|
||||
darwin_test_archs(10.4 DARWIN_10.4_ARCHS i386 x86_64)
|
||||
message(STATUS "OSX 10.4 supported builtin arches: ${DARWIN_10.4_ARCHS}")
|
||||
if(DARWIN_10.4_ARCHS)
|
||||
# don't include the Haswell slice in the 10.4 compatibility library
|
||||
list(REMOVE_ITEM DARWIN_10.4_ARCHS x86_64h)
|
||||
list(APPEND BUILTIN_SUPPORTED_OS 10.4)
|
||||
endif()
|
||||
|
||||
foreach(platform ${DARWIN_EMBEDDED_PLATFORMS})
|
||||
if(DARWIN_${platform}sim_SYSROOT)
|
||||
set(DARWIN_${platform}sim_BUILTIN_MIN_VER
|
||||
${DARWIN_${platform}_BUILTIN_MIN_VER})
|
||||
set(DARWIN_${platform}sim_BUILTIN_MIN_VER_FLAG
|
||||
${DARWIN_${platform}_BUILTIN_MIN_VER_FLAG})
|
||||
|
||||
set(DARWIN_${platform}sim_SKIP_CC_KEXT On)
|
||||
|
||||
set(test_arches ${DARWIN_sim_ARCHS})
|
||||
if(DARWIN_${platform}sim_ARCHS)
|
||||
set(test_arches DARWIN_${platform}sim_ARCHS)
|
||||
endif()
|
||||
|
||||
darwin_test_archs(${platform}sim
|
||||
DARWIN_${platform}sim_ARCHS
|
||||
${test_arches})
|
||||
message(STATUS "${platform} Simulator supported builtin arches: ${DARWIN_${platform}sim_ARCHS}")
|
||||
if(DARWIN_${platform}sim_ARCHS)
|
||||
list(APPEND BUILTIN_SUPPORTED_OS ${platform}sim)
|
||||
endif()
|
||||
foreach(arch ${DARWIN_${platform}sim_ARCHS})
|
||||
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
|
||||
set(CAN_TARGET_${arch} 1)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if(DARWIN_${platform}_SYSROOT)
|
||||
set(test_arches ${DARWIN_device_ARCHS})
|
||||
if(DARWIN_${platform}_ARCHS)
|
||||
set(test_arches DARWIN_${platform}_ARCHS)
|
||||
endif()
|
||||
|
||||
darwin_test_archs(${platform}
|
||||
DARWIN_${platform}_ARCHS
|
||||
${test_arches})
|
||||
message(STATUS "${platform} supported builtin arches: ${DARWIN_${platform}_ARCHS}")
|
||||
if(DARWIN_${platform}_ARCHS)
|
||||
list(APPEND BUILTIN_SUPPORTED_OS ${platform})
|
||||
endif()
|
||||
foreach(arch ${DARWIN_${platform}_ARCHS})
|
||||
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
|
||||
set(CAN_TARGET_${arch} 1)
|
||||
endforeach()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
list_intersect(BUILTIN_SUPPORTED_ARCH ALL_BUILTIN_SUPPORTED_ARCH COMPILER_RT_SUPPORTED_ARCH)
|
||||
|
||||
else()
|
||||
# If we're not building the builtins standalone, just rely on the tests in
|
||||
# config-ix.cmake to tell us what to build. Otherwise we need to do some leg
|
||||
# work here...
|
||||
if(COMPILER_RT_BUILTINS_STANDALONE_BUILD)
|
||||
test_targets()
|
||||
endif()
|
||||
# Architectures supported by compiler-rt libraries.
|
||||
filter_available_targets(BUILTIN_SUPPORTED_ARCH
|
||||
${ALL_BUILTIN_SUPPORTED_ARCH})
|
||||
endif()
|
||||
|
||||
message(STATUS "Builtin supported architectures: ${BUILTIN_SUPPORTED_ARCH}")
|
|
@ -142,82 +142,7 @@ if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4 AND
|
|||
message(FATAL_ERROR "Please use architecture with 4 or 8 byte pointers.")
|
||||
endif()
|
||||
|
||||
# Find and run MSVC (not clang-cl) and get its version. This will tell clang-cl
|
||||
# what version of MSVC to pretend to be so that the STL works.
|
||||
set(MSVC_VERSION_FLAG "")
|
||||
if (MSVC)
|
||||
# Find and run MSVC (not clang-cl) and get its version. This will tell
|
||||
# clang-cl what version of MSVC to pretend to be so that the STL works.
|
||||
execute_process(COMMAND "$ENV{VSINSTALLDIR}/VC/bin/cl.exe"
|
||||
OUTPUT_QUIET
|
||||
ERROR_VARIABLE MSVC_COMPAT_VERSION
|
||||
)
|
||||
string(REGEX REPLACE "^.*Compiler Version ([0-9.]+) for .*$" "\\1"
|
||||
MSVC_COMPAT_VERSION "${MSVC_COMPAT_VERSION}")
|
||||
if (MSVC_COMPAT_VERSION MATCHES "^[0-9].+$")
|
||||
set(MSVC_VERSION_FLAG "-fms-compatibility-version=${MSVC_COMPAT_VERSION}")
|
||||
# Add this flag into the host build if this is clang-cl.
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
append("${MSVC_VERSION_FLAG}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Generate the COMPILER_RT_SUPPORTED_ARCH list.
|
||||
if(ANDROID)
|
||||
# Examine compiler output to determine target architecture.
|
||||
detect_target_arch()
|
||||
set(COMPILER_RT_OS_SUFFIX "-android")
|
||||
elseif(NOT APPLE) # Supported archs for Apple platforms are generated later
|
||||
if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "i[2-6]86|x86|amd64")
|
||||
if(NOT MSVC)
|
||||
test_target_arch(x86_64 "" "-m64")
|
||||
# FIXME: We build runtimes for both i686 and i386, as "clang -m32" may
|
||||
# target different variant than "$CMAKE_C_COMPILER -m32". This part should
|
||||
# be gone after we resolve PR14109.
|
||||
test_target_arch(i686 __i686__ "-m32")
|
||||
test_target_arch(i386 __i386__ "-m32")
|
||||
else()
|
||||
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
test_target_arch(i386 "" "${MSVC_VERSION_FLAG}")
|
||||
else()
|
||||
test_target_arch(x86_64 "" "${MSVC_VERSION_FLAG}")
|
||||
endif()
|
||||
endif()
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc")
|
||||
TEST_BIG_ENDIAN(HOST_IS_BIG_ENDIAN)
|
||||
if(HOST_IS_BIG_ENDIAN)
|
||||
test_target_arch(powerpc64 "" "-m64")
|
||||
else()
|
||||
test_target_arch(powerpc64le "" "-m64")
|
||||
endif()
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
|
||||
test_target_arch(s390x "" "")
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mipsel|mips64el")
|
||||
# Gcc doesn't accept -m32/-m64 so we do the next best thing and use
|
||||
# -mips32r2/-mips64r2. We don't use -mips1/-mips3 because we want to match
|
||||
# clang's default CPU's. In the 64-bit case, we must also specify the ABI
|
||||
# since the default ABI differs between gcc and clang.
|
||||
# FIXME: Ideally, we would build the N32 library too.
|
||||
test_target_arch(mipsel "" "-mips32r2" "--target=mipsel-linux-gnu")
|
||||
test_target_arch(mips64el "" "-mips64r2" "--target=mips64el-linux-gnu" "-mabi=n64")
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mips")
|
||||
test_target_arch(mips "" "-mips32r2" "--target=mips-linux-gnu")
|
||||
test_target_arch(mips64 "" "-mips64r2" "--target=mips64-linux-gnu" "-mabi=n64")
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "arm")
|
||||
test_target_arch(arm "" "-march=armv7-a" "-mfloat-abi=soft")
|
||||
test_target_arch(armhf "" "-march=armv7-a" "-mfloat-abi=hard")
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch32")
|
||||
test_target_arch(aarch32 "" "-march=armv8-a")
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch64")
|
||||
test_target_arch(aarch64 "" "-march=armv8-a")
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "wasm32")
|
||||
test_target_arch(wasm32 "" "--target=wasm32-unknown-unknown")
|
||||
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "wasm64")
|
||||
test_target_arch(wasm64 "" "--target=wasm64-unknown-unknown")
|
||||
endif()
|
||||
set(COMPILER_RT_OS_SUFFIX "")
|
||||
endif()
|
||||
test_targets()
|
||||
|
||||
# Returns a list of architecture specific target cflags in @out_var list.
|
||||
function(get_target_flags_for_arch arch out_var)
|
||||
|
@ -253,8 +178,6 @@ if(APPLE)
|
|||
set(X86_64 x86_64 x86_64h)
|
||||
endif()
|
||||
|
||||
set(ALL_BUILTIN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
|
||||
${MIPS32} ${MIPS64} ${WASM32} ${WASM64})
|
||||
set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64}
|
||||
${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X})
|
||||
set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
|
||||
|
@ -274,21 +197,6 @@ set(ALL_ESAN_SUPPORTED_ARCH ${X86_64})
|
|||
if(APPLE)
|
||||
include(CompilerRTDarwinUtils)
|
||||
|
||||
# On Darwin if /usr/include doesn't exist, the user probably has Xcode but not
|
||||
# the command line tools. If this is the case, we need to find the OS X
|
||||
# sysroot to pass to clang.
|
||||
if(NOT EXISTS /usr/include)
|
||||
execute_process(COMMAND xcodebuild -version -sdk macosx Path
|
||||
OUTPUT_VARIABLE OSX_SYSROOT
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
set(OSX_SYSROOT_FLAG "-isysroot${OSX_SYSROOT}")
|
||||
endif()
|
||||
|
||||
option(COMPILER_RT_ENABLE_IOS "Enable building for iOS" Off)
|
||||
option(COMPILER_RT_ENABLE_WATCHOS "Enable building for watchOS - Experimental" Off)
|
||||
option(COMPILER_RT_ENABLE_TVOS "Enable building for tvOS - Experimental" Off)
|
||||
|
||||
find_darwin_sdk_dir(DARWIN_osx_SYSROOT macosx)
|
||||
find_darwin_sdk_dir(DARWIN_iossim_SYSROOT iphonesimulator)
|
||||
find_darwin_sdk_dir(DARWIN_ios_SYSROOT iphoneos)
|
||||
|
@ -302,33 +210,23 @@ if(APPLE)
|
|||
set(DARWIN_ios_MIN_VER_FLAG -miphoneos-version-min)
|
||||
set(DARWIN_ios_SANITIZER_MIN_VER_FLAG
|
||||
${DARWIN_ios_MIN_VER_FLAG}=7.0)
|
||||
set(DARWIN_ios_BUILTIN_MIN_VER 6.0)
|
||||
set(DARWIN_ios_BUILTIN_MIN_VER_FLAG
|
||||
${DARWIN_ios_MIN_VER_FLAG}=${DARWIN_ios_BUILTIN_MIN_VER})
|
||||
endif()
|
||||
if(COMPILER_RT_ENABLE_WATCHOS)
|
||||
list(APPEND DARWIN_EMBEDDED_PLATFORMS watchos)
|
||||
set(DARWIN_watchos_MIN_VER_FLAG -mwatchos-version-min)
|
||||
set(DARWIN_watchos_SANITIZER_MIN_VER_FLAG
|
||||
${DARWIN_watchos_MIN_VER_FLAG}=2.0)
|
||||
set(DARWIN_watchos_BUILTIN_MIN_VER 2.0)
|
||||
set(DARWIN_watchos_BUILTIN_MIN_VER_FLAG
|
||||
${DARWIN_watchos_MIN_VER_FLAG}=${DARWIN_watchos_BUILTIN_MIN_VER})
|
||||
endif()
|
||||
if(COMPILER_RT_ENABLE_TVOS)
|
||||
list(APPEND DARWIN_EMBEDDED_PLATFORMS tvos)
|
||||
set(DARWIN_tvos_MIN_VER_FLAG -mtvos-version-min)
|
||||
set(DARWIN_tvos_SANITIZER_MIN_VER_FLAG
|
||||
${DARWIN_tvos_MIN_VER_FLAG}=9.0)
|
||||
set(DARWIN_tvos_BUILTIN_MIN_VER 9.0)
|
||||
set(DARWIN_tvos_BUILTIN_MIN_VER_FLAG
|
||||
${DARWIN_tvos_MIN_VER_FLAG}=${DARWIN_tvos_BUILTIN_MIN_VER})
|
||||
endif()
|
||||
|
||||
# Note: In order to target x86_64h on OS X the minimum deployment target must
|
||||
# be 10.8 or higher.
|
||||
set(SANITIZER_COMMON_SUPPORTED_OS osx)
|
||||
set(BUILTIN_SUPPORTED_OS osx)
|
||||
set(PROFILE_SUPPORTED_OS osx)
|
||||
set(TSAN_SUPPORTED_OS osx)
|
||||
if(NOT SANITIZER_MIN_OSX_VERSION)
|
||||
|
@ -366,9 +264,6 @@ if(APPLE)
|
|||
set(DARWIN_osx_LINKFLAGS
|
||||
${DARWIN_COMMON_LINKFLAGS}
|
||||
-mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION})
|
||||
set(DARWIN_osx_BUILTIN_MIN_VER 10.5)
|
||||
set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
|
||||
-mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
|
||||
|
||||
if(DARWIN_osx_SYSROOT)
|
||||
list(APPEND DARWIN_osx_CFLAGS -isysroot ${DARWIN_osx_SYSROOT})
|
||||
|
@ -389,22 +284,6 @@ if(APPLE)
|
|||
set(CAN_TARGET_${arch} 1)
|
||||
endforeach()
|
||||
|
||||
# Need to build a 10.4 compatible libclang_rt
|
||||
set(DARWIN_10.4_SYSROOT ${DARWIN_osx_SYSROOT})
|
||||
set(DARWIN_10.4_BUILTIN_MIN_VER 10.4)
|
||||
set(DARWIN_10.4_BUILTIN_MIN_VER_FLAG
|
||||
-mmacosx-version-min=${DARWIN_10.4_BUILTIN_MIN_VER})
|
||||
set(DARWIN_10.4_SKIP_CC_KEXT On)
|
||||
darwin_test_archs(10.4
|
||||
DARWIN_10.4_ARCHS
|
||||
${toolchain_arches})
|
||||
message(STATUS "OSX 10.4 supported arches: ${DARWIN_10.4_ARCHS}")
|
||||
if(DARWIN_10.4_ARCHS)
|
||||
# don't include the Haswell slice in the 10.4 compatibility library
|
||||
list(REMOVE_ITEM DARWIN_10.4_ARCHS x86_64h)
|
||||
list(APPEND BUILTIN_SUPPORTED_OS 10.4)
|
||||
endif()
|
||||
|
||||
foreach(platform ${DARWIN_EMBEDDED_PLATFORMS})
|
||||
if(DARWIN_${platform}sim_SYSROOT)
|
||||
set(DARWIN_${platform}sim_CFLAGS
|
||||
|
@ -415,10 +294,6 @@ if(APPLE)
|
|||
${DARWIN_COMMON_LINKFLAGS}
|
||||
${DARWIN_${platform}_SANITIZER_MIN_VER_FLAG}
|
||||
-isysroot ${DARWIN_${platform}sim_SYSROOT})
|
||||
set(DARWIN_${platform}sim_BUILTIN_MIN_VER
|
||||
${DARWIN_${platform}_BUILTIN_MIN_VER})
|
||||
set(DARWIN_${platform}sim_BUILTIN_MIN_VER_FLAG
|
||||
${DARWIN_${platform}_BUILTIN_MIN_VER_FLAG})
|
||||
|
||||
set(DARWIN_${platform}sim_SKIP_CC_KEXT On)
|
||||
darwin_test_archs(${platform}sim
|
||||
|
@ -427,7 +302,6 @@ if(APPLE)
|
|||
message(STATUS "${platform} Simulator supported arches: ${DARWIN_${platform}sim_ARCHS}")
|
||||
if(DARWIN_${platform}_ARCHS)
|
||||
list(APPEND SANITIZER_COMMON_SUPPORTED_OS ${platform}sim)
|
||||
list(APPEND BUILTIN_SUPPORTED_OS ${platform}sim)
|
||||
list(APPEND PROFILE_SUPPORTED_OS ${platform}sim)
|
||||
if(DARWIN_${platform}_SYSROOT_INTERNAL)
|
||||
list(APPEND TSAN_SUPPORTED_OS ${platform}sim)
|
||||
|
@ -455,7 +329,6 @@ if(APPLE)
|
|||
message(STATUS "${platform} supported arches: ${DARWIN_${platform}_ARCHS}")
|
||||
if(DARWIN_${platform}_ARCHS)
|
||||
list(APPEND SANITIZER_COMMON_SUPPORTED_OS ${platform})
|
||||
list(APPEND BUILTIN_SUPPORTED_OS ${platform})
|
||||
list(APPEND PROFILE_SUPPORTED_OS ${platform})
|
||||
endif()
|
||||
foreach(arch ${DARWIN_${platform}_ARCHS})
|
||||
|
@ -469,7 +342,6 @@ if(APPLE)
|
|||
# for list_intersect
|
||||
include(CompilerRTUtils)
|
||||
|
||||
list_intersect(BUILTIN_SUPPORTED_ARCH ALL_BUILTIN_SUPPORTED_ARCH toolchain_arches)
|
||||
|
||||
list_intersect(SANITIZER_COMMON_SUPPORTED_ARCH
|
||||
ALL_SANITIZER_COMMON_SUPPORTED_ARCH
|
||||
|
@ -509,8 +381,6 @@ if(APPLE)
|
|||
SANITIZER_COMMON_SUPPORTED_ARCH)
|
||||
else()
|
||||
# Architectures supported by compiler-rt libraries.
|
||||
filter_available_targets(BUILTIN_SUPPORTED_ARCH
|
||||
${ALL_BUILTIN_SUPPORTED_ARCH})
|
||||
filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH
|
||||
${ALL_SANITIZER_COMMON_SUPPORTED_ARCH})
|
||||
# LSan and UBSan common files should be available on all architectures
|
||||
|
|
|
@ -2,9 +2,27 @@
|
|||
# generic implementations of the core runtime library along with optimized
|
||||
# architecture-specific code in various subdirectories.
|
||||
|
||||
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
cmake_minimum_required(VERSION 2.8.12.1)
|
||||
|
||||
project(CompilerRTBuiltins C ASM)
|
||||
set(COMPILER_RT_STANDALONE_BUILD TRUE)
|
||||
set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE)
|
||||
list(INSERT CMAKE_MODULE_PATH 0
|
||||
"${CMAKE_SOURCE_DIR}/../../cmake"
|
||||
"${CMAKE_SOURCE_DIR}/../../cmake/Modules")
|
||||
include(base-config-ix)
|
||||
include(CompilerRTUtils)
|
||||
if(APPLE)
|
||||
include(CompilerRTDarwinUtils)
|
||||
endif()
|
||||
include(AddCompilerRT)
|
||||
endif()
|
||||
|
||||
include(builtin-config-ix)
|
||||
|
||||
# TODO: Need to add a mechanism for logging errors when builtin source files are
|
||||
# added to a sub-directory and not this CMakeLists file.
|
||||
|
||||
set(GENERIC_SOURCES
|
||||
absvdi2.c
|
||||
absvsi2.c
|
||||
|
|
Loading…
Reference in New Issue