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 if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
20 list(APPEND LLVM_COMPILE_FLAGS "-fno-exceptions")
22 list(APPEND LLVM_COMPILE_DEFINITIONS _HAS_EXCEPTIONS=0)
23 list(APPEND LLVM_COMPILE_FLAGS "/EHs-c-")
27 # LLVM_REQUIRES_RTTI is an internal flag that individual
28 # targets can use to force RTTI
29 set(LLVM_CONFIG_HAS_RTTI YES CACHE INTERNAL "")
30 if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI))
31 set(LLVM_CONFIG_HAS_RTTI NO CACHE INTERNAL "")
32 list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0)
33 if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
34 list(APPEND LLVM_COMPILE_FLAGS "-fno-rtti")
36 list(APPEND LLVM_COMPILE_FLAGS "/GR-")
41 # - LLVM_COMPILE_FLAGS is list.
42 # - PROPERTY COMPILE_FLAGS is string.
43 string(REPLACE ";" " " target_compile_flags " ${LLVM_COMPILE_FLAGS}")
46 foreach(fn ${sources})
47 get_filename_component(suf ${fn} EXT)
48 if("${suf}" STREQUAL ".cpp")
49 set_property(SOURCE ${fn} APPEND_STRING PROPERTY
50 COMPILE_FLAGS "${target_compile_flags}")
54 # Update target props, since all sources are C++.
55 set_property(TARGET ${name} APPEND_STRING PROPERTY
56 COMPILE_FLAGS "${target_compile_flags}")
59 set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS ${LLVM_COMPILE_DEFINITIONS})
62 function(add_llvm_symbol_exports target_name export_file)
63 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
64 set(native_export_file "${target_name}.exports")
65 add_custom_command(OUTPUT ${native_export_file}
66 COMMAND sed -e "s/^/_/" < ${export_file} > ${native_export_file}
67 DEPENDS ${export_file}
69 COMMENT "Creating export file for ${target_name}")
70 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
71 LINK_FLAGS " -Wl,-exported_symbols_list,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
72 elseif(LLVM_HAVE_LINK_VERSION_SCRIPT)
73 # Gold and BFD ld require a version script rather than a plain list.
74 set(native_export_file "${target_name}.exports")
75 # FIXME: Don't write the "local:" line on OpenBSD.
76 add_custom_command(OUTPUT ${native_export_file}
77 COMMAND echo "{" > ${native_export_file}
78 COMMAND grep -q "[[:alnum:]]" ${export_file} && echo " global:" >> ${native_export_file} || :
79 COMMAND sed -e "s/$/;/" -e "s/^/ /" < ${export_file} >> ${native_export_file}
80 COMMAND echo " local: *;" >> ${native_export_file}
81 COMMAND echo "};" >> ${native_export_file}
82 DEPENDS ${export_file}
84 COMMENT "Creating export file for ${target_name}")
85 if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
86 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
87 LINK_FLAGS " -Wl,-M,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
89 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
90 LINK_FLAGS " -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
93 set(native_export_file "${target_name}.def")
95 add_custom_command(OUTPUT ${native_export_file}
96 COMMAND ${PYTHON_EXECUTABLE} -c "import sys;print(''.join(['EXPORTS\\n']+sys.stdin.readlines(),))"
97 < ${export_file} > ${native_export_file}
98 DEPENDS ${export_file}
100 COMMENT "Creating export file for ${target_name}")
101 set(export_file_linker_flag "${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
103 set(export_file_linker_flag "/DEF:\"${export_file_linker_flag}\"")
105 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
106 LINK_FLAGS " ${export_file_linker_flag}")
109 add_custom_target(${target_name}_exports DEPENDS ${native_export_file})
110 set_target_properties(${target_name}_exports PROPERTIES FOLDER "Misc")
112 get_property(srcs TARGET ${target_name} PROPERTY SOURCES)
114 get_filename_component(extension ${src} EXT)
115 if(extension STREQUAL ".cpp")
116 set(first_source_file ${src})
121 # Force re-linking when the exports file changes. Actually, it
122 # forces recompilation of the source file. The LINK_DEPENDS target
123 # property only works for makefile-based generators.
124 # FIXME: This is not safe because this will create the same target
125 # ${native_export_file} in several different file:
126 # - One where we emitted ${target_name}_exports
127 # - One where we emitted the build command for the following object.
128 # set_property(SOURCE ${first_source_file} APPEND PROPERTY
129 # OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${native_export_file})
131 set_property(DIRECTORY APPEND
132 PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${native_export_file})
134 add_dependencies(${target_name} ${target_name}_exports)
136 # Add dependency to *_exports later -- CMake issue 14747
137 list(APPEND LLVM_COMMON_DEPENDS ${target_name}_exports)
138 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)
139 endfunction(add_llvm_symbol_exports)
141 if(NOT WIN32 AND NOT APPLE)
143 COMMAND ${CMAKE_C_COMPILER} -Wl,--version
144 OUTPUT_VARIABLE stdout
147 if("${stdout}" MATCHES "GNU gold")
148 set(LLVM_LINKER_IS_GOLD ON)
152 function(add_link_opts target_name)
153 # Don't use linker optimizations in debug builds since it slows down the
154 # linker in a context where the optimizations are not important.
155 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
157 # Pass -O3 to the linker. This enabled different optimizations on different
159 if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|SunOS" OR WIN32))
160 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
161 LINK_FLAGS " -Wl,-O3")
164 if(LLVM_LINKER_IS_GOLD)
165 # With gold gc-sections is always safe.
166 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
167 LINK_FLAGS " -Wl,--gc-sections")
168 # Note that there is a bug with -Wl,--icf=safe so it is not safe
169 # to enable. See https://sourceware.org/bugzilla/show_bug.cgi?id=17704.
172 if(NOT LLVM_NO_DEAD_STRIP)
173 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
174 # ld64's implementation of -dead_strip breaks tools that use plugins.
175 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
176 LINK_FLAGS " -Wl,-dead_strip")
177 elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
178 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
179 LINK_FLAGS " -Wl,-z -Wl,discard-unused=sections")
180 elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD)
181 # Object files are compiled with -ffunction-data-sections.
182 # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks
183 # tools that use plugins. Always pass --gc-sections once we require
185 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
186 LINK_FLAGS " -Wl,--gc-sections")
190 endfunction(add_link_opts)
192 # Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}.
193 # Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more,
194 # or a certain builder, for eaxample, msbuild.exe, would be confused.
195 function(set_output_directory target)
196 cmake_parse_arguments(ARG "" "BINARY_DIR;LIBRARY_DIR" "" ${ARGN})
198 # module_dir -- corresponding to LIBRARY_OUTPUT_DIRECTORY.
199 # It affects output of add_library(MODULE).
202 set(module_dir ${ARG_BINARY_DIR})
204 set(module_dir ${ARG_LIBRARY_DIR})
206 if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
207 foreach(build_mode ${CMAKE_CONFIGURATION_TYPES})
208 string(TOUPPER "${build_mode}" CONFIG_SUFFIX)
210 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} bi ${ARG_BINARY_DIR})
211 set_target_properties(${target} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${bi})
214 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} li ${ARG_LIBRARY_DIR})
215 set_target_properties(${target} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li})
218 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} mi ${module_dir})
219 set_target_properties(${target} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${mi})
224 set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ARG_BINARY_DIR})
227 set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${ARG_LIBRARY_DIR})
230 set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${module_dir})
235 # If on Windows and building with MSVC, add the resource script containing the
236 # VERSIONINFO data to the project. This embeds version resource information
237 # into the output .exe or .dll.
238 # TODO: Enable for MinGW Windows builds too.
240 function(add_windows_version_resource_file OUT_VAR)
243 set(resource_file ${LLVM_SOURCE_DIR}/resources/windows_version_resource.rc)
244 if(EXISTS ${resource_file})
245 set(sources ${sources} ${resource_file})
246 source_group("Resource Files" ${resource_file})
247 set(windows_resource_file ${resource_file} PARENT_SCOPE)
251 set(${OUT_VAR} ${sources} PARENT_SCOPE)
252 endfunction(add_windows_version_resource_file)
254 # set_windows_version_resource_properties(name resource_file...
256 # Optional major version number (defaults to LLVM_VERSION_MAJOR)
258 # Optional minor version number (defaults to LLVM_VERSION_MINOR)
259 # VERSION_PATCHLEVEL int
260 # Optional patchlevel version number (defaults to LLVM_VERSION_PATCH)
262 # Optional version string (defaults to PACKAGE_VERSION)
264 # Optional product name string (defaults to "LLVM")
266 function(set_windows_version_resource_properties name resource_file)
267 cmake_parse_arguments(ARG
269 "VERSION_MAJOR;VERSION_MINOR;VERSION_PATCHLEVEL;VERSION_STRING;PRODUCT_NAME"
273 if (NOT DEFINED ARG_VERSION_MAJOR)
274 set(ARG_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
277 if (NOT DEFINED ARG_VERSION_MINOR)
278 set(ARG_VERSION_MINOR ${LLVM_VERSION_MINOR})
281 if (NOT DEFINED ARG_VERSION_PATCHLEVEL)
282 set(ARG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH})
285 if (NOT DEFINED ARG_VERSION_STRING)
286 set(ARG_VERSION_STRING ${PACKAGE_VERSION})
289 if (NOT DEFINED ARG_PRODUCT_NAME)
290 set(ARG_PRODUCT_NAME "LLVM")
293 set_property(SOURCE ${resource_file}
294 PROPERTY COMPILE_FLAGS /nologo)
295 set_property(SOURCE ${resource_file}
296 PROPERTY COMPILE_DEFINITIONS
297 "RC_VERSION_FIELD_1=${ARG_VERSION_MAJOR}"
298 "RC_VERSION_FIELD_2=${ARG_VERSION_MINOR}"
299 "RC_VERSION_FIELD_3=${ARG_VERSION_PATCHLEVEL}"
300 "RC_VERSION_FIELD_4=0"
301 "RC_FILE_VERSION=\"${ARG_VERSION_STRING}\""
302 "RC_INTERNAL_NAME=\"${name}\""
303 "RC_PRODUCT_NAME=\"${ARG_PRODUCT_NAME}\""
304 "RC_PRODUCT_VERSION=\"${ARG_VERSION_STRING}\"")
305 endfunction(set_windows_version_resource_properties)
307 # llvm_add_library(name sources...
309 # STATIC by default w/o BUILD_SHARED_LIBS.
310 # SHARED by default w/ BUILD_SHARED_LIBS.
312 # Also create an OBJECT library target. Default if STATIC && SHARED.
314 # Target ${name} might not be created on unsupported platforms.
315 # Check with "if(TARGET ${name})".
316 # DISABLE_LLVM_LINK_LLVM_DYLIB
317 # Do not link this library to libLLVM, even if
318 # LLVM_LINK_LLVM_DYLIB is enabled.
320 # Corresponds to OUTPUT_NAME in target properties.
322 # Same semantics as add_dependencies().
323 # LINK_COMPONENTS components...
324 # Same as the variable LLVM_LINK_COMPONENTS.
325 # LINK_LIBS lib_targets...
326 # Same semantics as target_link_libraries().
328 # May specify header files for IDE generators.
330 # Should set SONAME link flags and create symlinks
332 function(llvm_add_library name)
333 cmake_parse_arguments(ARG
334 "MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME"
336 "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS"
338 list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
339 if(ARG_ADDITIONAL_HEADERS)
340 # Pass through ADDITIONAL_HEADERS.
341 set(ARG_ADDITIONAL_HEADERS ADDITIONAL_HEADERS ${ARG_ADDITIONAL_HEADERS})
344 set(ALL_FILES ${ARG_OBJLIBS})
346 llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS})
350 if(ARG_SHARED OR ARG_STATIC)
351 message(WARNING "MODULE with SHARED|STATIC doesn't make sense.")
353 if(NOT LLVM_ENABLE_PLUGINS)
354 message(STATUS "${name} ignored -- Loadable modules not supported on this platform.")
358 if(BUILD_SHARED_LIBS AND NOT ARG_STATIC)
367 if((ARG_SHARED AND ARG_STATIC) OR ARG_OBJECT)
368 # Generate an obj library for both targets.
369 set(obj_name "obj.${name}")
370 add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL
373 llvm_update_compile_flags(${obj_name})
374 set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>")
376 # Do add_dependencies(obj) later due to CMake issue 14747.
377 list(APPEND objlibs ${obj_name})
379 set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
382 if(ARG_SHARED AND ARG_STATIC)
384 set(name_static "${name}_static")
386 set(output_name OUTPUT_NAME "${ARG_OUTPUT_NAME}")
388 # DEPENDS has been appended to LLVM_COMMON_LIBS.
389 llvm_add_library(${name_static} STATIC
391 OBJLIBS ${ALL_FILES} # objlib
392 LINK_LIBS ${ARG_LINK_LIBS}
393 LINK_COMPONENTS ${ARG_LINK_COMPONENTS}
395 # FIXME: Add name_static to anywhere in TARGET ${name}'s PROPERTY.
400 add_library(${name} MODULE ${ALL_FILES})
402 add_windows_version_resource_file(ALL_FILES ${ALL_FILES})
403 add_library(${name} SHARED ${ALL_FILES})
405 add_library(${name} STATIC ${ALL_FILES})
408 if(DEFINED windows_resource_file)
409 set_windows_version_resource_properties(${name} ${windows_resource_file})
410 set(windows_resource_file ${windows_resource_file} PARENT_SCOPE)
413 set_output_directory(${name} BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR} LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
414 # $<TARGET_OBJECTS> doesn't require compile flags.
416 llvm_update_compile_flags(${name})
418 add_link_opts( ${name} )
420 set_target_properties(${name}
422 OUTPUT_NAME ${ARG_OUTPUT_NAME}
427 set_target_properties(${name} PROPERTIES
429 SUFFIX ${LLVM_PLUGIN_EXT}
435 set_target_properties(${name} PROPERTIES
441 if(ARG_MODULE OR ARG_SHARED)
442 # Do not add -Dname_EXPORTS to the command-line when building files in this
443 # target. Doing so is actively harmful for the modules build because it
444 # creates extra module variants, and not useful because we don't use these
446 set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
448 if (LLVM_EXPORTED_SYMBOL_FILE)
449 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
453 if(ARG_SHARED AND UNIX)
454 if(NOT APPLE AND ARG_SONAME)
455 get_target_property(output_name ${name} OUTPUT_NAME)
456 if(${output_name} STREQUAL "output_name-NOTFOUND")
457 set(output_name ${name})
459 set(library_name ${output_name}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX})
460 set(api_name ${output_name}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX})
461 set_target_properties(${name} PROPERTIES OUTPUT_NAME ${library_name})
462 llvm_install_library_symlink(${api_name} ${library_name} SHARED
465 llvm_install_library_symlink(${output_name} ${library_name} SHARED
471 if (DEFINED LLVM_LINK_COMPONENTS OR DEFINED ARG_LINK_COMPONENTS)
472 if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
475 llvm_map_components_to_libnames(llvm_libs
476 ${ARG_LINK_COMPONENTS}
477 ${LLVM_LINK_COMPONENTS}
481 # Components have not been defined explicitly in CMake, so add the
482 # dependency information for this library as defined by LLVMBuild.
484 # It would be nice to verify that we have the dependencies for this library
485 # name, but using get_property(... SET) doesn't suffice to determine if a
486 # property has been set to an empty value.
487 get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
490 if(CMAKE_VERSION VERSION_LESS 2.8.12)
491 # Link libs w/o keywords, assuming PUBLIC.
492 target_link_libraries(${name}
498 target_link_libraries(${name} INTERFACE
504 # We can use PRIVATE since SO knows its dependent libs.
505 target_link_libraries(${name} PRIVATE
512 if(LLVM_COMMON_DEPENDS)
513 add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
514 # Add dependencies also to objlibs.
515 # CMake issue 14747 -- add_dependencies() might be ignored to objlib's user.
516 foreach(objlib ${objlibs})
517 add_dependencies(${objlib} ${LLVM_COMMON_DEPENDS})
521 if(ARG_SHARED OR ARG_MODULE)
522 llvm_externalize_debuginfo(${name})
526 macro(add_llvm_library name)
527 cmake_parse_arguments(ARG
532 if( BUILD_SHARED_LIBS )
533 llvm_add_library(${name} SHARED ${ARGN})
535 llvm_add_library(${name} ${ARGN})
537 # The gtest libraries should not be installed or exported as a target
538 if ("${name}" STREQUAL gtest OR "${name}" STREQUAL gtest_main)
542 set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
545 if( EXCLUDE_FROM_ALL )
546 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
547 elseif(NOT _is_gtest)
548 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO")
549 set(install_dir lib${LLVM_LIBDIR_SUFFIX})
550 if(ARG_SHARED OR BUILD_SHARED_LIBS)
551 if(WIN32 OR CYGWIN OR MINGW)
552 set(install_type RUNTIME)
555 set(install_type LIBRARY)
558 set(install_type ARCHIVE)
561 install(TARGETS ${name}
563 ${install_type} DESTINATION ${install_dir}
566 if (NOT CMAKE_CONFIGURATION_TYPES)
567 add_custom_target(install-${name}
569 COMMAND "${CMAKE_COMMAND}"
570 -DCMAKE_INSTALL_COMPONENT=${name}
571 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
574 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
576 set_target_properties(${name} PROPERTIES FOLDER "Libraries")
577 endmacro(add_llvm_library name)
579 macro(add_llvm_loadable_module name)
580 llvm_add_library(${name} MODULE ${ARGN})
581 if(NOT TARGET ${name})
582 # Add empty "phony" target
583 add_custom_target(${name})
585 if( EXCLUDE_FROM_ALL )
586 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
588 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
593 set(dlldir "lib${LLVM_LIBDIR_SUFFIX}")
595 install(TARGETS ${name}
597 LIBRARY DESTINATION ${dlldir}
598 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
600 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
604 set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
605 endmacro(add_llvm_loadable_module name)
608 macro(add_llvm_executable name)
609 cmake_parse_arguments(ARG "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO" "" "" ${ARGN})
610 llvm_process_sources( ALL_FILES ${ARG_UNPARSED_ARGUMENTS} )
613 if(LLVM_ENABLE_OBJLIB)
614 # Generate an obj library for both targets.
615 set(obj_name "obj.${name}")
616 add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL
619 llvm_update_compile_flags(${obj_name})
620 set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>")
622 set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
625 add_windows_version_resource_file(ALL_FILES ${ALL_FILES})
628 # Note: the dummy.cpp source file provides no definitions. However,
629 # it forces Xcode to properly link the static library.
630 list(APPEND ALL_FILES "${LLVM_MAIN_SRC_DIR}/cmake/dummy.cpp")
633 if( EXCLUDE_FROM_ALL )
634 add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
636 add_executable(${name} ${ALL_FILES})
639 if(DEFINED windows_resource_file)
640 set_windows_version_resource_properties(${name} ${windows_resource_file})
643 # $<TARGET_OBJECTS> doesn't require compile flags.
644 if(NOT LLVM_ENABLE_OBJLIB)
645 llvm_update_compile_flags(${name})
647 add_link_opts( ${name} )
649 # Do not add -Dname_EXPORTS to the command-line when building files in this
650 # target. Doing so is actively harmful for the modules build because it
651 # creates extra module variants, and not useful because we don't use these
653 set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
655 if (LLVM_EXPORTED_SYMBOL_FILE)
656 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
657 endif(LLVM_EXPORTED_SYMBOL_FILE)
659 if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
660 set(USE_SHARED USE_SHARED)
663 set(EXCLUDE_FROM_ALL OFF)
664 set_output_directory(${name} BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR} LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
665 llvm_config( ${name} ${USE_SHARED} ${LLVM_LINK_COMPONENTS} )
666 if( LLVM_COMMON_DEPENDS )
667 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
668 endif( LLVM_COMMON_DEPENDS )
670 if(NOT ARG_IGNORE_EXTERNALIZE_DEBUGINFO)
671 llvm_externalize_debuginfo(${name})
673 endmacro(add_llvm_executable name)
675 function(export_executable_symbols target)
676 if (NOT MSVC) # MSVC's linker doesn't support exporting all symbols.
677 set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
679 set_property(TARGET ${target} APPEND_STRING PROPERTY
680 LINK_FLAGS " -rdynamic")
685 if(NOT LLVM_TOOLCHAIN_TOOLS)
686 set (LLVM_TOOLCHAIN_TOOLS
694 macro(add_llvm_tool name)
695 if( NOT LLVM_BUILD_TOOLS )
696 set(EXCLUDE_FROM_ALL ON)
698 add_llvm_executable(${name} ${ARGN})
700 list(FIND LLVM_TOOLCHAIN_TOOLS ${name} LLVM_IS_${name}_TOOLCHAIN_TOOL)
701 if (LLVM_IS_${name}_TOOLCHAIN_TOOL GREATER -1 OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
702 if( LLVM_BUILD_TOOLS )
703 install(TARGETS ${name}
705 RUNTIME DESTINATION bin
708 if (NOT CMAKE_CONFIGURATION_TYPES)
709 add_custom_target(install-${name}
711 COMMAND "${CMAKE_COMMAND}"
712 -DCMAKE_INSTALL_COMPONENT=${name}
713 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
717 if( LLVM_BUILD_TOOLS )
718 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
720 set_target_properties(${name} PROPERTIES FOLDER "Tools")
721 endmacro(add_llvm_tool name)
724 macro(add_llvm_example name)
725 if( NOT LLVM_BUILD_EXAMPLES )
726 set(EXCLUDE_FROM_ALL ON)
728 add_llvm_executable(${name} ${ARGN})
729 if( LLVM_BUILD_EXAMPLES )
730 install(TARGETS ${name} RUNTIME DESTINATION examples)
732 set_target_properties(${name} PROPERTIES FOLDER "Examples")
733 endmacro(add_llvm_example name)
736 macro(add_llvm_utility name)
737 add_llvm_executable(${name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN})
738 set_target_properties(${name} PROPERTIES FOLDER "Utils")
739 if( LLVM_INSTALL_UTILS )
740 install (TARGETS ${name}
741 RUNTIME DESTINATION bin
743 if (NOT CMAKE_CONFIGURATION_TYPES)
744 add_custom_target(install-${name}
746 COMMAND "${CMAKE_COMMAND}"
747 -DCMAKE_INSTALL_COMPONENT=${name}
748 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
751 endmacro(add_llvm_utility name)
754 macro(add_llvm_target target_name)
755 include_directories(BEFORE
756 ${CMAKE_CURRENT_BINARY_DIR}
757 ${CMAKE_CURRENT_SOURCE_DIR})
758 add_llvm_library(LLVM${target_name} ${ARGN})
759 set( CURRENT_LLVM_TARGET LLVM${target_name} )
760 endmacro(add_llvm_target)
762 function(canonicalize_tool_name name output)
763 string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" nameStrip ${name})
764 string(REPLACE "-" "_" nameUNDERSCORE ${nameStrip})
765 string(TOUPPER ${nameUNDERSCORE} nameUPPER)
766 set(${output} "${nameUPPER}" PARENT_SCOPE)
767 endfunction(canonicalize_tool_name)
769 # Custom add_subdirectory wrapper
770 # Takes in a project name (i.e. LLVM), the the subdirectory name, and an
771 # and an optional path if it differs from the name.
772 macro(add_llvm_subdirectory project type name)
773 set(add_llvm_external_dir "${ARGN}")
774 if("${add_llvm_external_dir}" STREQUAL "")
775 set(add_llvm_external_dir ${name})
777 canonicalize_tool_name(${name} nameUPPER)
778 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}/CMakeLists.txt)
779 # Treat it as in-tree subproject.
780 option(${project}_${type}_${nameUPPER}_BUILD
781 "Whether to build ${name} as part of ${project}" On)
782 mark_as_advanced(${project}_${type}_${name}_BUILD)
783 if(${project}_${type}_${nameUPPER}_BUILD)
784 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir} ${add_llvm_external_dir})
785 # Don't process it in add_llvm_implicit_projects().
786 set(${project}_${type}_${nameUPPER}_BUILD OFF)
789 set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR
790 "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}"
791 CACHE PATH "Path to ${name} source directory")
792 set(${project}_${type}_${nameUPPER}_BUILD_DEFAULT ON)
793 if(NOT LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR OR NOT EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR})
794 set(${project}_${type}_${nameUPPER}_BUILD_DEFAULT OFF)
796 if("${LLVM_EXTERNAL_${nameUPPER}_BUILD}" STREQUAL "OFF")
797 set(${project}_${type}_${nameUPPER}_BUILD_DEFAULT OFF)
799 option(${project}_${type}_${nameUPPER}_BUILD
800 "Whether to build ${name} as part of LLVM"
801 ${${project}_${type}_${nameUPPER}_BUILD_DEFAULT})
802 if (${project}_${type}_${nameUPPER}_BUILD)
803 if(EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR})
804 add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir})
805 elseif(NOT "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}" STREQUAL "")
806 message(WARNING "Nonexistent directory for ${name}: ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}")
808 # FIXME: It'd be redundant.
809 set(${project}_${type}_${nameUPPER}_BUILD Off)
814 # Add external project that may want to be built as part of llvm such as Clang,
815 # lld, and Polly. This adds two options. One for the source directory of the
816 # project, which defaults to ${CMAKE_CURRENT_SOURCE_DIR}/${name}. Another to
817 # enable or disable building it with everything else.
818 # Additional parameter can be specified as the name of directory.
819 macro(add_llvm_external_project name)
820 add_llvm_subdirectory(LLVM TOOL ${name} ${ARGN})
823 macro(add_llvm_tool_subdirectory name)
824 add_llvm_external_project(${name})
825 endmacro(add_llvm_tool_subdirectory)
827 function(get_project_name_from_src_var var output)
828 string(REGEX MATCH "LLVM_EXTERNAL_(.*)_SOURCE_DIR"
829 MACHED_TOOL "${var}")
831 set(${output} ${CMAKE_MATCH_1} PARENT_SCOPE)
833 set(${output} PARENT_SCOPE)
837 function(create_subdirectory_options project type)
838 file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
839 foreach(dir ${sub-dirs})
840 if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt")
841 canonicalize_tool_name(${dir} name)
842 option(${project}_${type}_${name}_BUILD
843 "Whether to build ${name} as part of ${project}" On)
844 mark_as_advanced(${project}_${type}_${name}_BUILD)
847 endfunction(create_subdirectory_options)
849 function(create_llvm_tool_options)
850 create_subdirectory_options(LLVM TOOL)
851 endfunction(create_llvm_tool_options)
853 function(llvm_add_implicit_projects project)
854 set(list_of_implicit_subdirs "")
855 file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
856 foreach(dir ${sub-dirs})
857 if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt")
858 canonicalize_tool_name(${dir} name)
859 if (${project}_TOOL_${name}_BUILD)
860 get_filename_component(fn "${dir}" NAME)
861 list(APPEND list_of_implicit_subdirs "${fn}")
866 foreach(external_proj ${list_of_implicit_subdirs})
867 add_llvm_subdirectory(${project} TOOL "${external_proj}" ${ARGN})
869 endfunction(llvm_add_implicit_projects)
871 function(add_llvm_implicit_projects)
872 llvm_add_implicit_projects(LLVM)
873 endfunction(add_llvm_implicit_projects)
875 # Generic support for adding a unittest.
876 function(add_unittest test_suite test_name)
877 if( NOT LLVM_BUILD_TESTS )
878 set(EXCLUDE_FROM_ALL ON)
881 include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
882 if (NOT LLVM_ENABLE_THREADS)
883 list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0)
886 if (SUPPORTS_NO_VARIADIC_MACROS_FLAG)
887 list(APPEND LLVM_COMPILE_FLAGS "-Wno-variadic-macros")
890 set(LLVM_REQUIRES_RTTI OFF)
892 list(APPEND LLVM_LINK_COMPONENTS Support) # gtest needs it for raw_ostream
893 add_llvm_executable(${test_name} IGNORE_EXTERNALIZE_DEBUGINFO ${ARGN})
894 set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
895 set_output_directory(${test_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir})
896 target_link_libraries(${test_name} gtest_main gtest)
898 add_dependencies(${test_suite} ${test_name})
899 get_target_property(test_suite_folder ${test_suite} FOLDER)
900 if (NOT ${test_suite_folder} STREQUAL "NOTFOUND")
901 set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}")
905 function(llvm_add_go_executable binary pkgpath)
906 cmake_parse_arguments(ARG "ALL" "" "DEPENDS;GOFLAGS" ${ARGN})
908 if(LLVM_BINDINGS MATCHES "go")
909 # FIXME: This should depend only on the libraries Go needs.
910 get_property(llvmlibs GLOBAL PROPERTY LLVM_LIBS)
911 set(binpath ${CMAKE_BINARY_DIR}/bin/${binary}${CMAKE_EXECUTABLE_SUFFIX})
912 set(cc "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
913 set(cxx "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
915 get_property(include_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
916 foreach(d ${include_dirs})
917 set(cppflags "${cppflags} -I${d}")
919 set(ldflags "${CMAKE_EXE_LINKER_FLAGS}")
920 add_custom_command(OUTPUT ${binpath}
921 COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "go=${GO_EXECUTABLE}" "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}"
922 ${ARG_GOFLAGS} build -o ${binpath} ${pkgpath}
923 DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX}
924 ${llvmlibs} ${ARG_DEPENDS}
925 COMMENT "Building Go executable ${binary}"
928 add_custom_target(${binary} ALL DEPENDS ${binpath})
930 add_custom_target(${binary} DEPENDS ${binpath})
935 # This function provides an automatic way to 'configure'-like generate a file
936 # based on a set of common and custom variables, specifically targeting the
937 # variables needed for the 'lit.site.cfg' files. This function bundles the
938 # common variables that any Lit instance is likely to need, and custom
939 # variables can be passed in.
940 function(configure_lit_site_cfg input output)
941 foreach(c ${LLVM_TARGETS_TO_BUILD})
942 set(TARGETS_BUILT "${TARGETS_BUILT} ${c}")
944 set(TARGETS_TO_BUILD ${TARGETS_BUILT})
946 set(SHLIBEXT "${LTDL_SHLIB_EXT}")
948 # Configuration-time: See Unit/lit.site.cfg.in
949 if (CMAKE_CFG_INTDIR STREQUAL ".")
950 set(LLVM_BUILD_MODE ".")
952 set(LLVM_BUILD_MODE "%(build_mode)s")
955 # They below might not be the build tree but provided binary tree.
956 set(LLVM_SOURCE_DIR ${LLVM_MAIN_SRC_DIR})
957 set(LLVM_BINARY_DIR ${LLVM_BINARY_DIR})
958 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_TOOLS_DIR ${LLVM_TOOLS_BINARY_DIR})
959 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_LIBS_DIR ${LLVM_LIBRARY_DIR})
961 # SHLIBDIR points the build tree.
962 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} SHLIBDIR "${LLVM_SHLIB_OUTPUT_INTDIR}")
964 set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
965 # FIXME: "ENABLE_SHARED" doesn't make sense, since it is used just for
966 # plugins. We may rename it.
967 if(LLVM_ENABLE_PLUGINS)
968 set(ENABLE_SHARED "1")
970 set(ENABLE_SHARED "0")
973 if(LLVM_ENABLE_ASSERTIONS AND NOT MSVC_IDE)
974 set(ENABLE_ASSERTIONS "1")
976 set(ENABLE_ASSERTIONS "0")
979 set(HOST_OS ${CMAKE_SYSTEM_NAME})
980 set(HOST_ARCH ${CMAKE_SYSTEM_PROCESSOR})
982 set(HOST_CC "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
983 set(HOST_CXX "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
984 set(HOST_LDFLAGS "${CMAKE_EXE_LINKER_FLAGS}")
986 configure_file(${input} ${output} @ONLY)
989 # A raw function to create a lit target. This is used to implement the testuite
990 # management functions.
991 function(add_lit_target target comment)
992 cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN})
993 set(LIT_ARGS "${ARG_ARGS} ${LLVM_LIT_ARGS}")
994 separate_arguments(LIT_ARGS)
995 if (NOT CMAKE_CFG_INTDIR STREQUAL ".")
996 list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR})
998 if (LLVM_MAIN_SRC_DIR)
999 set (LIT_COMMAND ${PYTHON_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
1001 find_program(LIT_COMMAND llvm-lit)
1003 list(APPEND LIT_COMMAND ${LIT_ARGS})
1004 foreach(param ${ARG_PARAMS})
1005 list(APPEND LIT_COMMAND --param ${param})
1007 if (ARG_UNPARSED_ARGUMENTS)
1008 add_custom_target(${target}
1009 COMMAND ${LIT_COMMAND} ${ARG_UNPARSED_ARGUMENTS}
1010 COMMENT "${comment}"
1011 ${cmake_3_2_USES_TERMINAL}
1014 add_custom_target(${target}
1015 COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, no tools built.")
1016 message(STATUS "${target} does nothing.")
1019 add_dependencies(${target} ${ARG_DEPENDS})
1022 # Tests should be excluded from "Build Solution".
1023 set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON)
1026 # A function to add a set of lit test suites to be driven through 'check-*' targets.
1027 function(add_lit_testsuite target comment)
1028 cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN})
1030 # EXCLUDE_FROM_ALL excludes the test ${target} out of check-all.
1031 if(NOT EXCLUDE_FROM_ALL)
1032 # Register the testsuites, params and depends for the global check rule.
1033 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_TESTSUITES ${ARG_UNPARSED_ARGUMENTS})
1034 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_PARAMS ${ARG_PARAMS})
1035 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_DEPENDS ${ARG_DEPENDS})
1036 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_EXTRA_ARGS ${ARG_ARGS})
1039 # Produce a specific suffixed check rule.
1040 add_lit_target(${target} ${comment}
1041 ${ARG_UNPARSED_ARGUMENTS}
1042 PARAMS ${ARG_PARAMS}
1043 DEPENDS ${ARG_DEPENDS}
1048 function(add_lit_testsuites project directory)
1049 if (NOT CMAKE_CONFIGURATION_TYPES)
1050 cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN})
1051 file(GLOB_RECURSE litCfg ${directory}/lit*.cfg)
1053 foreach(f ${litCfg})
1054 get_filename_component(dir ${f} DIRECTORY)
1055 set(lit_suites ${lit_suites} ${dir})
1057 list(REMOVE_DUPLICATES lit_suites)
1058 foreach(dir ${lit_suites})
1059 string(REPLACE ${directory} "" name_slash ${dir})
1061 string(REPLACE "/" "-" name_slash ${name_slash})
1062 string(REPLACE "\\" "-" name_dashes ${name_slash})
1063 string(TOLOWER "${project}${name_dashes}" name_var)
1064 add_lit_target("check-${name_var}" "Running lit suite ${dir}"
1066 PARAMS ${ARG_PARAMS}
1067 DEPENDS ${ARG_DEPENDS}
1075 function(llvm_install_library_symlink name dest type)
1076 cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
1077 foreach(path ${CMAKE_MODULE_PATH})
1078 if(EXISTS ${path}/LLVMInstallSymlink.cmake)
1079 set(INSTALL_SYMLINK ${path}/LLVMInstallSymlink.cmake)
1084 set(component ${ARG_COMPONENT})
1086 set(component ${name})
1089 set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX})
1090 set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX})
1092 set(output_dir lib${LLVM_LIBDIR_SUFFIX})
1093 if(WIN32 AND "${type}" STREQUAL "SHARED")
1097 install(SCRIPT ${INSTALL_SYMLINK}
1098 CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
1099 COMPONENT ${component})
1101 if (NOT CMAKE_CONFIGURATION_TYPES AND NOT ARG_ALWAYS_GENERATE)
1102 add_custom_target(install-${name}
1103 DEPENDS ${name} ${dest} install-${dest}
1104 COMMAND "${CMAKE_COMMAND}"
1105 -DCMAKE_INSTALL_COMPONENT=${name}
1106 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
1110 function(llvm_install_symlink name dest)
1111 cmake_parse_arguments(ARG "ALWAYS_GENERATE" "" "" ${ARGN})
1112 foreach(path ${CMAKE_MODULE_PATH})
1113 if(EXISTS ${path}/LLVMInstallSymlink.cmake)
1114 set(INSTALL_SYMLINK ${path}/LLVMInstallSymlink.cmake)
1119 if(ARG_ALWAYS_GENERATE)
1120 set(component ${dest})
1122 set(component ${name})
1125 set(full_name ${name}${CMAKE_EXECUTABLE_SUFFIX})
1126 set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX})
1128 install(SCRIPT ${INSTALL_SYMLINK}
1129 CODE "install_symlink(${full_name} ${full_dest} bin)"
1130 COMPONENT ${component})
1132 if (NOT CMAKE_CONFIGURATION_TYPES AND NOT ARG_ALWAYS_GENERATE)
1133 add_custom_target(install-${name}
1134 DEPENDS ${name} ${dest} install-${dest}
1135 COMMAND "${CMAKE_COMMAND}"
1136 -DCMAKE_INSTALL_COMPONENT=${name}
1137 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
1141 function(add_llvm_tool_symlink name dest)
1142 cmake_parse_arguments(ARG "ALWAYS_GENERATE" "" "" ${ARGN})
1144 set(LLVM_LINK_OR_COPY create_symlink)
1145 set(dest_binary "${dest}${CMAKE_EXECUTABLE_SUFFIX}")
1147 set(LLVM_LINK_OR_COPY copy)
1148 set(dest_binary "${LLVM_RUNTIME_OUTPUT_INTDIR}/${dest}${CMAKE_EXECUTABLE_SUFFIX}")
1151 set(output_path "${LLVM_RUNTIME_OUTPUT_INTDIR}/${name}${CMAKE_EXECUTABLE_SUFFIX}")
1153 if(ARG_ALWAYS_GENERATE)
1154 set_property(DIRECTORY APPEND PROPERTY
1155 ADDITIONAL_MAKE_CLEAN_FILES ${dest_binary})
1156 add_custom_command(TARGET ${dest} POST_BUILD
1157 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${dest_binary}" "${output_path}")
1159 add_custom_command(OUTPUT ${output_path}
1160 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${dest_binary}" "${output_path}"
1162 add_custom_target(${name} ALL DEPENDS ${output_path})
1163 set_target_properties(${name} PROPERTIES FOLDER Tools)
1165 # Make sure the parent tool is a toolchain tool, otherwise exclude this tool
1166 list(FIND LLVM_TOOLCHAIN_TOOLS ${dest} LLVM_IS_${dest}_TOOLCHAIN_TOOL)
1167 if (NOT LLVM_IS_${dest}_TOOLCHAIN_TOOL GREATER -1)
1168 set(LLVM_IS_${name}_TOOLCHAIN_TOOL ${LLVM_IS_${dest}_TOOLCHAIN_TOOL})
1170 list(FIND LLVM_TOOLCHAIN_TOOLS ${name} LLVM_IS_${name}_TOOLCHAIN_TOOL)
1173 # LLVM_IS_${name}_TOOLCHAIN_TOOL will only be greater than -1 if both this
1174 # tool and its parent tool are in LLVM_TOOLCHAIN_TOOLS
1175 if (LLVM_IS_${name}_TOOLCHAIN_TOOL GREATER -1 OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
1176 if( LLVM_BUILD_TOOLS )
1177 llvm_install_symlink(${name} ${dest})
1183 function(llvm_externalize_debuginfo name)
1184 if(NOT LLVM_EXTERNALIZE_DEBUGINFO)
1189 if(CMAKE_CXX_FLAGS MATCHES "-flto"
1190 OR CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} MATCHES "-flto")
1192 set(lto_object ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${name}-lto.o)
1193 set_property(TARGET ${name} APPEND_STRING PROPERTY
1194 LINK_FLAGS " -Wl,-object_path_lto,${lto_object}")
1196 add_custom_command(TARGET ${name} POST_BUILD
1197 COMMAND xcrun dsymutil $<TARGET_FILE:${name}>
1198 COMMAND xcrun strip -Sxl $<TARGET_FILE:${name}>)
1200 message(FATAL_ERROR "LLVM_EXTERNALIZE_DEBUGINFO isn't implemented for non-darwin platforms!")