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