aboutsummaryrefslogtreecommitdiff
path: root/cmake/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/Modules')
-rw-r--r--cmake/Modules/AddCompilerRT.cmake115
-rw-r--r--cmake/Modules/BuiltinTests.cmake62
-rw-r--r--cmake/Modules/CompilerRTCompile.cmake4
-rw-r--r--cmake/Modules/CompilerRTDarwinUtils.cmake38
-rw-r--r--cmake/Modules/CompilerRTUtils.cmake105
-rw-r--r--cmake/Modules/SanitizerUtils.cmake20
6 files changed, 289 insertions, 55 deletions
diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake
index 1ab590e34a88..334224854ba2 100644
--- a/cmake/Modules/AddCompilerRT.cmake
+++ b/cmake/Modules/AddCompilerRT.cmake
@@ -1,7 +1,28 @@
-include(AddLLVM)
include(ExternalProject)
include(CompilerRTUtils)
+function(set_target_output_directories target output_dir)
+ # For RUNTIME_OUTPUT_DIRECTORY variable, Multi-configuration generators
+ # append a per-configuration subdirectory to the specified directory.
+ # To avoid the appended folder, the configuration specific variable must be
+ # set 'RUNTIME_OUTPUT_DIRECTORY_${CONF}':
+ # RUNTIME_OUTPUT_DIRECTORY_DEBUG, RUNTIME_OUTPUT_DIRECTORY_RELEASE, ...
+ if(CMAKE_CONFIGURATION_TYPES)
+ foreach(build_mode ${CMAKE_CONFIGURATION_TYPES})
+ string(TOUPPER "${build_mode}" CONFIG_SUFFIX)
+ set_target_properties("${target}" PROPERTIES
+ "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${output_dir}
+ "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${output_dir}
+ "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${output_dir})
+ endforeach()
+ else()
+ set_target_properties("${target}" PROPERTIES
+ ARCHIVE_OUTPUT_DIRECTORY ${output_dir}
+ LIBRARY_OUTPUT_DIRECTORY ${output_dir}
+ RUNTIME_OUTPUT_DIRECTORY ${output_dir})
+ endif()
+endfunction()
+
# Tries to add an "object library" target for a given list of OSs and/or
# architectures with name "<name>.<arch>" for non-Darwin platforms if
# architecture can be targeted, and "<name>.<os>" for Darwin platforms.
@@ -32,13 +53,14 @@ function(add_compiler_rt_object_libraries name)
endif()
endforeach()
endif()
-
+
foreach(libname ${libnames})
add_library(${libname} OBJECT ${LIB_SOURCES})
set_target_compile_flags(${libname}
${CMAKE_CXX_FLAGS} ${extra_cflags_${libname}} ${LIB_CFLAGS})
set_property(TARGET ${libname} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
+ set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Libraries")
if(APPLE)
set_target_properties(${libname} PROPERTIES
OSX_ARCHITECTURES "${LIB_ARCHS_${libname}}")
@@ -107,7 +129,8 @@ function(add_compiler_rt_runtime name type)
set(output_name_${libname} ${libname}${COMPILER_RT_OS_SUFFIX})
else()
set(libname "${name}-dynamic-${arch}")
- set(extra_linkflags_${libname} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS} ${LIB_LINKFLAGS})
+ set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
+ set(extra_linkflags_${libname} ${TARGET_${arch}_LINKFLAGS} ${LIB_LINKFLAGS})
if(WIN32)
set(output_name_${libname} ${name}_dynamic-${arch}${COMPILER_RT_OS_SUFFIX})
else()
@@ -126,21 +149,42 @@ function(add_compiler_rt_runtime name type)
endif()
if(LIB_PARENT_TARGET)
- set(COMPONENT_OPTION COMPONENT ${LIB_PARENT_TARGET})
+ # If the parent targets aren't created we should create them
+ if(NOT TARGET ${LIB_PARENT_TARGET})
+ add_custom_target(${LIB_PARENT_TARGET})
+ endif()
+ if(NOT TARGET install-${LIB_PARENT_TARGET})
+ # The parent install target specifies the parent component to scrape up
+ # anything not installed by the individual install targets, and to handle
+ # installation when running the multi-configuration generators.
+ add_custom_target(install-${LIB_PARENT_TARGET}
+ DEPENDS ${LIB_PARENT_TARGET}
+ COMMAND "${CMAKE_COMMAND}"
+ -DCMAKE_INSTALL_COMPONENT=${LIB_PARENT_TARGET}
+ -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
+ set_target_properties(install-${LIB_PARENT_TARGET} PROPERTIES
+ FOLDER "Compiler-RT Misc")
+ endif()
endif()
foreach(libname ${libnames})
+ # If you are using a multi-configuration generator we don't generate
+ # per-library install rules, so we fall back to the parent target COMPONENT
+ if(CMAKE_CONFIGURATION_TYPES AND LIB_PARENT_TARGET)
+ set(COMPONENT_OPTION COMPONENT ${LIB_PARENT_TARGET})
+ else()
+ set(COMPONENT_OPTION COMPONENT ${libname})
+ endif()
+
add_library(${libname} ${type} ${sources_${libname}})
set_target_compile_flags(${libname} ${extra_cflags_${libname}})
set_target_link_flags(${libname} ${extra_linkflags_${libname}})
- set_property(TARGET ${libname} APPEND PROPERTY
+ set_property(TARGET ${libname} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
- set_target_properties(${libname} PROPERTIES
- ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
- LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
- RUNTIME_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+ set_target_output_directories(${libname} ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
set_target_properties(${libname} PROPERTIES
OUTPUT_NAME ${output_name_${libname}})
+ set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Runtime")
if(LIB_LINK_LIBS AND ${type} STREQUAL "SHARED")
target_link_libraries(${libname} ${LIB_LINK_LIBS})
endif()
@@ -151,6 +195,21 @@ function(add_compiler_rt_runtime name type)
${COMPONENT_OPTION}
RUNTIME DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
${COMPONENT_OPTION})
+
+ # We only want to generate per-library install targets if you aren't using
+ # an IDE because the extra targets get cluttered in IDEs.
+ if(NOT CMAKE_CONFIGURATION_TYPES)
+ add_custom_target(install-${libname}
+ DEPENDS ${libname}
+ COMMAND "${CMAKE_COMMAND}"
+ -DCMAKE_INSTALL_COMPONENT=${libname}
+ -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
+ # If you have a parent target specified, we bind the new install target
+ # to the parent install target.
+ if(LIB_PARENT_TARGET)
+ add_dependencies(install-${LIB_PARENT_TARGET} install-${libname})
+ endif()
+ endif()
if(APPLE)
set_target_properties(${libname} PROPERTIES
OSX_ARCHITECTURES "${LIB_ARCHS_${libname}}")
@@ -165,7 +224,10 @@ function(add_compiler_rt_runtime name type)
endif()
endfunction()
-set(COMPILER_RT_TEST_CFLAGS)
+# when cross compiling, COMPILER_RT_TEST_COMPILER_CFLAGS help
+# in compilation and linking of unittests.
+string(REPLACE " " ";" COMPILER_RT_UNITTEST_CFLAGS "${COMPILER_RT_TEST_COMPILER_CFLAGS}")
+set(COMPILER_RT_UNITTEST_LINKFLAGS ${COMPILER_RT_UNITTEST_CFLAGS})
# Unittests support.
set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest)
@@ -177,14 +239,14 @@ set(COMPILER_RT_GTEST_CFLAGS
-I${COMPILER_RT_GTEST_PATH}
)
-append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_TEST_CFLAGS)
+append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_UNITTEST_CFLAGS)
if(MSVC)
# clang doesn't support exceptions on Windows yet.
- list(APPEND COMPILER_RT_TEST_CFLAGS -D_HAS_EXCEPTIONS=0)
+ list(APPEND COMPILER_RT_UNITTEST_CFLAGS -D_HAS_EXCEPTIONS=0)
# We should teach clang to understand "#pragma intrinsic", see PR19898.
- list(APPEND COMPILER_RT_TEST_CFLAGS -Wno-undefined-inline)
+ list(APPEND COMPILER_RT_UNITTEST_CFLAGS -Wno-undefined-inline)
# Clang doesn't support SEH on Windows yet.
list(APPEND COMPILER_RT_GTEST_CFLAGS -DGTEST_HAS_SEH=0)
@@ -209,14 +271,18 @@ endif()
# LINK_FLAGS <link flags>)
macro(add_compiler_rt_test test_suite test_name)
cmake_parse_arguments(TEST "" "SUBDIR" "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN})
+ set(output_bin ${CMAKE_CURRENT_BINARY_DIR})
if(TEST_SUBDIR)
- set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${TEST_SUBDIR}/${test_name}")
- else()
- set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}")
+ set(output_bin "${output_bin}/${TEST_SUBDIR}")
+ endif()
+ if(CMAKE_CONFIGURATION_TYPES)
+ set(output_bin "${output_bin}/${CMAKE_CFG_INTDIR}")
endif()
+ set(output_bin "${output_bin}/${test_name}")
if(MSVC)
set(output_bin "${output_bin}.exe")
endif()
+
# Use host compiler in a standalone build, and just-built Clang otherwise.
if(NOT COMPILER_RT_STANDALONE_BUILD)
list(APPEND TEST_DEPS clang)
@@ -236,11 +302,13 @@ macro(add_compiler_rt_test test_suite test_name)
-o "${output_bin}"
${TEST_LINK_FLAGS}
DEPENDS ${TEST_DEPS})
+ set_target_properties(${test_name} PROPERTIES FOLDER "Compiler-RT Tests")
+
# Make the test suite depend on the binary.
add_dependencies(${test_suite} ${test_name})
endmacro()
-macro(add_compiler_rt_resource_file target_name file_name)
+macro(add_compiler_rt_resource_file target_name file_name component)
set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}")
set(dst_file "${COMPILER_RT_OUTPUT_DIR}/${file_name}")
add_custom_command(OUTPUT ${dst_file}
@@ -249,7 +317,12 @@ macro(add_compiler_rt_resource_file target_name file_name)
COMMENT "Copying ${file_name}...")
add_custom_target(${target_name} DEPENDS ${dst_file})
# Install in Clang resource directory.
- install(FILES ${file_name} DESTINATION ${COMPILER_RT_INSTALL_PATH})
+ install(FILES ${file_name}
+ DESTINATION ${COMPILER_RT_INSTALL_PATH}
+ COMPONENT ${component})
+ add_dependencies(${component} ${target_name})
+
+ set_target_properties(${target_name} PROPERTIES FOLDER "Compiler-RT Misc")
endmacro()
macro(add_compiler_rt_script name)
@@ -321,6 +394,10 @@ function(rt_externalize_debuginfo name)
return()
endif()
+ if(NOT COMPILER_RT_EXTERNALIZE_DEBUGINFO_SKIP_STRIP)
+ set(strip_command COMMAND xcrun strip -Sl $<TARGET_FILE:${name}>)
+ endif()
+
if(APPLE)
if(CMAKE_CXX_FLAGS MATCHES "-flto"
OR CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} MATCHES "-flto")
@@ -331,7 +408,7 @@ function(rt_externalize_debuginfo name)
endif()
add_custom_command(TARGET ${name} POST_BUILD
COMMAND xcrun dsymutil $<TARGET_FILE:${name}>
- COMMAND xcrun strip -Sl $<TARGET_FILE:${name}>)
+ ${strip_command})
else()
message(FATAL_ERROR "COMPILER_RT_EXTERNALIZE_DEBUGINFO isn't implemented for non-darwin platforms!")
endif()
diff --git a/cmake/Modules/BuiltinTests.cmake b/cmake/Modules/BuiltinTests.cmake
new file mode 100644
index 000000000000..1b03e94acf12
--- /dev/null
+++ b/cmake/Modules/BuiltinTests.cmake
@@ -0,0 +1,62 @@
+
+# This function takes an OS and a list of architectures and identifies the
+# subset of the architectures list that the installed toolchain can target.
+function(try_compile_only output)
+ set(SIMPLE_C ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.c)
+ file(WRITE ${SIMPLE_C} "int foo(int x, int y) { return x + y; }\n")
+ string(REGEX MATCHALL "<[A-Za-z0-9_]*>" substitutions
+ ${CMAKE_C_COMPILE_OBJECT})
+ string(REPLACE ";" " " extra_flags "${ARGN}")
+
+ set(test_compile_command "${CMAKE_C_COMPILE_OBJECT}")
+ foreach(substitution ${substitutions})
+ if(substitution STREQUAL "<CMAKE_C_COMPILER>")
+ string(REPLACE "<CMAKE_C_COMPILER>"
+ "${CMAKE_C_COMPILER}" test_compile_command ${test_compile_command})
+ elseif(substitution STREQUAL "<OBJECT>")
+ string(REPLACE "<OBJECT>"
+ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/test.o"
+ test_compile_command ${test_compile_command})
+ elseif(substitution STREQUAL "<SOURCE>")
+ string(REPLACE "<SOURCE>" "${SIMPLE_C}" test_compile_command
+ ${test_compile_command})
+ elseif(substitution STREQUAL "<FLAGS>")
+ string(REPLACE "<FLAGS>" "${CMAKE_C_FLAGS} ${extra_flags}"
+ test_compile_command ${test_compile_command})
+ else()
+ string(REPLACE "${substitution}" "" test_compile_command
+ ${test_compile_command})
+ endif()
+ endforeach()
+
+ string(REPLACE " " ";" test_compile_command "${test_compile_command}")
+
+ execute_process(
+ COMMAND ${test_compile_command}
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE TEST_OUTPUT
+ ERROR_VARIABLE TEST_ERROR
+ )
+ if(result EQUAL 0)
+ set(${output} True PARENT_SCOPE)
+ else()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Testing compiler for supporting " ${ARGN} ":\n"
+ "Command: ${test_compile_command}\n"
+ "${TEST_OUTPUT}\n${TEST_ERROR}\n${result}\n")
+ set(${output} False PARENT_SCOPE)
+ endif()
+endfunction()
+
+function(builtin_check_c_compiler_flag flag output)
+ if(NOT DEFINED ${output})
+ message(STATUS "Performing Test ${output}")
+ try_compile_only(result ${flag})
+ set(${output} ${result} CACHE INTERNAL "Compiler supports ${flag}")
+ if(${result})
+ message(STATUS "Performing Test ${output} - Success")
+ else()
+ message(STATUS "Performing Test ${output} - Failed")
+ endif()
+ endif()
+endfunction()
diff --git a/cmake/Modules/CompilerRTCompile.cmake b/cmake/Modules/CompilerRTCompile.cmake
index 48f40bf4f753..30663b695955 100644
--- a/cmake/Modules/CompilerRTCompile.cmake
+++ b/cmake/Modules/CompilerRTCompile.cmake
@@ -90,8 +90,8 @@ macro(clang_compiler_add_cxx_check)
" fi"
" echo 'This can also be fixed by checking out the libcxx project from llvm.org and installing the headers'"
" echo 'into your build directory:'"
- " echo ' cd ${LLVM_SOURCE_DIR}/projects && svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx'"
- " echo ' cd ${LLVM_BINARY_DIR} && make -C ${LLVM_SOURCE_DIR}/projects/libcxx installheaders HEADER_DIR=${LLVM_BINARY_DIR}/include'"
+ " echo ' cd ${LLVM_MAIN_SRC_DIR}/projects && svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx'"
+ " echo ' cd ${LLVM_BINARY_DIR} && make -C ${LLVM_MAIN_SRC_DIR}/projects/libcxx installheaders HEADER_DIR=${LLVM_BINARY_DIR}/include'"
" echo"
" false"
"fi"
diff --git a/cmake/Modules/CompilerRTDarwinUtils.cmake b/cmake/Modules/CompilerRTDarwinUtils.cmake
index 895ecdc31cfd..fd19ff9f6568 100644
--- a/cmake/Modules/CompilerRTDarwinUtils.cmake
+++ b/cmake/Modules/CompilerRTDarwinUtils.cmake
@@ -1,3 +1,5 @@
+include(CMakeParseArguments)
+
# On OS X SDKs can be installed anywhere on the base system and xcode-select can
# set the default Xcode to use. This function finds the SDKs that are present in
# the current Xcode.
@@ -16,6 +18,8 @@ function(find_darwin_sdk_dir var sdk_name)
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_FILE /dev/null
)
+ else()
+ set(${var}_INTERNAL ${var_internal} PARENT_SCOPE)
endif()
set(${var} ${var_internal} PARENT_SCOPE)
endfunction()
@@ -52,30 +56,36 @@ function(darwin_test_archs os valid_archs)
endif()
set(archs ${ARGN})
- message(STATUS "Finding valid architectures for ${os}...")
- set(SIMPLE_CPP ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.cpp)
- file(WRITE ${SIMPLE_CPP} "#include <iostream>\nint main() { std::cout << std::endl; return 0; }\n")
-
- set(os_linker_flags)
- foreach(flag ${DARWIN_${os}_LINKFLAGS})
- set(os_linker_flags "${os_linker_flags} ${flag}")
- endforeach()
+ if(NOT TEST_COMPILE_ONLY)
+ message(STATUS "Finding valid architectures for ${os}...")
+ set(SIMPLE_C ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.c)
+ file(WRITE ${SIMPLE_C} "#include <stdio.h>\nint main() { printf(__FILE__); return 0; }\n")
+
+ set(os_linker_flags)
+ foreach(flag ${DARWIN_${os}_LINKFLAGS})
+ set(os_linker_flags "${os_linker_flags} ${flag}")
+ endforeach()
+ endif()
# The simple program will build for x86_64h on the simulator because it is
# compatible with x86_64 libraries (mostly), but since x86_64h isn't actually
# a valid or useful architecture for the iOS simulator we should drop it.
- if(${os} STREQUAL "iossim")
+ if(${os} MATCHES "^(iossim|tvossim|watchossim)$")
list(REMOVE_ITEM archs "x86_64h")
endif()
set(working_archs)
foreach(arch ${archs})
-
+
set(arch_linker_flags "-arch ${arch} ${os_linker_flags}")
- try_compile(CAN_TARGET_${os}_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_CPP}
- COMPILE_DEFINITIONS "-v -arch ${arch}" ${DARWIN_${os}_CFLAGS}
- CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${arch_linker_flags}"
- OUTPUT_VARIABLE TEST_OUTPUT)
+ if(TEST_COMPILE_ONLY)
+ try_compile_only(CAN_TARGET_${os}_${arch} -v -arch ${arch} ${DARWIN_${os}_CFLAGS})
+ else()
+ try_compile(CAN_TARGET_${os}_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_C}
+ COMPILE_DEFINITIONS "-v -arch ${arch}" ${DARWIN_${os}_CFLAGS}
+ CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${arch_linker_flags}"
+ OUTPUT_VARIABLE TEST_OUTPUT)
+ endif()
if(${CAN_TARGET_${os}_${arch}})
list(APPEND working_archs ${arch})
else()
diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake
index ad9e70c0587a..78b6dceef887 100644
--- a/cmake/Modules/CompilerRTUtils.cmake
+++ b/cmake/Modules/CompilerRTUtils.cmake
@@ -1,3 +1,6 @@
+include(CMakePushCheckState)
+include(CheckSymbolExists)
+
# Because compiler-rt spends a lot of time setting up custom compile flags,
# define a handy helper function for it. The compile flags setting in CMake
# has serious issues that make its syntax challenging at best.
@@ -45,9 +48,14 @@ macro(append_string_if condition value)
endif()
endmacro()
-macro(append_no_rtti_flag list)
- append_list_if(COMPILER_RT_HAS_FNO_RTTI_FLAG -fno-rtti ${list})
- append_list_if(COMPILER_RT_HAS_GR_FLAG /GR- ${list})
+macro(append_rtti_flag polarity list)
+ if(polarity)
+ append_list_if(COMPILER_RT_HAS_FRTTI_FLAG -frtti ${list})
+ append_list_if(COMPILER_RT_HAS_GR_FLAG /GR ${list})
+ else()
+ append_list_if(COMPILER_RT_HAS_FNO_RTTI_FLAG -fno-rtti ${list})
+ append_list_if(COMPILER_RT_HAS_GR_FLAG /GR- ${list})
+ endif()
endmacro()
macro(append_have_file_definition filename varname list)
@@ -67,3 +75,94 @@ macro(list_intersect output input1 input2)
endif()
endforeach()
endmacro()
+
+# Takes ${ARGN} and puts only supported architectures in @out_var list.
+function(filter_available_targets out_var)
+ set(archs ${${out_var}})
+ foreach(arch ${ARGN})
+ list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
+ if(NOT (ARCH_INDEX EQUAL -1) AND CAN_TARGET_${arch})
+ list(APPEND archs ${arch})
+ endif()
+ endforeach()
+ set(${out_var} ${archs} PARENT_SCOPE)
+endfunction()
+
+function(check_compile_definition def argstring out_var)
+ if("${def}" STREQUAL "")
+ set(${out_var} TRUE PARENT_SCOPE)
+ return()
+ endif()
+ cmake_push_check_state()
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${argstring}")
+ check_symbol_exists(${def} "" ${out_var})
+ cmake_pop_check_state()
+endfunction()
+
+# test_target_arch(<arch> <def> <target flags...>)
+# Checks if architecture is supported: runs host compiler with provided
+# flags to verify that:
+# 1) <def> is defined (if non-empty)
+# 2) simple file can be successfully built.
+# If successful, saves target flags for this architecture.
+macro(test_target_arch arch def)
+ set(TARGET_${arch}_CFLAGS ${ARGN})
+ set(TARGET_${arch}_LINKFLAGS ${ARGN})
+ set(argstring "")
+ foreach(arg ${ARGN})
+ set(argstring "${argstring} ${arg}")
+ endforeach()
+ check_compile_definition("${def}" "${argstring}" HAS_${arch}_DEF)
+ if(NOT HAS_${arch}_DEF)
+ set(CAN_TARGET_${arch} FALSE)
+ elseif(TEST_COMPILE_ONLY)
+ try_compile_only(CAN_TARGET_${arch} ${TARGET_${arch}_CFLAGS})
+ else()
+ set(argstring "${CMAKE_EXE_LINKER_FLAGS} ${argstring}")
+ try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE}
+ COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS}"
+ OUTPUT_VARIABLE TARGET_${arch}_OUTPUT
+ CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${argstring}")
+ endif()
+ if(${CAN_TARGET_${arch}})
+ list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
+ elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "${arch}" AND
+ COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE)
+ # Bail out if we cannot target the architecture we plan to test.
+ message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}")
+ endif()
+endmacro()
+
+macro(detect_target_arch)
+ check_symbol_exists(__arm__ "" __ARM)
+ check_symbol_exists(__aarch64__ "" __AARCH64)
+ check_symbol_exists(__x86_64__ "" __X86_64)
+ check_symbol_exists(__i686__ "" __I686)
+ check_symbol_exists(__i386__ "" __I386)
+ check_symbol_exists(__mips__ "" __MIPS)
+ check_symbol_exists(__mips64__ "" __MIPS64)
+ check_symbol_exists(__s390x__ "" __S390X)
+ check_symbol_exists(__wasm32__ "" __WEBASSEMBLY32)
+ check_symbol_exists(__wasm64__ "" __WEBASSEMBLY64)
+ if(__ARM)
+ add_default_target_arch(arm)
+ elseif(__AARCH64)
+ add_default_target_arch(aarch64)
+ elseif(__X86_64)
+ add_default_target_arch(x86_64)
+ elseif(__I686)
+ add_default_target_arch(i686)
+ elseif(__I386)
+ add_default_target_arch(i386)
+ elseif(__MIPS64) # must be checked before __MIPS
+ add_default_target_arch(mips64)
+ elseif(__MIPS)
+ add_default_target_arch(mips)
+ elseif(__S390X)
+ add_default_target_arch(s390x)
+ elseif(__WEBASSEMBLY32)
+ add_default_target_arch(wasm32)
+ elseif(__WEBASSEMBLY64)
+ add_default_target_arch(wasm64)
+ endif()
+endmacro()
diff --git a/cmake/Modules/SanitizerUtils.cmake b/cmake/Modules/SanitizerUtils.cmake
index 3eb49c83f51c..c66083c24f47 100644
--- a/cmake/Modules/SanitizerUtils.cmake
+++ b/cmake/Modules/SanitizerUtils.cmake
@@ -38,22 +38,8 @@ macro(add_sanitizer_rt_symbols name)
DEPENDS ${stamp}
SOURCES ${SANITIZER_GEN_DYNAMIC_LIST} ${ARG_EXTRA})
- if(NOT CMAKE_VERSION VERSION_LESS 3.0)
- install(FILES $<TARGET_FILE:${target_name}>.syms
- DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
- else()
- # Per-config install location.
- if(CMAKE_CONFIGURATION_TYPES)
- foreach(c ${CMAKE_CONFIGURATION_TYPES})
- get_target_property(libfile ${target_name} LOCATION_${c})
- install(FILES ${libfile}.syms CONFIGURATIONS ${c}
+ install(FILES $<TARGET_FILE:${target_name}>.syms
DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
- endforeach()
- else()
- get_target_property(libfile ${target_name} LOCATION_${CMAKE_BUILD_TYPE})
- install(FILES ${libfile}.syms DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
- endif()
- endif()
if(ARG_PARENT_TARGET)
add_dependencies(${ARG_PARENT_TARGET} ${target_name}-symbols)
endif()
@@ -84,9 +70,9 @@ macro(add_sanitizer_rt_version_list name)
endmacro()
# Add target to check code style for sanitizer runtimes.
-if(UNIX)
+if(CMAKE_HOST_UNIX)
add_custom_target(SanitizerLintCheck
- COMMAND LLVM_CHECKOUT=${LLVM_MAIN_SRC_DIR} SILENT=1 TMPDIR=
+ COMMAND env LLVM_CHECKOUT=${LLVM_MAIN_SRC_DIR} SILENT=1 TMPDIR=
PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
COMPILER_RT=${COMPILER_RT_SOURCE_DIR}
${SANITIZER_LINT_SCRIPT}