2016-04-29 05:16:45 +08:00
|
|
|
include(CMakeParseArguments)
|
|
|
|
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-14 04:38:16 +08:00
|
|
|
# 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.
|
|
|
|
function(find_darwin_sdk_dir var sdk_name)
|
2017-07-07 09:06:20 +08:00
|
|
|
set(DARWIN_${sdk_name}_CACHED_SYSROOT "" CACHE STRING "Darwin SDK path for SDK ${sdk_name}.")
|
2017-07-13 01:11:53 +08:00
|
|
|
set(DARWIN_PREFER_PUBLIC_SDK OFF CACHE BOOL "Prefer Darwin public SDK, even when an internal SDK is present.")
|
|
|
|
|
2017-07-07 09:06:20 +08:00
|
|
|
if(DARWIN_${sdk_name}_CACHED_SYSROOT)
|
|
|
|
set(${var} ${DARWIN_${sdk_name}_CACHED_SYSROOT} PARENT_SCOPE)
|
|
|
|
return()
|
|
|
|
endif()
|
2017-07-07 07:09:16 +08:00
|
|
|
if(NOT DARWIN_PREFER_PUBLIC_SDK)
|
|
|
|
# Let's first try the internal SDK, otherwise use the public SDK.
|
|
|
|
execute_process(
|
|
|
|
COMMAND xcodebuild -version -sdk ${sdk_name}.internal Path
|
|
|
|
RESULT_VARIABLE result_process
|
|
|
|
OUTPUT_VARIABLE var_internal
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_FILE /dev/null
|
|
|
|
)
|
|
|
|
endif()
|
2016-08-20 06:22:35 +08:00
|
|
|
if((NOT result_process EQUAL 0) OR "" STREQUAL "${var_internal}")
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-14 04:38:16 +08:00
|
|
|
execute_process(
|
|
|
|
COMMAND xcodebuild -version -sdk ${sdk_name} Path
|
2016-08-20 06:22:35 +08:00
|
|
|
RESULT_VARIABLE result_process
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-14 04:38:16 +08:00
|
|
|
OUTPUT_VARIABLE var_internal
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_FILE /dev/null
|
|
|
|
)
|
2016-04-27 01:53:25 +08:00
|
|
|
else()
|
|
|
|
set(${var}_INTERNAL ${var_internal} PARENT_SCOPE)
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-14 04:38:16 +08:00
|
|
|
endif()
|
2016-08-20 06:22:35 +08:00
|
|
|
if(result_process EQUAL 0)
|
|
|
|
set(${var} ${var_internal} PARENT_SCOPE)
|
|
|
|
endif()
|
2017-07-07 09:06:20 +08:00
|
|
|
set(DARWIN_${sdk_name}_CACHED_SYSROOT ${var_internal} CACHE STRING "Darwin SDK path for SDK ${sdk_name}." FORCE)
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-14 04:38:16 +08:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# There isn't a clear mapping of what architectures are supported with a given
|
|
|
|
# target platform, but ld's version output does list the architectures it can
|
|
|
|
# link for.
|
|
|
|
function(darwin_get_toolchain_supported_archs output_var)
|
|
|
|
execute_process(
|
|
|
|
COMMAND ld -v
|
|
|
|
ERROR_VARIABLE LINKER_VERSION)
|
|
|
|
|
|
|
|
string(REGEX MATCH "configured to support archs: ([^\n]+)"
|
|
|
|
ARCHES_MATCHED "${LINKER_VERSION}")
|
|
|
|
if(ARCHES_MATCHED)
|
|
|
|
set(ARCHES "${CMAKE_MATCH_1}")
|
2015-08-20 00:23:19 +08:00
|
|
|
message(STATUS "Got ld supported ARCHES: ${ARCHES}")
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-14 04:38:16 +08:00
|
|
|
string(REPLACE " " ";" ARCHES ${ARCHES})
|
|
|
|
else()
|
|
|
|
# If auto-detecting fails, fall back to a default set
|
|
|
|
message(WARNING "Detecting supported architectures from 'ld -v' failed. Returning default set.")
|
|
|
|
set(ARCHES "i386;x86_64;armv7;armv7s;arm64")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(${output_var} ${ARCHES} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# 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(darwin_test_archs os valid_archs)
|
2015-12-04 01:02:07 +08:00
|
|
|
if(${valid_archs})
|
|
|
|
message(STATUS "Using cached valid architectures for ${os}.")
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-14 04:38:16 +08:00
|
|
|
set(archs ${ARGN})
|
2016-05-04 03:48:11 +08:00
|
|
|
if(NOT TEST_COMPILE_ONLY)
|
|
|
|
message(STATUS "Finding valid architectures for ${os}...")
|
2016-06-23 07:02:49 +08:00
|
|
|
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")
|
2016-05-04 03:48:11 +08:00
|
|
|
|
|
|
|
set(os_linker_flags)
|
2017-01-10 12:33:04 +08:00
|
|
|
foreach(flag ${DARWIN_${os}_LINK_FLAGS})
|
2016-05-04 03:48:11 +08:00
|
|
|
set(os_linker_flags "${os_linker_flags} ${flag}")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-14 04:38:16 +08:00
|
|
|
|
|
|
|
# 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.
|
2016-02-02 10:01:17 +08:00
|
|
|
if(${os} MATCHES "^(iossim|tvossim|watchossim)$")
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-14 04:38:16 +08:00
|
|
|
list(REMOVE_ITEM archs "x86_64h")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(working_archs)
|
|
|
|
foreach(arch ${archs})
|
2016-05-04 03:48:11 +08:00
|
|
|
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-14 04:38:16 +08:00
|
|
|
set(arch_linker_flags "-arch ${arch} ${os_linker_flags}")
|
2016-05-04 03:48:11 +08:00
|
|
|
if(TEST_COMPILE_ONLY)
|
|
|
|
try_compile_only(CAN_TARGET_${os}_${arch} -v -arch ${arch} ${DARWIN_${os}_CFLAGS})
|
|
|
|
else()
|
[compiler-rt] respect CMAKE_EXE_LINKER_FLAGS in compiler and library tests
Summary: check_cxx_compiler_flag and check_library_exists could fail because they ignored CMAKE_EXE_LINKER_FLAGS and therefore would always fail to produce executables. Cmake policy CMP0056 fixes this, but was explicitly set to OLD in our CMakeLists because it caused problems with test_target_arch. This change sets the policy to NEW to fix the problem with the compiler and library tests, and temporarily clears CMAKE_EXE_LINKER_FLAGS inside test_target_arch to emulate the old behavior there. This allows, for example, LTO builds that require lld to succeed.
Reviewers: davidxl, beanz
Reviewed By: beanz
Subscribers: fjricci, dberris, mgorny, mehdi_amini, tejohnson, rnk, llvm-commits
Differential Revision: https://reviews.llvm.org/D31098
llvm-svn: 298413
2017-03-22 02:25:35 +08:00
|
|
|
set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${arch_linker_flags}")
|
2016-06-23 07:02:49 +08:00
|
|
|
try_compile(CAN_TARGET_${os}_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_C}
|
2016-05-04 03:48:11 +08:00
|
|
|
COMPILE_DEFINITIONS "-v -arch ${arch}" ${DARWIN_${os}_CFLAGS}
|
|
|
|
OUTPUT_VARIABLE TEST_OUTPUT)
|
[compiler-rt] respect CMAKE_EXE_LINKER_FLAGS in compiler and library tests
Summary: check_cxx_compiler_flag and check_library_exists could fail because they ignored CMAKE_EXE_LINKER_FLAGS and therefore would always fail to produce executables. Cmake policy CMP0056 fixes this, but was explicitly set to OLD in our CMakeLists because it caused problems with test_target_arch. This change sets the policy to NEW to fix the problem with the compiler and library tests, and temporarily clears CMAKE_EXE_LINKER_FLAGS inside test_target_arch to emulate the old behavior there. This allows, for example, LTO builds that require lld to succeed.
Reviewers: davidxl, beanz
Reviewed By: beanz
Subscribers: fjricci, dberris, mgorny, mehdi_amini, tejohnson, rnk, llvm-commits
Differential Revision: https://reviews.llvm.org/D31098
llvm-svn: 298413
2017-03-22 02:25:35 +08:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS ${SAVED_CMAKE_EXE_LINKER_FLAGS})
|
2016-05-04 03:48:11 +08:00
|
|
|
endif()
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-14 04:38:16 +08:00
|
|
|
if(${CAN_TARGET_${os}_${arch}})
|
|
|
|
list(APPEND working_archs ${arch})
|
2015-12-10 08:39:57 +08:00
|
|
|
else()
|
|
|
|
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
|
|
|
"Testing compiler for supporting ${os}-${arch}:\n"
|
|
|
|
"${TEST_OUTPUT}\n")
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-14 04:38:16 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2015-12-04 01:02:07 +08:00
|
|
|
set(${valid_archs} ${working_archs}
|
|
|
|
CACHE STRING "List of valid architectures for platform ${os}.")
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-14 04:38:16 +08:00
|
|
|
endfunction()
|
2015-08-21 01:32:06 +08:00
|
|
|
|
|
|
|
# This function checks the host cpusubtype to see if it is post-haswell. Haswell
|
|
|
|
# and later machines can run x86_64h binaries. Haswell is cpusubtype 8.
|
|
|
|
function(darwin_filter_host_archs input output)
|
2016-01-27 17:28:01 +08:00
|
|
|
list_intersect(tmp_var DARWIN_osx_ARCHS ${input})
|
2015-08-21 01:32:06 +08:00
|
|
|
execute_process(
|
|
|
|
COMMAND sysctl hw.cpusubtype
|
|
|
|
OUTPUT_VARIABLE SUBTYPE)
|
|
|
|
|
|
|
|
string(REGEX MATCH "hw.cpusubtype: ([0-9]*)"
|
|
|
|
SUBTYPE_MATCHED "${SUBTYPE}")
|
|
|
|
set(HASWELL_SUPPORTED Off)
|
2015-08-22 02:05:57 +08:00
|
|
|
if(SUBTYPE_MATCHED)
|
|
|
|
if(${CMAKE_MATCH_1} GREATER 7)
|
2015-08-21 01:32:06 +08:00
|
|
|
set(HASWELL_SUPPORTED On)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
if(NOT HASWELL_SUPPORTED)
|
|
|
|
list(REMOVE_ITEM tmp_var x86_64h)
|
|
|
|
endif()
|
|
|
|
set(${output} ${tmp_var} PARENT_SCOPE)
|
|
|
|
endfunction()
|
2015-09-23 23:18:17 +08:00
|
|
|
|
|
|
|
# Read and process the exclude file into a list of symbols
|
2015-09-26 07:29:03 +08:00
|
|
|
function(darwin_read_list_from_file output_var file)
|
|
|
|
if(EXISTS ${file})
|
|
|
|
file(READ ${file} EXCLUDES)
|
|
|
|
string(REPLACE "\n" ";" EXCLUDES ${EXCLUDES})
|
|
|
|
set(${output_var} ${EXCLUDES} PARENT_SCOPE)
|
2015-09-23 23:18:17 +08:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# this function takes an OS, architecture and minimum version and provides a
|
|
|
|
# list of builtin functions to exclude
|
2015-09-25 05:51:09 +08:00
|
|
|
function(darwin_find_excluded_builtins_list output_var)
|
|
|
|
cmake_parse_arguments(LIB
|
|
|
|
""
|
|
|
|
"OS;ARCH;MIN_VERSION"
|
|
|
|
""
|
|
|
|
${ARGN})
|
|
|
|
|
|
|
|
if(NOT LIB_OS OR NOT LIB_ARCH)
|
|
|
|
message(FATAL_ERROR "Must specify OS and ARCH to darwin_find_excluded_builtins_list!")
|
|
|
|
endif()
|
|
|
|
|
2015-09-26 07:29:03 +08:00
|
|
|
darwin_read_list_from_file(${LIB_OS}_BUILTINS
|
|
|
|
${DARWIN_EXCLUDE_DIR}/${LIB_OS}.txt)
|
|
|
|
darwin_read_list_from_file(${LIB_OS}_${LIB_ARCH}_BASE_BUILTINS
|
|
|
|
${DARWIN_EXCLUDE_DIR}/${LIB_OS}-${LIB_ARCH}.txt)
|
2015-09-23 23:18:17 +08:00
|
|
|
|
2015-09-25 05:51:09 +08:00
|
|
|
if(LIB_MIN_VERSION)
|
|
|
|
file(GLOB builtin_lists ${DARWIN_EXCLUDE_DIR}/${LIB_OS}*-${LIB_ARCH}.txt)
|
|
|
|
foreach(builtin_list ${builtin_lists})
|
|
|
|
string(REGEX MATCH "${LIB_OS}([0-9\\.]*)-${LIB_ARCH}.txt" VERSION_MATCHED "${builtin_list}")
|
|
|
|
if (VERSION_MATCHED AND NOT CMAKE_MATCH_1 VERSION_LESS LIB_MIN_VERSION)
|
|
|
|
if(NOT smallest_version)
|
|
|
|
set(smallest_version ${CMAKE_MATCH_1})
|
|
|
|
elseif(CMAKE_MATCH_1 VERSION_LESS smallest_version)
|
|
|
|
set(smallest_version ${CMAKE_MATCH_1})
|
|
|
|
endif()
|
2015-09-23 23:18:17 +08:00
|
|
|
endif()
|
2015-09-25 05:51:09 +08:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if(smallest_version)
|
2015-09-26 07:29:03 +08:00
|
|
|
darwin_read_list_from_file(${LIB_ARCH}_${LIB_OS}_BUILTINS
|
|
|
|
${DARWIN_EXCLUDE_DIR}/${LIB_OS}${smallest_version}-${LIB_ARCH}.txt)
|
2015-09-23 23:18:17 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2015-09-25 05:51:09 +08:00
|
|
|
set(${output_var}
|
|
|
|
${${LIB_ARCH}_${LIB_OS}_BUILTINS}
|
|
|
|
${${LIB_OS}_${LIB_ARCH}_BASE_BUILTINS}
|
|
|
|
${${LIB_OS}_BUILTINS} PARENT_SCOPE)
|
2015-09-23 23:18:17 +08:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# adds a single builtin library for a single OS & ARCH
|
2015-09-24 07:05:32 +08:00
|
|
|
macro(darwin_add_builtin_library name suffix)
|
2015-09-23 23:18:17 +08:00
|
|
|
cmake_parse_arguments(LIB
|
|
|
|
""
|
|
|
|
"PARENT_TARGET;OS;ARCH"
|
2015-09-24 07:05:32 +08:00
|
|
|
"SOURCES;CFLAGS;DEFS"
|
2015-09-23 23:18:17 +08:00
|
|
|
${ARGN})
|
2015-09-24 07:05:32 +08:00
|
|
|
set(libname "${name}.${suffix}_${LIB_ARCH}_${LIB_OS}")
|
2015-09-23 23:18:17 +08:00
|
|
|
add_library(${libname} STATIC ${LIB_SOURCES})
|
2015-11-11 01:26:40 +08:00
|
|
|
if(DARWIN_${LIB_OS}_SYSROOT)
|
|
|
|
set(sysroot_flag -isysroot ${DARWIN_${LIB_OS}_SYSROOT})
|
|
|
|
endif()
|
2015-09-23 23:18:17 +08:00
|
|
|
set_target_compile_flags(${libname}
|
2015-11-11 01:26:40 +08:00
|
|
|
${sysroot_flag}
|
2015-09-23 23:18:17 +08:00
|
|
|
${DARWIN_${LIB_OS}_BUILTIN_MIN_VER_FLAG}
|
|
|
|
${LIB_CFLAGS})
|
2015-09-24 07:05:32 +08:00
|
|
|
set_property(TARGET ${libname} APPEND PROPERTY
|
|
|
|
COMPILE_DEFINITIONS ${LIB_DEFS})
|
2015-09-23 23:18:17 +08:00
|
|
|
set_target_properties(${libname} PROPERTIES
|
|
|
|
OUTPUT_NAME ${libname}${COMPILER_RT_OS_SUFFIX})
|
|
|
|
set_target_properties(${libname} PROPERTIES
|
|
|
|
OSX_ARCHITECTURES ${LIB_ARCH})
|
|
|
|
|
|
|
|
if(LIB_PARENT_TARGET)
|
|
|
|
add_dependencies(${LIB_PARENT_TARGET} ${libname})
|
|
|
|
endif()
|
2015-09-24 07:05:32 +08:00
|
|
|
|
2015-09-26 06:31:17 +08:00
|
|
|
list(APPEND ${LIB_OS}_${suffix}_libs ${libname})
|
|
|
|
list(APPEND ${LIB_OS}_${suffix}_lipo_flags -arch ${arch} $<TARGET_FILE:${libname}>)
|
2015-09-24 07:05:32 +08:00
|
|
|
endmacro()
|
|
|
|
|
|
|
|
function(darwin_lipo_libs name)
|
|
|
|
cmake_parse_arguments(LIB
|
|
|
|
""
|
2015-10-03 06:14:25 +08:00
|
|
|
"PARENT_TARGET;OUTPUT_DIR;INSTALL_DIR"
|
2015-09-24 07:05:32 +08:00
|
|
|
"LIPO_FLAGS;DEPENDS"
|
|
|
|
${ARGN})
|
2015-11-10 07:37:45 +08:00
|
|
|
if(LIB_DEPENDS AND LIB_LIPO_FLAGS)
|
2015-11-10 07:07:45 +08:00
|
|
|
add_custom_command(OUTPUT ${LIB_OUTPUT_DIR}/lib${name}.a
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIB_OUTPUT_DIR}
|
|
|
|
COMMAND lipo -output
|
|
|
|
${LIB_OUTPUT_DIR}/lib${name}.a
|
|
|
|
-create ${LIB_LIPO_FLAGS}
|
|
|
|
DEPENDS ${LIB_DEPENDS}
|
|
|
|
)
|
|
|
|
add_custom_target(${name}
|
|
|
|
DEPENDS ${LIB_OUTPUT_DIR}/lib${name}.a)
|
|
|
|
add_dependencies(${LIB_PARENT_TARGET} ${name})
|
|
|
|
install(FILES ${LIB_OUTPUT_DIR}/lib${name}.a
|
|
|
|
DESTINATION ${LIB_INSTALL_DIR})
|
|
|
|
else()
|
|
|
|
message(WARNING "Not generating lipo target for ${name} because no input libraries exist.")
|
|
|
|
endif()
|
2015-09-23 23:18:17 +08:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Generates builtin libraries for all operating systems specified in ARGN. Each
|
|
|
|
# OS library is constructed by lipo-ing together single-architecture libraries.
|
|
|
|
macro(darwin_add_builtin_libraries)
|
2015-09-30 07:13:45 +08:00
|
|
|
set(DARWIN_EXCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Darwin-excludes)
|
|
|
|
|
2015-11-13 06:37:03 +08:00
|
|
|
set(CFLAGS "-fPIC -O3 -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer")
|
2015-11-12 05:38:35 +08:00
|
|
|
set(CMAKE_C_FLAGS "")
|
|
|
|
set(CMAKE_CXX_FLAGS "")
|
|
|
|
set(CMAKE_ASM_FLAGS "")
|
2015-09-25 06:29:58 +08:00
|
|
|
|
|
|
|
set(PROFILE_SOURCES ../profile/InstrProfiling
|
|
|
|
../profile/InstrProfilingBuffer
|
2016-01-08 06:54:46 +08:00
|
|
|
../profile/InstrProfilingPlatformDarwin
|
2016-01-08 08:07:50 +08:00
|
|
|
../profile/InstrProfilingWriter)
|
2015-09-23 23:18:17 +08:00
|
|
|
foreach (os ${ARGN})
|
2016-01-27 17:28:01 +08:00
|
|
|
list_intersect(DARWIN_BUILTIN_ARCHS DARWIN_${os}_ARCHS BUILTIN_SUPPORTED_ARCH)
|
2015-09-29 06:20:25 +08:00
|
|
|
foreach (arch ${DARWIN_BUILTIN_ARCHS})
|
2015-09-25 05:51:09 +08:00
|
|
|
darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS
|
|
|
|
OS ${os}
|
|
|
|
ARCH ${arch}
|
|
|
|
MIN_VERSION ${DARWIN_${os}_BUILTIN_MIN_VER})
|
|
|
|
|
2017-08-31 01:12:57 +08:00
|
|
|
filter_builtin_sources(filtered_sources
|
2015-09-29 01:38:44 +08:00
|
|
|
EXCLUDE ${arch}_${os}_EXCLUDED_BUILTINS
|
|
|
|
${${arch}_SOURCES})
|
2015-09-23 23:18:17 +08:00
|
|
|
|
2015-09-24 07:05:32 +08:00
|
|
|
darwin_add_builtin_library(clang_rt builtins
|
2015-09-23 23:18:17 +08:00
|
|
|
OS ${os}
|
|
|
|
ARCH ${arch}
|
2015-09-25 05:40:06 +08:00
|
|
|
SOURCES ${filtered_sources}
|
2015-11-12 05:38:35 +08:00
|
|
|
CFLAGS ${CFLAGS} -arch ${arch}
|
2015-09-23 23:18:17 +08:00
|
|
|
PARENT_TARGET builtins)
|
|
|
|
endforeach()
|
|
|
|
|
2015-09-29 06:18:31 +08:00
|
|
|
# Don't build cc_kext libraries for simulator platforms
|
2015-10-01 04:25:10 +08:00
|
|
|
if(NOT DARWIN_${os}_SKIP_CC_KEXT)
|
2015-09-29 06:18:31 +08:00
|
|
|
foreach (arch ${DARWIN_BUILTIN_ARCHS})
|
2015-09-29 07:09:46 +08:00
|
|
|
# By not specifying MIN_VERSION this only reads the OS and OS-arch lists.
|
|
|
|
# We don't want to filter out the builtins that are present in libSystem
|
|
|
|
# because kexts can't link libSystem.
|
|
|
|
darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS
|
|
|
|
OS ${os}
|
|
|
|
ARCH ${arch})
|
|
|
|
|
2017-08-31 01:12:57 +08:00
|
|
|
filter_builtin_sources(filtered_sources
|
2015-09-29 07:09:46 +08:00
|
|
|
EXCLUDE ${arch}_${os}_EXCLUDED_BUILTINS
|
|
|
|
${${arch}_SOURCES})
|
|
|
|
|
2015-09-29 06:18:31 +08:00
|
|
|
# In addition to the builtins cc_kext includes some profile sources
|
|
|
|
darwin_add_builtin_library(clang_rt cc_kext
|
|
|
|
OS ${os}
|
|
|
|
ARCH ${arch}
|
2015-09-29 07:09:46 +08:00
|
|
|
SOURCES ${filtered_sources} ${PROFILE_SOURCES}
|
2015-11-12 05:38:35 +08:00
|
|
|
CFLAGS ${CFLAGS} -arch ${arch} -mkernel
|
2015-09-29 06:18:31 +08:00
|
|
|
DEFS KERNEL_USE
|
|
|
|
PARENT_TARGET builtins)
|
|
|
|
endforeach()
|
2015-10-10 02:38:34 +08:00
|
|
|
set(archive_name clang_rt.cc_kext_${os})
|
|
|
|
if(${os} STREQUAL "osx")
|
|
|
|
set(archive_name clang_rt.cc_kext)
|
|
|
|
endif()
|
|
|
|
darwin_lipo_libs(${archive_name}
|
2015-09-29 06:18:31 +08:00
|
|
|
PARENT_TARGET builtins
|
|
|
|
LIPO_FLAGS ${${os}_cc_kext_lipo_flags}
|
|
|
|
DEPENDS ${${os}_cc_kext_libs}
|
2015-10-03 06:14:25 +08:00
|
|
|
OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
|
|
|
|
INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
|
2015-09-29 06:18:31 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# We put the x86 sim slices into the archives for their base OS
|
|
|
|
foreach (os ${ARGN})
|
|
|
|
if(NOT ${os} MATCHES ".*sim$")
|
|
|
|
darwin_lipo_libs(clang_rt.${os}
|
|
|
|
PARENT_TARGET builtins
|
|
|
|
LIPO_FLAGS ${${os}_builtins_lipo_flags} ${${os}sim_builtins_lipo_flags}
|
|
|
|
DEPENDS ${${os}_builtins_libs} ${${os}sim_builtins_libs}
|
2015-10-03 06:14:25 +08:00
|
|
|
OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
|
|
|
|
INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
|
2015-09-29 06:18:31 +08:00
|
|
|
endif()
|
2015-09-23 23:18:17 +08:00
|
|
|
endforeach()
|
2015-09-30 07:13:45 +08:00
|
|
|
darwin_add_embedded_builtin_libraries()
|
2015-09-23 23:18:17 +08:00
|
|
|
endmacro()
|
|
|
|
|
2015-11-11 01:26:35 +08:00
|
|
|
macro(darwin_add_embedded_builtin_libraries)
|
2015-11-10 08:41:18 +08:00
|
|
|
# this is a hacky opt-out. If you can't target both intel and arm
|
|
|
|
# architectures we bail here.
|
|
|
|
set(DARWIN_SOFT_FLOAT_ARCHS armv6m armv7m armv7em armv7)
|
|
|
|
set(DARWIN_HARD_FLOAT_ARCHS armv7em armv7)
|
2015-11-21 02:45:42 +08:00
|
|
|
if(COMPILER_RT_SUPPORTED_ARCH MATCHES ".*armv.*")
|
|
|
|
list(FIND COMPILER_RT_SUPPORTED_ARCH i386 i386_idx)
|
|
|
|
if(i386_idx GREATER -1)
|
|
|
|
list(APPEND DARWIN_HARD_FLOAT_ARCHS i386)
|
|
|
|
endif()
|
2015-11-10 08:41:18 +08:00
|
|
|
|
2015-11-21 02:45:42 +08:00
|
|
|
list(FIND COMPILER_RT_SUPPORTED_ARCH x86_64 x86_64_idx)
|
|
|
|
if(x86_64_idx GREATER -1)
|
|
|
|
list(APPEND DARWIN_HARD_FLOAT_ARCHS x86_64)
|
|
|
|
endif()
|
2015-11-10 08:41:18 +08:00
|
|
|
|
2015-11-21 02:45:42 +08:00
|
|
|
set(MACHO_SYM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/macho_embedded)
|
2015-11-10 08:41:18 +08:00
|
|
|
|
2015-11-21 02:45:42 +08:00
|
|
|
set(CFLAGS "-Oz -Wall -fomit-frame-pointer -ffreestanding")
|
|
|
|
set(CMAKE_C_FLAGS "")
|
|
|
|
set(CMAKE_CXX_FLAGS "")
|
|
|
|
set(CMAKE_ASM_FLAGS "")
|
2015-09-30 07:13:45 +08:00
|
|
|
|
2015-11-21 02:45:42 +08:00
|
|
|
set(SOFT_FLOAT_FLAG -mfloat-abi=soft)
|
|
|
|
set(HARD_FLOAT_FLAG -mfloat-abi=hard)
|
2015-09-30 07:13:45 +08:00
|
|
|
|
2015-11-21 02:45:42 +08:00
|
|
|
set(ENABLE_PIC Off)
|
|
|
|
set(PIC_FLAG -fPIC)
|
|
|
|
set(STATIC_FLAG -static)
|
2015-09-30 07:13:45 +08:00
|
|
|
|
2015-11-21 02:45:42 +08:00
|
|
|
set(DARWIN_macho_embedded_ARCHS armv6m armv7m armv7em armv7 i386 x86_64)
|
2015-09-30 07:13:45 +08:00
|
|
|
|
2015-11-21 02:45:42 +08:00
|
|
|
set(DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR
|
|
|
|
${COMPILER_RT_OUTPUT_DIR}/lib/macho_embedded)
|
|
|
|
set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR
|
|
|
|
${COMPILER_RT_INSTALL_PATH}/lib/macho_embedded)
|
|
|
|
|
|
|
|
set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi")
|
|
|
|
set(CFLAGS_i386 "-march=pentium")
|
2015-09-30 07:13:45 +08:00
|
|
|
|
2015-11-21 02:45:42 +08:00
|
|
|
darwin_read_list_from_file(common_FUNCTIONS ${MACHO_SYM_DIR}/common.txt)
|
|
|
|
darwin_read_list_from_file(thumb2_FUNCTIONS ${MACHO_SYM_DIR}/thumb2.txt)
|
|
|
|
darwin_read_list_from_file(thumb2_64_FUNCTIONS ${MACHO_SYM_DIR}/thumb2-64.txt)
|
|
|
|
darwin_read_list_from_file(arm_FUNCTIONS ${MACHO_SYM_DIR}/arm.txt)
|
|
|
|
darwin_read_list_from_file(i386_FUNCTIONS ${MACHO_SYM_DIR}/i386.txt)
|
2015-09-30 07:13:45 +08:00
|
|
|
|
2015-11-21 02:45:42 +08:00
|
|
|
|
|
|
|
set(armv6m_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS})
|
|
|
|
set(armv7m_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS})
|
|
|
|
set(armv7em_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS})
|
|
|
|
set(armv7_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS} ${thumb2_64_FUNCTIONS})
|
|
|
|
set(i386_FUNCTIONS ${common_FUNCTIONS} ${i386_FUNCTIONS})
|
|
|
|
set(x86_64_FUNCTIONS ${common_FUNCTIONS})
|
|
|
|
|
|
|
|
foreach(arch ${DARWIN_macho_embedded_ARCHS})
|
2017-08-31 01:12:57 +08:00
|
|
|
filter_builtin_sources(${arch}_filtered_sources
|
2015-11-21 02:45:42 +08:00
|
|
|
INCLUDE ${arch}_FUNCTIONS
|
|
|
|
${${arch}_SOURCES})
|
|
|
|
if(NOT ${arch}_filtered_sources)
|
|
|
|
message("${arch}_SOURCES: ${${arch}_SOURCES}")
|
|
|
|
message("${arch}_FUNCTIONS: ${${arch}_FUNCTIONS}")
|
|
|
|
message(FATAL_ERROR "Empty filtered sources!")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
foreach(float_type SOFT HARD)
|
|
|
|
foreach(type PIC STATIC)
|
|
|
|
string(TOLOWER "${float_type}_${type}" lib_suffix)
|
|
|
|
foreach(arch ${DARWIN_${float_type}_FLOAT_ARCHS})
|
|
|
|
set(DARWIN_macho_embedded_SYSROOT ${DARWIN_osx_SYSROOT})
|
|
|
|
set(float_flag)
|
|
|
|
if(${arch} MATCHES "^arm")
|
|
|
|
# x86 targets are hard float by default, but the complain about the
|
|
|
|
# float ABI flag, so don't pass it unless we're targeting arm.
|
|
|
|
set(float_flag ${${float_type}_FLOAT_FLAG})
|
|
|
|
endif()
|
|
|
|
darwin_add_builtin_library(clang_rt ${lib_suffix}
|
|
|
|
OS macho_embedded
|
|
|
|
ARCH ${arch}
|
|
|
|
SOURCES ${${arch}_filtered_sources}
|
|
|
|
CFLAGS ${CFLAGS} -arch ${arch} ${${type}_FLAG} ${float_flag} ${CFLAGS_${arch}}
|
|
|
|
PARENT_TARGET builtins)
|
|
|
|
endforeach()
|
|
|
|
foreach(lib ${macho_embedded_${lib_suffix}_libs})
|
|
|
|
set_target_properties(${lib} PROPERTIES LINKER_LANGUAGE C)
|
|
|
|
endforeach()
|
|
|
|
darwin_lipo_libs(clang_rt.${lib_suffix}
|
|
|
|
PARENT_TARGET builtins
|
|
|
|
LIPO_FLAGS ${macho_embedded_${lib_suffix}_lipo_flags}
|
|
|
|
DEPENDS ${macho_embedded_${lib_suffix}_libs}
|
|
|
|
OUTPUT_DIR ${DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR}
|
|
|
|
INSTALL_DIR ${DARWIN_macho_embedded_LIBRARY_INSTALL_DIR})
|
2015-09-30 07:13:45 +08:00
|
|
|
endforeach()
|
|
|
|
endforeach()
|
2015-11-21 02:45:42 +08:00
|
|
|
endif()
|
2015-11-11 01:26:35 +08:00
|
|
|
endmacro()
|