1 include(LLVMProcessSources)
3 include(DetermineGCCCompatible)
5 function(llvm_update_compile_flags name)
6 get_property(sources TARGET ${name} PROPERTY SOURCES)
7 if("${sources}" MATCHES "\\.c(;|$)")
8 set(update_src_props ON)
11 # LLVM_REQUIRES_EH is an internal flag that individual targets can use to
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)
19 list(APPEND LLVM_COMPILE_FLAGS "/EHsc")
22 if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
23 list(APPEND LLVM_COMPILE_FLAGS "-fno-exceptions")
25 list(APPEND LLVM_COMPILE_DEFINITIONS _HAS_EXCEPTIONS=0)
26 list(APPEND LLVM_COMPILE_FLAGS "/EHs-c-")
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")
39 list(APPEND LLVM_COMPILE_FLAGS "/GR-")
42 list(APPEND LLVM_COMPILE_FLAGS "/GR")
46 # - LLVM_COMPILE_FLAGS is list.
47 # - PROPERTY COMPILE_FLAGS is string.
48 string(REPLACE ";" " " target_compile_flags " ${LLVM_COMPILE_FLAGS}")
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}")
59 # Update target props, since all sources are C++.
60 set_property(TARGET ${name} APPEND_STRING PROPERTY
61 COMPILE_FLAGS "${target_compile_flags}")
64 set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS ${LLVM_COMPILE_DEFINITIONS})
67 function(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}
74 COMMENT "Creating export file for ${target_name}")
75 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
76 LINK_FLAGS " -Wl,-exported_symbols_list,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"")
77 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}
93 COMMENT "Creating export file for ${target_name}")
94 if (${LLVM_LINKER_IS_SOLARISLD})
95 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
96 LINK_FLAGS " -Wl,-M,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"")
98 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
99 LINK_FLAGS " -Wl,--version-script,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"")
102 set(native_export_file "${target_name}.def")
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}
109 COMMENT "Creating export file for ${target_name}")
110 set(export_file_linker_flag "${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
112 set(export_file_linker_flag "/DEF:\"${export_file_linker_flag}\"")
114 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
115 LINK_FLAGS " ${export_file_linker_flag}")
118 add_custom_target(${target_name}_exports DEPENDS ${native_export_file})
119 set_target_properties(${target_name}_exports PROPERTIES FOLDER "Misc")
121 get_property(srcs TARGET ${target_name} PROPERTY SOURCES)
123 get_filename_component(extension ${src} EXT)
124 if(extension STREQUAL ".cpp")
125 set(first_source_file ${src})
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})
140 set_property(DIRECTORY APPEND
141 PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${native_export_file})
143 add_dependencies(${target_name} ${target_name}_exports)
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)
148 endfunction(add_llvm_symbol_exports)
152 COMMAND "${CMAKE_LINKER}" -v
153 ERROR_VARIABLE stderr
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")
160 set(LLVM_LINKER_DETECTED NO)
161 message(STATUS "Linker detection: unknown")
164 # Detect what linker we have here
165 if( LLVM_USE_LINKER )
166 set(command ${CMAKE_C_COMPILER} -fuse-ld=${LLVM_USE_LINKER} -Wl,--version)
168 separate_arguments(flags UNIX_COMMAND "${CMAKE_EXE_LINKER_FLAGS}")
169 set(command ${CMAKE_C_COMPILER} ${flags} -Wl,--version)
173 OUTPUT_VARIABLE stdout
174 ERROR_VARIABLE stderr
176 set(LLVM_LINKER_DETECTED YES)
177 if("${stdout}" MATCHES "GNU gold")
178 set(LLVM_LINKER_IS_GOLD YES)
179 message(STATUS "Linker detection: GNU Gold")
180 elseif("${stdout}" MATCHES "^LLD")
181 set(LLVM_LINKER_IS_LLD YES)
182 message(STATUS "Linker detection: LLD")
183 elseif("${stdout}" MATCHES "GNU ld")
184 set(LLVM_LINKER_IS_GNULD YES)
185 message(STATUS "Linker detection: GNU ld")
186 elseif("${stderr}" MATCHES "Solaris Link Editors" OR
187 "${stdout}" MATCHES "Solaris Link Editors")
188 set(LLVM_LINKER_IS_SOLARISLD YES)
189 message(STATUS "Linker detection: Solaris ld")
191 set(LLVM_LINKER_DETECTED NO)
192 message(STATUS "Linker detection: unknown")
196 function(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")
201 # Pass -O3 to the linker. This enabled different optimizations on different
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")
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.
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")
224 elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
225 # 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
229 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
230 LINK_FLAGS " -Wl,--gc-sections")
234 endfunction(add_link_opts)
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.
239 function(set_output_directory target)
240 cmake_parse_arguments(ARG "" "BINARY_DIR;LIBRARY_DIR" "" ${ARGN})
242 # module_dir -- corresponding to LIBRARY_OUTPUT_DIRECTORY.
243 # It affects output of add_library(MODULE).
246 set(module_dir ${ARG_BINARY_DIR})
248 set(module_dir ${ARG_LIBRARY_DIR})
250 if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
251 foreach(build_mode ${CMAKE_CONFIGURATION_TYPES})
252 string(TOUPPER "${build_mode}" CONFIG_SUFFIX)
254 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} bi ${ARG_BINARY_DIR})
255 set_target_properties(${target} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${bi})
258 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} li ${ARG_LIBRARY_DIR})
259 set_target_properties(${target} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li})
262 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} mi ${module_dir})
263 set_target_properties(${target} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${mi})
268 set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ARG_BINARY_DIR})
271 set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${ARG_LIBRARY_DIR})
274 set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${module_dir})
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.
284 function(add_windows_version_resource_file OUT_VAR)
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)
293 endif(MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
295 set(${OUT_VAR} ${sources} PARENT_SCOPE)
296 endfunction(add_windows_version_resource_file)
298 # set_windows_version_resource_properties(name resource_file...
300 # Optional major version number (defaults to LLVM_VERSION_MAJOR)
302 # Optional minor version number (defaults to LLVM_VERSION_MINOR)
303 # VERSION_PATCHLEVEL int
304 # Optional patchlevel version number (defaults to LLVM_VERSION_PATCH)
306 # Optional version string (defaults to PACKAGE_VERSION)
308 # Optional product name string (defaults to "LLVM")
310 function(set_windows_version_resource_properties name resource_file)
311 cmake_parse_arguments(ARG
313 "VERSION_MAJOR;VERSION_MINOR;VERSION_PATCHLEVEL;VERSION_STRING;PRODUCT_NAME"
317 if (NOT DEFINED ARG_VERSION_MAJOR)
318 set(ARG_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
321 if (NOT DEFINED ARG_VERSION_MINOR)
322 set(ARG_VERSION_MINOR ${LLVM_VERSION_MINOR})
325 if (NOT DEFINED ARG_VERSION_PATCHLEVEL)
326 set(ARG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH})
329 if (NOT DEFINED ARG_VERSION_STRING)
330 set(ARG_VERSION_STRING ${PACKAGE_VERSION})
333 if (NOT DEFINED ARG_PRODUCT_NAME)
334 set(ARG_PRODUCT_NAME "LLVM")
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}\"")
349 endfunction(set_windows_version_resource_properties)
351 # llvm_add_library(name sources...
353 # STATIC by default w/o BUILD_SHARED_LIBS.
354 # SHARED by default w/ BUILD_SHARED_LIBS.
356 # Also create an OBJECT library target. Default if STATIC && SHARED.
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.
364 # Corresponds to OUTPUT_NAME in target properties.
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().
372 # May specify header files for IDE generators.
374 # Should set SONAME link flags and create symlinks
376 # Suppress default RPATH settings in shared libraries.
378 # The tool (i.e. cmake target) that this plugin will link against
380 function(llvm_add_library name)
381 cmake_parse_arguments(ARG
382 "MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME;NO_INSTALL_RPATH"
383 "OUTPUT_NAME;PLUGIN_TOOL"
384 "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS"
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})
392 set(ALL_FILES ${ARG_OBJLIBS})
394 llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS})
398 if(ARG_SHARED OR ARG_STATIC)
399 message(WARNING "MODULE with SHARED|STATIC doesn't make sense.")
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.")
408 message(WARNING "PLUGIN_TOOL without MODULE doesn't make sense.")
410 if(BUILD_SHARED_LIBS AND NOT ARG_STATIC)
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
425 llvm_update_compile_flags(${obj_name})
426 set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>")
428 # Do add_dependencies(obj) later due to CMake issue 14747.
429 list(APPEND objlibs ${obj_name})
431 set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
434 if(ARG_SHARED AND ARG_STATIC)
436 set(name_static "${name}_static")
438 set(output_name OUTPUT_NAME "${ARG_OUTPUT_NAME}")
440 # DEPENDS has been appended to LLVM_COMMON_LIBS.
441 llvm_add_library(${name_static} STATIC
443 OBJLIBS ${ALL_FILES} # objlib
444 LINK_LIBS ${ARG_LINK_LIBS}
445 LINK_COMPONENTS ${ARG_LINK_COMPONENTS}
447 # FIXME: Add name_static to anywhere in TARGET ${name}'s PROPERTY.
452 add_library(${name} MODULE ${ALL_FILES})
454 add_windows_version_resource_file(ALL_FILES ${ALL_FILES})
455 add_library(${name} SHARED ${ALL_FILES})
457 add_library(${name} STATIC ${ALL_FILES})
460 if(NOT ARG_NO_INSTALL_RPATH)
461 if(ARG_MODULE OR ARG_SHARED)
462 llvm_setup_rpath(${name})
466 setup_dependency_debugging(${name} ${LLVM_COMMON_DEPENDS})
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)
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.
476 llvm_update_compile_flags(${name})
478 add_link_opts( ${name} )
480 set_target_properties(${name}
482 OUTPUT_NAME ${ARG_OUTPUT_NAME}
487 set_target_properties(${name} PROPERTIES
489 SUFFIX ${LLVM_PLUGIN_EXT}
495 set_target_properties(${name} PROPERTIES
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}
505 # Since 4.0.0, the ABI version is indicated by the major version
506 SOVERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}
507 VERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX})
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
516 set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
518 if (LLVM_EXPORTED_SYMBOL_FILE)
519 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
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})
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
535 llvm_install_library_symlink(${output_name} ${library_name} SHARED
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)
548 llvm_map_components_to_libnames(llvm_libs
549 ${ARG_LINK_COMPONENTS}
550 ${LLVM_LINK_COMPONENTS}
554 # Components have not been defined explicitly in CMake, so add the
555 # dependency information for this library as defined by LLVMBuild.
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})
564 set(libtype INTERFACE)
566 # We can use PRIVATE since SO knows its dependent libs.
570 target_link_libraries(${name} ${libtype}
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})
585 if(ARG_SHARED OR ARG_MODULE)
586 llvm_externalize_debuginfo(${name})
587 llvm_codesign(${name})
591 function(add_llvm_install_targets target)
592 cmake_parse_arguments(ARG "" "COMPONENT;PREFIX" "DEPENDS" ${ARGN})
594 set(component_option -DCMAKE_INSTALL_COMPONENT="${ARG_COMPONENT}")
597 set(prefix_option -DCMAKE_INSTALL_PREFIX="${ARG_PREFIX}")
600 add_custom_target(${target}
601 DEPENDS ${ARG_DEPENDS}
602 COMMAND "${CMAKE_COMMAND}"
605 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
607 add_custom_target(${target}-stripped
608 DEPENDS ${ARG_DEPENDS}
609 COMMAND "${CMAKE_COMMAND}"
612 -DCMAKE_INSTALL_DO_STRIP=1
613 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
617 macro(add_llvm_library name)
618 cmake_parse_arguments(ARG
619 "SHARED;BUILDTREE_ONLY;MODULE"
624 llvm_add_library(${name} MODULE ${ARG_UNPARSED_ARGUMENTS})
625 elseif( BUILD_SHARED_LIBS OR ARG_SHARED )
626 llvm_add_library(${name} SHARED ${ARG_UNPARSED_ARGUMENTS})
628 llvm_add_library(${name} ${ARG_UNPARSED_ARGUMENTS})
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
634 if (NOT ARG_BUILDTREE_ONLY AND NOT ARG_MODULE)
635 set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
638 if (ARG_MODULE AND NOT TARGET ${name})
639 # Add empty "phony" target
640 add_custom_target(${name})
641 elseif( EXCLUDE_FROM_ALL )
642 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})
646 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO" OR
647 ${name} STREQUAL "OptRemarks" OR
648 (LLVM_LINK_LLVM_DYLIB AND ${name} STREQUAL "LLVM"))
649 set(install_dir lib${LLVM_LIBDIR_SUFFIX})
650 if(ARG_MODULE OR ARG_SHARED OR BUILD_SHARED_LIBS)
651 if(WIN32 OR CYGWIN OR MINGW)
652 set(install_type RUNTIME)
655 set(install_type LIBRARY)
658 set(install_type ARCHIVE)
662 set(install_type LIBRARY)
665 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)
671 install(TARGETS ${name}
672 ${export_to_llvmexports}
673 ${install_type} DESTINATION ${install_dir}
676 if (NOT LLVM_ENABLE_IDE)
677 add_llvm_install_targets(install-${name}
682 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
685 set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
687 set_target_properties(${name} PROPERTIES FOLDER "Libraries")
689 endmacro(add_llvm_library name)
691 macro(add_llvm_executable name)
692 cmake_parse_arguments(ARG
693 "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH"
698 llvm_process_sources( ALL_FILES ${ARG_UNPARSED_ARGUMENTS} )
700 list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
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
709 llvm_update_compile_flags(${obj_name})
710 set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>")
712 set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
715 add_windows_version_resource_file(ALL_FILES ${ALL_FILES})
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")
723 if( EXCLUDE_FROM_ALL )
724 add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
726 add_executable(${name} ${ALL_FILES})
729 setup_dependency_debugging(${name} ${LLVM_COMMON_DEPENDS})
731 if(NOT ARG_NO_INSTALL_RPATH)
732 llvm_setup_rpath(${name})
735 if(DEFINED windows_resource_file)
736 set_windows_version_resource_properties(${name} ${windows_resource_file})
739 # $<TARGET_OBJECTS> doesn't require compile flags.
740 if(NOT LLVM_ENABLE_OBJLIB)
741 llvm_update_compile_flags(${name})
743 add_link_opts( ${name} )
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
749 set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
751 if (LLVM_EXPORTED_SYMBOL_FILE)
752 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
753 endif(LLVM_EXPORTED_SYMBOL_FILE)
755 if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
756 set(USE_SHARED USE_SHARED)
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 )
766 if(NOT ARG_IGNORE_EXTERNALIZE_DEBUGINFO)
767 llvm_externalize_debuginfo(${name})
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})
776 llvm_codesign(${name} ENTITLEMENTS ${ARG_ENTITLEMENTS})
777 endmacro(add_llvm_executable name)
779 function(export_executable_symbols target)
780 if (LLVM_EXPORTED_SYMBOL_FILE)
781 # The symbol file should contain the symbols we want the executable to
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})
797 get_target_property(lib_type ${lib} TYPE)
798 if("${lib_type}" STREQUAL "STATIC_LIBRARY")
799 list(APPEND static_libs ${lib})
801 list(APPEND other_libs ${lib})
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})
810 endforeach(transitive_lib)
813 set(new_libs ${newer_libs})
817 set(mangling microsoft)
819 set(mangling itanium)
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}
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.
837 set_target_properties(${target} PROPERTIES IMPORT_SUFFIX ".exe.a")
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)
845 set_property(TARGET ${target} APPEND_STRING PROPERTY
846 LINK_FLAGS " -rdynamic")
851 if(NOT LLVM_TOOLCHAIN_TOOLS)
852 set (LLVM_TOOLCHAIN_TOOLS
861 macro(add_llvm_tool name)
862 if( NOT LLVM_BUILD_TOOLS )
863 set(EXCLUDE_FROM_ALL ON)
865 add_llvm_executable(${name} ${ARGN})
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)
875 install(TARGETS ${name}
876 ${export_to_llvmexports}
877 RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR}
880 if (NOT LLVM_ENABLE_IDE)
881 add_llvm_install_targets(install-${name}
887 if( LLVM_BUILD_TOOLS )
888 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
890 set_target_properties(${name} PROPERTIES FOLDER "Tools")
891 endmacro(add_llvm_tool name)
894 macro(add_llvm_example name)
895 if( NOT LLVM_BUILD_EXAMPLES )
896 set(EXCLUDE_FROM_ALL ON)
898 add_llvm_executable(${name} ${ARGN})
899 if( LLVM_BUILD_EXAMPLES )
900 install(TARGETS ${name} RUNTIME DESTINATION examples)
902 set_target_properties(${name} PROPERTIES FOLDER "Examples")
903 endmacro(add_llvm_example name)
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.
907 macro(add_llvm_utility name)
908 if ( NOT LLVM_BUILD_UTILS )
909 set(EXCLUDE_FROM_ALL ON)
912 add_llvm_executable(${name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN})
913 set_target_properties(${name} PROPERTIES FOLDER "Utils")
914 if( LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS )
915 install (TARGETS ${name}
916 RUNTIME DESTINATION ${LLVM_UTILS_INSTALL_DIR}
918 if (NOT LLVM_ENABLE_IDE)
919 add_llvm_install_targets(install-${name}
923 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
924 elseif( LLVM_BUILD_UTILS )
925 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name})
927 endmacro(add_llvm_utility name)
929 macro(add_llvm_fuzzer name)
930 cmake_parse_arguments(ARG "" "DUMMY_MAIN" "" ${ARGN})
931 if( LLVM_LIB_FUZZING_ENGINE )
932 set(LLVM_OPTIONAL_SOURCES ${ARG_DUMMY_MAIN})
933 add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS})
934 target_link_libraries(${name} PRIVATE ${LLVM_LIB_FUZZING_ENGINE})
935 set_target_properties(${name} PROPERTIES FOLDER "Fuzzers")
936 elseif( LLVM_USE_SANITIZE_COVERAGE )
937 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer")
938 set(LLVM_OPTIONAL_SOURCES ${ARG_DUMMY_MAIN})
939 add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS})
940 set_target_properties(${name} PROPERTIES FOLDER "Fuzzers")
941 elseif( ARG_DUMMY_MAIN )
942 add_llvm_executable(${name} ${ARG_DUMMY_MAIN} ${ARG_UNPARSED_ARGUMENTS})
943 set_target_properties(${name} PROPERTIES FOLDER "Fuzzers")
947 macro(add_llvm_target target_name)
948 include_directories(BEFORE
949 ${CMAKE_CURRENT_BINARY_DIR}
950 ${CMAKE_CURRENT_SOURCE_DIR})
951 add_llvm_library(LLVM${target_name} ${ARGN})
952 set( CURRENT_LLVM_TARGET LLVM${target_name} )
953 endmacro(add_llvm_target)
955 function(canonicalize_tool_name name output)
956 string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" nameStrip ${name})
957 string(REPLACE "-" "_" nameUNDERSCORE ${nameStrip})
958 string(TOUPPER ${nameUNDERSCORE} nameUPPER)
959 set(${output} "${nameUPPER}" PARENT_SCOPE)
960 endfunction(canonicalize_tool_name)
962 # Custom add_subdirectory wrapper
963 # Takes in a project name (i.e. LLVM), the subdirectory name, and an optional
964 # path if it differs from the name.
965 function(add_llvm_subdirectory project type name)
966 set(add_llvm_external_dir "${ARGN}")
967 if("${add_llvm_external_dir}" STREQUAL "")
968 set(add_llvm_external_dir ${name})
970 canonicalize_tool_name(${name} nameUPPER)
971 set(canonical_full_name ${project}_${type}_${nameUPPER})
972 get_property(already_processed GLOBAL PROPERTY ${canonical_full_name}_PROCESSED)
973 if(already_processed)
976 set_property(GLOBAL PROPERTY ${canonical_full_name}_PROCESSED YES)
978 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}/CMakeLists.txt)
979 # Treat it as in-tree subproject.
980 option(${canonical_full_name}_BUILD
981 "Whether to build ${name} as part of ${project}" On)
982 mark_as_advanced(${project}_${type}_${name}_BUILD)
983 if(${canonical_full_name}_BUILD)
984 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir} ${add_llvm_external_dir})
987 set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR
988 "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}"
989 CACHE PATH "Path to ${name} source directory")
990 set(${canonical_full_name}_BUILD_DEFAULT ON)
991 if(NOT LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR OR NOT EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR})
992 set(${canonical_full_name}_BUILD_DEFAULT OFF)
994 if("${LLVM_EXTERNAL_${nameUPPER}_BUILD}" STREQUAL "OFF")
995 set(${canonical_full_name}_BUILD_DEFAULT OFF)
997 option(${canonical_full_name}_BUILD
998 "Whether to build ${name} as part of LLVM"
999 ${${canonical_full_name}_BUILD_DEFAULT})
1000 if (${canonical_full_name}_BUILD)
1001 if(EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR})
1002 add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir})
1003 elseif(NOT "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}" STREQUAL "")
1004 message(WARNING "Nonexistent directory for ${name}: ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}")
1010 # Add external project that may want to be built as part of llvm such as Clang,
1011 # lld, and Polly. This adds two options. One for the source directory of the
1012 # project, which defaults to ${CMAKE_CURRENT_SOURCE_DIR}/${name}. Another to
1013 # enable or disable building it with everything else.
1014 # Additional parameter can be specified as the name of directory.
1015 macro(add_llvm_external_project name)
1016 add_llvm_subdirectory(LLVM TOOL ${name} ${ARGN})
1019 macro(add_llvm_tool_subdirectory name)
1020 add_llvm_external_project(${name})
1021 endmacro(add_llvm_tool_subdirectory)
1023 function(get_project_name_from_src_var var output)
1024 string(REGEX MATCH "LLVM_EXTERNAL_(.*)_SOURCE_DIR"
1025 MACHED_TOOL "${var}")
1027 set(${output} ${CMAKE_MATCH_1} PARENT_SCOPE)
1029 set(${output} PARENT_SCOPE)
1033 function(create_subdirectory_options project type)
1034 file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
1035 foreach(dir ${sub-dirs})
1036 if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt")
1037 canonicalize_tool_name(${dir} name)
1038 option(${project}_${type}_${name}_BUILD
1039 "Whether to build ${name} as part of ${project}" On)
1040 mark_as_advanced(${project}_${type}_${name}_BUILD)
1043 endfunction(create_subdirectory_options)
1045 function(create_llvm_tool_options)
1046 create_subdirectory_options(LLVM TOOL)
1047 endfunction(create_llvm_tool_options)
1049 function(llvm_add_implicit_projects project)
1050 set(list_of_implicit_subdirs "")
1051 file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
1052 foreach(dir ${sub-dirs})
1053 if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt")
1054 canonicalize_tool_name(${dir} name)
1055 if (${project}_TOOL_${name}_BUILD)
1056 get_filename_component(fn "${dir}" NAME)
1057 list(APPEND list_of_implicit_subdirs "${fn}")
1062 foreach(external_proj ${list_of_implicit_subdirs})
1063 add_llvm_subdirectory(${project} TOOL "${external_proj}" ${ARGN})
1065 endfunction(llvm_add_implicit_projects)
1067 function(add_llvm_implicit_projects)
1068 llvm_add_implicit_projects(LLVM)
1069 endfunction(add_llvm_implicit_projects)
1071 # Generic support for adding a unittest.
1072 function(add_unittest test_suite test_name)
1073 if( NOT LLVM_BUILD_TESTS )
1074 set(EXCLUDE_FROM_ALL ON)
1077 # Our current version of gtest does not properly recognize C++11 support
1078 # with MSVC, so it falls back to tr1 / experimental classes. Since LLVM
1079 # itself requires C++11, we can safely force it on unconditionally so that
1080 # we don't have to fight with the buggy gtest check.
1081 add_definitions(-DGTEST_LANG_CXX11=1)
1082 add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
1084 include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
1085 include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include)
1086 if (NOT LLVM_ENABLE_THREADS)
1087 list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0)
1090 if (SUPPORTS_VARIADIC_MACROS_FLAG)
1091 list(APPEND LLVM_COMPILE_FLAGS "-Wno-variadic-macros")
1093 # Some parts of gtest rely on this GNU extension, don't warn on it.
1094 if(SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
1095 list(APPEND LLVM_COMPILE_FLAGS "-Wno-gnu-zero-variadic-macro-arguments")
1098 set(LLVM_REQUIRES_RTTI OFF)
1100 list(APPEND LLVM_LINK_COMPONENTS Support) # gtest needs it for raw_ostream
1101 add_llvm_executable(${test_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${ARGN})
1102 set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
1103 set_output_directory(${test_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir})
1104 # libpthreads overrides some standard library symbols, so main
1105 # executable must be linked with it in order to provide consistent
1106 # API for all shared libaries loaded by this executable.
1107 target_link_libraries(${test_name} PRIVATE gtest_main gtest ${LLVM_PTHREAD_LIB})
1109 add_dependencies(${test_suite} ${test_name})
1110 get_target_property(test_suite_folder ${test_suite} FOLDER)
1111 if (NOT ${test_suite_folder} STREQUAL "NOTFOUND")
1112 set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}")
1116 # Use for test binaries that call llvm::getInputFileDirectory(). Use of this
1118 function(add_unittest_with_input_files test_suite test_name)
1119 set(LLVM_UNITTEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
1121 ${LLVM_MAIN_SRC_DIR}/unittests/unittest.cfg.in
1122 ${CMAKE_CURRENT_BINARY_DIR}/llvm.srcdir.txt)
1124 add_unittest(${test_suite} ${test_name} ${ARGN})
1127 # Generic support for adding a benchmark.
1128 function(add_benchmark benchmark_name)
1129 if( NOT LLVM_BUILD_BENCHMARKS )
1130 set(EXCLUDE_FROM_ALL ON)
1133 add_llvm_executable(${benchmark_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${ARGN})
1134 set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
1135 set_output_directory(${benchmark_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir})
1136 set_property(TARGET ${benchmark_name} PROPERTY FOLDER "Utils")
1137 target_link_libraries(${benchmark_name} PRIVATE benchmark)
1140 function(llvm_add_go_executable binary pkgpath)
1141 cmake_parse_arguments(ARG "ALL" "" "DEPENDS;GOFLAGS" ${ARGN})
1143 if(LLVM_BINDINGS MATCHES "go")
1144 # FIXME: This should depend only on the libraries Go needs.
1145 get_property(llvmlibs GLOBAL PROPERTY LLVM_LIBS)
1146 set(binpath ${CMAKE_BINARY_DIR}/bin/${binary}${CMAKE_EXECUTABLE_SUFFIX})
1147 set(cc "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
1148 set(cxx "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
1150 get_property(include_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
1151 foreach(d ${include_dirs})
1152 set(cppflags "${cppflags} -I${d}")
1154 set(ldflags "${CMAKE_EXE_LINKER_FLAGS}")
1155 add_custom_command(OUTPUT ${binpath}
1156 COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "go=${GO_EXECUTABLE}" "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}" "packages=${LLVM_GO_PACKAGES}"
1157 ${ARG_GOFLAGS} build -o ${binpath} ${pkgpath}
1158 DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX}
1159 ${llvmlibs} ${ARG_DEPENDS}
1160 COMMENT "Building Go executable ${binary}"
1163 add_custom_target(${binary} ALL DEPENDS ${binpath})
1165 add_custom_target(${binary} DEPENDS ${binpath})
1170 # This function canonicalize the CMake variables passed by names
1171 # from CMake boolean to 0/1 suitable for passing into Python or C++,
1173 function(llvm_canonicalize_cmake_booleans)
1174 foreach(var ${ARGN})
1176 set(${var} 1 PARENT_SCOPE)
1178 set(${var} 0 PARENT_SCOPE)
1181 endfunction(llvm_canonicalize_cmake_booleans)
1183 macro(set_llvm_build_mode)
1184 # Configuration-time: See Unit/lit.site.cfg.in
1185 if (CMAKE_CFG_INTDIR STREQUAL ".")
1186 set(LLVM_BUILD_MODE ".")
1188 set(LLVM_BUILD_MODE "%(build_mode)s")
1192 # This function provides an automatic way to 'configure'-like generate a file
1193 # based on a set of common and custom variables, specifically targeting the
1194 # variables needed for the 'lit.site.cfg' files. This function bundles the
1195 # common variables that any Lit instance is likely to need, and custom
1196 # variables can be passed in.
1197 function(configure_lit_site_cfg site_in site_out)
1198 cmake_parse_arguments(ARG "" "" "MAIN_CONFIG;OUTPUT_MAPPING" ${ARGN})
1200 if ("${ARG_MAIN_CONFIG}" STREQUAL "")
1201 get_filename_component(INPUT_DIR ${site_in} DIRECTORY)
1202 set(ARG_MAIN_CONFIG "${INPUT_DIR}/lit.cfg")
1204 if ("${ARG_OUTPUT_MAPPING}" STREQUAL "")
1205 set(ARG_OUTPUT_MAPPING "${site_out}")
1208 foreach(c ${LLVM_TARGETS_TO_BUILD})
1209 set(TARGETS_BUILT "${TARGETS_BUILT} ${c}")
1211 set(TARGETS_TO_BUILD ${TARGETS_BUILT})
1213 set(SHLIBEXT "${LTDL_SHLIB_EXT}")
1215 set_llvm_build_mode()
1217 # They below might not be the build tree but provided binary tree.
1218 set(LLVM_SOURCE_DIR ${LLVM_MAIN_SRC_DIR})
1219 set(LLVM_BINARY_DIR ${LLVM_BINARY_DIR})
1220 string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" LLVM_TOOLS_DIR "${LLVM_TOOLS_BINARY_DIR}")
1221 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_LIBS_DIR "${LLVM_LIBRARY_DIR}")
1223 # SHLIBDIR points the build tree.
1224 string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" SHLIBDIR "${LLVM_SHLIB_OUTPUT_INTDIR}")
1226 set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
1227 # FIXME: "ENABLE_SHARED" doesn't make sense, since it is used just for
1228 # plugins. We may rename it.
1229 if(LLVM_ENABLE_PLUGINS)
1230 set(ENABLE_SHARED "1")
1232 set(ENABLE_SHARED "0")
1235 if(LLVM_ENABLE_ASSERTIONS AND NOT MSVC_IDE)
1236 set(ENABLE_ASSERTIONS "1")
1238 set(ENABLE_ASSERTIONS "0")
1241 set(HOST_OS ${CMAKE_SYSTEM_NAME})
1242 set(HOST_ARCH ${CMAKE_SYSTEM_PROCESSOR})
1244 set(HOST_CC "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
1245 set(HOST_CXX "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
1246 set(HOST_LDFLAGS "${CMAKE_EXE_LINKER_FLAGS}")
1248 set(LIT_SITE_CFG_IN_HEADER "## Autogenerated from ${site_in}\n## Do not edit!")
1250 # Override config_target_triple (and the env)
1251 if(LLVM_TARGET_TRIPLE_ENV)
1252 # This is expanded into the heading.
1253 string(CONCAT LIT_SITE_CFG_IN_HEADER "${LIT_SITE_CFG_IN_HEADER}\n\n"
1255 "target_env = \"${LLVM_TARGET_TRIPLE_ENV}\"\n"
1256 "config.target_triple = config.environment[target_env] = os.environ.get(target_env, \"${TARGET_TRIPLE}\")\n"
1259 # This is expanded to; config.target_triple = ""+config.target_triple+""
1260 set(TARGET_TRIPLE "\"+config.target_triple+\"")
1263 configure_file(${site_in} ${site_out} @ONLY)
1264 if (EXISTS "${ARG_MAIN_CONFIG}")
1265 set(PYTHON_STATEMENT "map_config('${ARG_MAIN_CONFIG}', '${site_out}')")
1266 get_property(LLVM_LIT_CONFIG_MAP GLOBAL PROPERTY LLVM_LIT_CONFIG_MAP)
1267 set(LLVM_LIT_CONFIG_MAP "${LLVM_LIT_CONFIG_MAP}\n${PYTHON_STATEMENT}")
1268 set_property(GLOBAL PROPERTY LLVM_LIT_CONFIG_MAP ${LLVM_LIT_CONFIG_MAP})
1272 function(dump_all_cmake_variables)
1273 get_cmake_property(_variableNames VARIABLES)
1274 foreach (_variableName ${_variableNames})
1275 message(STATUS "${_variableName}=${${_variableName}}")
1279 function(get_llvm_lit_path base_dir file_name)
1280 cmake_parse_arguments(ARG "ALLOW_EXTERNAL" "" "" ${ARGN})
1282 if (ARG_ALLOW_EXTERNAL)
1283 set(LLVM_DEFAULT_EXTERNAL_LIT "${LLVM_EXTERNAL_LIT}")
1284 set (LLVM_EXTERNAL_LIT "" CACHE STRING "Command used to spawn lit")
1285 if ("${LLVM_EXTERNAL_LIT}" STREQUAL "")
1286 set(LLVM_EXTERNAL_LIT "${LLVM_DEFAULT_EXTERNAL_LIT}")
1289 if (NOT "${LLVM_EXTERNAL_LIT}" STREQUAL "")
1290 if (EXISTS ${LLVM_EXTERNAL_LIT})
1291 get_filename_component(LIT_FILE_NAME ${LLVM_EXTERNAL_LIT} NAME)
1292 get_filename_component(LIT_BASE_DIR ${LLVM_EXTERNAL_LIT} DIRECTORY)
1293 set(${file_name} ${LIT_FILE_NAME} PARENT_SCOPE)
1294 set(${base_dir} ${LIT_BASE_DIR} PARENT_SCOPE)
1297 message(WARN "LLVM_EXTERNAL_LIT set to ${LLVM_EXTERNAL_LIT}, but the path does not exist.")
1302 set(lit_file_name "llvm-lit")
1303 if (CMAKE_HOST_WIN32 AND NOT CYGWIN)
1304 # llvm-lit needs suffix.py for multiprocess to find a main module.
1305 set(lit_file_name "${lit_file_name}.py")
1307 set(${file_name} ${lit_file_name} PARENT_SCOPE)
1309 get_property(LLVM_LIT_BASE_DIR GLOBAL PROPERTY LLVM_LIT_BASE_DIR)
1310 if (NOT "${LLVM_LIT_BASE_DIR}" STREQUAL "")
1311 set(${base_dir} ${LLVM_LIT_BASE_DIR} PARENT_SCOPE)
1314 # Allow individual projects to provide an override
1315 if (NOT "${LLVM_LIT_OUTPUT_DIR}" STREQUAL "")
1316 set(LLVM_LIT_BASE_DIR ${LLVM_LIT_OUTPUT_DIR})
1317 elseif(NOT "${LLVM_RUNTIME_OUTPUT_INTDIR}" STREQUAL "")
1318 set(LLVM_LIT_BASE_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
1320 set(LLVM_LIT_BASE_DIR "")
1323 # Cache this so we don't have to do it again and have subsequent calls
1324 # potentially disagree on the value.
1325 set_property(GLOBAL PROPERTY LLVM_LIT_BASE_DIR ${LLVM_LIT_BASE_DIR})
1326 set(${base_dir} ${LLVM_LIT_BASE_DIR} PARENT_SCOPE)
1329 # A raw function to create a lit target. This is used to implement the testuite
1330 # management functions.
1331 function(add_lit_target target comment)
1332 cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN})
1333 set(LIT_ARGS "${ARG_ARGS} ${LLVM_LIT_ARGS}")
1334 separate_arguments(LIT_ARGS)
1335 if (NOT CMAKE_CFG_INTDIR STREQUAL ".")
1336 list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR})
1339 # Get the path to the lit to *run* tests with. This can be overriden by
1340 # the user by specifying -DLLVM_EXTERNAL_LIT=<path-to-lit.py>
1347 set(LIT_COMMAND "${PYTHON_EXECUTABLE};${lit_base_dir}/${lit_file_name}")
1348 list(APPEND LIT_COMMAND ${LIT_ARGS})
1349 foreach(param ${ARG_PARAMS})
1350 list(APPEND LIT_COMMAND --param ${param})
1352 if (ARG_UNPARSED_ARGUMENTS)
1353 add_custom_target(${target}
1354 COMMAND ${LIT_COMMAND} ${ARG_UNPARSED_ARGUMENTS}
1355 COMMENT "${comment}"
1359 add_custom_target(${target}
1360 COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, no tools built.")
1361 message(STATUS "${target} does nothing.")
1365 add_dependencies(${target} ${ARG_DEPENDS})
1368 # Tests should be excluded from "Build Solution".
1369 set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON)
1372 # A function to add a set of lit test suites to be driven through 'check-*' targets.
1373 function(add_lit_testsuite target comment)
1374 cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN})
1376 # EXCLUDE_FROM_ALL excludes the test ${target} out of check-all.
1377 if(NOT EXCLUDE_FROM_ALL)
1378 # Register the testsuites, params and depends for the global check rule.
1379 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_TESTSUITES ${ARG_UNPARSED_ARGUMENTS})
1380 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_PARAMS ${ARG_PARAMS})
1381 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_DEPENDS ${ARG_DEPENDS})
1382 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_EXTRA_ARGS ${ARG_ARGS})
1385 # Produce a specific suffixed check rule.
1386 add_lit_target(${target} ${comment}
1387 ${ARG_UNPARSED_ARGUMENTS}
1388 PARAMS ${ARG_PARAMS}
1389 DEPENDS ${ARG_DEPENDS}
1394 function(add_lit_testsuites project directory)
1395 if (NOT LLVM_ENABLE_IDE)
1396 cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN})
1398 # Search recursively for test directories by assuming anything not
1399 # in a directory called Inputs contains tests.
1400 file(GLOB_RECURSE to_process LIST_DIRECTORIES true ${directory}/*)
1401 foreach(lit_suite ${to_process})
1402 if(NOT IS_DIRECTORY ${lit_suite})
1405 string(FIND ${lit_suite} Inputs is_inputs)
1406 string(FIND ${lit_suite} Output is_output)
1407 if (NOT (is_inputs EQUAL -1 AND is_output EQUAL -1))
1411 # Create a check- target for the directory.
1412 string(REPLACE ${directory} "" name_slash ${lit_suite})
1414 string(REPLACE "/" "-" name_slash ${name_slash})
1415 string(REPLACE "\\" "-" name_dashes ${name_slash})
1416 string(TOLOWER "${project}${name_dashes}" name_var)
1417 add_lit_target("check-${name_var}" "Running lit suite ${lit_suite}"
1419 PARAMS ${ARG_PARAMS}
1420 DEPENDS ${ARG_DEPENDS}
1428 function(llvm_install_library_symlink name dest type)
1429 cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
1430 foreach(path ${CMAKE_MODULE_PATH})
1431 if(EXISTS ${path}/LLVMInstallSymlink.cmake)
1432 set(INSTALL_SYMLINK ${path}/LLVMInstallSymlink.cmake)
1437 set(component ${ARG_COMPONENT})
1439 set(component ${name})
1442 set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX})
1443 set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX})
1445 set(output_dir lib${LLVM_LIBDIR_SUFFIX})
1446 if(WIN32 AND "${type}" STREQUAL "SHARED")
1450 install(SCRIPT ${INSTALL_SYMLINK}
1451 CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
1452 COMPONENT ${component})
1454 if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)
1455 add_llvm_install_targets(install-${name}
1456 DEPENDS ${name} ${dest} install-${dest}
1461 function(llvm_install_symlink name dest)
1462 cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
1463 foreach(path ${CMAKE_MODULE_PATH})
1464 if(EXISTS ${path}/LLVMInstallSymlink.cmake)
1465 set(INSTALL_SYMLINK ${path}/LLVMInstallSymlink.cmake)
1471 set(component ${ARG_COMPONENT})
1473 if(ARG_ALWAYS_GENERATE)
1474 set(component ${dest})
1476 set(component ${name})
1480 set(full_name ${name}${CMAKE_EXECUTABLE_SUFFIX})
1481 set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX})
1483 install(SCRIPT ${INSTALL_SYMLINK}
1484 CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})"
1485 COMPONENT ${component})
1487 if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)
1488 add_llvm_install_targets(install-${name}
1489 DEPENDS ${name} ${dest} install-${dest}
1494 function(add_llvm_tool_symlink link_name target)
1495 cmake_parse_arguments(ARG "ALWAYS_GENERATE" "OUTPUT_DIR" "" ${ARGN})
1496 set(dest_binary "$<TARGET_FILE:${target}>")
1498 # This got a bit gross... For multi-configuration generators the target
1499 # properties return the resolved value of the string, not the build system
1500 # expression. To reconstruct the platform-agnostic path we have to do some
1501 # magic. First we grab one of the types, and a type-specific path. Then from
1502 # the type-specific path we find the last occurrence of the type in the path,
1503 # and replace it with CMAKE_CFG_INTDIR. This allows the build step to be type
1505 if(NOT ARG_OUTPUT_DIR)
1506 # If you're not overriding the OUTPUT_DIR, we can make the link relative in
1507 # the same directory.
1509 set(dest_binary "$<TARGET_FILE_NAME:${target}>")
1511 if(CMAKE_CONFIGURATION_TYPES)
1512 list(GET CMAKE_CONFIGURATION_TYPES 0 first_type)
1513 string(TOUPPER ${first_type} first_type_upper)
1514 set(first_type_suffix _${first_type_upper})
1516 get_target_property(target_type ${target} TYPE)
1517 if(${target_type} STREQUAL "STATIC_LIBRARY")
1518 get_target_property(ARG_OUTPUT_DIR ${target} ARCHIVE_OUTPUT_DIRECTORY${first_type_suffix})
1519 elseif(UNIX AND ${target_type} STREQUAL "SHARED_LIBRARY")
1520 get_target_property(ARG_OUTPUT_DIR ${target} LIBRARY_OUTPUT_DIRECTORY${first_type_suffix})
1522 get_target_property(ARG_OUTPUT_DIR ${target} RUNTIME_OUTPUT_DIRECTORY${first_type_suffix})
1524 if(CMAKE_CONFIGURATION_TYPES)
1525 string(FIND "${ARG_OUTPUT_DIR}" "/${first_type}/" type_start REVERSE)
1526 string(SUBSTRING "${ARG_OUTPUT_DIR}" 0 ${type_start} path_prefix)
1527 string(SUBSTRING "${ARG_OUTPUT_DIR}" ${type_start} -1 path_suffix)
1528 string(REPLACE "/${first_type}/" "/${CMAKE_CFG_INTDIR}/"
1529 path_suffix ${path_suffix})
1530 set(ARG_OUTPUT_DIR ${path_prefix}${path_suffix})
1535 set(LLVM_LINK_OR_COPY create_symlink)
1537 set(LLVM_LINK_OR_COPY copy)
1540 set(output_path "${ARG_OUTPUT_DIR}/${link_name}${CMAKE_EXECUTABLE_SUFFIX}")
1542 set(target_name ${link_name})
1543 if(TARGET ${link_name})
1544 set(target_name ${link_name}-link)
1548 if(ARG_ALWAYS_GENERATE)
1549 set_property(DIRECTORY APPEND PROPERTY
1550 ADDITIONAL_MAKE_CLEAN_FILES ${dest_binary})
1551 add_custom_command(TARGET ${target} POST_BUILD
1552 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${dest_binary}" "${output_path}")
1554 add_custom_command(OUTPUT ${output_path}
1555 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${dest_binary}" "${output_path}"
1557 add_custom_target(${target_name} ALL DEPENDS ${target} ${output_path})
1558 set_target_properties(${target_name} PROPERTIES FOLDER Tools)
1560 # Make sure both the link and target are toolchain tools
1561 if (${link_name} IN_LIST LLVM_TOOLCHAIN_TOOLS AND ${target} IN_LIST LLVM_TOOLCHAIN_TOOLS)
1562 set(TOOL_IS_TOOLCHAIN ON)
1565 if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS)
1566 llvm_install_symlink(${link_name} ${target})
1571 function(llvm_externalize_debuginfo name)
1572 if(NOT LLVM_EXTERNALIZE_DEBUGINFO)
1576 if(NOT LLVM_EXTERNALIZE_DEBUGINFO_SKIP_STRIP)
1579 set(CMAKE_STRIP xcrun strip)
1581 set(strip_command COMMAND ${CMAKE_STRIP} -Sxl $<TARGET_FILE:${name}>)
1583 set(strip_command COMMAND ${CMAKE_STRIP} -g -x $<TARGET_FILE:${name}>)
1587 if(LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR)
1589 set(output_name "$<TARGET_FILE_NAME:${name}>.dSYM")
1590 set(output_path "-o=${LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR}/${output_name}")
1595 if(CMAKE_CXX_FLAGS MATCHES "-flto"
1596 OR CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} MATCHES "-flto")
1598 set(lto_object ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${name}-lto.o)
1599 set_property(TARGET ${name} APPEND_STRING PROPERTY
1600 LINK_FLAGS " -Wl,-object_path_lto,${lto_object}")
1602 if(NOT CMAKE_DSYMUTIL)
1603 set(CMAKE_DSYMUTIL xcrun dsymutil)
1605 add_custom_command(TARGET ${name} POST_BUILD
1606 COMMAND ${CMAKE_DSYMUTIL} ${output_path} $<TARGET_FILE:${name}>
1610 add_custom_command(TARGET ${name} POST_BUILD
1611 COMMAND ${CMAKE_OBJCOPY} --only-keep-debug $<TARGET_FILE:${name}> $<TARGET_FILE:${name}>.debug
1612 ${strip_command} -R .gnu_debuglink
1613 COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=$<TARGET_FILE:${name}>.debug $<TARGET_FILE:${name}>
1618 # Usage: llvm_codesign(name [ENTITLEMENTS file])
1619 function(llvm_codesign name)
1620 cmake_parse_arguments(ARG "" "ENTITLEMENTS" "" ${ARGN})
1622 if(NOT LLVM_CODESIGNING_IDENTITY)
1626 if(CMAKE_GENERATOR STREQUAL "Xcode")
1627 set_target_properties(${name} PROPERTIES
1628 XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${LLVM_CODESIGNING_IDENTITY}
1630 if(DEFINED ARG_ENTITLEMENTS)
1631 set_target_properties(${name} PROPERTIES
1632 XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS ${ARG_ENTITLEMENTS}
1636 if(NOT CMAKE_CODESIGN)
1637 set(CMAKE_CODESIGN xcrun codesign)
1639 if(NOT CMAKE_CODESIGN_ALLOCATE)
1641 COMMAND xcrun -f codesign_allocate
1642 OUTPUT_STRIP_TRAILING_WHITESPACE
1643 OUTPUT_VARIABLE CMAKE_CODESIGN_ALLOCATE
1646 if(DEFINED ARG_ENTITLEMENTS)
1647 set(pass_entitlements --entitlements ${ARG_ENTITLEMENTS})
1651 TARGET ${name} POST_BUILD
1652 COMMAND ${CMAKE_COMMAND} -E
1653 env CODESIGN_ALLOCATE=${CMAKE_CODESIGN_ALLOCATE}
1654 ${CMAKE_CODESIGN} -s ${LLVM_CODESIGNING_IDENTITY}
1655 ${pass_entitlements} $<TARGET_FILE:${name}>
1660 function(llvm_setup_rpath name)
1661 if(CMAKE_INSTALL_RPATH)
1665 if(LLVM_INSTALL_PREFIX AND NOT (LLVM_INSTALL_PREFIX STREQUAL CMAKE_INSTALL_PREFIX))
1666 set(extra_libdir ${LLVM_LIBRARY_DIR})
1667 elseif(LLVM_BUILD_LIBRARY_DIR)
1668 set(extra_libdir ${LLVM_LIBRARY_DIR})
1672 set(_install_name_dir INSTALL_NAME_DIR "@rpath")
1673 set(_install_rpath "@loader_path/../lib" ${extra_libdir})
1675 set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
1676 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
1677 set_property(TARGET ${name} APPEND_STRING PROPERTY
1678 LINK_FLAGS " -Wl,-z,origin ")
1680 if(LLVM_LINKER_IS_GNULD)
1681 # $ORIGIN is not interpreted at link time by ld.bfd
1682 set_property(TARGET ${name} APPEND_STRING PROPERTY
1683 LINK_FLAGS " -Wl,-rpath-link,${LLVM_LIBRARY_OUTPUT_INTDIR} ")
1689 set_target_properties(${name} PROPERTIES
1690 BUILD_WITH_INSTALL_RPATH On
1691 INSTALL_RPATH "${_install_rpath}"
1692 ${_install_name_dir})
1695 function(setup_dependency_debugging name)
1696 if(NOT LLVM_DEPENDENCY_DEBUGGING)
1700 if("intrinsics_gen" IN_LIST ARGN)
1704 set(deny_attributes_inc "(deny file* (literal \"${LLVM_BINARY_DIR}/include/llvm/IR/Attributes.inc\"))")
1705 set(deny_intrinsics_inc "(deny file* (literal \"${LLVM_BINARY_DIR}/include/llvm/IR/Intrinsics.inc\"))")
1707 set(sandbox_command "sandbox-exec -p '(version 1) (allow default) ${deny_attributes_inc} ${deny_intrinsics_inc}'")
1708 set_target_properties(${name} PROPERTIES RULE_LAUNCH_COMPILE ${sandbox_command})
1711 # Figure out if we can track VC revisions.
1712 function(find_first_existing_file out_var)
1713 foreach(file ${ARGN})
1714 if(EXISTS "${file}")
1715 set(${out_var} "${file}" PARENT_SCOPE)
1721 macro(find_first_existing_vc_file out_var path)
1722 find_program(git_executable NAMES git git.exe git.cmd)
1723 # Run from a subdirectory to force git to print an absolute path.
1724 execute_process(COMMAND ${git_executable} rev-parse --git-dir
1725 WORKING_DIRECTORY ${path}/cmake
1726 RESULT_VARIABLE git_result
1727 OUTPUT_VARIABLE git_dir
1729 if(git_result EQUAL 0)
1730 string(STRIP "${git_dir}" git_dir)
1731 set(${out_var} "${git_dir}/logs/HEAD")
1732 # some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD
1733 if (NOT EXISTS "${git_dir}/logs/HEAD")
1734 file(WRITE "${git_dir}/logs/HEAD" "")
1737 find_first_existing_file(${out_var}
1738 "${path}/.svn/wc.db" # SVN 1.7
1739 "${path}/.svn/entries" # SVN 1.6