brintos

brintos / llvm-project-archived public Read only

0
0
Text · 23.4 KiB · c6777bd Raw
619 lines · plain
1include(CompilerRTUtils)2include(BuiltinTests)3 4set(CMAKE_LIPO "lipo" CACHE PATH "path to the lipo tool")5 6# On OS X SDKs can be installed anywhere on the base system and xcode-select can7# set the default Xcode to use. This function finds the SDKs that are present in8# the current Xcode.9function(find_darwin_sdk_dir var sdk_name)10  set(DARWIN_${sdk_name}_CACHED_SYSROOT "" CACHE STRING "Darwin SDK path for SDK ${sdk_name}.")11  set(DARWIN_PREFER_PUBLIC_SDK OFF CACHE BOOL "Prefer Darwin public SDK, even when an internal SDK is present.")12 13  if(DARWIN_${sdk_name}_CACHED_SYSROOT)14    set(${var} ${DARWIN_${sdk_name}_CACHED_SYSROOT} PARENT_SCOPE)15    return()16  endif()17  if(NOT DARWIN_PREFER_PUBLIC_SDK)18    # Let's first try the internal SDK, otherwise use the public SDK.19    execute_process(20      COMMAND xcrun --sdk ${sdk_name}.internal --show-sdk-path21      RESULT_VARIABLE result_process22      OUTPUT_VARIABLE var_internal23      OUTPUT_STRIP_TRAILING_WHITESPACE24      ERROR_FILE /dev/null25    )26  endif()27  if((NOT result_process EQUAL 0) OR "" STREQUAL "${var_internal}")28    execute_process(29      COMMAND xcrun --sdk ${sdk_name} --show-sdk-path30      RESULT_VARIABLE result_process31      OUTPUT_VARIABLE var_internal32      OUTPUT_STRIP_TRAILING_WHITESPACE33      ERROR_FILE /dev/null34    )35  else()36    set(${var}_INTERNAL ${var_internal} PARENT_SCOPE)37  endif()38  if(result_process EQUAL 0)39    set(${var} ${var_internal} PARENT_SCOPE)40  endif()41  message(STATUS "Checking DARWIN_${sdk_name}_SYSROOT - '${var_internal}'")42  set(DARWIN_${sdk_name}_CACHED_SYSROOT ${var_internal} CACHE STRING "Darwin SDK path for SDK ${sdk_name}." FORCE)43endfunction()44 45function(find_darwin_sdk_version var sdk_name)46  if (DARWIN_${sdk_name}_OVERRIDE_SDK_VERSION)47    message(WARNING "Overriding ${sdk_name} SDK version to ${DARWIN_${sdk_name}_OVERRIDE_SDK_VERSION}")48    set(${var} "${DARWIN_${sdk_name}_OVERRIDE_SDK_VERSION}" PARENT_SCOPE)49    return()50  endif()51  set(result_process 1)52  if(NOT DARWIN_PREFER_PUBLIC_SDK)53    # Let's first try the internal SDK, otherwise use the public SDK.54    execute_process(55      COMMAND xcrun --sdk ${sdk_name}.internal --show-sdk-version56      RESULT_VARIABLE result_process57      OUTPUT_VARIABLE var_internal58      OUTPUT_STRIP_TRAILING_WHITESPACE59      ERROR_FILE /dev/null60    )61  endif()62  if((NOT ${result_process} EQUAL 0) OR "" STREQUAL "${var_internal}")63    execute_process(64      COMMAND xcrun --sdk ${sdk_name} --show-sdk-version65      RESULT_VARIABLE result_process66      OUTPUT_VARIABLE var_internal67      OUTPUT_STRIP_TRAILING_WHITESPACE68      ERROR_FILE /dev/null69    )70  endif()71  if(NOT result_process EQUAL 0)72    message(FATAL_ERROR73      "Failed to determine SDK version for \"${sdk_name}\" SDK")74  endif()75  # Check reported version looks sane.76  if (NOT "${var_internal}" MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+)?$")77    message(FATAL_ERROR78      "Reported SDK version \"${var_internal}\" does not look like a version")79  endif()80  set(${var} ${var_internal} PARENT_SCOPE)81endfunction()82 83# There isn't a clear mapping of what architectures are supported with a given84# target platform, but ld's version output does list the architectures it can85# link for.86function(darwin_get_toolchain_supported_archs output_var)87  execute_process(88    COMMAND "${CMAKE_LINKER}" -v89    ERROR_VARIABLE LINKER_VERSION)90 91  string(REGEX MATCH "configured to support archs: ([^\n]+)"92         ARCHES_MATCHED "${LINKER_VERSION}")93  if(ARCHES_MATCHED)94    set(ARCHES "${CMAKE_MATCH_1}")95    message(STATUS "Got ld supported ARCHES: ${ARCHES}")96    string(REPLACE " " ";" ARCHES ${ARCHES})97  else()98    # If auto-detecting fails, fall back to a default set99    message(WARNING "Detecting supported architectures from 'ld -v' failed. Returning default set.")100    set(ARCHES "i386;x86_64;armv7;armv7s;arm64")101  endif()102  set(${output_var} ${ARCHES} PARENT_SCOPE)103endfunction()104 105# This function takes an OS and a list of architectures and identifies the106# subset of the architectures list that the installed toolchain can target.107function(darwin_test_archs os valid_archs)108  if(${valid_archs})109    message(STATUS "Using cached valid architectures for ${os}.")110    return()111  endif()112 113  set(archs ${ARGN})114  if(NOT TEST_COMPILE_ONLY)115    message(STATUS "Finding valid architectures for ${os}...")116    set(SIMPLE_C ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.c)117    file(WRITE ${SIMPLE_C} "#include <stdio.h>\n#include <unistd.h>\nint main(void) { printf(__FILE__); fork(); return 0; }\n")118 119    set(os_linker_flags)120    foreach(flag ${DARWIN_${os}_LINK_FLAGS})121      set(os_linker_flags "${os_linker_flags} ${flag}")122    endforeach()123 124    # Disable building for i386 for macOS SDK >= 10.15. The SDK doesn't support125    # linking for i386 and the corresponding OS doesn't allow running macOS i386126    # binaries.127    if ("${os}" STREQUAL "osx")128      find_darwin_sdk_version(macosx_sdk_version "macosx")129      if ("${macosx_sdk_version}" VERSION_GREATER 10.15 OR "${macosx_sdk_version}" VERSION_EQUAL 10.15)130        message(STATUS "Disabling i386 slice for ${valid_archs}")131        list(REMOVE_ITEM archs "i386")132      endif()133    endif()134  endif()135 136  # The simple program will build for x86_64h on the simulator because it is137  # compatible with x86_64 libraries (mostly), but since x86_64h isn't actually138  # a valid or useful architecture for the simulators. We should drop it.139  if(${os} MATCHES "^(iossim|tvossim|watchossim)$")140    list(REMOVE_ITEM archs "x86_64h")141    if ("i386" IN_LIST archs)142      list(REMOVE_ITEM archs "i386")143      message(STATUS "Disabling i386 slice for simulator")144    endif()145  endif()146 147  if(${os} MATCHES "^ios$")148    message(STATUS "Disabling sanitizers armv7* slice for ios")149    list(FILTER archs EXCLUDE REGEX "armv7.*")150  endif()151 152  set(working_archs)153  foreach(arch ${archs})154 155    set(arch_linker_flags "-arch ${arch} ${os_linker_flags}")156    if(TEST_COMPILE_ONLY)157      # `-w` is used to surpress compiler warnings which `try_compile_only()` treats as an error.158      try_compile_only(CAN_TARGET_${os}_${arch} FLAGS -v -arch ${arch} ${DARWIN_${os}_CFLAGS} -w)159    else()160      set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})161      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${arch_linker_flags}")162      try_compile(CAN_TARGET_${os}_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_C}163                  COMPILE_DEFINITIONS "-v -arch ${arch}" ${DARWIN_${os}_CFLAGS}164                  OUTPUT_VARIABLE TEST_OUTPUT)165      set(CMAKE_EXE_LINKER_FLAGS ${SAVED_CMAKE_EXE_LINKER_FLAGS})166    endif()167    if(${CAN_TARGET_${os}_${arch}})168      list(APPEND working_archs ${arch})169    else()170      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log171        "Testing compiler for supporting ${os}-${arch}:\n"172        "${TEST_OUTPUT}\n")173    endif()174  endforeach()175  set(${valid_archs} ${working_archs}176    CACHE STRING "List of valid architectures for platform ${os}." FORCE)177endfunction()178 179# This function checks the host cputype/cpusubtype to filter supported180# architecture for the host OS. This is used to determine which tests are181# available for the host.182function(darwin_filter_host_archs input output)183  list_intersect(tmp_var DARWIN_osx_ARCHS ${input})184  execute_process(185    COMMAND sysctl hw.cputype186    OUTPUT_VARIABLE CPUTYPE)187  string(REGEX MATCH "hw.cputype: ([0-9]*)"188         CPUTYPE_MATCHED "${CPUTYPE}")189  set(ARM_HOST Off)190  if(CPUTYPE_MATCHED)191    # ARM cputype is (0x01000000 | 12) and X86(_64) is always 7.192    if(${CMAKE_MATCH_1} GREATER 11)193      set(ARM_HOST On)194    endif()195  endif()196 197  # arm64e isn't usually supported out of the box on darwin, because of ABI.198  list(REMOVE_ITEM tmp_var arm64e)199 200  if(ARM_HOST)201    list(REMOVE_ITEM tmp_var i386)202    list(REMOVE_ITEM tmp_var x86_64)203    list(REMOVE_ITEM tmp_var x86_64h)204  else()205    list(REMOVE_ITEM tmp_var arm64)206    execute_process(207      COMMAND sysctl hw.cpusubtype208      OUTPUT_VARIABLE SUBTYPE)209    string(REGEX MATCH "hw.cpusubtype: ([0-9]*)"210           SUBTYPE_MATCHED "${SUBTYPE}")211 212    set(HASWELL_SUPPORTED Off)213    if(SUBTYPE_MATCHED)214      if(${CMAKE_MATCH_1} GREATER 7)215        set(HASWELL_SUPPORTED On)216      endif()217    endif()218    if(NOT HASWELL_SUPPORTED)219      list(REMOVE_ITEM tmp_var x86_64h)220    endif()221  endif()222 223  set(${output} ${tmp_var} PARENT_SCOPE)224endfunction()225 226# Read and process the exclude file into a list of symbols227function(darwin_read_list_from_file output_var file)228  if(EXISTS ${file})229    file(READ ${file} EXCLUDES)230    string(REPLACE "\n" ";" EXCLUDES ${EXCLUDES})231    set(${output_var} ${EXCLUDES} PARENT_SCOPE)232  endif()233endfunction()234 235# this function takes an OS, architecture and minimum version and provides a236# list of builtin functions to exclude237function(darwin_find_excluded_builtins_list output_var)238  cmake_parse_arguments(LIB239    ""240    "OS;ARCH;MIN_VERSION"241    ""242    ${ARGN})243 244  if(NOT LIB_OS OR NOT LIB_ARCH)245    message(FATAL_ERROR "Must specify OS and ARCH to darwin_find_excluded_builtins_list!")246  endif()247 248  darwin_read_list_from_file(${LIB_OS}_BUILTINS249    ${DARWIN_EXCLUDE_DIR}/${LIB_OS}.txt)250  darwin_read_list_from_file(${LIB_OS}_${LIB_ARCH}_BASE_BUILTINS251    ${DARWIN_EXCLUDE_DIR}/${LIB_OS}-${LIB_ARCH}.txt)252 253  if(LIB_MIN_VERSION)254    file(GLOB builtin_lists ${DARWIN_EXCLUDE_DIR}/${LIB_OS}*-${LIB_ARCH}.txt)255    foreach(builtin_list ${builtin_lists})256      string(REGEX MATCH "${LIB_OS}([0-9\\.]*)-${LIB_ARCH}.txt" VERSION_MATCHED "${builtin_list}")257      if (VERSION_MATCHED AND NOT CMAKE_MATCH_1 VERSION_LESS LIB_MIN_VERSION)258        if(NOT smallest_version)259          set(smallest_version ${CMAKE_MATCH_1})260        elseif(CMAKE_MATCH_1 VERSION_LESS smallest_version)261          set(smallest_version ${CMAKE_MATCH_1})262        endif()263      endif()264    endforeach()265 266    if(smallest_version)267      darwin_read_list_from_file(${LIB_ARCH}_${LIB_OS}_BUILTINS268        ${DARWIN_EXCLUDE_DIR}/${LIB_OS}${smallest_version}-${LIB_ARCH}.txt)269    endif()270  endif()271 272  set(${output_var}273      ${${LIB_ARCH}_${LIB_OS}_BUILTINS}274      ${${LIB_OS}_${LIB_ARCH}_BASE_BUILTINS}275      ${${LIB_OS}_BUILTINS} PARENT_SCOPE)276endfunction()277 278# adds a single builtin library for a single OS & ARCH279macro(darwin_add_builtin_library name suffix)280  cmake_parse_arguments(LIB281    ""282    "PARENT_TARGET;OS;ARCH"283    "SOURCES;CFLAGS;DEFS;INCLUDE_DIRS"284    ${ARGN})285  set(libname "${name}.${suffix}_${LIB_ARCH}_${LIB_OS}")286  add_library(${libname} STATIC ${LIB_SOURCES})287  if(DARWIN_${LIB_OS}_SYSROOT)288    set(sysroot_flag -isysroot ${DARWIN_${LIB_OS}_SYSROOT})289  endif()290 291  # Make a copy of the compilation flags.292  set(builtin_cflags ${LIB_CFLAGS})293 294  # Strip out any inappropriate flags for the target.295  if("${LIB_ARCH}" MATCHES "^(armv7|armv7k|armv7s)$")296    set(builtin_cflags "")297    foreach(cflag "${LIB_CFLAGS}")298      string(REPLACE "-fomit-frame-pointer" "" cflag "${cflag}")299      list(APPEND builtin_cflags ${cflag})300    endforeach(cflag)301  endif()302 303  if ("${LIB_OS}" MATCHES ".*sim$")304    # Pass an explicit -simulator environment to the -target option to ensure305    # that we don't rely on the architecture to infer whether we're building306    # for the simulator.307    string(REGEX REPLACE "sim" "" base_os "${LIB_OS}")308    list(APPEND builtin_cflags309         -target "${LIB_ARCH}-apple-${base_os}${DARWIN_${LIBOS}_BUILTIN_MIN_VER}-simulator")310  endif()311 312  if ("${COMPILER_RT_ENABLE_MACCATALYST}" AND313      "${LIB_OS}" MATCHES "^osx$")314    # Build the macOS builtins with Mac Catalyst support.315    list(APPEND builtin_cflags316      "SHELL:-target ${LIB_ARCH}-apple-macos${DARWIN_osx_BUILTIN_MIN_VER} -darwin-target-variant ${LIB_ARCH}-apple-ios13.1-macabi")317  endif()318 319  set_target_compile_flags(${libname}320    ${sysroot_flag}321    ${DARWIN_${LIB_OS}_BUILTIN_MIN_VER_FLAG}322    ${builtin_cflags})323  target_include_directories(${libname}324    PRIVATE ${LIB_INCLUDE_DIRS})325  set_property(TARGET ${libname} APPEND PROPERTY326      COMPILE_DEFINITIONS ${LIB_DEFS})327  set_target_properties(${libname} PROPERTIES328      OUTPUT_NAME ${libname}${COMPILER_RT_OS_SUFFIX})329  set_target_properties(${libname} PROPERTIES330    OSX_ARCHITECTURES ${LIB_ARCH})331 332  if(LIB_PARENT_TARGET)333    add_dependencies(${LIB_PARENT_TARGET} ${libname})334  endif()335 336  list(APPEND ${LIB_OS}_${suffix}_libs ${libname})337  list(APPEND ${LIB_OS}_${suffix}_lipo_flags -arch ${arch} $<TARGET_FILE:${libname}>)338  set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT/Libraries")339endmacro()340 341function(darwin_lipo_libs name)342  cmake_parse_arguments(LIB343    ""344    "PARENT_TARGET;OUTPUT_DIR;INSTALL_DIR"345    "LIPO_FLAGS;DEPENDS"346    ${ARGN})347  if(LIB_DEPENDS AND LIB_LIPO_FLAGS)348    add_custom_command(OUTPUT ${LIB_OUTPUT_DIR}/lib${name}.a349      COMMAND ${CMAKE_COMMAND} -E make_directory ${LIB_OUTPUT_DIR}350      COMMAND ${CMAKE_LIPO} -output351              ${LIB_OUTPUT_DIR}/lib${name}.a352              -create ${LIB_LIPO_FLAGS}353      DEPENDS ${LIB_DEPENDS}354      )355    add_custom_target(${name}356      DEPENDS ${LIB_OUTPUT_DIR}/lib${name}.a)357    set_target_properties(${name} PROPERTIES FOLDER "Compiler-RT/Misc")358    add_dependencies(${LIB_PARENT_TARGET} ${name})359 360    if(CMAKE_CONFIGURATION_TYPES)361      set(install_component ${LIB_PARENT_TARGET})362    else()363      set(install_component ${name})364    endif()365    install(FILES ${LIB_OUTPUT_DIR}/lib${name}.a366      DESTINATION ${LIB_INSTALL_DIR}367      COMPONENT ${install_component})368    add_compiler_rt_install_targets(${name} PARENT_TARGET ${LIB_PARENT_TARGET})369  else()370    message(WARNING "Not generating lipo target for ${name} because no input libraries exist.")371  endif()372endfunction()373 374# Filter the list of builtin sources for Darwin, then delegate to the generic375# filtering.376#377# `exclude_or_include` must be one of:378#  - EXCLUDE: remove every item whose name (w/o extension) matches a name in379#    `excluded_list`.380#  - INCLUDE: keep only items whose name (w/o extension) matches something381#    in `excluded_list`.382function(darwin_filter_builtin_sources output_var name exclude_or_include excluded_list)383  if(exclude_or_include STREQUAL "EXCLUDE")384    set(filter_action GREATER)385    set(filter_value -1)386  elseif(exclude_or_include STREQUAL "INCLUDE")387    set(filter_action LESS)388    set(filter_value 0)389  else()390    message(FATAL_ERROR "darwin_filter_builtin_sources called without EXCLUDE|INCLUDE")391  endif()392 393  set(intermediate ${ARGN})394  foreach(_file ${intermediate})395    get_filename_component(_name_we ${_file} NAME_WE)396    list(FIND ${excluded_list} ${_name_we} _found)397    if(_found ${filter_action} ${filter_value})398      list(REMOVE_ITEM intermediate ${_file})399    endif()400  endforeach()401 402  filter_builtin_sources(intermediate ${name})403  set(${output_var} ${intermediate} PARENT_SCOPE)404endfunction()405 406# Generates builtin libraries for all operating systems specified in ARGN. Each407# OS library is constructed by lipo-ing together single-architecture libraries.408macro(darwin_add_builtin_libraries)409  set(DARWIN_EXCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Darwin-excludes)410 411  set(CFLAGS -fPIC -O3 -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer)412  set(CMAKE_C_FLAGS "")413  set(CMAKE_CXX_FLAGS "")414  set(CMAKE_ASM_FLAGS "")415 416  append_list_if(COMPILER_RT_HAS_ASM_LSE -DHAS_ASM_LSE CFLAGS)417 418  set(PROFILE_SOURCES ../profile/InstrProfiling.c419                      ../profile/InstrProfilingBuffer.c420                      ../profile/InstrProfilingPlatformDarwin.c421                      ../profile/InstrProfilingWriter.c422                      ../profile/InstrProfilingInternal.c423                      ../profile/InstrProfilingVersionVar.c)424  foreach (os ${ARGN})425    set(macosx_sdk_version 99999)426    if ("${os}" STREQUAL "osx")427      find_darwin_sdk_version(macosx_sdk_version "macosx")428    endif()429    add_security_warnings(CFLAGS ${macosx_sdk_version})430 431    list_intersect(DARWIN_BUILTIN_ARCHS DARWIN_${os}_BUILTIN_ARCHS BUILTIN_SUPPORTED_ARCH)432 433    if((arm64 IN_LIST DARWIN_BUILTIN_ARCHS OR arm64e IN_LIST DARWIN_BUILTIN_ARCHS) AND NOT TARGET lse_builtin_symlinks)434      add_custom_target(435        lse_builtin_symlinks436        BYPRODUCTS ${lse_builtins}437        ${arm64_lse_commands}438      )439 440      set(deps_arm64 lse_builtin_symlinks)441      set(deps_arm64e lse_builtin_symlinks)442    endif()443 444    foreach (arch ${DARWIN_BUILTIN_ARCHS})445      darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS446                              OS ${os}447                              ARCH ${arch}448                              MIN_VERSION ${DARWIN_${os}_BUILTIN_MIN_VER})449      check_c_source_compiles("_Float16 foo(_Float16 x) { return x; }"450                              COMPILER_RT_HAS_${arch}_FLOAT16)451      append_list_if(COMPILER_RT_HAS_${arch}_FLOAT16 -DCOMPILER_RT_HAS_FLOAT16 BUILTIN_CFLAGS_${arch})452      check_c_source_compiles("__bf16 foo(__bf16 x) { return x; }"453                              COMPILER_RT_HAS_${arch}_BFLOAT16)454      # Build BF16 files only when "__bf16" is available.455      if(COMPILER_RT_HAS_${arch}_BFLOAT16)456        list(APPEND ${arch}_SOURCES ${BF16_SOURCES})457      endif()458      darwin_filter_builtin_sources(filtered_sources459        ${os}_${arch}460        EXCLUDE ${arch}_${os}_EXCLUDED_BUILTINS461        ${${arch}_SOURCES})462 463      darwin_add_builtin_library(clang_rt builtins464                              OS ${os}465                              ARCH ${arch}466                              DEPS ${deps_${arch}}467                              SOURCES ${filtered_sources}468                              CFLAGS ${CFLAGS} -arch ${arch}469                              PARENT_TARGET builtins)470    endforeach()471 472    # Don't build cc_kext libraries for simulator platforms473    if(NOT DARWIN_${os}_SKIP_CC_KEXT)474      foreach (arch ${DARWIN_BUILTIN_ARCHS})475        # By not specifying MIN_VERSION this only reads the OS and OS-arch lists.476        # We don't want to filter out the builtins that are present in libSystem477        # because kexts can't link libSystem.478        darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS479                              OS ${os}480                              ARCH ${arch})481 482        darwin_filter_builtin_sources(filtered_sources483          cc_kext_${os}_${arch}484          EXCLUDE ${arch}_${os}_EXCLUDED_BUILTINS485          ${${arch}_SOURCES})486 487        # In addition to the builtins cc_kext includes some profile sources488        darwin_add_builtin_library(clang_rt cc_kext489                                OS ${os}490                                ARCH ${arch}491                                DEPS ${deps_${arch}}492                                SOURCES ${filtered_sources} ${PROFILE_SOURCES}493                                CFLAGS ${CFLAGS} -arch ${arch} -mkernel494                                DEFS KERNEL_USE495                                INCLUDE_DIRS ../../include496                                PARENT_TARGET builtins)497      endforeach()498      set(archive_name clang_rt.cc_kext_${os})499      if(${os} STREQUAL "osx")500        set(archive_name clang_rt.cc_kext)501      endif()502      darwin_lipo_libs(${archive_name}503                      PARENT_TARGET builtins504                      LIPO_FLAGS ${${os}_cc_kext_lipo_flags}505                      DEPENDS ${${os}_cc_kext_libs}506                      OUTPUT_DIR ${COMPILER_RT_OUTPUT_LIBRARY_DIR}507                      INSTALL_DIR ${COMPILER_RT_INSTALL_LIBRARY_DIR})508    endif()509  endforeach()510 511  foreach (os ${ARGN})512    darwin_lipo_libs(clang_rt.${os}513                     PARENT_TARGET builtins514                     LIPO_FLAGS ${${os}_builtins_lipo_flags}515                     DEPENDS ${${os}_builtins_libs}516                     OUTPUT_DIR ${COMPILER_RT_OUTPUT_LIBRARY_DIR}517                     INSTALL_DIR ${COMPILER_RT_INSTALL_LIBRARY_DIR})518  endforeach()519  darwin_add_embedded_builtin_libraries()520endmacro()521 522macro(darwin_add_embedded_builtin_libraries)523  # this is a hacky opt-out. If you can't target both intel and arm524  # architectures we bail here.525  set(DARWIN_SOFT_FLOAT_ARCHS armv6m armv7m armv7em armv7)526  set(DARWIN_HARD_FLOAT_ARCHS armv7em armv7)527  if(COMPILER_RT_SUPPORTED_ARCH MATCHES ".*armv.*")528    list(FIND COMPILER_RT_SUPPORTED_ARCH i386 i386_idx)529    if(i386_idx GREATER -1)530      list(APPEND DARWIN_HARD_FLOAT_ARCHS i386)531    endif()532 533    list(FIND COMPILER_RT_SUPPORTED_ARCH x86_64 x86_64_idx)534    if(x86_64_idx GREATER -1)535      list(APPEND DARWIN_HARD_FLOAT_ARCHS x86_64)536    endif()537 538    set(MACHO_SYM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/macho_embedded)539 540    set(CFLAGS -Oz -Wall -fomit-frame-pointer -ffreestanding)541    set(CMAKE_C_FLAGS "")542    set(CMAKE_CXX_FLAGS "")543    set(CMAKE_ASM_FLAGS "")544 545    set(SOFT_FLOAT_FLAG -mfloat-abi=soft)546    set(HARD_FLOAT_FLAG -mfloat-abi=hard)547 548    set(ENABLE_PIC Off)549    set(PIC_FLAG -fPIC)550    set(STATIC_FLAG -static)551 552    set(DARWIN_macho_embedded_ARCHS armv6m armv7m armv7em armv7 i386 x86_64)553 554    set(DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR555      ${COMPILER_RT_OUTPUT_LIBRARY_DIR}/macho_embedded)556    set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR557      ${COMPILER_RT_INSTALL_LIBRARY_DIR}/macho_embedded)558 559    set(CFLAGS_armv7 -target thumbv7-apple-darwin-eabi)560    set(CFLAGS_i386 -march=pentium)561 562    darwin_read_list_from_file(common_FUNCTIONS ${MACHO_SYM_DIR}/common.txt)563    darwin_read_list_from_file(thumb2_FUNCTIONS ${MACHO_SYM_DIR}/thumb2.txt)564    darwin_read_list_from_file(thumb2_64_FUNCTIONS ${MACHO_SYM_DIR}/thumb2-64.txt)565    darwin_read_list_from_file(arm_FUNCTIONS ${MACHO_SYM_DIR}/arm.txt)566    darwin_read_list_from_file(i386_FUNCTIONS ${MACHO_SYM_DIR}/i386.txt)567 568 569    set(armv6m_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS})570    set(armv7m_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS})571    set(armv7em_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS})572    set(armv7_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS} ${thumb2_64_FUNCTIONS})573    set(i386_FUNCTIONS ${common_FUNCTIONS} ${i386_FUNCTIONS})574    set(x86_64_FUNCTIONS ${common_FUNCTIONS})575 576    foreach(arch ${DARWIN_macho_embedded_ARCHS})577      darwin_filter_builtin_sources(${arch}_filtered_sources578        macho_embedded_${arch}579        INCLUDE ${arch}_FUNCTIONS580        ${${arch}_SOURCES})581      if(NOT ${arch}_filtered_sources)582        message(WARNING "${arch}_SOURCES: ${${arch}_SOURCES}")583        message(WARNING "${arch}_FUNCTIONS: ${${arch}_FUNCTIONS}")584        message(FATAL_ERROR "Empty filtered sources!")585      endif()586    endforeach()587 588    foreach(float_type SOFT HARD)589      foreach(type PIC STATIC)590        string(TOLOWER "${float_type}_${type}" lib_suffix)591        foreach(arch ${DARWIN_${float_type}_FLOAT_ARCHS})592          set(DARWIN_macho_embedded_SYSROOT ${DARWIN_osx_SYSROOT})593          set(float_flag)594          if(${arch} MATCHES "^arm")595            # x86 targets are hard float by default, but the complain about the596            # float ABI flag, so don't pass it unless we're targeting arm.597            set(float_flag ${${float_type}_FLOAT_FLAG})598          endif()599          darwin_add_builtin_library(clang_rt ${lib_suffix}600                                OS macho_embedded601                                ARCH ${arch}602                                SOURCES ${${arch}_filtered_sources}603                                CFLAGS ${CFLAGS} -arch ${arch} ${${type}_FLAG} ${float_flag} ${CFLAGS_${arch}}604                                PARENT_TARGET builtins)605        endforeach()606        foreach(lib ${macho_embedded_${lib_suffix}_libs})607          set_target_properties(${lib} PROPERTIES LINKER_LANGUAGE C)608        endforeach()609        darwin_lipo_libs(clang_rt.${lib_suffix}610                      PARENT_TARGET builtins611                      LIPO_FLAGS ${macho_embedded_${lib_suffix}_lipo_flags}612                      DEPENDS ${macho_embedded_${lib_suffix}_libs}613                      OUTPUT_DIR ${DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR}614                      INSTALL_DIR ${DARWIN_macho_embedded_LIBRARY_INSTALL_DIR})615      endforeach()616    endforeach()617  endif()618endmacro()619