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