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 if (DARWIN_${sdk_name}_OVERRIDE_SDK_VERSION) 48 message(WARNING "Overriding ${sdk_name} SDK version to ${DARWIN_${sdk_name}_OVERRIDE_SDK_VERSION}") 49 set(${var} "${DARWIN_${sdk_name}_OVERRIDE_SDK_VERSION}" PARENT_SCOPE) 50 return() 51 endif() 52 set(result_process 1) 53 if(NOT DARWIN_PREFER_PUBLIC_SDK) 54 # Let's first try the internal SDK, otherwise use the public SDK. 55 execute_process( 56 COMMAND xcrun --sdk ${sdk_name}.internal --show-sdk-version 57 RESULT_VARIABLE result_process 58 OUTPUT_VARIABLE var_internal 59 OUTPUT_STRIP_TRAILING_WHITESPACE 60 ERROR_FILE /dev/null 61 ) 62 endif() 63 if((NOT ${result_process} EQUAL 0) OR "" STREQUAL "${var_internal}") 64 execute_process( 65 COMMAND xcrun --sdk ${sdk_name} --show-sdk-version 66 RESULT_VARIABLE result_process 67 OUTPUT_VARIABLE var_internal 68 OUTPUT_STRIP_TRAILING_WHITESPACE 69 ERROR_FILE /dev/null 70 ) 71 endif() 72 if(NOT result_process EQUAL 0) 73 message(FATAL_ERROR 74 "Failed to determine SDK version for \"${sdk_name}\" SDK") 75 endif() 76 # Check reported version looks sane. 77 if (NOT "${var_internal}" MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+)?$") 78 message(FATAL_ERROR 79 "Reported SDK version \"${var_internal}\" does not look like a version") 80 endif() 81 set(${var} ${var_internal} PARENT_SCOPE) 82endfunction() 83 84# There isn't a clear mapping of what architectures are supported with a given 85# target platform, but ld's version output does list the architectures it can 86# link for. 87function(darwin_get_toolchain_supported_archs output_var) 88 execute_process( 89 COMMAND "${CMAKE_LINKER}" -v 90 ERROR_VARIABLE LINKER_VERSION) 91 92 string(REGEX MATCH "configured to support archs: ([^\n]+)" 93 ARCHES_MATCHED "${LINKER_VERSION}") 94 if(ARCHES_MATCHED) 95 set(ARCHES "${CMAKE_MATCH_1}") 96 message(STATUS "Got ld supported ARCHES: ${ARCHES}") 97 string(REPLACE " " ";" ARCHES ${ARCHES}) 98 else() 99 # If auto-detecting fails, fall back to a default set 100 message(WARNING "Detecting supported architectures from 'ld -v' failed. Returning default set.") 101 set(ARCHES "i386;x86_64;armv7;armv7s;arm64") 102 endif() 103 104 set(${output_var} ${ARCHES} PARENT_SCOPE) 105endfunction() 106 107# This function takes an OS and a list of architectures and identifies the 108# subset of the architectures list that the installed toolchain can target. 109function(darwin_test_archs os valid_archs) 110 if(${valid_archs}) 111 message(STATUS "Using cached valid architectures for ${os}.") 112 return() 113 endif() 114 115 set(archs ${ARGN}) 116 if(NOT TEST_COMPILE_ONLY) 117 message(STATUS "Finding valid architectures for ${os}...") 118 set(SIMPLE_C ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.c) 119 file(WRITE ${SIMPLE_C} "#include <stdio.h>\nint main() { printf(__FILE__); return 0; }\n") 120 121 set(os_linker_flags) 122 foreach(flag ${DARWIN_${os}_LINK_FLAGS}) 123 set(os_linker_flags "${os_linker_flags} ${flag}") 124 endforeach() 125 126 # Disable building for i386 for macOS SDK >= 10.15. The SDK doesn't support 127 # linking for i386 and the corresponding OS doesn't allow running macOS i386 128 # binaries. 129 if ("${os}" STREQUAL "osx") 130 find_darwin_sdk_version(macosx_sdk_version "macosx") 131 if ("${macosx_sdk_version}" VERSION_GREATER 10.15 OR "${macosx_sdk_version}" VERSION_EQUAL 10.15) 132 message(STATUS "Disabling i386 slice for ${valid_archs}") 133 list(REMOVE_ITEM archs "i386") 134 endif() 135 endif() 136 endif() 137 138 # The simple program will build for x86_64h on the simulator because it is 139 # compatible with x86_64 libraries (mostly), but since x86_64h isn't actually 140 # a valid or useful architecture for the iOS simulator we should drop it. 141 if(${os} MATCHES "^(iossim|tvossim|watchossim)$") 142 list(REMOVE_ITEM archs "x86_64h") 143 endif() 144 145 set(working_archs) 146 foreach(arch ${archs}) 147 148 set(arch_linker_flags "-arch ${arch} ${os_linker_flags}") 149 if(TEST_COMPILE_ONLY) 150 # `-w` is used to surpress compiler warnings which `try_compile_only()` treats as an error. 151 try_compile_only(CAN_TARGET_${os}_${arch} FLAGS -v -arch ${arch} ${DARWIN_${os}_CFLAGS} -w) 152 else() 153 set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}) 154 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${arch_linker_flags}") 155 try_compile(CAN_TARGET_${os}_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_C} 156 COMPILE_DEFINITIONS "-v -arch ${arch}" ${DARWIN_${os}_CFLAGS} 157 OUTPUT_VARIABLE TEST_OUTPUT) 158 set(CMAKE_EXE_LINKER_FLAGS ${SAVED_CMAKE_EXE_LINKER_FLAGS}) 159 endif() 160 if(${CAN_TARGET_${os}_${arch}}) 161 list(APPEND working_archs ${arch}) 162 else() 163 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 164 "Testing compiler for supporting ${os}-${arch}:\n" 165 "${TEST_OUTPUT}\n") 166 endif() 167 endforeach() 168 set(${valid_archs} ${working_archs} 169 CACHE STRING "List of valid architectures for platform ${os}." FORCE) 170endfunction() 171 172# This function checks the host cputype/cpusubtype to filter supported 173# architecture for the host OS. This is used to determine which tests are 174# available for the host. 175function(darwin_filter_host_archs input output) 176 list_intersect(tmp_var DARWIN_osx_ARCHS ${input}) 177 execute_process( 178 COMMAND sysctl hw.cputype 179 OUTPUT_VARIABLE CPUTYPE) 180 string(REGEX MATCH "hw.cputype: ([0-9]*)" 181 CPUTYPE_MATCHED "${CPUTYPE}") 182 set(ARM_HOST Off) 183 if(CPUTYPE_MATCHED) 184 # ARM cputype is (0x01000000 | 12) and X86(_64) is always 7. 185 if(${CMAKE_MATCH_1} GREATER 11) 186 set(ARM_HOST On) 187 endif() 188 endif() 189 190 if(ARM_HOST) 191 list(REMOVE_ITEM tmp_var i386) 192 else() 193 list(REMOVE_ITEM tmp_var arm64) 194 list(REMOVE_ITEM tmp_var arm64e) 195 execute_process( 196 COMMAND sysctl hw.cpusubtype 197 OUTPUT_VARIABLE SUBTYPE) 198 string(REGEX MATCH "hw.cpusubtype: ([0-9]*)" 199 SUBTYPE_MATCHED "${SUBTYPE}") 200 201 set(HASWELL_SUPPORTED Off) 202 if(SUBTYPE_MATCHED) 203 if(${CMAKE_MATCH_1} GREATER 7) 204 set(HASWELL_SUPPORTED On) 205 endif() 206 endif() 207 if(NOT HASWELL_SUPPORTED) 208 list(REMOVE_ITEM tmp_var x86_64h) 209 endif() 210 endif() 211 212 set(${output} ${tmp_var} PARENT_SCOPE) 213endfunction() 214 215# Read and process the exclude file into a list of symbols 216function(darwin_read_list_from_file output_var file) 217 if(EXISTS ${file}) 218 file(READ ${file} EXCLUDES) 219 string(REPLACE "\n" ";" EXCLUDES ${EXCLUDES}) 220 set(${output_var} ${EXCLUDES} PARENT_SCOPE) 221 endif() 222endfunction() 223 224# this function takes an OS, architecture and minimum version and provides a 225# list of builtin functions to exclude 226function(darwin_find_excluded_builtins_list output_var) 227 cmake_parse_arguments(LIB 228 "" 229 "OS;ARCH;MIN_VERSION" 230 "" 231 ${ARGN}) 232 233 if(NOT LIB_OS OR NOT LIB_ARCH) 234 message(FATAL_ERROR "Must specify OS and ARCH to darwin_find_excluded_builtins_list!") 235 endif() 236 237 darwin_read_list_from_file(${LIB_OS}_BUILTINS 238 ${DARWIN_EXCLUDE_DIR}/${LIB_OS}.txt) 239 darwin_read_list_from_file(${LIB_OS}_${LIB_ARCH}_BASE_BUILTINS 240 ${DARWIN_EXCLUDE_DIR}/${LIB_OS}-${LIB_ARCH}.txt) 241 242 if(LIB_MIN_VERSION) 243 file(GLOB builtin_lists ${DARWIN_EXCLUDE_DIR}/${LIB_OS}*-${LIB_ARCH}.txt) 244 foreach(builtin_list ${builtin_lists}) 245 string(REGEX MATCH "${LIB_OS}([0-9\\.]*)-${LIB_ARCH}.txt" VERSION_MATCHED "${builtin_list}") 246 if (VERSION_MATCHED AND NOT CMAKE_MATCH_1 VERSION_LESS LIB_MIN_VERSION) 247 if(NOT smallest_version) 248 set(smallest_version ${CMAKE_MATCH_1}) 249 elseif(CMAKE_MATCH_1 VERSION_LESS smallest_version) 250 set(smallest_version ${CMAKE_MATCH_1}) 251 endif() 252 endif() 253 endforeach() 254 255 if(smallest_version) 256 darwin_read_list_from_file(${LIB_ARCH}_${LIB_OS}_BUILTINS 257 ${DARWIN_EXCLUDE_DIR}/${LIB_OS}${smallest_version}-${LIB_ARCH}.txt) 258 endif() 259 endif() 260 261 set(${output_var} 262 ${${LIB_ARCH}_${LIB_OS}_BUILTINS} 263 ${${LIB_OS}_${LIB_ARCH}_BASE_BUILTINS} 264 ${${LIB_OS}_BUILTINS} PARENT_SCOPE) 265endfunction() 266 267# adds a single builtin library for a single OS & ARCH 268macro(darwin_add_builtin_library name suffix) 269 cmake_parse_arguments(LIB 270 "" 271 "PARENT_TARGET;OS;ARCH" 272 "SOURCES;CFLAGS;DEFS;INCLUDE_DIRS" 273 ${ARGN}) 274 set(libname "${name}.${suffix}_${LIB_ARCH}_${LIB_OS}") 275 add_library(${libname} STATIC ${LIB_SOURCES}) 276 if(DARWIN_${LIB_OS}_SYSROOT) 277 set(sysroot_flag -isysroot ${DARWIN_${LIB_OS}_SYSROOT}) 278 endif() 279 280 # Make a copy of the compilation flags. 281 set(builtin_cflags ${LIB_CFLAGS}) 282 283 # Strip out any inappropriate flags for the target. 284 if("${LIB_ARCH}" MATCHES "^(armv7|armv7k|armv7s)$") 285 set(builtin_cflags "") 286 foreach(cflag "${LIB_CFLAGS}") 287 string(REPLACE "-fomit-frame-pointer" "" cflag "${cflag}") 288 list(APPEND builtin_cflags ${cflag}) 289 endforeach(cflag) 290 endif() 291 292 if ("${LIB_OS}" MATCHES ".*sim$") 293 # Pass an explicit -simulator environment to the -target option to ensure 294 # that we don't rely on the architecture to infer whether we're building 295 # for the simulator. 296 string(REGEX REPLACE "sim" "" base_os "${LIB_OS}") 297 list(APPEND builtin_cflags 298 -target "${LIB_ARCH}-apple-${base_os}${DARWIN_${LIBOS}_BUILTIN_MIN_VER}-simulator") 299 endif() 300 301 set_target_compile_flags(${libname} 302 ${sysroot_flag} 303 ${DARWIN_${LIB_OS}_BUILTIN_MIN_VER_FLAG} 304 ${builtin_cflags}) 305 target_include_directories(${libname} 306 PRIVATE ${LIB_INCLUDE_DIRS}) 307 set_property(TARGET ${libname} APPEND PROPERTY 308 COMPILE_DEFINITIONS ${LIB_DEFS}) 309 set_target_properties(${libname} PROPERTIES 310 OUTPUT_NAME ${libname}${COMPILER_RT_OS_SUFFIX}) 311 set_target_properties(${libname} PROPERTIES 312 OSX_ARCHITECTURES ${LIB_ARCH}) 313 314 if(LIB_PARENT_TARGET) 315 add_dependencies(${LIB_PARENT_TARGET} ${libname}) 316 endif() 317 318 list(APPEND ${LIB_OS}_${suffix}_libs ${libname}) 319 list(APPEND ${LIB_OS}_${suffix}_lipo_flags -arch ${arch} $<TARGET_FILE:${libname}>) 320 set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Libraries") 321endmacro() 322 323function(darwin_lipo_libs name) 324 cmake_parse_arguments(LIB 325 "" 326 "PARENT_TARGET;OUTPUT_DIR;INSTALL_DIR" 327 "LIPO_FLAGS;DEPENDS" 328 ${ARGN}) 329 if(LIB_DEPENDS AND LIB_LIPO_FLAGS) 330 add_custom_command(OUTPUT ${LIB_OUTPUT_DIR}/lib${name}.a 331 COMMAND ${CMAKE_COMMAND} -E make_directory ${LIB_OUTPUT_DIR} 332 COMMAND ${CMAKE_LIPO} -output 333 ${LIB_OUTPUT_DIR}/lib${name}.a 334 -create ${LIB_LIPO_FLAGS} 335 DEPENDS ${LIB_DEPENDS} 336 ) 337 add_custom_target(${name} 338 DEPENDS ${LIB_OUTPUT_DIR}/lib${name}.a) 339 set_target_properties(${name} PROPERTIES FOLDER "Compiler-RT Misc") 340 add_dependencies(${LIB_PARENT_TARGET} ${name}) 341 342 if(CMAKE_CONFIGURATION_TYPES) 343 set(install_component ${LIB_PARENT_TARGET}) 344 else() 345 set(install_component ${name}) 346 endif() 347 install(FILES ${LIB_OUTPUT_DIR}/lib${name}.a 348 DESTINATION ${LIB_INSTALL_DIR} 349 COMPONENT ${install_component}) 350 add_compiler_rt_install_targets(${name} PARENT_TARGET ${LIB_PARENT_TARGET}) 351 else() 352 message(WARNING "Not generating lipo target for ${name} because no input libraries exist.") 353 endif() 354endfunction() 355 356# Filter the list of builtin sources for Darwin, then delegate to the generic 357# filtering. 358# 359# `exclude_or_include` must be one of: 360# - EXCLUDE: remove every item whose name (w/o extension) matches a name in 361# `excluded_list`. 362# - INCLUDE: keep only items whose name (w/o extension) matches something 363# in `excluded_list`. 364function(darwin_filter_builtin_sources output_var name exclude_or_include excluded_list) 365 if(exclude_or_include STREQUAL "EXCLUDE") 366 set(filter_action GREATER) 367 set(filter_value -1) 368 elseif(exclude_or_include STREQUAL "INCLUDE") 369 set(filter_action LESS) 370 set(filter_value 0) 371 else() 372 message(FATAL_ERROR "darwin_filter_builtin_sources called without EXCLUDE|INCLUDE") 373 endif() 374 375 set(intermediate ${ARGN}) 376 foreach(_file ${intermediate}) 377 get_filename_component(_name_we ${_file} NAME_WE) 378 list(FIND ${excluded_list} ${_name_we} _found) 379 if(_found ${filter_action} ${filter_value}) 380 list(REMOVE_ITEM intermediate ${_file}) 381 endif() 382 endforeach() 383 384 filter_builtin_sources(intermediate ${name}) 385 set(${output_var} ${intermediate} PARENT_SCOPE) 386endfunction() 387 388# Generates builtin libraries for all operating systems specified in ARGN. Each 389# OS library is constructed by lipo-ing together single-architecture libraries. 390macro(darwin_add_builtin_libraries) 391 set(DARWIN_EXCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Darwin-excludes) 392 393 set(CFLAGS "-fPIC -O3 -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer") 394 set(CMAKE_C_FLAGS "") 395 set(CMAKE_CXX_FLAGS "") 396 set(CMAKE_ASM_FLAGS "") 397 398 append_string_if(COMPILER_RT_HAS_ASM_LSE " -DHAS_ASM_LSE" CFLAGS) 399 400 set(PROFILE_SOURCES ../profile/InstrProfiling.c 401 ../profile/InstrProfilingBuffer.c 402 ../profile/InstrProfilingPlatformDarwin.c 403 ../profile/InstrProfilingWriter.c 404 ../profile/InstrProfilingInternal.c 405 ../profile/InstrProfilingVersionVar.c) 406 foreach (os ${ARGN}) 407 list_intersect(DARWIN_BUILTIN_ARCHS DARWIN_${os}_BUILTIN_ARCHS BUILTIN_SUPPORTED_ARCH) 408 409 if((arm64 IN_LIST DARWIN_BUILTIN_ARCHS OR arm64e IN_LIST DARWIN_BUILTIN_ARCHS) AND NOT TARGET lse_builtin_symlinks) 410 add_custom_target( 411 lse_builtin_symlinks 412 BYPRODUCTS ${lse_builtins} 413 ${arm64_lse_commands} 414 ) 415 416 set(deps_arm64 lse_builtin_symlinks) 417 set(deps_arm64e lse_builtin_symlinks) 418 endif() 419 420 foreach (arch ${DARWIN_BUILTIN_ARCHS}) 421 darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS 422 OS ${os} 423 ARCH ${arch} 424 MIN_VERSION ${DARWIN_${os}_BUILTIN_MIN_VER}) 425 426 darwin_filter_builtin_sources(filtered_sources 427 ${os}_${arch} 428 EXCLUDE ${arch}_${os}_EXCLUDED_BUILTINS 429 ${${arch}_SOURCES}) 430 431 darwin_add_builtin_library(clang_rt builtins 432 OS ${os} 433 ARCH ${arch} 434 DEPS ${deps_${arch}} 435 SOURCES ${filtered_sources} 436 CFLAGS ${CFLAGS} -arch ${arch} 437 PARENT_TARGET builtins) 438 endforeach() 439 440 # Don't build cc_kext libraries for simulator platforms 441 if(NOT DARWIN_${os}_SKIP_CC_KEXT) 442 foreach (arch ${DARWIN_BUILTIN_ARCHS}) 443 # By not specifying MIN_VERSION this only reads the OS and OS-arch lists. 444 # We don't want to filter out the builtins that are present in libSystem 445 # because kexts can't link libSystem. 446 darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS 447 OS ${os} 448 ARCH ${arch}) 449 450 darwin_filter_builtin_sources(filtered_sources 451 cc_kext_${os}_${arch} 452 EXCLUDE ${arch}_${os}_EXCLUDED_BUILTINS 453 ${${arch}_SOURCES}) 454 455 # In addition to the builtins cc_kext includes some profile sources 456 darwin_add_builtin_library(clang_rt cc_kext 457 OS ${os} 458 ARCH ${arch} 459 DEPS ${deps_${arch}} 460 SOURCES ${filtered_sources} ${PROFILE_SOURCES} 461 CFLAGS ${CFLAGS} -arch ${arch} -mkernel 462 DEFS KERNEL_USE 463 INCLUDE_DIRS ../../include 464 PARENT_TARGET builtins) 465 endforeach() 466 set(archive_name clang_rt.cc_kext_${os}) 467 if(${os} STREQUAL "osx") 468 set(archive_name clang_rt.cc_kext) 469 endif() 470 darwin_lipo_libs(${archive_name} 471 PARENT_TARGET builtins 472 LIPO_FLAGS ${${os}_cc_kext_lipo_flags} 473 DEPENDS ${${os}_cc_kext_libs} 474 OUTPUT_DIR ${COMPILER_RT_OUTPUT_LIBRARY_DIR} 475 INSTALL_DIR ${COMPILER_RT_INSTALL_LIBRARY_DIR}) 476 endif() 477 endforeach() 478 479 foreach (os ${ARGN}) 480 darwin_lipo_libs(clang_rt.${os} 481 PARENT_TARGET builtins 482 LIPO_FLAGS ${${os}_builtins_lipo_flags} 483 DEPENDS ${${os}_builtins_libs} 484 OUTPUT_DIR ${COMPILER_RT_OUTPUT_LIBRARY_DIR} 485 INSTALL_DIR ${COMPILER_RT_INSTALL_LIBRARY_DIR}) 486 endforeach() 487 darwin_add_embedded_builtin_libraries() 488endmacro() 489 490macro(darwin_add_embedded_builtin_libraries) 491 # this is a hacky opt-out. If you can't target both intel and arm 492 # architectures we bail here. 493 set(DARWIN_SOFT_FLOAT_ARCHS armv6m armv7m armv7em armv7) 494 set(DARWIN_HARD_FLOAT_ARCHS armv7em armv7) 495 if(COMPILER_RT_SUPPORTED_ARCH MATCHES ".*armv.*") 496 list(FIND COMPILER_RT_SUPPORTED_ARCH i386 i386_idx) 497 if(i386_idx GREATER -1) 498 list(APPEND DARWIN_HARD_FLOAT_ARCHS i386) 499 endif() 500 501 list(FIND COMPILER_RT_SUPPORTED_ARCH x86_64 x86_64_idx) 502 if(x86_64_idx GREATER -1) 503 list(APPEND DARWIN_HARD_FLOAT_ARCHS x86_64) 504 endif() 505 506 set(MACHO_SYM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/macho_embedded) 507 508 set(CFLAGS "-Oz -Wall -fomit-frame-pointer -ffreestanding") 509 set(CMAKE_C_FLAGS "") 510 set(CMAKE_CXX_FLAGS "") 511 set(CMAKE_ASM_FLAGS "") 512 513 set(SOFT_FLOAT_FLAG -mfloat-abi=soft) 514 set(HARD_FLOAT_FLAG -mfloat-abi=hard) 515 516 set(ENABLE_PIC Off) 517 set(PIC_FLAG -fPIC) 518 set(STATIC_FLAG -static) 519 520 set(DARWIN_macho_embedded_ARCHS armv6m armv7m armv7em armv7 i386 x86_64) 521 522 set(DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR 523 ${COMPILER_RT_OUTPUT_LIBRARY_DIR}/macho_embedded) 524 set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR 525 ${COMPILER_RT_INSTALL_LIBRARY_DIR}/macho_embedded) 526 527 set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi") 528 set(CFLAGS_i386 "-march=pentium") 529 530 darwin_read_list_from_file(common_FUNCTIONS ${MACHO_SYM_DIR}/common.txt) 531 darwin_read_list_from_file(thumb2_FUNCTIONS ${MACHO_SYM_DIR}/thumb2.txt) 532 darwin_read_list_from_file(thumb2_64_FUNCTIONS ${MACHO_SYM_DIR}/thumb2-64.txt) 533 darwin_read_list_from_file(arm_FUNCTIONS ${MACHO_SYM_DIR}/arm.txt) 534 darwin_read_list_from_file(i386_FUNCTIONS ${MACHO_SYM_DIR}/i386.txt) 535 536 537 set(armv6m_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS}) 538 set(armv7m_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS}) 539 set(armv7em_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS}) 540 set(armv7_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS} ${thumb2_64_FUNCTIONS}) 541 set(i386_FUNCTIONS ${common_FUNCTIONS} ${i386_FUNCTIONS}) 542 set(x86_64_FUNCTIONS ${common_FUNCTIONS}) 543 544 foreach(arch ${DARWIN_macho_embedded_ARCHS}) 545 darwin_filter_builtin_sources(${arch}_filtered_sources 546 macho_embedded_${arch} 547 INCLUDE ${arch}_FUNCTIONS 548 ${${arch}_SOURCES}) 549 if(NOT ${arch}_filtered_sources) 550 message(WARNING "${arch}_SOURCES: ${${arch}_SOURCES}") 551 message(WARNING "${arch}_FUNCTIONS: ${${arch}_FUNCTIONS}") 552 message(FATAL_ERROR "Empty filtered sources!") 553 endif() 554 endforeach() 555 556 foreach(float_type SOFT HARD) 557 foreach(type PIC STATIC) 558 string(TOLOWER "${float_type}_${type}" lib_suffix) 559 foreach(arch ${DARWIN_${float_type}_FLOAT_ARCHS}) 560 set(DARWIN_macho_embedded_SYSROOT ${DARWIN_osx_SYSROOT}) 561 set(float_flag) 562 if(${arch} MATCHES "^arm") 563 # x86 targets are hard float by default, but the complain about the 564 # float ABI flag, so don't pass it unless we're targeting arm. 565 set(float_flag ${${float_type}_FLOAT_FLAG}) 566 endif() 567 darwin_add_builtin_library(clang_rt ${lib_suffix} 568 OS macho_embedded 569 ARCH ${arch} 570 SOURCES ${${arch}_filtered_sources} 571 CFLAGS ${CFLAGS} -arch ${arch} ${${type}_FLAG} ${float_flag} ${CFLAGS_${arch}} 572 PARENT_TARGET builtins) 573 endforeach() 574 foreach(lib ${macho_embedded_${lib_suffix}_libs}) 575 set_target_properties(${lib} PROPERTIES LINKER_LANGUAGE C) 576 endforeach() 577 darwin_lipo_libs(clang_rt.${lib_suffix} 578 PARENT_TARGET builtins 579 LIPO_FLAGS ${macho_embedded_${lib_suffix}_lipo_flags} 580 DEPENDS ${macho_embedded_${lib_suffix}_libs} 581 OUTPUT_DIR ${DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR} 582 INSTALL_DIR ${DARWIN_macho_embedded_LIBRARY_INSTALL_DIR}) 583 endforeach() 584 endforeach() 585 endif() 586endmacro() 587