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