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