[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)
|
|
|
|
# Let's first try the internal SDK, otherwise use the public SDK.
|
|
|
|
execute_process(
|
|
|
|
COMMAND xcodebuild -version -sdk ${sdk_name}.internal Path
|
|
|
|
OUTPUT_VARIABLE var_internal
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_FILE /dev/null
|
|
|
|
)
|
|
|
|
if("" STREQUAL "${var_internal}")
|
|
|
|
execute_process(
|
|
|
|
COMMAND xcodebuild -version -sdk ${sdk_name} Path
|
|
|
|
OUTPUT_VARIABLE var_internal
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_FILE /dev/null
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
set(${var} ${var_internal} PARENT_SCOPE)
|
|
|
|
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)
|
|
|
|
set(archs ${ARGN})
|
|
|
|
message(STATUS "Finding valid architectures for ${os}...")
|
|
|
|
set(SIMPLE_CPP ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.cpp)
|
2015-09-17 02:29:52 +08:00
|
|
|
file(WRITE ${SIMPLE_CPP} "#include <iostream>\nint main() { std::cout << std::endl; return 0; }\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
|
|
|
|
|
|
|
set(os_linker_flags)
|
|
|
|
foreach(flag ${DARWIN_${os}_LINKFLAGS})
|
|
|
|
set(os_linker_flags "${os_linker_flags} ${flag}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# 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")
|
|
|
|
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(${CAN_TARGET_${os}_${arch}})
|
|
|
|
list(APPEND working_archs ${arch})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(${valid_archs} ${working_archs} PARENT_SCOPE)
|
|
|
|
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)
|
|
|
|
list_union(tmp_var DARWIN_osx_ARCHS ${input})
|
|
|
|
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
|
|
|
|
|
|
|
set(DARWIN_EXCLUDE_DIR ${CMAKE_SOURCE_DIR}/lib/builtins/Darwin-excludes)
|
|
|
|
|
|
|
|
# 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})
|
|
|
|
set_target_compile_flags(${libname}
|
|
|
|
-isysroot ${DARWIN_${LIB_OS}_SYSROOT}
|
|
|
|
${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-09-26 07:55:53 +08:00
|
|
|
"PARENT_TARGET;OUTPUT_DIR"
|
2015-09-24 07:05:32 +08:00
|
|
|
"LIPO_FLAGS;DEPENDS"
|
|
|
|
${ARGN})
|
2015-09-26 07:55:53 +08:00
|
|
|
add_custom_command(OUTPUT ${LIB_OUTPUT_DIR}/lib${name}.a
|
2015-09-24 07:05:32 +08:00
|
|
|
COMMAND lipo -output
|
2015-09-26 07:55:53 +08:00
|
|
|
${LIB_OUTPUT_DIR}/lib${name}.a
|
2015-09-24 07:05:32 +08:00
|
|
|
-create ${LIB_LIPO_FLAGS}
|
|
|
|
DEPENDS ${LIB_DEPENDS}
|
|
|
|
)
|
|
|
|
add_custom_target(${name}
|
2015-09-26 07:55:53 +08:00
|
|
|
DEPENDS ${LIB_OUTPUT_DIR}/lib${name}.a)
|
2015-09-24 07:05:32 +08:00
|
|
|
add_dependencies(${LIB_PARENT_TARGET} ${name})
|
2015-09-26 07:55:53 +08:00
|
|
|
install(FILES ${LIB_OUTPUT_DIR}/lib${name}.a
|
2015-09-26 06:39:19 +08:00
|
|
|
DESTINATION ${COMPILER_RT_INSTALL_PATH})
|
2015-09-23 23:18:17 +08:00
|
|
|
endfunction()
|
|
|
|
|
2015-09-25 05:40:06 +08:00
|
|
|
# Filter out generic versions of routines that are re-implemented in
|
|
|
|
# architecture specific manner. This prevents multiple definitions of the
|
|
|
|
# same symbols, making the symbol selection non-deterministic.
|
|
|
|
function(darwin_filter_builtin_sources output_var excluded_list)
|
|
|
|
set(intermediate ${ARGN})
|
|
|
|
foreach (_file ${intermediate})
|
|
|
|
get_filename_component(_name_we ${_file} NAME_WE)
|
|
|
|
list(FIND ${excluded_list} ${_name_we} _found)
|
|
|
|
if(_found GREATER -1)
|
|
|
|
list(REMOVE_ITEM intermediate ${_file})
|
|
|
|
elseif(${_file} MATCHES ".*/.*\\.S")
|
|
|
|
get_filename_component(_name ${_file} NAME)
|
|
|
|
string(REPLACE ".S" ".c" _cname "${_name}")
|
|
|
|
list(REMOVE_ITEM intermediate ${_cname})
|
|
|
|
endif ()
|
|
|
|
endforeach ()
|
|
|
|
set(${output_var} ${intermediate} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
2015-09-23 23:18:17 +08:00
|
|
|
# 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-25 02:26:34 +08:00
|
|
|
if(CMAKE_CONFIGURATION_TYPES)
|
|
|
|
foreach(type ${CMAKE_CONFIGURATION_TYPES})
|
|
|
|
set(CMAKE_C_FLAGS_${type} -O3)
|
|
|
|
set(CMAKE_CXX_FLAGS_${type} -O3)
|
|
|
|
endforeach()
|
|
|
|
else()
|
|
|
|
set(CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE} -O3)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(CMAKE_C_FLAGS "-fPIC -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer")
|
|
|
|
set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS})
|
|
|
|
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
|
2015-09-25 06:29:58 +08:00
|
|
|
|
|
|
|
set(PROFILE_SOURCES ../profile/InstrProfiling
|
|
|
|
../profile/InstrProfilingBuffer
|
|
|
|
../profile/InstrProfilingPlatformDarwin)
|
2015-09-23 23:18:17 +08:00
|
|
|
foreach (os ${ARGN})
|
|
|
|
list_union(DARWIN_BUILTIN_ARCHS DARWIN_${os}_ARCHS BUILTIN_SUPPORTED_ARCH)
|
|
|
|
foreach (arch ${DARWIN_BUILTIN_ARCHS})
|
2015-09-25 06:29:58 +08:00
|
|
|
# In addition to the builtins cc_kext includes some profile sources
|
2015-09-24 07:05:32 +08:00
|
|
|
darwin_add_builtin_library(clang_rt cc_kext
|
|
|
|
OS ${os}
|
|
|
|
ARCH ${arch}
|
2015-09-25 06:29:58 +08:00
|
|
|
SOURCES ${${arch}_SOURCES} ${PROFILE_SOURCES}
|
2015-09-25 02:26:34 +08:00
|
|
|
CFLAGS -arch ${arch} -mkernel
|
2015-09-24 07:05:32 +08:00
|
|
|
DEFS KERNEL_USE
|
|
|
|
PARENT_TARGET builtins)
|
|
|
|
|
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})
|
|
|
|
|
2015-09-25 05:40:06 +08:00
|
|
|
darwin_filter_builtin_sources(filtered_sources ${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-09-25 02:26:34 +08:00
|
|
|
CFLAGS -arch ${arch}
|
2015-09-23 23:18:17 +08:00
|
|
|
PARENT_TARGET builtins)
|
|
|
|
endforeach()
|
|
|
|
|
2015-09-24 07:05:32 +08:00
|
|
|
darwin_lipo_libs(clang_rt.cc_kext_${os}
|
|
|
|
PARENT_TARGET builtins
|
|
|
|
LIPO_FLAGS ${${os}_cc_kext_lipo_flags}
|
2015-09-26 07:55:53 +08:00
|
|
|
DEPENDS ${${os}_cc_kext_libs}
|
|
|
|
OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
|
2015-09-24 07:05:32 +08:00
|
|
|
darwin_lipo_libs(clang_rt.${os}
|
|
|
|
PARENT_TARGET builtins
|
|
|
|
LIPO_FLAGS ${${os}_builtins_lipo_flags}
|
2015-09-26 07:55:53 +08:00
|
|
|
DEPENDS ${${os}_builtins_libs}
|
|
|
|
OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
|
2015-09-23 23:18:17 +08:00
|
|
|
endforeach()
|
|
|
|
endmacro()
|
|
|
|
|