1include(CMakeParseArguments)
2include(CompilerRTUtils)
3include(BuiltinTests)
4
5set(CMAKE_LIPO "lipo" CACHE PATH "path to the lipo tool")
6
7# On OS X SDKs can be installed anywhere on the base system and xcode-select can
8# set the default Xcode to use. This function finds the SDKs that are present in
9# the current Xcode.
10function(find_darwin_sdk_dir var sdk_name)
11  set(DARWIN_${sdk_name}_CACHED_SYSROOT "" CACHE STRING "Darwin SDK path for SDK ${sdk_name}.")
12  set(DARWIN_PREFER_PUBLIC_SDK OFF CACHE BOOL "Prefer Darwin public SDK, even when an internal SDK is present.")
13
14  if(DARWIN_${sdk_name}_CACHED_SYSROOT)
15    set(${var} ${DARWIN_${sdk_name}_CACHED_SYSROOT} PARENT_SCOPE)
16    return()
17  endif()
18  if(NOT DARWIN_PREFER_PUBLIC_SDK)
19    # Let's first try the internal SDK, otherwise use the public SDK.
20    execute_process(
21      COMMAND xcrun --sdk ${sdk_name}.internal --show-sdk-path
22      RESULT_VARIABLE result_process
23      OUTPUT_VARIABLE var_internal
24      OUTPUT_STRIP_TRAILING_WHITESPACE
25      ERROR_FILE /dev/null
26    )
27  endif()
28  if((NOT result_process EQUAL 0) OR "" STREQUAL "${var_internal}")
29    execute_process(
30      COMMAND xcrun --sdk ${sdk_name} --show-sdk-path
31      RESULT_VARIABLE result_process
32      OUTPUT_VARIABLE var_internal
33      OUTPUT_STRIP_TRAILING_WHITESPACE
34      ERROR_FILE /dev/null
35    )
36  else()
37    set(${var}_INTERNAL ${var_internal} PARENT_SCOPE)
38  endif()
39  if(result_process EQUAL 0)
40    set(${var} ${var_internal} PARENT_SCOPE)
41  endif()
42  message(STATUS "Checking DARWIN_${sdk_name}_SYSROOT - '${var_internal}'")
43  set(DARWIN_${sdk_name}_CACHED_SYSROOT ${var_internal} CACHE STRING "Darwin SDK path for SDK ${sdk_name}." FORCE)
44endfunction()
45
46function(find_darwin_sdk_version var sdk_name)
47  # We deliberately don't cache the result here because
48  # CMake's caching causes too many problems.
49  set(result_process 1)
50  if(NOT DARWIN_PREFER_PUBLIC_SDK)
51    # Let's first try the internal SDK, otherwise use the public SDK.
52    execute_process(
53      COMMAND xcrun --sdk ${sdk_name}.internal --show-sdk-version
54      RESULT_VARIABLE result_process
55      OUTPUT_VARIABLE var_internal
56      OUTPUT_STRIP_TRAILING_WHITESPACE
57      ERROR_FILE /dev/null
58    )
59  endif()
60  if((NOT ${result_process} EQUAL 0) OR "" STREQUAL "${var_internal}")
61    execute_process(
62      COMMAND xcrun --sdk ${sdk_name} --show-sdk-version
63      RESULT_VARIABLE result_process
64      OUTPUT_VARIABLE var_internal
65      OUTPUT_STRIP_TRAILING_WHITESPACE
66      ERROR_FILE /dev/null
67    )
68  endif()
69  if(NOT result_process EQUAL 0)
70    message(FATAL_ERROR
71      "Failed to determine SDK version for \"${sdk_name}\" SDK")
72  endif()
73  # Check reported version looks sane.
74  if (NOT "${var_internal}" MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+)?$")
75    message(FATAL_ERROR
76      "Reported SDK version \"${var_internal}\" does not look like a version")
77  endif()
78  set(${var} ${var_internal} PARENT_SCOPE)
79endfunction()
80
81# There isn't a clear mapping of what architectures are supported with a given
82# target platform, but ld's version output does list the architectures it can
83# link for.
84function(darwin_get_toolchain_supported_archs output_var)
85  execute_process(
86    COMMAND "${CMAKE_LINKER}" -v
87    ERROR_VARIABLE LINKER_VERSION)
88
89  string(REGEX MATCH "configured to support archs: ([^\n]+)"
90         ARCHES_MATCHED "${LINKER_VERSION}")
91  if(ARCHES_MATCHED)
92    set(ARCHES "${CMAKE_MATCH_1}")
93    message(STATUS "Got ld supported ARCHES: ${ARCHES}")
94    string(REPLACE " " ";" ARCHES ${ARCHES})
95  else()
96    # If auto-detecting fails, fall back to a default set
97    message(WARNING "Detecting supported architectures from 'ld -v' failed. Returning default set.")
98    set(ARCHES "i386;x86_64;armv7;armv7s;arm64")
99  endif()
100
101  set(${output_var} ${ARCHES} PARENT_SCOPE)
102endfunction()
103
104# This function takes an OS and a list of architectures and identifies the
105# subset of the architectures list that the installed toolchain can target.
106function(darwin_test_archs os valid_archs)
107  if(${valid_archs})
108    message(STATUS "Using cached valid architectures for ${os}.")
109    return()
110  endif()
111
112  set(archs ${ARGN})
113  if(NOT TEST_COMPILE_ONLY)
114    message(STATUS "Finding valid architectures for ${os}...")
115    set(SIMPLE_C ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.c)
116    file(WRITE ${SIMPLE_C} "#include <stdio.h>\nint main() { printf(__FILE__); return 0; }\n")
117
118    set(os_linker_flags)
119    foreach(flag ${DARWIN_${os}_LINK_FLAGS})
120      set(os_linker_flags "${os_linker_flags} ${flag}")
121    endforeach()
122
123    # Disable building for i386 for macOS SDK >= 10.15. The SDK doesn't support
124    # linking for i386 and the corresponding OS doesn't allow running macOS i386
125    # binaries.
126    if ("${os}" STREQUAL "osx")
127      find_darwin_sdk_version(macosx_sdk_version "macosx")
128      if ("${macosx_sdk_version}" VERSION_GREATER 10.15 OR "${macosx_sdk_version}" VERSION_EQUAL 10.15)
129        message(STATUS "Disabling i386 slice for ${valid_archs}")
130        list(REMOVE_ITEM archs "i386")
131      endif()
132    endif()
133  endif()
134
135  # The simple program will build for x86_64h on the simulator because it is
136  # compatible with x86_64 libraries (mostly), but since x86_64h isn't actually
137  # a valid or useful architecture for the iOS simulator we should drop it.
138  if(${os} MATCHES "^(iossim|tvossim|watchossim)$")
139    list(REMOVE_ITEM archs "x86_64h")
140  endif()
141
142  set(working_archs)
143  foreach(arch ${archs})
144
145    set(arch_linker_flags "-arch ${arch} ${os_linker_flags}")
146    if(TEST_COMPILE_ONLY)
147      # `-w` is used to surpress compiler warnings which `try_compile_only()` treats as an error.
148      try_compile_only(CAN_TARGET_${os}_${arch} FLAGS -v -arch ${arch} ${DARWIN_${os}_CFLAGS} -w)
149    else()
150      set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
151      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${arch_linker_flags}")
152      try_compile(CAN_TARGET_${os}_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_C}
153                  COMPILE_DEFINITIONS "-v -arch ${arch}" ${DARWIN_${os}_CFLAGS}
154                  OUTPUT_VARIABLE TEST_OUTPUT)
155      set(CMAKE_EXE_LINKER_FLAGS ${SAVED_CMAKE_EXE_LINKER_FLAGS})
156    endif()
157    if(${CAN_TARGET_${os}_${arch}})
158      list(APPEND working_archs ${arch})
159    else()
160      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
161        "Testing compiler for supporting ${os}-${arch}:\n"
162        "${TEST_OUTPUT}\n")
163    endif()
164  endforeach()
165  set(${valid_archs} ${working_archs}
166    CACHE STRING "List of valid architectures for platform ${os}." FORCE)
167endfunction()
168
169# This function checks the host cpusubtype to see if it is post-haswell. Haswell
170# and later machines can run x86_64h binaries. Haswell is cpusubtype 8.
171function(darwin_filter_host_archs input output)
172  list_intersect(tmp_var DARWIN_osx_ARCHS ${input})
173  execute_process(
174    COMMAND sysctl hw.cpusubtype
175    OUTPUT_VARIABLE SUBTYPE)
176
177  string(REGEX MATCH "hw.cpusubtype: ([0-9]*)"
178         SUBTYPE_MATCHED "${SUBTYPE}")
179  set(HASWELL_SUPPORTED Off)
180  if(SUBTYPE_MATCHED)
181    if(${CMAKE_MATCH_1} GREATER 7)
182      set(HASWELL_SUPPORTED On)
183    endif()
184  endif()
185  if(NOT HASWELL_SUPPORTED)
186    list(REMOVE_ITEM tmp_var x86_64h)
187  endif()
188  set(${output} ${tmp_var} PARENT_SCOPE)
189endfunction()
190
191# Read and process the exclude file into a list of symbols
192function(darwin_read_list_from_file output_var file)
193  if(EXISTS ${file})
194    file(READ ${file} EXCLUDES)
195    string(REPLACE "\n" ";" EXCLUDES ${EXCLUDES})
196    set(${output_var} ${EXCLUDES} PARENT_SCOPE)
197  endif()
198endfunction()
199
200# this function takes an OS, architecture and minimum version and provides a
201# list of builtin functions to exclude
202function(darwin_find_excluded_builtins_list output_var)
203  cmake_parse_arguments(LIB
204    ""
205    "OS;ARCH;MIN_VERSION"
206    ""
207    ${ARGN})
208
209  if(NOT LIB_OS OR NOT LIB_ARCH)
210    message(FATAL_ERROR "Must specify OS and ARCH to darwin_find_excluded_builtins_list!")
211  endif()
212
213  darwin_read_list_from_file(${LIB_OS}_BUILTINS
214    ${DARWIN_EXCLUDE_DIR}/${LIB_OS}.txt)
215  darwin_read_list_from_file(${LIB_OS}_${LIB_ARCH}_BASE_BUILTINS
216    ${DARWIN_EXCLUDE_DIR}/${LIB_OS}-${LIB_ARCH}.txt)
217
218  if(LIB_MIN_VERSION)
219    file(GLOB builtin_lists ${DARWIN_EXCLUDE_DIR}/${LIB_OS}*-${LIB_ARCH}.txt)
220    foreach(builtin_list ${builtin_lists})
221      string(REGEX MATCH "${LIB_OS}([0-9\\.]*)-${LIB_ARCH}.txt" VERSION_MATCHED "${builtin_list}")
222      if (VERSION_MATCHED AND NOT CMAKE_MATCH_1 VERSION_LESS LIB_MIN_VERSION)
223        if(NOT smallest_version)
224          set(smallest_version ${CMAKE_MATCH_1})
225        elseif(CMAKE_MATCH_1 VERSION_LESS smallest_version)
226          set(smallest_version ${CMAKE_MATCH_1})
227        endif()
228      endif()
229    endforeach()
230
231    if(smallest_version)
232      darwin_read_list_from_file(${LIB_ARCH}_${LIB_OS}_BUILTINS
233        ${DARWIN_EXCLUDE_DIR}/${LIB_OS}${smallest_version}-${LIB_ARCH}.txt)
234    endif()
235  endif()
236
237  set(${output_var}
238      ${${LIB_ARCH}_${LIB_OS}_BUILTINS}
239      ${${LIB_OS}_${LIB_ARCH}_BASE_BUILTINS}
240      ${${LIB_OS}_BUILTINS} PARENT_SCOPE)
241endfunction()
242
243# adds a single builtin library for a single OS & ARCH
244macro(darwin_add_builtin_library name suffix)
245  cmake_parse_arguments(LIB
246    ""
247    "PARENT_TARGET;OS;ARCH"
248    "SOURCES;CFLAGS;DEFS"
249    ${ARGN})
250  set(libname "${name}.${suffix}_${LIB_ARCH}_${LIB_OS}")
251  add_library(${libname} STATIC ${LIB_SOURCES})
252  if(DARWIN_${LIB_OS}_SYSROOT)
253    set(sysroot_flag -isysroot ${DARWIN_${LIB_OS}_SYSROOT})
254  endif()
255
256  # Make a copy of the compilation flags.
257  set(builtin_cflags ${LIB_CFLAGS})
258
259  # Strip out any inappropriate flags for the target.
260  if("${LIB_ARCH}" MATCHES "^(armv7|armv7k|armv7s)$")
261    set(builtin_cflags "")
262    foreach(cflag "${LIB_CFLAGS}")
263      string(REPLACE "-fomit-frame-pointer" "" cflag "${cflag}")
264      list(APPEND builtin_cflags ${cflag})
265    endforeach(cflag)
266  endif()
267
268  set_target_compile_flags(${libname}
269    ${sysroot_flag}
270    ${DARWIN_${LIB_OS}_BUILTIN_MIN_VER_FLAG}
271    ${builtin_cflags})
272  set_property(TARGET ${libname} APPEND PROPERTY
273      COMPILE_DEFINITIONS ${LIB_DEFS})
274  set_target_properties(${libname} PROPERTIES
275      OUTPUT_NAME ${libname}${COMPILER_RT_OS_SUFFIX})
276  set_target_properties(${libname} PROPERTIES
277    OSX_ARCHITECTURES ${LIB_ARCH})
278
279  if(LIB_PARENT_TARGET)
280    add_dependencies(${LIB_PARENT_TARGET} ${libname})
281  endif()
282
283  list(APPEND ${LIB_OS}_${suffix}_libs ${libname})
284  list(APPEND ${LIB_OS}_${suffix}_lipo_flags -arch ${arch} $<TARGET_FILE:${libname}>)
285  set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Libraries")
286endmacro()
287
288function(darwin_lipo_libs name)
289  cmake_parse_arguments(LIB
290    ""
291    "PARENT_TARGET;OUTPUT_DIR;INSTALL_DIR"
292    "LIPO_FLAGS;DEPENDS"
293    ${ARGN})
294  if(LIB_DEPENDS AND LIB_LIPO_FLAGS)
295    add_custom_command(OUTPUT ${LIB_OUTPUT_DIR}/lib${name}.a
296      COMMAND ${CMAKE_COMMAND} -E make_directory ${LIB_OUTPUT_DIR}
297      COMMAND ${CMAKE_LIPO} -output
298              ${LIB_OUTPUT_DIR}/lib${name}.a
299              -create ${LIB_LIPO_FLAGS}
300      DEPENDS ${LIB_DEPENDS}
301      )
302    add_custom_target(${name}
303      DEPENDS ${LIB_OUTPUT_DIR}/lib${name}.a)
304    set_target_properties(${name} PROPERTIES FOLDER "Compiler-RT Misc")
305    add_dependencies(${LIB_PARENT_TARGET} ${name})
306
307    if(CMAKE_CONFIGURATION_TYPES)
308      set(install_component ${LIB_PARENT_TARGET})
309    else()
310      set(install_component ${name})
311    endif()
312    install(FILES ${LIB_OUTPUT_DIR}/lib${name}.a
313      DESTINATION ${LIB_INSTALL_DIR}
314      COMPONENT ${install_component})
315    add_compiler_rt_install_targets(${name} PARENT_TARGET ${LIB_PARENT_TARGET})
316  else()
317    message(WARNING "Not generating lipo target for ${name} because no input libraries exist.")
318  endif()
319endfunction()
320
321# Generates builtin libraries for all operating systems specified in ARGN. Each
322# OS library is constructed by lipo-ing together single-architecture libraries.
323macro(darwin_add_builtin_libraries)
324  set(DARWIN_EXCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Darwin-excludes)
325
326  set(CFLAGS "-fPIC -O3 -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer")
327  set(CMAKE_C_FLAGS "")
328  set(CMAKE_CXX_FLAGS "")
329  set(CMAKE_ASM_FLAGS "")
330
331  set(PROFILE_SOURCES ../profile/InstrProfiling
332                      ../profile/InstrProfilingBuffer
333                      ../profile/InstrProfilingPlatformDarwin
334                      ../profile/InstrProfilingWriter)
335  foreach (os ${ARGN})
336    list_intersect(DARWIN_BUILTIN_ARCHS DARWIN_${os}_BUILTIN_ARCHS BUILTIN_SUPPORTED_ARCH)
337    foreach (arch ${DARWIN_BUILTIN_ARCHS})
338      darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS
339                              OS ${os}
340                              ARCH ${arch}
341                              MIN_VERSION ${DARWIN_${os}_BUILTIN_MIN_VER})
342
343      filter_builtin_sources(filtered_sources
344        EXCLUDE ${arch}_${os}_EXCLUDED_BUILTINS
345        ${${arch}_SOURCES})
346
347      darwin_add_builtin_library(clang_rt builtins
348                              OS ${os}
349                              ARCH ${arch}
350                              SOURCES ${filtered_sources}
351                              CFLAGS ${CFLAGS} -arch ${arch}
352                              PARENT_TARGET builtins)
353    endforeach()
354
355    # Don't build cc_kext libraries for simulator platforms
356    if(NOT DARWIN_${os}_SKIP_CC_KEXT)
357      foreach (arch ${DARWIN_BUILTIN_ARCHS})
358        # By not specifying MIN_VERSION this only reads the OS and OS-arch lists.
359        # We don't want to filter out the builtins that are present in libSystem
360        # because kexts can't link libSystem.
361        darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS
362                              OS ${os}
363                              ARCH ${arch})
364
365        filter_builtin_sources(filtered_sources
366          EXCLUDE ${arch}_${os}_EXCLUDED_BUILTINS
367          ${${arch}_SOURCES})
368
369        # In addition to the builtins cc_kext includes some profile sources
370        darwin_add_builtin_library(clang_rt cc_kext
371                                OS ${os}
372                                ARCH ${arch}
373                                SOURCES ${filtered_sources} ${PROFILE_SOURCES}
374                                CFLAGS ${CFLAGS} -arch ${arch} -mkernel
375                                DEFS KERNEL_USE
376                                PARENT_TARGET builtins)
377      endforeach()
378      set(archive_name clang_rt.cc_kext_${os})
379      if(${os} STREQUAL "osx")
380        set(archive_name clang_rt.cc_kext)
381      endif()
382      darwin_lipo_libs(${archive_name}
383                      PARENT_TARGET builtins
384                      LIPO_FLAGS ${${os}_cc_kext_lipo_flags}
385                      DEPENDS ${${os}_cc_kext_libs}
386                      OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
387                      INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
388    endif()
389  endforeach()
390
391  # We put the x86 sim slices into the archives for their base OS
392  foreach (os ${ARGN})
393    if(NOT ${os} MATCHES ".*sim$")
394      darwin_lipo_libs(clang_rt.${os}
395                        PARENT_TARGET builtins
396                        LIPO_FLAGS ${${os}_builtins_lipo_flags} ${${os}sim_builtins_lipo_flags}
397                        DEPENDS ${${os}_builtins_libs} ${${os}sim_builtins_libs}
398                        OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
399                        INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
400    endif()
401  endforeach()
402  darwin_add_embedded_builtin_libraries()
403endmacro()
404
405macro(darwin_add_embedded_builtin_libraries)
406  # this is a hacky opt-out. If you can't target both intel and arm
407  # architectures we bail here.
408  set(DARWIN_SOFT_FLOAT_ARCHS armv6m armv7m armv7em armv7)
409  set(DARWIN_HARD_FLOAT_ARCHS armv7em armv7)
410  if(COMPILER_RT_SUPPORTED_ARCH MATCHES ".*armv.*")
411    list(FIND COMPILER_RT_SUPPORTED_ARCH i386 i386_idx)
412    if(i386_idx GREATER -1)
413      list(APPEND DARWIN_HARD_FLOAT_ARCHS i386)
414    endif()
415
416    list(FIND COMPILER_RT_SUPPORTED_ARCH x86_64 x86_64_idx)
417    if(x86_64_idx GREATER -1)
418      list(APPEND DARWIN_HARD_FLOAT_ARCHS x86_64)
419    endif()
420
421    set(MACHO_SYM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/macho_embedded)
422
423    set(CFLAGS "-Oz -Wall -fomit-frame-pointer -ffreestanding")
424    set(CMAKE_C_FLAGS "")
425    set(CMAKE_CXX_FLAGS "")
426    set(CMAKE_ASM_FLAGS "")
427
428    set(SOFT_FLOAT_FLAG -mfloat-abi=soft)
429    set(HARD_FLOAT_FLAG -mfloat-abi=hard)
430
431    set(ENABLE_PIC Off)
432    set(PIC_FLAG -fPIC)
433    set(STATIC_FLAG -static)
434
435    set(DARWIN_macho_embedded_ARCHS armv6m armv7m armv7em armv7 i386 x86_64)
436
437    set(DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR
438      ${COMPILER_RT_OUTPUT_DIR}/lib/macho_embedded)
439    set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR
440      ${COMPILER_RT_INSTALL_PATH}/lib/macho_embedded)
441
442    set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi")
443    set(CFLAGS_i386 "-march=pentium")
444
445    darwin_read_list_from_file(common_FUNCTIONS ${MACHO_SYM_DIR}/common.txt)
446    darwin_read_list_from_file(thumb2_FUNCTIONS ${MACHO_SYM_DIR}/thumb2.txt)
447    darwin_read_list_from_file(thumb2_64_FUNCTIONS ${MACHO_SYM_DIR}/thumb2-64.txt)
448    darwin_read_list_from_file(arm_FUNCTIONS ${MACHO_SYM_DIR}/arm.txt)
449    darwin_read_list_from_file(i386_FUNCTIONS ${MACHO_SYM_DIR}/i386.txt)
450
451
452    set(armv6m_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS})
453    set(armv7m_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS})
454    set(armv7em_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS})
455    set(armv7_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS} ${thumb2_64_FUNCTIONS})
456    set(i386_FUNCTIONS ${common_FUNCTIONS} ${i386_FUNCTIONS})
457    set(x86_64_FUNCTIONS ${common_FUNCTIONS})
458
459    foreach(arch ${DARWIN_macho_embedded_ARCHS})
460      filter_builtin_sources(${arch}_filtered_sources
461        INCLUDE ${arch}_FUNCTIONS
462        ${${arch}_SOURCES})
463      if(NOT ${arch}_filtered_sources)
464        message(WARNING "${arch}_SOURCES: ${${arch}_SOURCES}")
465        message(WARNING "${arch}_FUNCTIONS: ${${arch}_FUNCTIONS}")
466        message(FATAL_ERROR "Empty filtered sources!")
467      endif()
468    endforeach()
469
470    foreach(float_type SOFT HARD)
471      foreach(type PIC STATIC)
472        string(TOLOWER "${float_type}_${type}" lib_suffix)
473        foreach(arch ${DARWIN_${float_type}_FLOAT_ARCHS})
474          set(DARWIN_macho_embedded_SYSROOT ${DARWIN_osx_SYSROOT})
475          set(float_flag)
476          if(${arch} MATCHES "^arm")
477            # x86 targets are hard float by default, but the complain about the
478            # float ABI flag, so don't pass it unless we're targeting arm.
479            set(float_flag ${${float_type}_FLOAT_FLAG})
480          endif()
481          darwin_add_builtin_library(clang_rt ${lib_suffix}
482                                OS macho_embedded
483                                ARCH ${arch}
484                                SOURCES ${${arch}_filtered_sources}
485                                CFLAGS ${CFLAGS} -arch ${arch} ${${type}_FLAG} ${float_flag} ${CFLAGS_${arch}}
486                                PARENT_TARGET builtins)
487        endforeach()
488        foreach(lib ${macho_embedded_${lib_suffix}_libs})
489          set_target_properties(${lib} PROPERTIES LINKER_LANGUAGE C)
490        endforeach()
491        darwin_lipo_libs(clang_rt.${lib_suffix}
492                      PARENT_TARGET builtins
493                      LIPO_FLAGS ${macho_embedded_${lib_suffix}_lipo_flags}
494                      DEPENDS ${macho_embedded_${lib_suffix}_libs}
495                      OUTPUT_DIR ${DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR}
496                      INSTALL_DIR ${DARWIN_macho_embedded_LIBRARY_INSTALL_DIR})
497      endforeach()
498    endforeach()
499  endif()
500endmacro()
501