150
|
1 include(CMakePushCheckState)
|
|
2 include(CheckSymbolExists)
|
|
3
|
|
4 # Because compiler-rt spends a lot of time setting up custom compile flags,
|
|
5 # define a handy helper function for it. The compile flags setting in CMake
|
|
6 # has serious issues that make its syntax challenging at best.
|
|
7 function(set_target_compile_flags target)
|
|
8 set(argstring "")
|
|
9 foreach(arg ${ARGN})
|
|
10 set(argstring "${argstring} ${arg}")
|
|
11 endforeach()
|
|
12 set_property(TARGET ${target} PROPERTY COMPILE_FLAGS "${argstring}")
|
|
13 endfunction()
|
|
14
|
|
15 function(set_target_link_flags target)
|
|
16 set(argstring "")
|
|
17 foreach(arg ${ARGN})
|
|
18 set(argstring "${argstring} ${arg}")
|
|
19 endforeach()
|
|
20 set_property(TARGET ${target} PROPERTY LINK_FLAGS "${argstring}")
|
|
21 endfunction()
|
|
22
|
|
23 # Set the variable var_PYBOOL to True if var holds a true-ish string,
|
|
24 # otherwise set it to False.
|
|
25 macro(pythonize_bool var)
|
|
26 if (${var})
|
|
27 set(${var}_PYBOOL True)
|
|
28 else()
|
|
29 set(${var}_PYBOOL False)
|
|
30 endif()
|
|
31 endmacro()
|
|
32
|
|
33 # Appends value to all lists in ARGN, if the condition is true.
|
|
34 macro(append_list_if condition value)
|
|
35 if(${condition})
|
|
36 foreach(list ${ARGN})
|
|
37 list(APPEND ${list} ${value})
|
|
38 endforeach()
|
|
39 endif()
|
|
40 endmacro()
|
|
41
|
|
42 # Appends value to all strings in ARGN, if the condition is true.
|
|
43 macro(append_string_if condition value)
|
|
44 if(${condition})
|
|
45 foreach(str ${ARGN})
|
|
46 set(${str} "${${str}} ${value}")
|
|
47 endforeach()
|
|
48 endif()
|
|
49 endmacro()
|
|
50
|
|
51 macro(append_rtti_flag polarity list)
|
|
52 if(${polarity})
|
|
53 append_list_if(COMPILER_RT_HAS_FRTTI_FLAG -frtti ${list})
|
|
54 append_list_if(COMPILER_RT_HAS_GR_FLAG /GR ${list})
|
|
55 else()
|
|
56 append_list_if(COMPILER_RT_HAS_FNO_RTTI_FLAG -fno-rtti ${list})
|
|
57 append_list_if(COMPILER_RT_HAS_GR_FLAG /GR- ${list})
|
|
58 endif()
|
|
59 endmacro()
|
|
60
|
|
61 macro(list_intersect output input1 input2)
|
|
62 set(${output})
|
|
63 foreach(it ${${input1}})
|
|
64 list(FIND ${input2} ${it} index)
|
|
65 if( NOT (index EQUAL -1))
|
|
66 list(APPEND ${output} ${it})
|
|
67 endif()
|
|
68 endforeach()
|
|
69 endmacro()
|
|
70
|
|
71 function(list_replace input_list old new)
|
|
72 set(replaced_list)
|
|
73 foreach(item ${${input_list}})
|
|
74 if(${item} STREQUAL ${old})
|
|
75 list(APPEND replaced_list ${new})
|
|
76 else()
|
|
77 list(APPEND replaced_list ${item})
|
|
78 endif()
|
|
79 endforeach()
|
|
80 set(${input_list} "${replaced_list}" PARENT_SCOPE)
|
|
81 endfunction()
|
|
82
|
|
83 # Takes ${ARGN} and puts only supported architectures in @out_var list.
|
|
84 function(filter_available_targets out_var)
|
|
85 set(archs ${${out_var}})
|
|
86 foreach(arch ${ARGN})
|
|
87 list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
|
|
88 if(NOT (ARCH_INDEX EQUAL -1) AND CAN_TARGET_${arch})
|
|
89 list(APPEND archs ${arch})
|
|
90 endif()
|
|
91 endforeach()
|
|
92 set(${out_var} ${archs} PARENT_SCOPE)
|
|
93 endfunction()
|
|
94
|
|
95 # Add $arch as supported with no additional flags.
|
|
96 macro(add_default_target_arch arch)
|
|
97 set(TARGET_${arch}_CFLAGS "")
|
|
98 set(CAN_TARGET_${arch} 1)
|
|
99 list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
|
|
100 endmacro()
|
|
101
|
|
102 function(check_compile_definition def argstring out_var)
|
|
103 if("${def}" STREQUAL "")
|
|
104 set(${out_var} TRUE PARENT_SCOPE)
|
|
105 return()
|
|
106 endif()
|
|
107 cmake_push_check_state()
|
|
108 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${argstring}")
|
|
109 check_symbol_exists(${def} "" ${out_var})
|
|
110 cmake_pop_check_state()
|
|
111 endfunction()
|
|
112
|
|
113 # test_target_arch(<arch> <def> <target flags...>)
|
|
114 # Checks if architecture is supported: runs host compiler with provided
|
|
115 # flags to verify that:
|
|
116 # 1) <def> is defined (if non-empty)
|
|
117 # 2) simple file can be successfully built.
|
|
118 # If successful, saves target flags for this architecture.
|
|
119 macro(test_target_arch arch def)
|
|
120 set(TARGET_${arch}_CFLAGS ${ARGN})
|
|
121 set(TARGET_${arch}_LINK_FLAGS ${ARGN})
|
|
122 set(argstring "")
|
|
123 foreach(arg ${ARGN})
|
|
124 set(argstring "${argstring} ${arg}")
|
|
125 endforeach()
|
|
126 check_compile_definition("${def}" "${argstring}" HAS_${arch}_DEF)
|
|
127 if(NOT DEFINED CAN_TARGET_${arch})
|
|
128 if(NOT HAS_${arch}_DEF)
|
|
129 set(CAN_TARGET_${arch} FALSE)
|
|
130 elseif(TEST_COMPILE_ONLY)
|
|
131 try_compile_only(CAN_TARGET_${arch} FLAGS ${TARGET_${arch}_CFLAGS})
|
|
132 else()
|
|
133 set(FLAG_NO_EXCEPTIONS "")
|
|
134 if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG)
|
|
135 set(FLAG_NO_EXCEPTIONS " -fno-exceptions ")
|
|
136 endif()
|
|
137 set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
|
|
138 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${argstring}")
|
|
139 try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE}
|
|
140 COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS} ${FLAG_NO_EXCEPTIONS}"
|
|
141 OUTPUT_VARIABLE TARGET_${arch}_OUTPUT)
|
|
142 set(CMAKE_EXE_LINKER_FLAGS ${SAVED_CMAKE_EXE_LINKER_FLAGS})
|
|
143 endif()
|
|
144 endif()
|
|
145 if(${CAN_TARGET_${arch}})
|
|
146 list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
|
|
147 elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" STREQUAL "${arch}" AND
|
|
148 COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE)
|
|
149 # Bail out if we cannot target the architecture we plan to test.
|
|
150 message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}")
|
|
151 endif()
|
|
152 endmacro()
|
|
153
|
|
154 macro(detect_target_arch)
|
|
155 check_symbol_exists(__arm__ "" __ARM)
|
|
156 check_symbol_exists(__aarch64__ "" __AARCH64)
|
|
157 check_symbol_exists(__x86_64__ "" __X86_64)
|
|
158 check_symbol_exists(__i386__ "" __I386)
|
|
159 check_symbol_exists(__mips__ "" __MIPS)
|
|
160 check_symbol_exists(__mips64__ "" __MIPS64)
|
|
161 check_symbol_exists(__powerpc64__ "" __PPC64)
|
|
162 check_symbol_exists(__powerpc64le__ "" __PPC64LE)
|
|
163 check_symbol_exists(__riscv "" __RISCV)
|
|
164 check_symbol_exists(__s390x__ "" __S390X)
|
|
165 check_symbol_exists(__sparc "" __SPARC)
|
|
166 check_symbol_exists(__sparcv9 "" __SPARCV9)
|
|
167 check_symbol_exists(__wasm32__ "" __WEBASSEMBLY32)
|
|
168 check_symbol_exists(__wasm64__ "" __WEBASSEMBLY64)
|
|
169 if(__ARM)
|
|
170 add_default_target_arch(arm)
|
|
171 elseif(__AARCH64)
|
|
172 add_default_target_arch(aarch64)
|
|
173 elseif(__X86_64)
|
|
174 add_default_target_arch(x86_64)
|
|
175 elseif(__I386)
|
|
176 add_default_target_arch(i386)
|
|
177 elseif(__MIPS64) # must be checked before __MIPS
|
|
178 add_default_target_arch(mips64)
|
|
179 elseif(__MIPS)
|
|
180 add_default_target_arch(mips)
|
|
181 elseif(__PPC64)
|
|
182 add_default_target_arch(powerpc64)
|
|
183 elseif(__PPC64LE)
|
|
184 add_default_target_arch(powerpc64le)
|
|
185 elseif(__RISCV)
|
|
186 if(CMAKE_SIZEOF_VOID_P EQUAL "4")
|
|
187 add_default_target_arch(riscv32)
|
|
188 elseif(CMAKE_SIZEOF_VOID_P EQUAL "8")
|
|
189 add_default_target_arch(riscv64)
|
|
190 else()
|
|
191 message(FATAL_ERROR "Unsupport XLEN for RISC-V")
|
|
192 endif()
|
|
193 elseif(__S390X)
|
|
194 add_default_target_arch(s390x)
|
|
195 elseif(__SPARCV9)
|
|
196 add_default_target_arch(sparcv9)
|
|
197 elseif(__SPARC)
|
|
198 add_default_target_arch(sparc)
|
|
199 elseif(__WEBASSEMBLY32)
|
|
200 add_default_target_arch(wasm32)
|
|
201 elseif(__WEBASSEMBLY64)
|
|
202 add_default_target_arch(wasm64)
|
|
203 endif()
|
|
204 endmacro()
|
|
205
|
|
206 macro(load_llvm_config)
|
|
207 if (NOT LLVM_CONFIG_PATH)
|
|
208 find_program(LLVM_CONFIG_PATH "llvm-config"
|
|
209 DOC "Path to llvm-config binary")
|
|
210 if (NOT LLVM_CONFIG_PATH)
|
|
211 message(WARNING "UNSUPPORTED COMPILER-RT CONFIGURATION DETECTED: "
|
|
212 "llvm-config not found.\n"
|
|
213 "Reconfigure with -DLLVM_CONFIG_PATH=path/to/llvm-config.")
|
|
214 endif()
|
|
215 endif()
|
|
216 if (LLVM_CONFIG_PATH)
|
|
217 execute_process(
|
|
218 COMMAND ${LLVM_CONFIG_PATH} "--obj-root" "--bindir" "--libdir" "--src-root" "--includedir"
|
|
219 RESULT_VARIABLE HAD_ERROR
|
|
220 OUTPUT_VARIABLE CONFIG_OUTPUT)
|
|
221 if (HAD_ERROR)
|
|
222 message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
|
|
223 endif()
|
|
224 string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT ${CONFIG_OUTPUT})
|
|
225 list(GET CONFIG_OUTPUT 0 BINARY_DIR)
|
|
226 list(GET CONFIG_OUTPUT 1 TOOLS_BINARY_DIR)
|
|
227 list(GET CONFIG_OUTPUT 2 LIBRARY_DIR)
|
|
228 list(GET CONFIG_OUTPUT 3 MAIN_SRC_DIR)
|
|
229 list(GET CONFIG_OUTPUT 4 INCLUDE_DIR)
|
|
230
|
|
231 set(LLVM_BINARY_DIR ${BINARY_DIR} CACHE PATH "Path to LLVM build tree")
|
|
232 set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib")
|
|
233 set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
|
|
234 set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")
|
|
235 set(LLVM_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Paths to LLVM headers")
|
|
236
|
|
237 # Detect if we have the LLVMXRay and TestingSupport library installed and
|
|
238 # available from llvm-config.
|
|
239 execute_process(
|
|
240 COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "xray"
|
|
241 RESULT_VARIABLE HAD_ERROR
|
|
242 OUTPUT_VARIABLE CONFIG_OUTPUT
|
|
243 ERROR_QUIET)
|
|
244 if (HAD_ERROR)
|
|
245 message(WARNING "llvm-config finding xray failed with status ${HAD_ERROR}")
|
|
246 set(COMPILER_RT_HAS_LLVMXRAY FALSE)
|
|
247 else()
|
|
248 string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT ${CONFIG_OUTPUT})
|
|
249 list(GET CONFIG_OUTPUT 0 LDFLAGS)
|
|
250 list(GET CONFIG_OUTPUT 1 LIBLIST)
|
|
251 file(TO_CMAKE_PATH "${LDFLAGS}" LDFLAGS)
|
|
252 file(TO_CMAKE_PATH "${LIBLIST}" LIBLIST)
|
|
253 set(LLVM_XRAY_LDFLAGS ${LDFLAGS} CACHE STRING "Linker flags for LLVMXRay library")
|
|
254 set(LLVM_XRAY_LIBLIST ${LIBLIST} CACHE STRING "Library list for LLVMXRay")
|
|
255 set(COMPILER_RT_HAS_LLVMXRAY TRUE)
|
|
256 endif()
|
|
257
|
|
258 set(COMPILER_RT_HAS_LLVMTESTINGSUPPORT FALSE)
|
|
259 execute_process(
|
|
260 COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "testingsupport"
|
|
261 RESULT_VARIABLE HAD_ERROR
|
|
262 OUTPUT_VARIABLE CONFIG_OUTPUT
|
|
263 ERROR_QUIET)
|
|
264 if (HAD_ERROR)
|
|
265 message(WARNING "llvm-config finding testingsupport failed with status ${HAD_ERROR}")
|
|
266 else()
|
|
267 string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT ${CONFIG_OUTPUT})
|
|
268 list(GET CONFIG_OUTPUT 0 LDFLAGS)
|
|
269 list(GET CONFIG_OUTPUT 1 LIBLIST)
|
|
270 if (LIBLIST STREQUAL "")
|
|
271 message(WARNING "testingsupport library not installed, some tests will be skipped")
|
|
272 else()
|
|
273 file(TO_CMAKE_PATH "${LDFLAGS}" LDFLAGS)
|
|
274 file(TO_CMAKE_PATH "${LIBLIST}" LIBLIST)
|
|
275 set(LLVM_TESTINGSUPPORT_LDFLAGS ${LDFLAGS} CACHE STRING "Linker flags for LLVMTestingSupport library")
|
|
276 set(LLVM_TESTINGSUPPORT_LIBLIST ${LIBLIST} CACHE STRING "Library list for LLVMTestingSupport")
|
|
277 set(COMPILER_RT_HAS_LLVMTESTINGSUPPORT TRUE)
|
|
278 endif()
|
|
279 endif()
|
|
280
|
|
281 # Make use of LLVM CMake modules.
|
|
282 # --cmakedir is supported since llvm r291218 (4.0 release)
|
|
283 execute_process(
|
|
284 COMMAND ${LLVM_CONFIG_PATH} --cmakedir
|
|
285 RESULT_VARIABLE HAD_ERROR
|
|
286 OUTPUT_VARIABLE CONFIG_OUTPUT)
|
|
287 if(NOT HAD_ERROR)
|
|
288 string(STRIP "${CONFIG_OUTPUT}" LLVM_CMAKE_PATH_FROM_LLVM_CONFIG)
|
|
289 file(TO_CMAKE_PATH ${LLVM_CMAKE_PATH_FROM_LLVM_CONFIG} LLVM_CMAKE_PATH)
|
|
290 else()
|
|
291 file(TO_CMAKE_PATH ${LLVM_BINARY_DIR} LLVM_BINARY_DIR_CMAKE_STYLE)
|
|
292 set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR_CMAKE_STYLE}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
|
|
293 endif()
|
|
294
|
|
295 list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
|
|
296 # Get some LLVM variables from LLVMConfig.
|
|
297 include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
|
|
298
|
|
299 set(LLVM_LIBRARY_OUTPUT_INTDIR
|
|
300 ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
|
|
301 endif()
|
|
302 endmacro()
|
|
303
|
|
304 macro(construct_compiler_rt_default_triple)
|
|
305 if(COMPILER_RT_DEFAULT_TARGET_ONLY)
|
|
306 if(DEFINED COMPILER_RT_DEFAULT_TARGET_TRIPLE)
|
|
307 message(FATAL_ERROR "COMPILER_RT_DEFAULT_TARGET_TRIPLE isn't supported when building for default target only")
|
|
308 endif()
|
|
309 set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${CMAKE_C_COMPILER_TARGET})
|
|
310 else()
|
|
311 set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${TARGET_TRIPLE} CACHE STRING
|
|
312 "Default triple for which compiler-rt runtimes will be built.")
|
|
313 endif()
|
|
314
|
|
315 if(DEFINED COMPILER_RT_TEST_TARGET_TRIPLE)
|
|
316 # Backwards compatibility: this variable used to be called
|
|
317 # COMPILER_RT_TEST_TARGET_TRIPLE.
|
|
318 set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${COMPILER_RT_TEST_TARGET_TRIPLE})
|
|
319 endif()
|
|
320
|
|
321 string(REPLACE "-" ";" TARGET_TRIPLE_LIST ${COMPILER_RT_DEFAULT_TARGET_TRIPLE})
|
|
322 list(GET TARGET_TRIPLE_LIST 0 COMPILER_RT_DEFAULT_TARGET_ARCH)
|
|
323 # Determine if test target triple is specified explicitly, and doesn't match the
|
|
324 # default.
|
|
325 if(NOT COMPILER_RT_DEFAULT_TARGET_TRIPLE STREQUAL TARGET_TRIPLE)
|
|
326 set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE TRUE)
|
|
327 else()
|
|
328 set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE FALSE)
|
|
329 endif()
|
|
330 endmacro()
|
|
331
|
|
332 # Filter out generic versions of routines that are re-implemented in
|
|
333 # architecture specific manner. This prevents multiple definitions of the
|
|
334 # same symbols, making the symbol selection non-deterministic.
|
|
335 function(filter_builtin_sources output_var exclude_or_include excluded_list)
|
|
336 if(exclude_or_include STREQUAL "EXCLUDE")
|
|
337 set(filter_action GREATER)
|
|
338 set(filter_value -1)
|
|
339 elseif(exclude_or_include STREQUAL "INCLUDE")
|
|
340 set(filter_action LESS)
|
|
341 set(filter_value 0)
|
|
342 else()
|
|
343 message(FATAL_ERROR "filter_builtin_sources called without EXCLUDE|INCLUDE")
|
|
344 endif()
|
|
345
|
|
346 set(intermediate ${ARGN})
|
|
347 foreach (_file ${intermediate})
|
|
348 get_filename_component(_name_we ${_file} NAME_WE)
|
|
349 list(FIND ${excluded_list} ${_name_we} _found)
|
|
350 if(_found ${filter_action} ${filter_value})
|
|
351 list(REMOVE_ITEM intermediate ${_file})
|
|
352 elseif(${_file} MATCHES ".*/.*\\.S" OR ${_file} MATCHES ".*/.*\\.c")
|
|
353 get_filename_component(_name ${_file} NAME)
|
|
354 string(REPLACE ".S" ".c" _cname "${_name}")
|
|
355 list(REMOVE_ITEM intermediate ${_cname})
|
|
356 endif ()
|
|
357 endforeach ()
|
|
358 set(${output_var} ${intermediate} PARENT_SCOPE)
|
|
359 endfunction()
|
|
360
|
|
361 function(get_compiler_rt_target arch variable)
|
|
362 string(FIND ${COMPILER_RT_DEFAULT_TARGET_TRIPLE} "-" dash_index)
|
|
363 string(SUBSTRING ${COMPILER_RT_DEFAULT_TARGET_TRIPLE} ${dash_index} -1 triple_suffix)
|
|
364 if(COMPILER_RT_DEFAULT_TARGET_ONLY)
|
|
365 # Use exact spelling when building only for the target specified to CMake.
|
|
366 set(target "${COMPILER_RT_DEFAULT_TARGET_TRIPLE}")
|
|
367 elseif(ANDROID AND ${arch} STREQUAL "i386")
|
|
368 set(target "i686${COMPILER_RT_OS_SUFFIX}${triple_suffix}")
|
|
369 else()
|
|
370 set(target "${arch}${triple_suffix}")
|
|
371 endif()
|
|
372 set(${variable} ${target} PARENT_SCOPE)
|
|
373 endfunction()
|
|
374
|
|
375 function(get_compiler_rt_install_dir arch install_dir)
|
|
376 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
|
|
377 get_compiler_rt_target(${arch} target)
|
|
378 set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/lib/${target} PARENT_SCOPE)
|
|
379 else()
|
|
380 set(${install_dir} ${COMPILER_RT_LIBRARY_INSTALL_DIR} PARENT_SCOPE)
|
|
381 endif()
|
|
382 endfunction()
|
|
383
|
|
384 function(get_compiler_rt_output_dir arch output_dir)
|
|
385 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
|
|
386 get_compiler_rt_target(${arch} target)
|
|
387 set(${output_dir} ${COMPILER_RT_OUTPUT_DIR}/lib/${target} PARENT_SCOPE)
|
|
388 else()
|
|
389 set(${output_dir} ${COMPILER_RT_LIBRARY_OUTPUT_DIR} PARENT_SCOPE)
|
|
390 endif()
|
|
391 endfunction()
|
|
392
|
|
393 # compiler_rt_process_sources(
|
|
394 # <OUTPUT_VAR>
|
|
395 # <SOURCE_FILE> ...
|
|
396 # [ADDITIONAL_HEADERS <header> ...]
|
|
397 # )
|
|
398 #
|
|
399 # Process the provided sources and write the list of new sources
|
|
400 # into `<OUTPUT_VAR>`.
|
|
401 #
|
|
402 # ADDITIONAL_HEADERS - Adds the supplied header to list of sources for IDEs.
|
|
403 #
|
|
404 # This function is very similar to `llvm_process_sources()` but exists here
|
|
405 # because we need to support standalone builds of compiler-rt.
|
|
406 function(compiler_rt_process_sources OUTPUT_VAR)
|
|
407 cmake_parse_arguments(
|
|
408 ARG
|
|
409 ""
|
|
410 ""
|
|
411 "ADDITIONAL_HEADERS"
|
|
412 ${ARGN}
|
|
413 )
|
|
414 set(sources ${ARG_UNPARSED_ARGUMENTS})
|
|
415 set(headers "")
|
|
416 if (XCODE OR MSVC_IDE OR CMAKE_EXTRA_GENERATOR)
|
|
417 # For IDEs we need to tell CMake about header files.
|
|
418 # Otherwise they won't show up in UI.
|
|
419 set(headers ${ARG_ADDITIONAL_HEADERS})
|
|
420 list(LENGTH headers headers_length)
|
|
421 if (${headers_length} GREATER 0)
|
|
422 set_source_files_properties(${headers}
|
|
423 PROPERTIES HEADER_FILE_ONLY ON)
|
|
424 endif()
|
|
425 endif()
|
|
426 set("${OUTPUT_VAR}" ${sources} ${headers} PARENT_SCOPE)
|
|
427 endfunction()
|
|
428
|
|
429 # Create install targets for a library and its parent component (if specified).
|
|
430 function(add_compiler_rt_install_targets name)
|
|
431 cmake_parse_arguments(ARG "" "PARENT_TARGET" "" ${ARGN})
|
|
432
|
|
433 if(ARG_PARENT_TARGET AND NOT TARGET install-${ARG_PARENT_TARGET})
|
|
434 # The parent install target specifies the parent component to scrape up
|
|
435 # anything not installed by the individual install targets, and to handle
|
|
436 # installation when running the multi-configuration generators.
|
|
437 add_custom_target(install-${ARG_PARENT_TARGET}
|
|
438 DEPENDS ${ARG_PARENT_TARGET}
|
|
439 COMMAND "${CMAKE_COMMAND}"
|
|
440 -DCMAKE_INSTALL_COMPONENT=${ARG_PARENT_TARGET}
|
|
441 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
|
442 add_custom_target(install-${ARG_PARENT_TARGET}-stripped
|
|
443 DEPENDS ${ARG_PARENT_TARGET}
|
|
444 COMMAND "${CMAKE_COMMAND}"
|
|
445 -DCMAKE_INSTALL_COMPONENT=${ARG_PARENT_TARGET}
|
|
446 -DCMAKE_INSTALL_DO_STRIP=1
|
|
447 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
|
448 set_target_properties(install-${ARG_PARENT_TARGET} PROPERTIES
|
|
449 FOLDER "Compiler-RT Misc")
|
|
450 set_target_properties(install-${ARG_PARENT_TARGET}-stripped PROPERTIES
|
|
451 FOLDER "Compiler-RT Misc")
|
|
452 add_dependencies(install-compiler-rt install-${ARG_PARENT_TARGET})
|
|
453 add_dependencies(install-compiler-rt-stripped install-${ARG_PARENT_TARGET}-stripped)
|
|
454 endif()
|
|
455
|
|
456 # We only want to generate per-library install targets if you aren't using
|
|
457 # an IDE because the extra targets get cluttered in IDEs.
|
|
458 if(NOT CMAKE_CONFIGURATION_TYPES)
|
|
459 add_custom_target(install-${name}
|
|
460 DEPENDS ${name}
|
|
461 COMMAND "${CMAKE_COMMAND}"
|
|
462 -DCMAKE_INSTALL_COMPONENT=${name}
|
|
463 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
|
464 add_custom_target(install-${name}-stripped
|
|
465 DEPENDS ${name}
|
|
466 COMMAND "${CMAKE_COMMAND}"
|
|
467 -DCMAKE_INSTALL_COMPONENT=${name}
|
|
468 -DCMAKE_INSTALL_DO_STRIP=1
|
|
469 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
|
470 # If you have a parent target specified, we bind the new install target
|
|
471 # to the parent install target.
|
|
472 if(LIB_PARENT_TARGET)
|
|
473 add_dependencies(install-${LIB_PARENT_TARGET} install-${name})
|
|
474 add_dependencies(install-${LIB_PARENT_TARGET}-stripped install-${name}-stripped)
|
|
475 endif()
|
|
476 endif()
|
|
477 endfunction()
|