blob: 95a88af3bbf3d5714ecb06342dcd473bf4505439 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001include(LLVMProcessSources)
2include(LLVM-Config)
3include(DetermineGCCCompatible)
4
5function(llvm_update_compile_flags name)
6 get_property(sources TARGET ${name} PROPERTY SOURCES)
7 if("${sources}" MATCHES "\\.c(;|$)")
8 set(update_src_props ON)
9 endif()
10
11 # LLVM_REQUIRES_EH is an internal flag that individual targets can use to
12 # force EH
13 if(LLVM_REQUIRES_EH OR LLVM_ENABLE_EH)
14 if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI))
15 message(AUTHOR_WARNING "Exception handling requires RTTI. Enabling RTTI for ${name}")
16 set(LLVM_REQUIRES_RTTI ON)
17 endif()
18 if(MSVC)
19 list(APPEND LLVM_COMPILE_FLAGS "/EHsc")
20 endif()
21 else()
22 if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
23 list(APPEND LLVM_COMPILE_FLAGS "-fno-exceptions")
24 elseif(MSVC)
25 list(APPEND LLVM_COMPILE_DEFINITIONS _HAS_EXCEPTIONS=0)
26 list(APPEND LLVM_COMPILE_FLAGS "/EHs-c-")
27 endif()
28 endif()
29
30 # LLVM_REQUIRES_RTTI is an internal flag that individual
31 # targets can use to force RTTI
32 set(LLVM_CONFIG_HAS_RTTI YES CACHE INTERNAL "")
33 if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI))
34 set(LLVM_CONFIG_HAS_RTTI NO CACHE INTERNAL "")
35 list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0)
36 if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
37 list(APPEND LLVM_COMPILE_FLAGS "-fno-rtti")
38 elseif (MSVC)
39 list(APPEND LLVM_COMPILE_FLAGS "/GR-")
40 endif ()
41 elseif(MSVC)
42 list(APPEND LLVM_COMPILE_FLAGS "/GR")
43 endif()
44
45 # Assume that;
46 # - LLVM_COMPILE_FLAGS is list.
47 # - PROPERTY COMPILE_FLAGS is string.
48 string(REPLACE ";" " " target_compile_flags " ${LLVM_COMPILE_FLAGS}")
49
50 if(update_src_props)
51 foreach(fn ${sources})
52 get_filename_component(suf ${fn} EXT)
53 if("${suf}" STREQUAL ".cpp")
54 set_property(SOURCE ${fn} APPEND_STRING PROPERTY
55 COMPILE_FLAGS "${target_compile_flags}")
56 endif()
57 endforeach()
58 else()
59 # Update target props, since all sources are C++.
60 set_property(TARGET ${name} APPEND_STRING PROPERTY
61 COMPILE_FLAGS "${target_compile_flags}")
62 endif()
63
64 set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS ${LLVM_COMPILE_DEFINITIONS})
65endfunction()
66
67function(add_llvm_symbol_exports target_name export_file)
68 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
69 set(native_export_file "${target_name}.exports")
70 add_custom_command(OUTPUT ${native_export_file}
71 COMMAND sed -e "s/^/_/" < ${export_file} > ${native_export_file}
72 DEPENDS ${export_file}
73 VERBATIM
74 COMMENT "Creating export file for ${target_name}")
75 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
Andrew Walbran16937d02019-10-22 13:54:20 +010076 LINK_FLAGS " -Wl,-exported_symbols_list,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"")
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010077 elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
78 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
79 LINK_FLAGS " -Wl,-bE:${export_file}")
80 elseif(LLVM_HAVE_LINK_VERSION_SCRIPT)
81 # Gold and BFD ld require a version script rather than a plain list.
82 set(native_export_file "${target_name}.exports")
83 # FIXME: Don't write the "local:" line on OpenBSD.
84 # in the export file, also add a linker script to version LLVM symbols (form: LLVM_N.M)
85 add_custom_command(OUTPUT ${native_export_file}
86 COMMAND echo "LLVM_${LLVM_VERSION_MAJOR} {" > ${native_export_file}
87 COMMAND grep -q "[[:alnum:]]" ${export_file} && echo " global:" >> ${native_export_file} || :
88 COMMAND sed -e "s/$/;/" -e "s/^/ /" < ${export_file} >> ${native_export_file}
89 COMMAND echo " local: *;" >> ${native_export_file}
90 COMMAND echo "};" >> ${native_export_file}
91 DEPENDS ${export_file}
92 VERBATIM
93 COMMENT "Creating export file for ${target_name}")
94 if (${LLVM_LINKER_IS_SOLARISLD})
95 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
Andrew Walbran16937d02019-10-22 13:54:20 +010096 LINK_FLAGS " -Wl,-M,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"")
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010097 else()
98 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
Andrew Walbran16937d02019-10-22 13:54:20 +010099 LINK_FLAGS " -Wl,--version-script,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"")
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100100 endif()
101 else()
102 set(native_export_file "${target_name}.def")
103
104 add_custom_command(OUTPUT ${native_export_file}
105 COMMAND ${PYTHON_EXECUTABLE} -c "import sys;print(''.join(['EXPORTS\\n']+sys.stdin.readlines(),))"
106 < ${export_file} > ${native_export_file}
107 DEPENDS ${export_file}
108 VERBATIM
109 COMMENT "Creating export file for ${target_name}")
110 set(export_file_linker_flag "${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
111 if(MSVC)
112 set(export_file_linker_flag "/DEF:\"${export_file_linker_flag}\"")
113 endif()
114 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
115 LINK_FLAGS " ${export_file_linker_flag}")
116 endif()
117
118 add_custom_target(${target_name}_exports DEPENDS ${native_export_file})
119 set_target_properties(${target_name}_exports PROPERTIES FOLDER "Misc")
120
121 get_property(srcs TARGET ${target_name} PROPERTY SOURCES)
122 foreach(src ${srcs})
123 get_filename_component(extension ${src} EXT)
124 if(extension STREQUAL ".cpp")
125 set(first_source_file ${src})
126 break()
127 endif()
128 endforeach()
129
130 # Force re-linking when the exports file changes. Actually, it
131 # forces recompilation of the source file. The LINK_DEPENDS target
132 # property only works for makefile-based generators.
133 # FIXME: This is not safe because this will create the same target
134 # ${native_export_file} in several different file:
135 # - One where we emitted ${target_name}_exports
136 # - One where we emitted the build command for the following object.
137 # set_property(SOURCE ${first_source_file} APPEND PROPERTY
138 # OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${native_export_file})
139
140 set_property(DIRECTORY APPEND
141 PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${native_export_file})
142
143 add_dependencies(${target_name} ${target_name}_exports)
144
145 # Add dependency to *_exports later -- CMake issue 14747
146 list(APPEND LLVM_COMMON_DEPENDS ${target_name}_exports)
147 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)
148endfunction(add_llvm_symbol_exports)
149
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100150if(APPLE)
151 execute_process(
152 COMMAND "${CMAKE_LINKER}" -v
153 ERROR_VARIABLE stderr
154 )
155 set(LLVM_LINKER_DETECTED YES)
156 if("${stderr}" MATCHES "PROJECT:ld64")
157 set(LLVM_LINKER_IS_LD64 YES)
158 message(STATUS "Linker detection: ld64")
159 else()
160 set(LLVM_LINKER_DETECTED NO)
161 message(STATUS "Linker detection: unknown")
162 endif()
163elseif(NOT WIN32)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100164 # Detect what linker we have here
165 if( LLVM_USE_LINKER )
166 set(command ${CMAKE_C_COMPILER} -fuse-ld=${LLVM_USE_LINKER} -Wl,--version)
167 else()
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100168 separate_arguments(flags UNIX_COMMAND "${CMAKE_EXE_LINKER_FLAGS}")
169 set(command ${CMAKE_C_COMPILER} ${flags} -Wl,--version)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100170 endif()
171 execute_process(
172 COMMAND ${command}
173 OUTPUT_VARIABLE stdout
174 ERROR_VARIABLE stderr
175 )
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100176 set(LLVM_LINKER_DETECTED YES)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100177 if("${stdout}" MATCHES "GNU gold")
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100178 set(LLVM_LINKER_IS_GOLD YES)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100179 message(STATUS "Linker detection: GNU Gold")
180 elseif("${stdout}" MATCHES "^LLD")
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100181 set(LLVM_LINKER_IS_LLD YES)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100182 message(STATUS "Linker detection: LLD")
183 elseif("${stdout}" MATCHES "GNU ld")
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100184 set(LLVM_LINKER_IS_GNULD YES)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100185 message(STATUS "Linker detection: GNU ld")
186 elseif("${stderr}" MATCHES "Solaris Link Editors" OR
187 "${stdout}" MATCHES "Solaris Link Editors")
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100188 set(LLVM_LINKER_IS_SOLARISLD YES)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100189 message(STATUS "Linker detection: Solaris ld")
190 else()
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100191 set(LLVM_LINKER_DETECTED NO)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100192 message(STATUS "Linker detection: unknown")
193 endif()
194endif()
195
196function(add_link_opts target_name)
197 # Don't use linker optimizations in debug builds since it slows down the
198 # linker in a context where the optimizations are not important.
199 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
200
201 # Pass -O3 to the linker. This enabled different optimizations on different
202 # linkers.
203 if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|SunOS|AIX" OR WIN32))
204 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
205 LINK_FLAGS " -Wl,-O3")
206 endif()
207
208 if(LLVM_LINKER_IS_GOLD)
209 # With gold gc-sections is always safe.
210 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
211 LINK_FLAGS " -Wl,--gc-sections")
212 # Note that there is a bug with -Wl,--icf=safe so it is not safe
213 # to enable. See https://sourceware.org/bugzilla/show_bug.cgi?id=17704.
214 endif()
215
216 if(NOT LLVM_NO_DEAD_STRIP)
217 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
218 # ld64's implementation of -dead_strip breaks tools that use plugins.
219 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
220 LINK_FLAGS " -Wl,-dead_strip")
221 elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
222 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
223 LINK_FLAGS " -Wl,-z -Wl,discard-unused=sections")
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100224 elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100225 # Object files are compiled with -ffunction-data-sections.
226 # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks
227 # tools that use plugins. Always pass --gc-sections once we require
228 # a newer linker.
229 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
230 LINK_FLAGS " -Wl,--gc-sections")
231 endif()
232 endif()
233 endif()
234endfunction(add_link_opts)
235
236# Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}.
237# Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more,
238# or a certain builder, for eaxample, msbuild.exe, would be confused.
239function(set_output_directory target)
240 cmake_parse_arguments(ARG "" "BINARY_DIR;LIBRARY_DIR" "" ${ARGN})
241
242 # module_dir -- corresponding to LIBRARY_OUTPUT_DIRECTORY.
243 # It affects output of add_library(MODULE).
244 if(WIN32 OR CYGWIN)
245 # DLL platform
246 set(module_dir ${ARG_BINARY_DIR})
247 else()
248 set(module_dir ${ARG_LIBRARY_DIR})
249 endif()
250 if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
251 foreach(build_mode ${CMAKE_CONFIGURATION_TYPES})
252 string(TOUPPER "${build_mode}" CONFIG_SUFFIX)
253 if(ARG_BINARY_DIR)
254 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} bi ${ARG_BINARY_DIR})
255 set_target_properties(${target} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${bi})
256 endif()
257 if(ARG_LIBRARY_DIR)
258 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} li ${ARG_LIBRARY_DIR})
259 set_target_properties(${target} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li})
260 endif()
261 if(module_dir)
262 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} mi ${module_dir})
263 set_target_properties(${target} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${mi})
264 endif()
265 endforeach()
266 else()
267 if(ARG_BINARY_DIR)
268 set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ARG_BINARY_DIR})
269 endif()
270 if(ARG_LIBRARY_DIR)
271 set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${ARG_LIBRARY_DIR})
272 endif()
273 if(module_dir)
274 set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${module_dir})
275 endif()
276 endif()
277endfunction()
278
279# If on Windows and building with MSVC, add the resource script containing the
280# VERSIONINFO data to the project. This embeds version resource information
281# into the output .exe or .dll.
282# TODO: Enable for MinGW Windows builds too.
283#
284function(add_windows_version_resource_file OUT_VAR)
285 set(sources ${ARGN})
286 if (MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
287 set(resource_file ${LLVM_SOURCE_DIR}/resources/windows_version_resource.rc)
288 if(EXISTS ${resource_file})
289 set(sources ${sources} ${resource_file})
290 source_group("Resource Files" ${resource_file})
291 set(windows_resource_file ${resource_file} PARENT_SCOPE)
292 endif()
293 endif(MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
294
295 set(${OUT_VAR} ${sources} PARENT_SCOPE)
296endfunction(add_windows_version_resource_file)
297
298# set_windows_version_resource_properties(name resource_file...
299# VERSION_MAJOR int
300# Optional major version number (defaults to LLVM_VERSION_MAJOR)
301# VERSION_MINOR int
302# Optional minor version number (defaults to LLVM_VERSION_MINOR)
303# VERSION_PATCHLEVEL int
304# Optional patchlevel version number (defaults to LLVM_VERSION_PATCH)
305# VERSION_STRING
306# Optional version string (defaults to PACKAGE_VERSION)
307# PRODUCT_NAME
308# Optional product name string (defaults to "LLVM")
309# )
310function(set_windows_version_resource_properties name resource_file)
311 cmake_parse_arguments(ARG
312 ""
313 "VERSION_MAJOR;VERSION_MINOR;VERSION_PATCHLEVEL;VERSION_STRING;PRODUCT_NAME"
314 ""
315 ${ARGN})
316
317 if (NOT DEFINED ARG_VERSION_MAJOR)
318 set(ARG_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
319 endif()
320
321 if (NOT DEFINED ARG_VERSION_MINOR)
322 set(ARG_VERSION_MINOR ${LLVM_VERSION_MINOR})
323 endif()
324
325 if (NOT DEFINED ARG_VERSION_PATCHLEVEL)
326 set(ARG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH})
327 endif()
328
329 if (NOT DEFINED ARG_VERSION_STRING)
330 set(ARG_VERSION_STRING ${PACKAGE_VERSION})
331 endif()
332
333 if (NOT DEFINED ARG_PRODUCT_NAME)
334 set(ARG_PRODUCT_NAME "LLVM")
335 endif()
336
337 set_property(SOURCE ${resource_file}
338 PROPERTY COMPILE_FLAGS /nologo)
339 set_property(SOURCE ${resource_file}
340 PROPERTY COMPILE_DEFINITIONS
341 "RC_VERSION_FIELD_1=${ARG_VERSION_MAJOR}"
342 "RC_VERSION_FIELD_2=${ARG_VERSION_MINOR}"
343 "RC_VERSION_FIELD_3=${ARG_VERSION_PATCHLEVEL}"
344 "RC_VERSION_FIELD_4=0"
345 "RC_FILE_VERSION=\"${ARG_VERSION_STRING}\""
346 "RC_INTERNAL_NAME=\"${name}\""
347 "RC_PRODUCT_NAME=\"${ARG_PRODUCT_NAME}\""
348 "RC_PRODUCT_VERSION=\"${ARG_VERSION_STRING}\"")
349endfunction(set_windows_version_resource_properties)
350
351# llvm_add_library(name sources...
352# SHARED;STATIC
353# STATIC by default w/o BUILD_SHARED_LIBS.
354# SHARED by default w/ BUILD_SHARED_LIBS.
355# OBJECT
356# Also create an OBJECT library target. Default if STATIC && SHARED.
357# MODULE
358# Target ${name} might not be created on unsupported platforms.
359# Check with "if(TARGET ${name})".
360# DISABLE_LLVM_LINK_LLVM_DYLIB
361# Do not link this library to libLLVM, even if
362# LLVM_LINK_LLVM_DYLIB is enabled.
363# OUTPUT_NAME name
364# Corresponds to OUTPUT_NAME in target properties.
365# DEPENDS targets...
366# Same semantics as add_dependencies().
367# LINK_COMPONENTS components...
368# Same as the variable LLVM_LINK_COMPONENTS.
369# LINK_LIBS lib_targets...
370# Same semantics as target_link_libraries().
371# ADDITIONAL_HEADERS
372# May specify header files for IDE generators.
373# SONAME
374# Should set SONAME link flags and create symlinks
Andrew Walbran16937d02019-10-22 13:54:20 +0100375# NO_INSTALL_RPATH
376# Suppress default RPATH settings in shared libraries.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100377# PLUGIN_TOOL
378# The tool (i.e. cmake target) that this plugin will link against
379# )
380function(llvm_add_library name)
381 cmake_parse_arguments(ARG
Andrew Walbran16937d02019-10-22 13:54:20 +0100382 "MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME;NO_INSTALL_RPATH"
383 "OUTPUT_NAME;PLUGIN_TOOL;ENTITLEMENTS"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100384 "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS"
385 ${ARGN})
386 list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
387 if(ARG_ADDITIONAL_HEADERS)
388 # Pass through ADDITIONAL_HEADERS.
389 set(ARG_ADDITIONAL_HEADERS ADDITIONAL_HEADERS ${ARG_ADDITIONAL_HEADERS})
390 endif()
391 if(ARG_OBJLIBS)
392 set(ALL_FILES ${ARG_OBJLIBS})
393 else()
394 llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS})
395 endif()
396
397 if(ARG_MODULE)
398 if(ARG_SHARED OR ARG_STATIC)
399 message(WARNING "MODULE with SHARED|STATIC doesn't make sense.")
400 endif()
401 # Plugins that link against a tool are allowed even when plugins in general are not
402 if(NOT LLVM_ENABLE_PLUGINS AND NOT (ARG_PLUGIN_TOOL AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS))
403 message(STATUS "${name} ignored -- Loadable modules not supported on this platform.")
404 return()
405 endif()
406 else()
407 if(ARG_PLUGIN_TOOL)
408 message(WARNING "PLUGIN_TOOL without MODULE doesn't make sense.")
409 endif()
410 if(BUILD_SHARED_LIBS AND NOT ARG_STATIC)
411 set(ARG_SHARED TRUE)
412 endif()
413 if(NOT ARG_SHARED)
414 set(ARG_STATIC TRUE)
415 endif()
416 endif()
417
418 # Generate objlib
419 if((ARG_SHARED AND ARG_STATIC) OR ARG_OBJECT)
420 # Generate an obj library for both targets.
421 set(obj_name "obj.${name}")
422 add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL
423 ${ALL_FILES}
424 )
425 llvm_update_compile_flags(${obj_name})
426 set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>")
427
428 # Do add_dependencies(obj) later due to CMake issue 14747.
429 list(APPEND objlibs ${obj_name})
430
431 set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
432 endif()
433
434 if(ARG_SHARED AND ARG_STATIC)
435 # static
436 set(name_static "${name}_static")
437 if(ARG_OUTPUT_NAME)
438 set(output_name OUTPUT_NAME "${ARG_OUTPUT_NAME}")
439 endif()
440 # DEPENDS has been appended to LLVM_COMMON_LIBS.
441 llvm_add_library(${name_static} STATIC
442 ${output_name}
443 OBJLIBS ${ALL_FILES} # objlib
444 LINK_LIBS ${ARG_LINK_LIBS}
445 LINK_COMPONENTS ${ARG_LINK_COMPONENTS}
446 )
447 # FIXME: Add name_static to anywhere in TARGET ${name}'s PROPERTY.
448 set(ARG_STATIC)
449 endif()
450
451 if(ARG_MODULE)
452 add_library(${name} MODULE ${ALL_FILES})
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100453 elseif(ARG_SHARED)
454 add_windows_version_resource_file(ALL_FILES ${ALL_FILES})
455 add_library(${name} SHARED ${ALL_FILES})
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100456 else()
457 add_library(${name} STATIC ${ALL_FILES})
458 endif()
459
Andrew Walbran16937d02019-10-22 13:54:20 +0100460 if(NOT ARG_NO_INSTALL_RPATH)
461 if(ARG_MODULE OR ARG_SHARED)
462 llvm_setup_rpath(${name})
463 endif()
464 endif()
465
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100466 setup_dependency_debugging(${name} ${LLVM_COMMON_DEPENDS})
467
468 if(DEFINED windows_resource_file)
469 set_windows_version_resource_properties(${name} ${windows_resource_file})
470 set(windows_resource_file ${windows_resource_file} PARENT_SCOPE)
471 endif()
472
473 set_output_directory(${name} BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR} LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
474 # $<TARGET_OBJECTS> doesn't require compile flags.
475 if(NOT obj_name)
476 llvm_update_compile_flags(${name})
477 endif()
478 add_link_opts( ${name} )
479 if(ARG_OUTPUT_NAME)
480 set_target_properties(${name}
481 PROPERTIES
482 OUTPUT_NAME ${ARG_OUTPUT_NAME}
483 )
484 endif()
485
486 if(ARG_MODULE)
487 set_target_properties(${name} PROPERTIES
488 PREFIX ""
489 SUFFIX ${LLVM_PLUGIN_EXT}
490 )
491 endif()
492
493 if(ARG_SHARED)
494 if(WIN32)
495 set_target_properties(${name} PROPERTIES
496 PREFIX ""
497 )
498 endif()
499
500 # Set SOVERSION on shared libraries that lack explicit SONAME
501 # specifier, on *nix systems that are not Darwin.
502 if(UNIX AND NOT APPLE AND NOT ARG_SONAME)
503 set_target_properties(${name}
504 PROPERTIES
505 # Since 4.0.0, the ABI version is indicated by the major version
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100506 SOVERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100507 VERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX})
508 endif()
509 endif()
510
511 if(ARG_MODULE OR ARG_SHARED)
512 # Do not add -Dname_EXPORTS to the command-line when building files in this
513 # target. Doing so is actively harmful for the modules build because it
514 # creates extra module variants, and not useful because we don't use these
515 # macros.
516 set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
517
518 if (LLVM_EXPORTED_SYMBOL_FILE)
519 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
520 endif()
521 endif()
522
523 if(ARG_SHARED AND UNIX)
524 if(NOT APPLE AND ARG_SONAME)
525 get_target_property(output_name ${name} OUTPUT_NAME)
526 if(${output_name} STREQUAL "output_name-NOTFOUND")
527 set(output_name ${name})
528 endif()
529 set(library_name ${output_name}-${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX})
530 set(api_name ${output_name}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX})
531 set_target_properties(${name} PROPERTIES OUTPUT_NAME ${library_name})
532 llvm_install_library_symlink(${api_name} ${library_name} SHARED
533 COMPONENT ${name}
534 ALWAYS_GENERATE)
535 llvm_install_library_symlink(${output_name} ${library_name} SHARED
536 COMPONENT ${name}
537 ALWAYS_GENERATE)
538 endif()
539 endif()
540
541 if(ARG_MODULE AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS AND ARG_PLUGIN_TOOL AND (WIN32 OR CYGWIN))
542 # On DLL platforms symbols are imported from the tool by linking against it.
543 set(llvm_libs ${ARG_PLUGIN_TOOL})
544 elseif (DEFINED LLVM_LINK_COMPONENTS OR DEFINED ARG_LINK_COMPONENTS)
545 if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
546 set(llvm_libs LLVM)
547 else()
548 llvm_map_components_to_libnames(llvm_libs
549 ${ARG_LINK_COMPONENTS}
550 ${LLVM_LINK_COMPONENTS}
551 )
552 endif()
553 else()
554 # Components have not been defined explicitly in CMake, so add the
555 # dependency information for this library as defined by LLVMBuild.
556 #
557 # It would be nice to verify that we have the dependencies for this library
558 # name, but using get_property(... SET) doesn't suffice to determine if a
559 # property has been set to an empty value.
560 get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
561 endif()
562
563 if(ARG_STATIC)
564 set(libtype INTERFACE)
565 else()
566 # We can use PRIVATE since SO knows its dependent libs.
567 set(libtype PRIVATE)
568 endif()
569
570 target_link_libraries(${name} ${libtype}
571 ${ARG_LINK_LIBS}
572 ${lib_deps}
573 ${llvm_libs}
574 )
575
576 if(LLVM_COMMON_DEPENDS)
577 add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
578 # Add dependencies also to objlibs.
579 # CMake issue 14747 -- add_dependencies() might be ignored to objlib's user.
580 foreach(objlib ${objlibs})
581 add_dependencies(${objlib} ${LLVM_COMMON_DEPENDS})
582 endforeach()
583 endif()
584
585 if(ARG_SHARED OR ARG_MODULE)
586 llvm_externalize_debuginfo(${name})
Andrew Walbran16937d02019-10-22 13:54:20 +0100587 llvm_codesign(${name} ENTITLEMENTS ${ARG_ENTITLEMENTS})
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100588 endif()
589endfunction()
590
591function(add_llvm_install_targets target)
592 cmake_parse_arguments(ARG "" "COMPONENT;PREFIX" "DEPENDS" ${ARGN})
593 if(ARG_COMPONENT)
594 set(component_option -DCMAKE_INSTALL_COMPONENT="${ARG_COMPONENT}")
595 endif()
596 if(ARG_PREFIX)
597 set(prefix_option -DCMAKE_INSTALL_PREFIX="${ARG_PREFIX}")
598 endif()
599
600 add_custom_target(${target}
601 DEPENDS ${ARG_DEPENDS}
602 COMMAND "${CMAKE_COMMAND}"
603 ${component_option}
604 ${prefix_option}
605 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
606 USES_TERMINAL)
607 add_custom_target(${target}-stripped
608 DEPENDS ${ARG_DEPENDS}
609 COMMAND "${CMAKE_COMMAND}"
610 ${component_option}
611 ${prefix_option}
612 -DCMAKE_INSTALL_DO_STRIP=1
613 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
614 USES_TERMINAL)
615endfunction()
616
617macro(add_llvm_library name)
618 cmake_parse_arguments(ARG
Andrew Walbran16937d02019-10-22 13:54:20 +0100619 "SHARED;BUILDTREE_ONLY;MODULE"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100620 ""
621 ""
622 ${ARGN})
Andrew Walbran16937d02019-10-22 13:54:20 +0100623 if(ARG_MODULE)
624 llvm_add_library(${name} MODULE ${ARG_UNPARSED_ARGUMENTS})
625 elseif( BUILD_SHARED_LIBS OR ARG_SHARED )
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100626 llvm_add_library(${name} SHARED ${ARG_UNPARSED_ARGUMENTS})
627 else()
628 llvm_add_library(${name} ${ARG_UNPARSED_ARGUMENTS})
629 endif()
630
631 # Libraries that are meant to only be exposed via the build tree only are
632 # never installed and are only exported as a target in the special build tree
633 # config file.
Andrew Walbran16937d02019-10-22 13:54:20 +0100634 if (NOT ARG_BUILDTREE_ONLY AND NOT ARG_MODULE)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100635 set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
636 endif()
637
Andrew Walbran16937d02019-10-22 13:54:20 +0100638 if (ARG_MODULE AND NOT TARGET ${name})
639 # Add empty "phony" target
640 add_custom_target(${name})
641 elseif( EXCLUDE_FROM_ALL )
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100642 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
643 elseif(ARG_BUILDTREE_ONLY)
644 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name})
645 else()
646 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO" OR
Andrew Walbran16937d02019-10-22 13:54:20 +0100647 ${name} STREQUAL "OptRemarks" OR
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100648 (LLVM_LINK_LLVM_DYLIB AND ${name} STREQUAL "LLVM"))
649 set(install_dir lib${LLVM_LIBDIR_SUFFIX})
Andrew Walbran16937d02019-10-22 13:54:20 +0100650 if(ARG_MODULE OR ARG_SHARED OR BUILD_SHARED_LIBS)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100651 if(WIN32 OR CYGWIN OR MINGW)
652 set(install_type RUNTIME)
653 set(install_dir bin)
654 else()
655 set(install_type LIBRARY)
656 endif()
657 else()
658 set(install_type ARCHIVE)
659 endif()
660
Andrew Walbran16937d02019-10-22 13:54:20 +0100661 if (ARG_MODULE)
662 set(install_type LIBRARY)
663 endif()
664
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100665 if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
666 NOT LLVM_DISTRIBUTION_COMPONENTS)
667 set(export_to_llvmexports EXPORT LLVMExports)
668 set_property(GLOBAL PROPERTY LLVM_HAS_EXPORTS True)
669 endif()
670
671 install(TARGETS ${name}
672 ${export_to_llvmexports}
673 ${install_type} DESTINATION ${install_dir}
674 COMPONENT ${name})
675
Andrew Walbran16937d02019-10-22 13:54:20 +0100676 if (NOT LLVM_ENABLE_IDE)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100677 add_llvm_install_targets(install-${name}
678 DEPENDS ${name}
679 COMPONENT ${name})
680 endif()
681 endif()
682 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
683 endif()
Andrew Walbran16937d02019-10-22 13:54:20 +0100684 if (ARG_MODULE)
685 set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
686 else()
687 set_target_properties(${name} PROPERTIES FOLDER "Libraries")
688 endif()
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100689endmacro(add_llvm_library name)
690
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100691macro(add_llvm_executable name)
Andrew Walbran16937d02019-10-22 13:54:20 +0100692 cmake_parse_arguments(ARG
693 "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH"
694 "ENTITLEMENTS"
695 "DEPENDS"
696 ${ARGN})
697
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100698 llvm_process_sources( ALL_FILES ${ARG_UNPARSED_ARGUMENTS} )
699
700 list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
701
702 # Generate objlib
703 if(LLVM_ENABLE_OBJLIB)
704 # Generate an obj library for both targets.
705 set(obj_name "obj.${name}")
706 add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL
707 ${ALL_FILES}
708 )
709 llvm_update_compile_flags(${obj_name})
710 set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>")
711
712 set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
713 endif()
714
715 add_windows_version_resource_file(ALL_FILES ${ALL_FILES})
716
717 if(XCODE)
718 # Note: the dummy.cpp source file provides no definitions. However,
719 # it forces Xcode to properly link the static library.
720 list(APPEND ALL_FILES "${LLVM_MAIN_SRC_DIR}/cmake/dummy.cpp")
721 endif()
722
723 if( EXCLUDE_FROM_ALL )
724 add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
725 else()
726 add_executable(${name} ${ALL_FILES})
727 endif()
728
729 setup_dependency_debugging(${name} ${LLVM_COMMON_DEPENDS})
730
731 if(NOT ARG_NO_INSTALL_RPATH)
732 llvm_setup_rpath(${name})
733 endif()
734
735 if(DEFINED windows_resource_file)
736 set_windows_version_resource_properties(${name} ${windows_resource_file})
737 endif()
738
739 # $<TARGET_OBJECTS> doesn't require compile flags.
740 if(NOT LLVM_ENABLE_OBJLIB)
741 llvm_update_compile_flags(${name})
742 endif()
743 add_link_opts( ${name} )
744
745 # Do not add -Dname_EXPORTS to the command-line when building files in this
746 # target. Doing so is actively harmful for the modules build because it
747 # creates extra module variants, and not useful because we don't use these
748 # macros.
749 set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
750
751 if (LLVM_EXPORTED_SYMBOL_FILE)
752 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
753 endif(LLVM_EXPORTED_SYMBOL_FILE)
754
755 if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
756 set(USE_SHARED USE_SHARED)
757 endif()
758
759 set(EXCLUDE_FROM_ALL OFF)
760 set_output_directory(${name} BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR} LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
761 llvm_config( ${name} ${USE_SHARED} ${LLVM_LINK_COMPONENTS} )
762 if( LLVM_COMMON_DEPENDS )
763 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
764 endif( LLVM_COMMON_DEPENDS )
765
766 if(NOT ARG_IGNORE_EXTERNALIZE_DEBUGINFO)
767 llvm_externalize_debuginfo(${name})
768 endif()
769 if (LLVM_PTHREAD_LIB)
770 # libpthreads overrides some standard library symbols, so main
771 # executable must be linked with it in order to provide consistent
772 # API for all shared libaries loaded by this executable.
773 target_link_libraries(${name} PRIVATE ${LLVM_PTHREAD_LIB})
774 endif()
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100775
Andrew Walbran16937d02019-10-22 13:54:20 +0100776 llvm_codesign(${name} ENTITLEMENTS ${ARG_ENTITLEMENTS})
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100777endmacro(add_llvm_executable name)
778
779function(export_executable_symbols target)
780 if (LLVM_EXPORTED_SYMBOL_FILE)
781 # The symbol file should contain the symbols we want the executable to
782 # export
783 set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
784 elseif (LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)
785 # Extract the symbols to export from the static libraries that the
786 # executable links against.
787 set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
788 set(exported_symbol_file ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${target}.symbols)
789 # We need to consider not just the direct link dependencies, but also the
790 # transitive link dependencies. Do this by starting with the set of direct
791 # dependencies, then the dependencies of those dependencies, and so on.
792 get_target_property(new_libs ${target} LINK_LIBRARIES)
793 set(link_libs ${new_libs})
794 while(NOT "${new_libs}" STREQUAL "")
795 foreach(lib ${new_libs})
796 if(TARGET ${lib})
797 get_target_property(lib_type ${lib} TYPE)
798 if("${lib_type}" STREQUAL "STATIC_LIBRARY")
799 list(APPEND static_libs ${lib})
800 else()
801 list(APPEND other_libs ${lib})
802 endif()
803 get_target_property(transitive_libs ${lib} INTERFACE_LINK_LIBRARIES)
804 foreach(transitive_lib ${transitive_libs})
805 list(FIND link_libs ${transitive_lib} idx)
806 if(TARGET ${transitive_lib} AND idx EQUAL -1)
807 list(APPEND newer_libs ${transitive_lib})
808 list(APPEND link_libs ${transitive_lib})
809 endif()
810 endforeach(transitive_lib)
811 endif()
812 endforeach(lib)
813 set(new_libs ${newer_libs})
814 set(newer_libs "")
815 endwhile()
816 if (MSVC)
817 set(mangling microsoft)
818 else()
819 set(mangling itanium)
820 endif()
821 add_custom_command(OUTPUT ${exported_symbol_file}
822 COMMAND ${PYTHON_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py --mangling=${mangling} ${static_libs} -o ${exported_symbol_file}
823 WORKING_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR}
824 DEPENDS ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py ${static_libs}
825 VERBATIM
826 COMMENT "Generating export list for ${target}")
827 add_llvm_symbol_exports( ${target} ${exported_symbol_file} )
828 # If something links against this executable then we want a
829 # transitive link against only the libraries whose symbols
830 # we aren't exporting.
831 set_target_properties(${target} PROPERTIES INTERFACE_LINK_LIBRARIES "${other_libs}")
832 # The default import library suffix that cmake uses for cygwin/mingw is
833 # ".dll.a", but for clang.exe that causes a collision with libclang.dll,
834 # where the import libraries of both get named libclang.dll.a. Use a suffix
835 # of ".exe.a" to avoid this.
836 if(CYGWIN OR MINGW)
837 set_target_properties(${target} PROPERTIES IMPORT_SUFFIX ".exe.a")
838 endif()
839 elseif(NOT (WIN32 OR CYGWIN))
840 # On Windows auto-exporting everything doesn't work because of the limit on
841 # the size of the exported symbol table, but on other platforms we can do
842 # it without any trouble.
843 set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
844 if (APPLE)
845 set_property(TARGET ${target} APPEND_STRING PROPERTY
846 LINK_FLAGS " -rdynamic")
847 endif()
848 endif()
849endfunction()
850
851if(NOT LLVM_TOOLCHAIN_TOOLS)
852 set (LLVM_TOOLCHAIN_TOOLS
853 llvm-ar
854 llvm-ranlib
855 llvm-lib
856 llvm-objdump
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100857 llvm-rc
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100858 )
859endif()
860
861macro(add_llvm_tool name)
862 if( NOT LLVM_BUILD_TOOLS )
863 set(EXCLUDE_FROM_ALL ON)
864 endif()
865 add_llvm_executable(${name} ${ARGN})
866
867 if ( ${name} IN_LIST LLVM_TOOLCHAIN_TOOLS OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
868 if( LLVM_BUILD_TOOLS )
869 if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
870 NOT LLVM_DISTRIBUTION_COMPONENTS)
871 set(export_to_llvmexports EXPORT LLVMExports)
872 set_property(GLOBAL PROPERTY LLVM_HAS_EXPORTS True)
873 endif()
874
875 install(TARGETS ${name}
876 ${export_to_llvmexports}
877 RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR}
878 COMPONENT ${name})
879
Andrew Walbran16937d02019-10-22 13:54:20 +0100880 if (NOT LLVM_ENABLE_IDE)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100881 add_llvm_install_targets(install-${name}
882 DEPENDS ${name}
883 COMPONENT ${name})
884 endif()
885 endif()
886 endif()
887 if( LLVM_BUILD_TOOLS )
888 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
889 endif()
890 set_target_properties(${name} PROPERTIES FOLDER "Tools")
891endmacro(add_llvm_tool name)
892
893
894macro(add_llvm_example name)
895 if( NOT LLVM_BUILD_EXAMPLES )
896 set(EXCLUDE_FROM_ALL ON)
897 endif()
898 add_llvm_executable(${name} ${ARGN})
899 if( LLVM_BUILD_EXAMPLES )
900 install(TARGETS ${name} RUNTIME DESTINATION examples)
901 endif()
902 set_target_properties(${name} PROPERTIES FOLDER "Examples")
903endmacro(add_llvm_example name)
904
905# This is a macro that is used to create targets for executables that are needed
906# for development, but that are not intended to be installed by default.
907macro(add_llvm_utility name)
908 if ( NOT LLVM_BUILD_UTILS )
909 set(EXCLUDE_FROM_ALL ON)
910 endif()
911
912 add_llvm_executable(${name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN})
913 set_target_properties(${name} PROPERTIES FOLDER "Utils")
Andrew Walbran16937d02019-10-22 13:54:20 +0100914 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
915 if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS)
916 if (${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
917 NOT LLVM_DISTRIBUTION_COMPONENTS)
918 set(export_to_llvmexports EXPORT LLVMExports)
919 set_property(GLOBAL PROPERTY LLVM_HAS_EXPORTS True)
920 endif()
921
922 install(TARGETS ${name}
923 ${export_to_llvmexports}
924 RUNTIME DESTINATION ${LLVM_UTILS_INSTALL_DIR}
925 COMPONENT ${name})
926
927 if (NOT LLVM_ENABLE_IDE)
928 add_llvm_install_targets(install-${name}
929 DEPENDS ${name}
930 COMPONENT ${name})
931 endif()
932 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
933 elseif(LLVM_BUILD_UTILS)
934 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name})
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100935 endif()
936 endif()
937endmacro(add_llvm_utility name)
938
939macro(add_llvm_fuzzer name)
940 cmake_parse_arguments(ARG "" "DUMMY_MAIN" "" ${ARGN})
941 if( LLVM_LIB_FUZZING_ENGINE )
942 set(LLVM_OPTIONAL_SOURCES ${ARG_DUMMY_MAIN})
943 add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS})
944 target_link_libraries(${name} PRIVATE ${LLVM_LIB_FUZZING_ENGINE})
945 set_target_properties(${name} PROPERTIES FOLDER "Fuzzers")
946 elseif( LLVM_USE_SANITIZE_COVERAGE )
947 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer")
948 set(LLVM_OPTIONAL_SOURCES ${ARG_DUMMY_MAIN})
949 add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS})
950 set_target_properties(${name} PROPERTIES FOLDER "Fuzzers")
951 elseif( ARG_DUMMY_MAIN )
952 add_llvm_executable(${name} ${ARG_DUMMY_MAIN} ${ARG_UNPARSED_ARGUMENTS})
953 set_target_properties(${name} PROPERTIES FOLDER "Fuzzers")
954 endif()
955endmacro()
956
957macro(add_llvm_target target_name)
958 include_directories(BEFORE
959 ${CMAKE_CURRENT_BINARY_DIR}
960 ${CMAKE_CURRENT_SOURCE_DIR})
961 add_llvm_library(LLVM${target_name} ${ARGN})
962 set( CURRENT_LLVM_TARGET LLVM${target_name} )
963endmacro(add_llvm_target)
964
965function(canonicalize_tool_name name output)
966 string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" nameStrip ${name})
967 string(REPLACE "-" "_" nameUNDERSCORE ${nameStrip})
968 string(TOUPPER ${nameUNDERSCORE} nameUPPER)
969 set(${output} "${nameUPPER}" PARENT_SCOPE)
970endfunction(canonicalize_tool_name)
971
972# Custom add_subdirectory wrapper
973# Takes in a project name (i.e. LLVM), the subdirectory name, and an optional
974# path if it differs from the name.
Andrew Walbran16937d02019-10-22 13:54:20 +0100975function(add_llvm_subdirectory project type name)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100976 set(add_llvm_external_dir "${ARGN}")
977 if("${add_llvm_external_dir}" STREQUAL "")
978 set(add_llvm_external_dir ${name})
979 endif()
980 canonicalize_tool_name(${name} nameUPPER)
Andrew Walbran16937d02019-10-22 13:54:20 +0100981 set(canonical_full_name ${project}_${type}_${nameUPPER})
982 get_property(already_processed GLOBAL PROPERTY ${canonical_full_name}_PROCESSED)
983 if(already_processed)
984 return()
985 endif()
986 set_property(GLOBAL PROPERTY ${canonical_full_name}_PROCESSED YES)
987
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100988 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}/CMakeLists.txt)
989 # Treat it as in-tree subproject.
Andrew Walbran16937d02019-10-22 13:54:20 +0100990 option(${canonical_full_name}_BUILD
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100991 "Whether to build ${name} as part of ${project}" On)
992 mark_as_advanced(${project}_${type}_${name}_BUILD)
Andrew Walbran16937d02019-10-22 13:54:20 +0100993 if(${canonical_full_name}_BUILD)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100994 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir} ${add_llvm_external_dir})
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100995 endif()
996 else()
997 set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR
998 "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}"
999 CACHE PATH "Path to ${name} source directory")
Andrew Walbran16937d02019-10-22 13:54:20 +01001000 set(${canonical_full_name}_BUILD_DEFAULT ON)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001001 if(NOT LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR OR NOT EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR})
Andrew Walbran16937d02019-10-22 13:54:20 +01001002 set(${canonical_full_name}_BUILD_DEFAULT OFF)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001003 endif()
1004 if("${LLVM_EXTERNAL_${nameUPPER}_BUILD}" STREQUAL "OFF")
Andrew Walbran16937d02019-10-22 13:54:20 +01001005 set(${canonical_full_name}_BUILD_DEFAULT OFF)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001006 endif()
Andrew Walbran16937d02019-10-22 13:54:20 +01001007 option(${canonical_full_name}_BUILD
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001008 "Whether to build ${name} as part of LLVM"
Andrew Walbran16937d02019-10-22 13:54:20 +01001009 ${${canonical_full_name}_BUILD_DEFAULT})
1010 if (${canonical_full_name}_BUILD)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001011 if(EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR})
1012 add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir})
1013 elseif(NOT "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}" STREQUAL "")
1014 message(WARNING "Nonexistent directory for ${name}: ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}")
1015 endif()
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001016 endif()
1017 endif()
Andrew Walbran16937d02019-10-22 13:54:20 +01001018endfunction()
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001019
1020# Add external project that may want to be built as part of llvm such as Clang,
1021# lld, and Polly. This adds two options. One for the source directory of the
1022# project, which defaults to ${CMAKE_CURRENT_SOURCE_DIR}/${name}. Another to
1023# enable or disable building it with everything else.
1024# Additional parameter can be specified as the name of directory.
1025macro(add_llvm_external_project name)
1026 add_llvm_subdirectory(LLVM TOOL ${name} ${ARGN})
1027endmacro()
1028
1029macro(add_llvm_tool_subdirectory name)
1030 add_llvm_external_project(${name})
1031endmacro(add_llvm_tool_subdirectory)
1032
1033function(get_project_name_from_src_var var output)
1034 string(REGEX MATCH "LLVM_EXTERNAL_(.*)_SOURCE_DIR"
1035 MACHED_TOOL "${var}")
1036 if(MACHED_TOOL)
1037 set(${output} ${CMAKE_MATCH_1} PARENT_SCOPE)
1038 else()
1039 set(${output} PARENT_SCOPE)
1040 endif()
1041endfunction()
1042
1043function(create_subdirectory_options project type)
1044 file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
1045 foreach(dir ${sub-dirs})
1046 if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt")
1047 canonicalize_tool_name(${dir} name)
1048 option(${project}_${type}_${name}_BUILD
1049 "Whether to build ${name} as part of ${project}" On)
1050 mark_as_advanced(${project}_${type}_${name}_BUILD)
1051 endif()
1052 endforeach()
1053endfunction(create_subdirectory_options)
1054
1055function(create_llvm_tool_options)
1056 create_subdirectory_options(LLVM TOOL)
1057endfunction(create_llvm_tool_options)
1058
1059function(llvm_add_implicit_projects project)
1060 set(list_of_implicit_subdirs "")
1061 file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
1062 foreach(dir ${sub-dirs})
1063 if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt")
1064 canonicalize_tool_name(${dir} name)
1065 if (${project}_TOOL_${name}_BUILD)
1066 get_filename_component(fn "${dir}" NAME)
1067 list(APPEND list_of_implicit_subdirs "${fn}")
1068 endif()
1069 endif()
1070 endforeach()
1071
1072 foreach(external_proj ${list_of_implicit_subdirs})
1073 add_llvm_subdirectory(${project} TOOL "${external_proj}" ${ARGN})
1074 endforeach()
1075endfunction(llvm_add_implicit_projects)
1076
1077function(add_llvm_implicit_projects)
1078 llvm_add_implicit_projects(LLVM)
1079endfunction(add_llvm_implicit_projects)
1080
1081# Generic support for adding a unittest.
1082function(add_unittest test_suite test_name)
1083 if( NOT LLVM_BUILD_TESTS )
1084 set(EXCLUDE_FROM_ALL ON)
1085 endif()
1086
1087 # Our current version of gtest does not properly recognize C++11 support
1088 # with MSVC, so it falls back to tr1 / experimental classes. Since LLVM
1089 # itself requires C++11, we can safely force it on unconditionally so that
Andrew Scull0372a572018-11-16 15:47:06 +00001090 # we don't have to fight with the buggy gtest check.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001091 add_definitions(-DGTEST_LANG_CXX11=1)
1092 add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
1093
1094 include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
1095 include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include)
1096 if (NOT LLVM_ENABLE_THREADS)
1097 list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0)
1098 endif ()
1099
1100 if (SUPPORTS_VARIADIC_MACROS_FLAG)
1101 list(APPEND LLVM_COMPILE_FLAGS "-Wno-variadic-macros")
1102 endif ()
1103 # Some parts of gtest rely on this GNU extension, don't warn on it.
1104 if(SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
1105 list(APPEND LLVM_COMPILE_FLAGS "-Wno-gnu-zero-variadic-macro-arguments")
1106 endif()
1107
1108 set(LLVM_REQUIRES_RTTI OFF)
1109
1110 list(APPEND LLVM_LINK_COMPONENTS Support) # gtest needs it for raw_ostream
1111 add_llvm_executable(${test_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${ARGN})
1112 set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
1113 set_output_directory(${test_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir})
1114 # libpthreads overrides some standard library symbols, so main
1115 # executable must be linked with it in order to provide consistent
1116 # API for all shared libaries loaded by this executable.
1117 target_link_libraries(${test_name} PRIVATE gtest_main gtest ${LLVM_PTHREAD_LIB})
1118
1119 add_dependencies(${test_suite} ${test_name})
1120 get_target_property(test_suite_folder ${test_suite} FOLDER)
1121 if (NOT ${test_suite_folder} STREQUAL "NOTFOUND")
1122 set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}")
1123 endif ()
1124endfunction()
1125
Andrew Scull0372a572018-11-16 15:47:06 +00001126# Use for test binaries that call llvm::getInputFileDirectory(). Use of this
1127# is discouraged.
1128function(add_unittest_with_input_files test_suite test_name)
1129 set(LLVM_UNITTEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
1130 configure_file(
1131 ${LLVM_MAIN_SRC_DIR}/unittests/unittest.cfg.in
1132 ${CMAKE_CURRENT_BINARY_DIR}/llvm.srcdir.txt)
1133
1134 add_unittest(${test_suite} ${test_name} ${ARGN})
1135endfunction()
1136
1137# Generic support for adding a benchmark.
1138function(add_benchmark benchmark_name)
1139 if( NOT LLVM_BUILD_BENCHMARKS )
1140 set(EXCLUDE_FROM_ALL ON)
1141 endif()
1142
1143 add_llvm_executable(${benchmark_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${ARGN})
1144 set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
1145 set_output_directory(${benchmark_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir})
1146 set_property(TARGET ${benchmark_name} PROPERTY FOLDER "Utils")
1147 target_link_libraries(${benchmark_name} PRIVATE benchmark)
1148endfunction()
1149
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001150function(llvm_add_go_executable binary pkgpath)
1151 cmake_parse_arguments(ARG "ALL" "" "DEPENDS;GOFLAGS" ${ARGN})
1152
1153 if(LLVM_BINDINGS MATCHES "go")
1154 # FIXME: This should depend only on the libraries Go needs.
1155 get_property(llvmlibs GLOBAL PROPERTY LLVM_LIBS)
1156 set(binpath ${CMAKE_BINARY_DIR}/bin/${binary}${CMAKE_EXECUTABLE_SUFFIX})
1157 set(cc "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
1158 set(cxx "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
1159 set(cppflags "")
1160 get_property(include_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
1161 foreach(d ${include_dirs})
1162 set(cppflags "${cppflags} -I${d}")
1163 endforeach(d)
1164 set(ldflags "${CMAKE_EXE_LINKER_FLAGS}")
1165 add_custom_command(OUTPUT ${binpath}
1166 COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "go=${GO_EXECUTABLE}" "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}" "packages=${LLVM_GO_PACKAGES}"
1167 ${ARG_GOFLAGS} build -o ${binpath} ${pkgpath}
1168 DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX}
1169 ${llvmlibs} ${ARG_DEPENDS}
1170 COMMENT "Building Go executable ${binary}"
1171 VERBATIM)
1172 if (ARG_ALL)
1173 add_custom_target(${binary} ALL DEPENDS ${binpath})
1174 else()
1175 add_custom_target(${binary} DEPENDS ${binpath})
1176 endif()
1177 endif()
1178endfunction()
1179
1180# This function canonicalize the CMake variables passed by names
1181# from CMake boolean to 0/1 suitable for passing into Python or C++,
1182# in place.
1183function(llvm_canonicalize_cmake_booleans)
1184 foreach(var ${ARGN})
1185 if(${var})
1186 set(${var} 1 PARENT_SCOPE)
1187 else()
1188 set(${var} 0 PARENT_SCOPE)
1189 endif()
1190 endforeach()
1191endfunction(llvm_canonicalize_cmake_booleans)
1192
1193macro(set_llvm_build_mode)
1194 # Configuration-time: See Unit/lit.site.cfg.in
1195 if (CMAKE_CFG_INTDIR STREQUAL ".")
1196 set(LLVM_BUILD_MODE ".")
1197 else ()
1198 set(LLVM_BUILD_MODE "%(build_mode)s")
1199 endif ()
1200endmacro()
1201
1202# This function provides an automatic way to 'configure'-like generate a file
1203# based on a set of common and custom variables, specifically targeting the
1204# variables needed for the 'lit.site.cfg' files. This function bundles the
1205# common variables that any Lit instance is likely to need, and custom
1206# variables can be passed in.
1207function(configure_lit_site_cfg site_in site_out)
1208 cmake_parse_arguments(ARG "" "" "MAIN_CONFIG;OUTPUT_MAPPING" ${ARGN})
1209
1210 if ("${ARG_MAIN_CONFIG}" STREQUAL "")
1211 get_filename_component(INPUT_DIR ${site_in} DIRECTORY)
1212 set(ARG_MAIN_CONFIG "${INPUT_DIR}/lit.cfg")
1213 endif()
1214 if ("${ARG_OUTPUT_MAPPING}" STREQUAL "")
1215 set(ARG_OUTPUT_MAPPING "${site_out}")
1216 endif()
1217
1218 foreach(c ${LLVM_TARGETS_TO_BUILD})
1219 set(TARGETS_BUILT "${TARGETS_BUILT} ${c}")
1220 endforeach(c)
1221 set(TARGETS_TO_BUILD ${TARGETS_BUILT})
1222
1223 set(SHLIBEXT "${LTDL_SHLIB_EXT}")
1224
1225 set_llvm_build_mode()
1226
1227 # They below might not be the build tree but provided binary tree.
1228 set(LLVM_SOURCE_DIR ${LLVM_MAIN_SRC_DIR})
1229 set(LLVM_BINARY_DIR ${LLVM_BINARY_DIR})
1230 string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" LLVM_TOOLS_DIR "${LLVM_TOOLS_BINARY_DIR}")
1231 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_LIBS_DIR "${LLVM_LIBRARY_DIR}")
1232
1233 # SHLIBDIR points the build tree.
1234 string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" SHLIBDIR "${LLVM_SHLIB_OUTPUT_INTDIR}")
1235
1236 set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
1237 # FIXME: "ENABLE_SHARED" doesn't make sense, since it is used just for
1238 # plugins. We may rename it.
1239 if(LLVM_ENABLE_PLUGINS)
1240 set(ENABLE_SHARED "1")
1241 else()
1242 set(ENABLE_SHARED "0")
1243 endif()
1244
1245 if(LLVM_ENABLE_ASSERTIONS AND NOT MSVC_IDE)
1246 set(ENABLE_ASSERTIONS "1")
1247 else()
1248 set(ENABLE_ASSERTIONS "0")
1249 endif()
1250
1251 set(HOST_OS ${CMAKE_SYSTEM_NAME})
1252 set(HOST_ARCH ${CMAKE_SYSTEM_PROCESSOR})
1253
1254 set(HOST_CC "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
1255 set(HOST_CXX "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
1256 set(HOST_LDFLAGS "${CMAKE_EXE_LINKER_FLAGS}")
1257
1258 set(LIT_SITE_CFG_IN_HEADER "## Autogenerated from ${site_in}\n## Do not edit!")
1259
1260 # Override config_target_triple (and the env)
1261 if(LLVM_TARGET_TRIPLE_ENV)
1262 # This is expanded into the heading.
1263 string(CONCAT LIT_SITE_CFG_IN_HEADER "${LIT_SITE_CFG_IN_HEADER}\n\n"
1264 "import os\n"
1265 "target_env = \"${LLVM_TARGET_TRIPLE_ENV}\"\n"
1266 "config.target_triple = config.environment[target_env] = os.environ.get(target_env, \"${TARGET_TRIPLE}\")\n"
1267 )
1268
1269 # This is expanded to; config.target_triple = ""+config.target_triple+""
1270 set(TARGET_TRIPLE "\"+config.target_triple+\"")
1271 endif()
1272
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001273 configure_file(${site_in} ${site_out} @ONLY)
1274 if (EXISTS "${ARG_MAIN_CONFIG}")
1275 set(PYTHON_STATEMENT "map_config('${ARG_MAIN_CONFIG}', '${site_out}')")
1276 get_property(LLVM_LIT_CONFIG_MAP GLOBAL PROPERTY LLVM_LIT_CONFIG_MAP)
1277 set(LLVM_LIT_CONFIG_MAP "${LLVM_LIT_CONFIG_MAP}\n${PYTHON_STATEMENT}")
1278 set_property(GLOBAL PROPERTY LLVM_LIT_CONFIG_MAP ${LLVM_LIT_CONFIG_MAP})
1279 endif()
1280endfunction()
1281
1282function(dump_all_cmake_variables)
1283 get_cmake_property(_variableNames VARIABLES)
1284 foreach (_variableName ${_variableNames})
1285 message(STATUS "${_variableName}=${${_variableName}}")
1286 endforeach()
1287endfunction()
1288
1289function(get_llvm_lit_path base_dir file_name)
1290 cmake_parse_arguments(ARG "ALLOW_EXTERNAL" "" "" ${ARGN})
1291
1292 if (ARG_ALLOW_EXTERNAL)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001293 set (LLVM_EXTERNAL_LIT "" CACHE STRING "Command used to spawn lit")
1294 if ("${LLVM_EXTERNAL_LIT}" STREQUAL "")
1295 set(LLVM_EXTERNAL_LIT "${LLVM_DEFAULT_EXTERNAL_LIT}")
1296 endif()
1297
1298 if (NOT "${LLVM_EXTERNAL_LIT}" STREQUAL "")
1299 if (EXISTS ${LLVM_EXTERNAL_LIT})
1300 get_filename_component(LIT_FILE_NAME ${LLVM_EXTERNAL_LIT} NAME)
1301 get_filename_component(LIT_BASE_DIR ${LLVM_EXTERNAL_LIT} DIRECTORY)
1302 set(${file_name} ${LIT_FILE_NAME} PARENT_SCOPE)
1303 set(${base_dir} ${LIT_BASE_DIR} PARENT_SCOPE)
1304 return()
1305 else()
1306 message(WARN "LLVM_EXTERNAL_LIT set to ${LLVM_EXTERNAL_LIT}, but the path does not exist.")
1307 endif()
1308 endif()
1309 endif()
1310
1311 set(lit_file_name "llvm-lit")
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001312 if (CMAKE_HOST_WIN32 AND NOT CYGWIN)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001313 # llvm-lit needs suffix.py for multiprocess to find a main module.
1314 set(lit_file_name "${lit_file_name}.py")
1315 endif ()
1316 set(${file_name} ${lit_file_name} PARENT_SCOPE)
1317
1318 get_property(LLVM_LIT_BASE_DIR GLOBAL PROPERTY LLVM_LIT_BASE_DIR)
1319 if (NOT "${LLVM_LIT_BASE_DIR}" STREQUAL "")
1320 set(${base_dir} ${LLVM_LIT_BASE_DIR} PARENT_SCOPE)
1321 endif()
1322
1323 # Allow individual projects to provide an override
1324 if (NOT "${LLVM_LIT_OUTPUT_DIR}" STREQUAL "")
1325 set(LLVM_LIT_BASE_DIR ${LLVM_LIT_OUTPUT_DIR})
1326 elseif(NOT "${LLVM_RUNTIME_OUTPUT_INTDIR}" STREQUAL "")
1327 set(LLVM_LIT_BASE_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
1328 else()
1329 set(LLVM_LIT_BASE_DIR "")
1330 endif()
1331
1332 # Cache this so we don't have to do it again and have subsequent calls
1333 # potentially disagree on the value.
1334 set_property(GLOBAL PROPERTY LLVM_LIT_BASE_DIR ${LLVM_LIT_BASE_DIR})
1335 set(${base_dir} ${LLVM_LIT_BASE_DIR} PARENT_SCOPE)
1336endfunction()
1337
1338# A raw function to create a lit target. This is used to implement the testuite
1339# management functions.
1340function(add_lit_target target comment)
1341 cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN})
1342 set(LIT_ARGS "${ARG_ARGS} ${LLVM_LIT_ARGS}")
1343 separate_arguments(LIT_ARGS)
1344 if (NOT CMAKE_CFG_INTDIR STREQUAL ".")
1345 list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR})
1346 endif ()
1347
1348 # Get the path to the lit to *run* tests with. This can be overriden by
1349 # the user by specifying -DLLVM_EXTERNAL_LIT=<path-to-lit.py>
1350 get_llvm_lit_path(
1351 lit_base_dir
1352 lit_file_name
1353 ALLOW_EXTERNAL
1354 )
1355
1356 set(LIT_COMMAND "${PYTHON_EXECUTABLE};${lit_base_dir}/${lit_file_name}")
1357 list(APPEND LIT_COMMAND ${LIT_ARGS})
1358 foreach(param ${ARG_PARAMS})
1359 list(APPEND LIT_COMMAND --param ${param})
1360 endforeach()
1361 if (ARG_UNPARSED_ARGUMENTS)
1362 add_custom_target(${target}
1363 COMMAND ${LIT_COMMAND} ${ARG_UNPARSED_ARGUMENTS}
1364 COMMENT "${comment}"
1365 USES_TERMINAL
1366 )
1367 else()
1368 add_custom_target(${target}
1369 COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, no tools built.")
1370 message(STATUS "${target} does nothing.")
1371 endif()
Andrew Scull0372a572018-11-16 15:47:06 +00001372
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001373 if (ARG_DEPENDS)
1374 add_dependencies(${target} ${ARG_DEPENDS})
1375 endif()
1376
1377 # Tests should be excluded from "Build Solution".
1378 set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON)
1379endfunction()
1380
1381# A function to add a set of lit test suites to be driven through 'check-*' targets.
1382function(add_lit_testsuite target comment)
1383 cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN})
1384
1385 # EXCLUDE_FROM_ALL excludes the test ${target} out of check-all.
1386 if(NOT EXCLUDE_FROM_ALL)
1387 # Register the testsuites, params and depends for the global check rule.
1388 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_TESTSUITES ${ARG_UNPARSED_ARGUMENTS})
1389 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_PARAMS ${ARG_PARAMS})
1390 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_DEPENDS ${ARG_DEPENDS})
1391 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_EXTRA_ARGS ${ARG_ARGS})
1392 endif()
1393
1394 # Produce a specific suffixed check rule.
1395 add_lit_target(${target} ${comment}
1396 ${ARG_UNPARSED_ARGUMENTS}
1397 PARAMS ${ARG_PARAMS}
1398 DEPENDS ${ARG_DEPENDS}
1399 ARGS ${ARG_ARGS}
1400 )
1401endfunction()
1402
1403function(add_lit_testsuites project directory)
Andrew Walbran16937d02019-10-22 13:54:20 +01001404 if (NOT LLVM_ENABLE_IDE)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001405 cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN})
1406
1407 # Search recursively for test directories by assuming anything not
1408 # in a directory called Inputs contains tests.
1409 file(GLOB_RECURSE to_process LIST_DIRECTORIES true ${directory}/*)
1410 foreach(lit_suite ${to_process})
1411 if(NOT IS_DIRECTORY ${lit_suite})
1412 continue()
1413 endif()
1414 string(FIND ${lit_suite} Inputs is_inputs)
1415 string(FIND ${lit_suite} Output is_output)
1416 if (NOT (is_inputs EQUAL -1 AND is_output EQUAL -1))
1417 continue()
1418 endif()
1419
1420 # Create a check- target for the directory.
1421 string(REPLACE ${directory} "" name_slash ${lit_suite})
1422 if (name_slash)
1423 string(REPLACE "/" "-" name_slash ${name_slash})
1424 string(REPLACE "\\" "-" name_dashes ${name_slash})
1425 string(TOLOWER "${project}${name_dashes}" name_var)
1426 add_lit_target("check-${name_var}" "Running lit suite ${lit_suite}"
1427 ${lit_suite}
1428 PARAMS ${ARG_PARAMS}
1429 DEPENDS ${ARG_DEPENDS}
1430 ARGS ${ARG_ARGS}
1431 )
1432 endif()
1433 endforeach()
1434 endif()
1435endfunction()
1436
1437function(llvm_install_library_symlink name dest type)
1438 cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
1439 foreach(path ${CMAKE_MODULE_PATH})
1440 if(EXISTS ${path}/LLVMInstallSymlink.cmake)
1441 set(INSTALL_SYMLINK ${path}/LLVMInstallSymlink.cmake)
1442 break()
1443 endif()
1444 endforeach()
1445
1446 set(component ${ARG_COMPONENT})
1447 if(NOT component)
1448 set(component ${name})
1449 endif()
1450
1451 set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX})
1452 set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX})
1453
1454 set(output_dir lib${LLVM_LIBDIR_SUFFIX})
1455 if(WIN32 AND "${type}" STREQUAL "SHARED")
1456 set(output_dir bin)
1457 endif()
1458
1459 install(SCRIPT ${INSTALL_SYMLINK}
1460 CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
1461 COMPONENT ${component})
1462
Andrew Walbran16937d02019-10-22 13:54:20 +01001463 if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001464 add_llvm_install_targets(install-${name}
1465 DEPENDS ${name} ${dest} install-${dest}
1466 COMPONENT ${name})
1467 endif()
1468endfunction()
1469
1470function(llvm_install_symlink name dest)
1471 cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
1472 foreach(path ${CMAKE_MODULE_PATH})
1473 if(EXISTS ${path}/LLVMInstallSymlink.cmake)
1474 set(INSTALL_SYMLINK ${path}/LLVMInstallSymlink.cmake)
1475 break()
1476 endif()
1477 endforeach()
1478
1479 if(ARG_COMPONENT)
1480 set(component ${ARG_COMPONENT})
1481 else()
1482 if(ARG_ALWAYS_GENERATE)
1483 set(component ${dest})
1484 else()
1485 set(component ${name})
1486 endif()
1487 endif()
1488
1489 set(full_name ${name}${CMAKE_EXECUTABLE_SUFFIX})
1490 set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX})
1491
1492 install(SCRIPT ${INSTALL_SYMLINK}
1493 CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})"
1494 COMPONENT ${component})
1495
Andrew Walbran16937d02019-10-22 13:54:20 +01001496 if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001497 add_llvm_install_targets(install-${name}
1498 DEPENDS ${name} ${dest} install-${dest}
1499 COMPONENT ${name})
1500 endif()
1501endfunction()
1502
1503function(add_llvm_tool_symlink link_name target)
1504 cmake_parse_arguments(ARG "ALWAYS_GENERATE" "OUTPUT_DIR" "" ${ARGN})
1505 set(dest_binary "$<TARGET_FILE:${target}>")
1506
1507 # This got a bit gross... For multi-configuration generators the target
1508 # properties return the resolved value of the string, not the build system
1509 # expression. To reconstruct the platform-agnostic path we have to do some
1510 # magic. First we grab one of the types, and a type-specific path. Then from
1511 # the type-specific path we find the last occurrence of the type in the path,
1512 # and replace it with CMAKE_CFG_INTDIR. This allows the build step to be type
1513 # agnostic again.
1514 if(NOT ARG_OUTPUT_DIR)
1515 # If you're not overriding the OUTPUT_DIR, we can make the link relative in
1516 # the same directory.
1517 if(CMAKE_HOST_UNIX)
1518 set(dest_binary "$<TARGET_FILE_NAME:${target}>")
1519 endif()
1520 if(CMAKE_CONFIGURATION_TYPES)
1521 list(GET CMAKE_CONFIGURATION_TYPES 0 first_type)
1522 string(TOUPPER ${first_type} first_type_upper)
1523 set(first_type_suffix _${first_type_upper})
1524 endif()
1525 get_target_property(target_type ${target} TYPE)
1526 if(${target_type} STREQUAL "STATIC_LIBRARY")
1527 get_target_property(ARG_OUTPUT_DIR ${target} ARCHIVE_OUTPUT_DIRECTORY${first_type_suffix})
1528 elseif(UNIX AND ${target_type} STREQUAL "SHARED_LIBRARY")
1529 get_target_property(ARG_OUTPUT_DIR ${target} LIBRARY_OUTPUT_DIRECTORY${first_type_suffix})
1530 else()
1531 get_target_property(ARG_OUTPUT_DIR ${target} RUNTIME_OUTPUT_DIRECTORY${first_type_suffix})
1532 endif()
1533 if(CMAKE_CONFIGURATION_TYPES)
1534 string(FIND "${ARG_OUTPUT_DIR}" "/${first_type}/" type_start REVERSE)
1535 string(SUBSTRING "${ARG_OUTPUT_DIR}" 0 ${type_start} path_prefix)
1536 string(SUBSTRING "${ARG_OUTPUT_DIR}" ${type_start} -1 path_suffix)
1537 string(REPLACE "/${first_type}/" "/${CMAKE_CFG_INTDIR}/"
1538 path_suffix ${path_suffix})
1539 set(ARG_OUTPUT_DIR ${path_prefix}${path_suffix})
1540 endif()
1541 endif()
1542
1543 if(CMAKE_HOST_UNIX)
1544 set(LLVM_LINK_OR_COPY create_symlink)
1545 else()
1546 set(LLVM_LINK_OR_COPY copy)
1547 endif()
1548
1549 set(output_path "${ARG_OUTPUT_DIR}/${link_name}${CMAKE_EXECUTABLE_SUFFIX}")
1550
1551 set(target_name ${link_name})
1552 if(TARGET ${link_name})
1553 set(target_name ${link_name}-link)
1554 endif()
1555
1556
1557 if(ARG_ALWAYS_GENERATE)
1558 set_property(DIRECTORY APPEND PROPERTY
1559 ADDITIONAL_MAKE_CLEAN_FILES ${dest_binary})
1560 add_custom_command(TARGET ${target} POST_BUILD
1561 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${dest_binary}" "${output_path}")
1562 else()
1563 add_custom_command(OUTPUT ${output_path}
1564 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${dest_binary}" "${output_path}"
1565 DEPENDS ${target})
1566 add_custom_target(${target_name} ALL DEPENDS ${target} ${output_path})
1567 set_target_properties(${target_name} PROPERTIES FOLDER Tools)
1568
1569 # Make sure both the link and target are toolchain tools
1570 if (${link_name} IN_LIST LLVM_TOOLCHAIN_TOOLS AND ${target} IN_LIST LLVM_TOOLCHAIN_TOOLS)
1571 set(TOOL_IS_TOOLCHAIN ON)
1572 endif()
1573
1574 if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS)
1575 llvm_install_symlink(${link_name} ${target})
1576 endif()
1577 endif()
1578endfunction()
1579
1580function(llvm_externalize_debuginfo name)
1581 if(NOT LLVM_EXTERNALIZE_DEBUGINFO)
1582 return()
1583 endif()
1584
1585 if(NOT LLVM_EXTERNALIZE_DEBUGINFO_SKIP_STRIP)
1586 if(APPLE)
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001587 if(NOT CMAKE_STRIP)
1588 set(CMAKE_STRIP xcrun strip)
1589 endif()
1590 set(strip_command COMMAND ${CMAKE_STRIP} -Sxl $<TARGET_FILE:${name}>)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001591 else()
Andrew Scull0372a572018-11-16 15:47:06 +00001592 set(strip_command COMMAND ${CMAKE_STRIP} -g -x $<TARGET_FILE:${name}>)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001593 endif()
1594 endif()
1595
Andrew Walbran16937d02019-10-22 13:54:20 +01001596 if(LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR)
1597 if(APPLE)
1598 set(output_name "$<TARGET_FILE_NAME:${name}>.dSYM")
1599 set(output_path "-o=${LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR}/${output_name}")
1600 endif()
1601 endif()
1602
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001603 if(APPLE)
1604 if(CMAKE_CXX_FLAGS MATCHES "-flto"
1605 OR CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} MATCHES "-flto")
1606
1607 set(lto_object ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${name}-lto.o)
1608 set_property(TARGET ${name} APPEND_STRING PROPERTY
1609 LINK_FLAGS " -Wl,-object_path_lto,${lto_object}")
1610 endif()
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001611 if(NOT CMAKE_DSYMUTIL)
1612 set(CMAKE_DSYMUTIL xcrun dsymutil)
1613 endif()
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001614 add_custom_command(TARGET ${name} POST_BUILD
Andrew Walbran16937d02019-10-22 13:54:20 +01001615 COMMAND ${CMAKE_DSYMUTIL} ${output_path} $<TARGET_FILE:${name}>
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001616 ${strip_command}
1617 )
1618 else()
1619 add_custom_command(TARGET ${name} POST_BUILD
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001620 COMMAND ${CMAKE_OBJCOPY} --only-keep-debug $<TARGET_FILE:${name}> $<TARGET_FILE:${name}>.debug
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001621 ${strip_command} -R .gnu_debuglink
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001622 COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=$<TARGET_FILE:${name}>.debug $<TARGET_FILE:${name}>
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001623 )
1624 endif()
1625endfunction()
1626
Andrew Walbran16937d02019-10-22 13:54:20 +01001627# Usage: llvm_codesign(name [ENTITLEMENTS file])
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001628function(llvm_codesign name)
Andrew Walbran16937d02019-10-22 13:54:20 +01001629 cmake_parse_arguments(ARG "" "ENTITLEMENTS" "" ${ARGN})
1630
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001631 if(NOT LLVM_CODESIGNING_IDENTITY)
1632 return()
1633 endif()
1634
Andrew Walbran16937d02019-10-22 13:54:20 +01001635 if(CMAKE_GENERATOR STREQUAL "Xcode")
1636 set_target_properties(${name} PROPERTIES
1637 XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${LLVM_CODESIGNING_IDENTITY}
1638 )
1639 if(DEFINED ARG_ENTITLEMENTS)
1640 set_target_properties(${name} PROPERTIES
1641 XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS ${ARG_ENTITLEMENTS}
1642 )
1643 endif()
1644 elseif(APPLE)
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001645 if(NOT CMAKE_CODESIGN)
1646 set(CMAKE_CODESIGN xcrun codesign)
1647 endif()
1648 if(NOT CMAKE_CODESIGN_ALLOCATE)
1649 execute_process(
1650 COMMAND xcrun -f codesign_allocate
1651 OUTPUT_STRIP_TRAILING_WHITESPACE
1652 OUTPUT_VARIABLE CMAKE_CODESIGN_ALLOCATE
1653 )
1654 endif()
Andrew Walbran16937d02019-10-22 13:54:20 +01001655 if(DEFINED ARG_ENTITLEMENTS)
1656 set(pass_entitlements --entitlements ${ARG_ENTITLEMENTS})
1657 endif()
1658
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001659 add_custom_command(
1660 TARGET ${name} POST_BUILD
1661 COMMAND ${CMAKE_COMMAND} -E
1662 env CODESIGN_ALLOCATE=${CMAKE_CODESIGN_ALLOCATE}
1663 ${CMAKE_CODESIGN} -s ${LLVM_CODESIGNING_IDENTITY}
Andrew Walbran16937d02019-10-22 13:54:20 +01001664 ${pass_entitlements} $<TARGET_FILE:${name}>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001665 )
1666 endif()
1667endfunction()
1668
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001669function(llvm_setup_rpath name)
1670 if(CMAKE_INSTALL_RPATH)
1671 return()
1672 endif()
1673
1674 if(LLVM_INSTALL_PREFIX AND NOT (LLVM_INSTALL_PREFIX STREQUAL CMAKE_INSTALL_PREFIX))
1675 set(extra_libdir ${LLVM_LIBRARY_DIR})
1676 elseif(LLVM_BUILD_LIBRARY_DIR)
1677 set(extra_libdir ${LLVM_LIBRARY_DIR})
1678 endif()
1679
1680 if (APPLE)
1681 set(_install_name_dir INSTALL_NAME_DIR "@rpath")
1682 set(_install_rpath "@loader_path/../lib" ${extra_libdir})
1683 elseif(UNIX)
1684 set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
1685 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
1686 set_property(TARGET ${name} APPEND_STRING PROPERTY
1687 LINK_FLAGS " -Wl,-z,origin ")
1688 endif()
1689 if(LLVM_LINKER_IS_GNULD)
1690 # $ORIGIN is not interpreted at link time by ld.bfd
1691 set_property(TARGET ${name} APPEND_STRING PROPERTY
1692 LINK_FLAGS " -Wl,-rpath-link,${LLVM_LIBRARY_OUTPUT_INTDIR} ")
1693 endif()
1694 else()
1695 return()
1696 endif()
1697
1698 set_target_properties(${name} PROPERTIES
1699 BUILD_WITH_INSTALL_RPATH On
1700 INSTALL_RPATH "${_install_rpath}"
1701 ${_install_name_dir})
1702endfunction()
1703
1704function(setup_dependency_debugging name)
1705 if(NOT LLVM_DEPENDENCY_DEBUGGING)
1706 return()
1707 endif()
1708
1709 if("intrinsics_gen" IN_LIST ARGN)
1710 return()
1711 endif()
1712
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001713 set(deny_attributes_inc "(deny file* (literal \"${LLVM_BINARY_DIR}/include/llvm/IR/Attributes.inc\"))")
1714 set(deny_intrinsics_inc "(deny file* (literal \"${LLVM_BINARY_DIR}/include/llvm/IR/Intrinsics.inc\"))")
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001715
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001716 set(sandbox_command "sandbox-exec -p '(version 1) (allow default) ${deny_attributes_inc} ${deny_intrinsics_inc}'")
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001717 set_target_properties(${name} PROPERTIES RULE_LAUNCH_COMPILE ${sandbox_command})
1718endfunction()
1719
Andrew Walbran16937d02019-10-22 13:54:20 +01001720function(find_first_existing_vc_file path out_var)
1721 if(EXISTS "${path}/.svn")
1722 set(svn_files
1723 "${path}/.svn/wc.db" # SVN 1.7
1724 "${path}/.svn/entries" # SVN 1.6
1725 )
1726 foreach(file IN LISTS svn_files)
1727 if(EXISTS "${file}")
1728 set(${out_var} "${file}" PARENT_SCOPE)
1729 return()
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001730 endif()
Andrew Walbran16937d02019-10-22 13:54:20 +01001731 endforeach()
1732 else()
1733 find_package(Git)
1734 if(GIT_FOUND)
1735 execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --git-dir
1736 WORKING_DIRECTORY ${path}
1737 RESULT_VARIABLE git_result
1738 OUTPUT_VARIABLE git_output
1739 ERROR_QUIET)
1740 if(git_result EQUAL 0)
1741 string(STRIP "${git_output}" git_output)
1742 get_filename_component(git_dir ${git_output} ABSOLUTE BASE_DIR ${path})
1743 # Some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD
1744 if (NOT EXISTS "${git_dir}/logs/HEAD")
1745 file(WRITE "${git_dir}/logs/HEAD" "")
1746 endif()
1747 set(${out_var} "${git_dir}/logs/HEAD" PARENT_SCOPE)
1748 endif()
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001749 endif()
Andrew Walbran16937d02019-10-22 13:54:20 +01001750 endif()
1751endfunction()