blob: 95a06ce9fec8016a21d3ed1e2e87a2557baeb972 [file] [log] [blame]
Chris Bieneman257fe3a2016-04-28 21:16:45 +00001include(CMakeParseArguments)
2
Chris Bieneman361231e2015-08-13 20:38:16 +00003# 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.
6function(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
10 OUTPUT_VARIABLE var_internal
11 OUTPUT_STRIP_TRAILING_WHITESPACE
12 ERROR_FILE /dev/null
13 )
14 if("" STREQUAL "${var_internal}")
15 execute_process(
16 COMMAND xcodebuild -version -sdk ${sdk_name} Path
17 OUTPUT_VARIABLE var_internal
18 OUTPUT_STRIP_TRAILING_WHITESPACE
19 ERROR_FILE /dev/null
20 )
Chris Bieneman380ebd02016-04-26 17:53:25 +000021 else()
22 set(${var}_INTERNAL ${var_internal} PARENT_SCOPE)
Chris Bieneman361231e2015-08-13 20:38:16 +000023 endif()
24 set(${var} ${var_internal} PARENT_SCOPE)
25endfunction()
26
27# There isn't a clear mapping of what architectures are supported with a given
28# target platform, but ld's version output does list the architectures it can
29# link for.
30function(darwin_get_toolchain_supported_archs output_var)
31 execute_process(
32 COMMAND ld -v
33 ERROR_VARIABLE LINKER_VERSION)
34
35 string(REGEX MATCH "configured to support archs: ([^\n]+)"
36 ARCHES_MATCHED "${LINKER_VERSION}")
37 if(ARCHES_MATCHED)
38 set(ARCHES "${CMAKE_MATCH_1}")
Filipe Cabecinhas3e963672015-08-19 16:23:19 +000039 message(STATUS "Got ld supported ARCHES: ${ARCHES}")
Chris Bieneman361231e2015-08-13 20:38:16 +000040 string(REPLACE " " ";" ARCHES ${ARCHES})
41 else()
42 # If auto-detecting fails, fall back to a default set
43 message(WARNING "Detecting supported architectures from 'ld -v' failed. Returning default set.")
44 set(ARCHES "i386;x86_64;armv7;armv7s;arm64")
45 endif()
46
47 set(${output_var} ${ARCHES} PARENT_SCOPE)
48endfunction()
49
50# This function takes an OS and a list of architectures and identifies the
51# subset of the architectures list that the installed toolchain can target.
52function(darwin_test_archs os valid_archs)
Kuba Brecka3daf7b42015-12-03 17:02:07 +000053 if(${valid_archs})
54 message(STATUS "Using cached valid architectures for ${os}.")
55 return()
56 endif()
57
Chris Bieneman361231e2015-08-13 20:38:16 +000058 set(archs ${ARGN})
Chris Bienemanaa3d2c12016-05-03 19:48:11 +000059 if(NOT TEST_COMPILE_ONLY)
60 message(STATUS "Finding valid architectures for ${os}...")
Chris Bieneman38adadf2016-06-22 23:02:49 +000061 set(SIMPLE_C ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.c)
62 file(WRITE ${SIMPLE_C} "#include <stdio.h>\nint main() { printf(__FILE__); return 0; }\n")
Chris Bienemanaa3d2c12016-05-03 19:48:11 +000063
64 set(os_linker_flags)
65 foreach(flag ${DARWIN_${os}_LINKFLAGS})
66 set(os_linker_flags "${os_linker_flags} ${flag}")
67 endforeach()
68 endif()
Chris Bieneman361231e2015-08-13 20:38:16 +000069
70 # The simple program will build for x86_64h on the simulator because it is
71 # compatible with x86_64 libraries (mostly), but since x86_64h isn't actually
72 # a valid or useful architecture for the iOS simulator we should drop it.
Anna Zaksc77a0802016-02-02 02:01:17 +000073 if(${os} MATCHES "^(iossim|tvossim|watchossim)$")
Chris Bieneman361231e2015-08-13 20:38:16 +000074 list(REMOVE_ITEM archs "x86_64h")
75 endif()
76
77 set(working_archs)
78 foreach(arch ${archs})
Chris Bienemanaa3d2c12016-05-03 19:48:11 +000079
Chris Bieneman361231e2015-08-13 20:38:16 +000080 set(arch_linker_flags "-arch ${arch} ${os_linker_flags}")
Chris Bienemanaa3d2c12016-05-03 19:48:11 +000081 if(TEST_COMPILE_ONLY)
82 try_compile_only(CAN_TARGET_${os}_${arch} -v -arch ${arch} ${DARWIN_${os}_CFLAGS})
83 else()
Chris Bieneman38adadf2016-06-22 23:02:49 +000084 try_compile(CAN_TARGET_${os}_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_C}
Chris Bienemanaa3d2c12016-05-03 19:48:11 +000085 COMPILE_DEFINITIONS "-v -arch ${arch}" ${DARWIN_${os}_CFLAGS}
86 CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${arch_linker_flags}"
87 OUTPUT_VARIABLE TEST_OUTPUT)
88 endif()
Chris Bieneman361231e2015-08-13 20:38:16 +000089 if(${CAN_TARGET_${os}_${arch}})
90 list(APPEND working_archs ${arch})
Chris Bienemana5841582015-12-10 00:39:57 +000091 else()
92 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
93 "Testing compiler for supporting ${os}-${arch}:\n"
94 "${TEST_OUTPUT}\n")
Chris Bieneman361231e2015-08-13 20:38:16 +000095 endif()
96 endforeach()
Kuba Brecka3daf7b42015-12-03 17:02:07 +000097 set(${valid_archs} ${working_archs}
98 CACHE STRING "List of valid architectures for platform ${os}.")
Chris Bieneman361231e2015-08-13 20:38:16 +000099endfunction()
Chris Bieneman5eae1972015-08-20 17:32:06 +0000100
101# This function checks the host cpusubtype to see if it is post-haswell. Haswell
102# and later machines can run x86_64h binaries. Haswell is cpusubtype 8.
103function(darwin_filter_host_archs input output)
Daniel Sandersde098c92016-01-27 09:28:01 +0000104 list_intersect(tmp_var DARWIN_osx_ARCHS ${input})
Chris Bieneman5eae1972015-08-20 17:32:06 +0000105 execute_process(
106 COMMAND sysctl hw.cpusubtype
107 OUTPUT_VARIABLE SUBTYPE)
108
109 string(REGEX MATCH "hw.cpusubtype: ([0-9]*)"
110 SUBTYPE_MATCHED "${SUBTYPE}")
111 set(HASWELL_SUPPORTED Off)
Chris Bieneman797f5b32015-08-21 18:05:57 +0000112 if(SUBTYPE_MATCHED)
113 if(${CMAKE_MATCH_1} GREATER 7)
Chris Bieneman5eae1972015-08-20 17:32:06 +0000114 set(HASWELL_SUPPORTED On)
115 endif()
116 endif()
117 if(NOT HASWELL_SUPPORTED)
118 list(REMOVE_ITEM tmp_var x86_64h)
119 endif()
120 set(${output} ${tmp_var} PARENT_SCOPE)
121endfunction()
Chris Bieneman0d427982015-09-23 15:18:17 +0000122
Chris Bieneman0d427982015-09-23 15:18:17 +0000123# Read and process the exclude file into a list of symbols
Chris Bienemancc8c7772015-09-25 23:29:03 +0000124function(darwin_read_list_from_file output_var file)
125 if(EXISTS ${file})
126 file(READ ${file} EXCLUDES)
127 string(REPLACE "\n" ";" EXCLUDES ${EXCLUDES})
128 set(${output_var} ${EXCLUDES} PARENT_SCOPE)
Chris Bieneman0d427982015-09-23 15:18:17 +0000129 endif()
130endfunction()
131
132# this function takes an OS, architecture and minimum version and provides a
133# list of builtin functions to exclude
Chris Bieneman590a48d2015-09-24 21:51:09 +0000134function(darwin_find_excluded_builtins_list output_var)
135 cmake_parse_arguments(LIB
136 ""
137 "OS;ARCH;MIN_VERSION"
138 ""
139 ${ARGN})
Chris Bieneman0d427982015-09-23 15:18:17 +0000140
Chris Bieneman590a48d2015-09-24 21:51:09 +0000141 if(NOT LIB_OS OR NOT LIB_ARCH)
142 message(FATAL_ERROR "Must specify OS and ARCH to darwin_find_excluded_builtins_list!")
143 endif()
144
Chris Bienemancc8c7772015-09-25 23:29:03 +0000145 darwin_read_list_from_file(${LIB_OS}_BUILTINS
146 ${DARWIN_EXCLUDE_DIR}/${LIB_OS}.txt)
147 darwin_read_list_from_file(${LIB_OS}_${LIB_ARCH}_BASE_BUILTINS
148 ${DARWIN_EXCLUDE_DIR}/${LIB_OS}-${LIB_ARCH}.txt)
Chris Bieneman590a48d2015-09-24 21:51:09 +0000149
150 if(LIB_MIN_VERSION)
151 file(GLOB builtin_lists ${DARWIN_EXCLUDE_DIR}/${LIB_OS}*-${LIB_ARCH}.txt)
152 foreach(builtin_list ${builtin_lists})
153 string(REGEX MATCH "${LIB_OS}([0-9\\.]*)-${LIB_ARCH}.txt" VERSION_MATCHED "${builtin_list}")
154 if (VERSION_MATCHED AND NOT CMAKE_MATCH_1 VERSION_LESS LIB_MIN_VERSION)
155 if(NOT smallest_version)
156 set(smallest_version ${CMAKE_MATCH_1})
157 elseif(CMAKE_MATCH_1 VERSION_LESS smallest_version)
158 set(smallest_version ${CMAKE_MATCH_1})
159 endif()
Chris Bieneman0d427982015-09-23 15:18:17 +0000160 endif()
Chris Bieneman590a48d2015-09-24 21:51:09 +0000161 endforeach()
162
163 if(smallest_version)
Chris Bienemancc8c7772015-09-25 23:29:03 +0000164 darwin_read_list_from_file(${LIB_ARCH}_${LIB_OS}_BUILTINS
165 ${DARWIN_EXCLUDE_DIR}/${LIB_OS}${smallest_version}-${LIB_ARCH}.txt)
Chris Bieneman0d427982015-09-23 15:18:17 +0000166 endif()
Chris Bieneman0d427982015-09-23 15:18:17 +0000167 endif()
168
Chris Bieneman590a48d2015-09-24 21:51:09 +0000169 set(${output_var}
170 ${${LIB_ARCH}_${LIB_OS}_BUILTINS}
171 ${${LIB_OS}_${LIB_ARCH}_BASE_BUILTINS}
172 ${${LIB_OS}_BUILTINS} PARENT_SCOPE)
Chris Bieneman0d427982015-09-23 15:18:17 +0000173endfunction()
174
175# adds a single builtin library for a single OS & ARCH
Chris Bieneman01ebf002015-09-23 23:05:32 +0000176macro(darwin_add_builtin_library name suffix)
Chris Bieneman0d427982015-09-23 15:18:17 +0000177 cmake_parse_arguments(LIB
178 ""
179 "PARENT_TARGET;OS;ARCH"
Chris Bieneman01ebf002015-09-23 23:05:32 +0000180 "SOURCES;CFLAGS;DEFS"
Chris Bieneman0d427982015-09-23 15:18:17 +0000181 ${ARGN})
Chris Bieneman01ebf002015-09-23 23:05:32 +0000182 set(libname "${name}.${suffix}_${LIB_ARCH}_${LIB_OS}")
Chris Bieneman0d427982015-09-23 15:18:17 +0000183 add_library(${libname} STATIC ${LIB_SOURCES})
Chris Bieneman45c40ff2015-11-10 17:26:40 +0000184 if(DARWIN_${LIB_OS}_SYSROOT)
185 set(sysroot_flag -isysroot ${DARWIN_${LIB_OS}_SYSROOT})
186 endif()
Chris Bieneman0d427982015-09-23 15:18:17 +0000187 set_target_compile_flags(${libname}
Chris Bieneman45c40ff2015-11-10 17:26:40 +0000188 ${sysroot_flag}
Chris Bieneman0d427982015-09-23 15:18:17 +0000189 ${DARWIN_${LIB_OS}_BUILTIN_MIN_VER_FLAG}
190 ${LIB_CFLAGS})
Chris Bieneman01ebf002015-09-23 23:05:32 +0000191 set_property(TARGET ${libname} APPEND PROPERTY
192 COMPILE_DEFINITIONS ${LIB_DEFS})
Chris Bieneman0d427982015-09-23 15:18:17 +0000193 set_target_properties(${libname} PROPERTIES
194 OUTPUT_NAME ${libname}${COMPILER_RT_OS_SUFFIX})
195 set_target_properties(${libname} PROPERTIES
196 OSX_ARCHITECTURES ${LIB_ARCH})
197
198 if(LIB_PARENT_TARGET)
199 add_dependencies(${LIB_PARENT_TARGET} ${libname})
200 endif()
Chris Bieneman01ebf002015-09-23 23:05:32 +0000201
Chris Bieneman75c7c9c2015-09-25 22:31:17 +0000202 list(APPEND ${LIB_OS}_${suffix}_libs ${libname})
203 list(APPEND ${LIB_OS}_${suffix}_lipo_flags -arch ${arch} $<TARGET_FILE:${libname}>)
Chris Bieneman01ebf002015-09-23 23:05:32 +0000204endmacro()
205
206function(darwin_lipo_libs name)
207 cmake_parse_arguments(LIB
208 ""
Chris Bienemanbe8b60b2015-10-02 22:14:25 +0000209 "PARENT_TARGET;OUTPUT_DIR;INSTALL_DIR"
Chris Bieneman01ebf002015-09-23 23:05:32 +0000210 "LIPO_FLAGS;DEPENDS"
211 ${ARGN})
Chris Bieneman7068fc32015-11-09 23:37:45 +0000212 if(LIB_DEPENDS AND LIB_LIPO_FLAGS)
Chris Bieneman7ccc6132015-11-09 23:07:45 +0000213 add_custom_command(OUTPUT ${LIB_OUTPUT_DIR}/lib${name}.a
214 COMMAND ${CMAKE_COMMAND} -E make_directory ${LIB_OUTPUT_DIR}
215 COMMAND lipo -output
216 ${LIB_OUTPUT_DIR}/lib${name}.a
217 -create ${LIB_LIPO_FLAGS}
218 DEPENDS ${LIB_DEPENDS}
219 )
220 add_custom_target(${name}
221 DEPENDS ${LIB_OUTPUT_DIR}/lib${name}.a)
222 add_dependencies(${LIB_PARENT_TARGET} ${name})
223 install(FILES ${LIB_OUTPUT_DIR}/lib${name}.a
224 DESTINATION ${LIB_INSTALL_DIR})
225 else()
226 message(WARNING "Not generating lipo target for ${name} because no input libraries exist.")
227 endif()
Chris Bieneman0d427982015-09-23 15:18:17 +0000228endfunction()
229
Chris Bieneman5fbaeb92015-09-24 21:40:06 +0000230# Filter out generic versions of routines that are re-implemented in
231# architecture specific manner. This prevents multiple definitions of the
232# same symbols, making the symbol selection non-deterministic.
Chris Bieneman8aba4b02015-09-28 17:38:44 +0000233function(darwin_filter_builtin_sources output_var exclude_or_include excluded_list)
234 if(exclude_or_include STREQUAL "EXCLUDE")
235 set(filter_action GREATER)
236 set(filter_value -1)
237 elseif(exclude_or_include STREQUAL "INCLUDE")
238 set(filter_action LESS)
239 set(filter_value 0)
240 else()
241 message(FATAL_ERROR "darwin_filter_builtin_sources called without EXCLUDE|INCLUDE")
242 endif()
243
Chris Bieneman5fbaeb92015-09-24 21:40:06 +0000244 set(intermediate ${ARGN})
245 foreach (_file ${intermediate})
246 get_filename_component(_name_we ${_file} NAME_WE)
247 list(FIND ${excluded_list} ${_name_we} _found)
Chris Bieneman8aba4b02015-09-28 17:38:44 +0000248 if(_found ${filter_action} ${filter_value})
Chris Bieneman5fbaeb92015-09-24 21:40:06 +0000249 list(REMOVE_ITEM intermediate ${_file})
Chris Bieneman472d9372015-11-06 23:19:29 +0000250 elseif(${_file} MATCHES ".*/.*\\.S" OR ${_file} MATCHES ".*/.*\\.c")
Chris Bieneman5fbaeb92015-09-24 21:40:06 +0000251 get_filename_component(_name ${_file} NAME)
252 string(REPLACE ".S" ".c" _cname "${_name}")
253 list(REMOVE_ITEM intermediate ${_cname})
254 endif ()
255 endforeach ()
256 set(${output_var} ${intermediate} PARENT_SCOPE)
257endfunction()
258
Chris Bieneman0d427982015-09-23 15:18:17 +0000259# Generates builtin libraries for all operating systems specified in ARGN. Each
260# OS library is constructed by lipo-ing together single-architecture libraries.
261macro(darwin_add_builtin_libraries)
Chris Bieneman6e18e1e2015-09-29 23:13:45 +0000262 set(DARWIN_EXCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Darwin-excludes)
263
Chris Bieneman14679e92015-11-12 22:37:03 +0000264 set(CFLAGS "-fPIC -O3 -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer")
Chris Bieneman66c126a2015-11-11 21:38:35 +0000265 set(CMAKE_C_FLAGS "")
266 set(CMAKE_CXX_FLAGS "")
267 set(CMAKE_ASM_FLAGS "")
Chris Bieneman7146f7b2015-09-24 22:29:58 +0000268
269 set(PROFILE_SOURCES ../profile/InstrProfiling
270 ../profile/InstrProfilingBuffer
Vedant Kumarc5b779c2016-01-07 22:54:46 +0000271 ../profile/InstrProfilingPlatformDarwin
Vedant Kumarb6262312016-01-08 00:07:50 +0000272 ../profile/InstrProfilingWriter)
Chris Bieneman0d427982015-09-23 15:18:17 +0000273 foreach (os ${ARGN})
Daniel Sandersde098c92016-01-27 09:28:01 +0000274 list_intersect(DARWIN_BUILTIN_ARCHS DARWIN_${os}_ARCHS BUILTIN_SUPPORTED_ARCH)
Chris Bieneman88d85342015-09-28 22:20:25 +0000275 foreach (arch ${DARWIN_BUILTIN_ARCHS})
Chris Bieneman590a48d2015-09-24 21:51:09 +0000276 darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS
277 OS ${os}
278 ARCH ${arch}
279 MIN_VERSION ${DARWIN_${os}_BUILTIN_MIN_VER})
280
Chris Bieneman8aba4b02015-09-28 17:38:44 +0000281 darwin_filter_builtin_sources(filtered_sources
282 EXCLUDE ${arch}_${os}_EXCLUDED_BUILTINS
283 ${${arch}_SOURCES})
Chris Bieneman0d427982015-09-23 15:18:17 +0000284
Chris Bieneman01ebf002015-09-23 23:05:32 +0000285 darwin_add_builtin_library(clang_rt builtins
Chris Bieneman0d427982015-09-23 15:18:17 +0000286 OS ${os}
287 ARCH ${arch}
Chris Bieneman5fbaeb92015-09-24 21:40:06 +0000288 SOURCES ${filtered_sources}
Chris Bieneman66c126a2015-11-11 21:38:35 +0000289 CFLAGS ${CFLAGS} -arch ${arch}
Chris Bieneman0d427982015-09-23 15:18:17 +0000290 PARENT_TARGET builtins)
Chris Bieneman0d427982015-09-23 15:18:17 +0000291 endforeach()
292
Chris Bieneman13414722015-09-28 22:18:31 +0000293 # Don't build cc_kext libraries for simulator platforms
Chris Bienemand8233022015-09-30 20:25:10 +0000294 if(NOT DARWIN_${os}_SKIP_CC_KEXT)
Chris Bieneman13414722015-09-28 22:18:31 +0000295 foreach (arch ${DARWIN_BUILTIN_ARCHS})
Chris Bieneman5def2a82015-09-28 23:09:46 +0000296 # By not specifying MIN_VERSION this only reads the OS and OS-arch lists.
297 # We don't want to filter out the builtins that are present in libSystem
298 # because kexts can't link libSystem.
299 darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS
300 OS ${os}
301 ARCH ${arch})
302
303 darwin_filter_builtin_sources(filtered_sources
304 EXCLUDE ${arch}_${os}_EXCLUDED_BUILTINS
305 ${${arch}_SOURCES})
306
Chris Bieneman13414722015-09-28 22:18:31 +0000307 # In addition to the builtins cc_kext includes some profile sources
308 darwin_add_builtin_library(clang_rt cc_kext
309 OS ${os}
310 ARCH ${arch}
Chris Bieneman5def2a82015-09-28 23:09:46 +0000311 SOURCES ${filtered_sources} ${PROFILE_SOURCES}
Chris Bieneman66c126a2015-11-11 21:38:35 +0000312 CFLAGS ${CFLAGS} -arch ${arch} -mkernel
Chris Bieneman13414722015-09-28 22:18:31 +0000313 DEFS KERNEL_USE
314 PARENT_TARGET builtins)
315 endforeach()
Chris Bieneman2c23a802015-10-09 18:38:34 +0000316 set(archive_name clang_rt.cc_kext_${os})
317 if(${os} STREQUAL "osx")
318 set(archive_name clang_rt.cc_kext)
319 endif()
320 darwin_lipo_libs(${archive_name}
Chris Bieneman13414722015-09-28 22:18:31 +0000321 PARENT_TARGET builtins
322 LIPO_FLAGS ${${os}_cc_kext_lipo_flags}
323 DEPENDS ${${os}_cc_kext_libs}
Chris Bienemanbe8b60b2015-10-02 22:14:25 +0000324 OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
325 INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
Chris Bieneman13414722015-09-28 22:18:31 +0000326 endif()
327 endforeach()
328
329 # We put the x86 sim slices into the archives for their base OS
330 foreach (os ${ARGN})
331 if(NOT ${os} MATCHES ".*sim$")
332 darwin_lipo_libs(clang_rt.${os}
333 PARENT_TARGET builtins
334 LIPO_FLAGS ${${os}_builtins_lipo_flags} ${${os}sim_builtins_lipo_flags}
335 DEPENDS ${${os}_builtins_libs} ${${os}sim_builtins_libs}
Chris Bienemanbe8b60b2015-10-02 22:14:25 +0000336 OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
337 INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
Chris Bieneman13414722015-09-28 22:18:31 +0000338 endif()
Chris Bieneman0d427982015-09-23 15:18:17 +0000339 endforeach()
Chris Bieneman6e18e1e2015-09-29 23:13:45 +0000340 darwin_add_embedded_builtin_libraries()
Chris Bieneman0d427982015-09-23 15:18:17 +0000341endmacro()
342
Chris Bieneman9a6afeb2015-11-10 17:26:35 +0000343macro(darwin_add_embedded_builtin_libraries)
Chris Bieneman7d824da2015-11-10 00:41:18 +0000344 # this is a hacky opt-out. If you can't target both intel and arm
345 # architectures we bail here.
346 set(DARWIN_SOFT_FLOAT_ARCHS armv6m armv7m armv7em armv7)
347 set(DARWIN_HARD_FLOAT_ARCHS armv7em armv7)
Chris Bieneman80854752015-11-20 18:45:42 +0000348 if(COMPILER_RT_SUPPORTED_ARCH MATCHES ".*armv.*")
349 list(FIND COMPILER_RT_SUPPORTED_ARCH i386 i386_idx)
350 if(i386_idx GREATER -1)
351 list(APPEND DARWIN_HARD_FLOAT_ARCHS i386)
Chris Bieneman6e18e1e2015-09-29 23:13:45 +0000352 endif()
Chris Bieneman6e18e1e2015-09-29 23:13:45 +0000353
Chris Bieneman80854752015-11-20 18:45:42 +0000354 list(FIND COMPILER_RT_SUPPORTED_ARCH x86_64 x86_64_idx)
355 if(x86_64_idx GREATER -1)
356 list(APPEND DARWIN_HARD_FLOAT_ARCHS x86_64)
357 endif()
358
359 set(MACHO_SYM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/macho_embedded)
360
361 set(CFLAGS "-Oz -Wall -fomit-frame-pointer -ffreestanding")
362 set(CMAKE_C_FLAGS "")
363 set(CMAKE_CXX_FLAGS "")
364 set(CMAKE_ASM_FLAGS "")
365
366 set(SOFT_FLOAT_FLAG -mfloat-abi=soft)
367 set(HARD_FLOAT_FLAG -mfloat-abi=hard)
368
369 set(ENABLE_PIC Off)
370 set(PIC_FLAG -fPIC)
371 set(STATIC_FLAG -static)
372
373 set(DARWIN_macho_embedded_ARCHS armv6m armv7m armv7em armv7 i386 x86_64)
374
375 set(DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR
376 ${COMPILER_RT_OUTPUT_DIR}/lib/macho_embedded)
377 set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR
378 ${COMPILER_RT_INSTALL_PATH}/lib/macho_embedded)
379
380 set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi")
381 set(CFLAGS_i386 "-march=pentium")
382
383 darwin_read_list_from_file(common_FUNCTIONS ${MACHO_SYM_DIR}/common.txt)
384 darwin_read_list_from_file(thumb2_FUNCTIONS ${MACHO_SYM_DIR}/thumb2.txt)
385 darwin_read_list_from_file(thumb2_64_FUNCTIONS ${MACHO_SYM_DIR}/thumb2-64.txt)
386 darwin_read_list_from_file(arm_FUNCTIONS ${MACHO_SYM_DIR}/arm.txt)
387 darwin_read_list_from_file(i386_FUNCTIONS ${MACHO_SYM_DIR}/i386.txt)
388
389
390 set(armv6m_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS})
391 set(armv7m_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS})
392 set(armv7em_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS})
393 set(armv7_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS} ${thumb2_64_FUNCTIONS})
394 set(i386_FUNCTIONS ${common_FUNCTIONS} ${i386_FUNCTIONS})
395 set(x86_64_FUNCTIONS ${common_FUNCTIONS})
396
397 foreach(arch ${DARWIN_macho_embedded_ARCHS})
398 darwin_filter_builtin_sources(${arch}_filtered_sources
399 INCLUDE ${arch}_FUNCTIONS
400 ${${arch}_SOURCES})
401 if(NOT ${arch}_filtered_sources)
402 message("${arch}_SOURCES: ${${arch}_SOURCES}")
403 message("${arch}_FUNCTIONS: ${${arch}_FUNCTIONS}")
404 message(FATAL_ERROR "Empty filtered sources!")
405 endif()
Chris Bieneman6e18e1e2015-09-29 23:13:45 +0000406 endforeach()
Chris Bieneman80854752015-11-20 18:45:42 +0000407
408 foreach(float_type SOFT HARD)
409 foreach(type PIC STATIC)
410 string(TOLOWER "${float_type}_${type}" lib_suffix)
411 foreach(arch ${DARWIN_${float_type}_FLOAT_ARCHS})
412 set(DARWIN_macho_embedded_SYSROOT ${DARWIN_osx_SYSROOT})
413 set(float_flag)
414 if(${arch} MATCHES "^arm")
415 # x86 targets are hard float by default, but the complain about the
416 # float ABI flag, so don't pass it unless we're targeting arm.
417 set(float_flag ${${float_type}_FLOAT_FLAG})
418 endif()
419 darwin_add_builtin_library(clang_rt ${lib_suffix}
420 OS macho_embedded
421 ARCH ${arch}
422 SOURCES ${${arch}_filtered_sources}
423 CFLAGS ${CFLAGS} -arch ${arch} ${${type}_FLAG} ${float_flag} ${CFLAGS_${arch}}
424 PARENT_TARGET builtins)
425 endforeach()
426 foreach(lib ${macho_embedded_${lib_suffix}_libs})
427 set_target_properties(${lib} PROPERTIES LINKER_LANGUAGE C)
428 endforeach()
429 darwin_lipo_libs(clang_rt.${lib_suffix}
430 PARENT_TARGET builtins
431 LIPO_FLAGS ${macho_embedded_${lib_suffix}_lipo_flags}
432 DEPENDS ${macho_embedded_${lib_suffix}_libs}
433 OUTPUT_DIR ${DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR}
434 INSTALL_DIR ${DARWIN_macho_embedded_LIBRARY_INSTALL_DIR})
435 endforeach()
436 endforeach()
437 endif()
Chris Bieneman9a6afeb2015-11-10 17:26:35 +0000438endmacro()