1include(LLVMProcessSources)
2include(LLVM-Config)
3include(DetermineGCCCompatible)
4
5function(llvm_update_compile_flags name)
6  get_property(sources TARGET ${name} PROPERTY SOURCES)
7  if("${sources}" MATCHES "\\.c(;|$)")
8    set(update_src_props ON)
9  endif()
10
11  # LLVM_REQUIRES_EH is an internal flag that individual targets can use to
12  # force EH
13  if(LLVM_REQUIRES_EH OR LLVM_ENABLE_EH)
14    if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI))
15      message(AUTHOR_WARNING "Exception handling requires RTTI. Enabling RTTI for ${name}")
16      set(LLVM_REQUIRES_RTTI ON)
17    endif()
18    if(MSVC)
19      list(APPEND LLVM_COMPILE_FLAGS "/EHsc")
20    endif()
21  else()
22    if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
23      list(APPEND LLVM_COMPILE_FLAGS "-fno-exceptions")
24    elseif(MSVC)
25      list(APPEND LLVM_COMPILE_DEFINITIONS _HAS_EXCEPTIONS=0)
26      list(APPEND LLVM_COMPILE_FLAGS "/EHs-c-")
27    endif()
28  endif()
29
30  # LLVM_REQUIRES_RTTI is an internal flag that individual
31  # targets can use to force RTTI
32  set(LLVM_CONFIG_HAS_RTTI YES CACHE INTERNAL "")
33  if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI))
34    set(LLVM_CONFIG_HAS_RTTI NO CACHE INTERNAL "")
35    list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0)
36    if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
37      list(APPEND LLVM_COMPILE_FLAGS "-fno-rtti")
38    elseif (MSVC)
39      list(APPEND LLVM_COMPILE_FLAGS "/GR-")
40    endif ()
41  elseif(MSVC)
42    list(APPEND LLVM_COMPILE_FLAGS "/GR")
43  endif()
44
45  # Assume that;
46  #   - LLVM_COMPILE_FLAGS is list.
47  #   - PROPERTY COMPILE_FLAGS is string.
48  string(REPLACE ";" " " target_compile_flags " ${LLVM_COMPILE_FLAGS}")
49
50  if(update_src_props)
51    foreach(fn ${sources})
52      get_filename_component(suf ${fn} EXT)
53      if("${suf}" STREQUAL ".cpp")
54        set_property(SOURCE ${fn} APPEND_STRING PROPERTY
55          COMPILE_FLAGS "${target_compile_flags}")
56      endif()
57    endforeach()
58  else()
59    # Update target props, since all sources are C++.
60    set_property(TARGET ${name} APPEND_STRING PROPERTY
61      COMPILE_FLAGS "${target_compile_flags}")
62  endif()
63
64  set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS ${LLVM_COMPILE_DEFINITIONS})
65endfunction()
66
67function(add_llvm_symbol_exports target_name export_file)
68  if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
69    set(native_export_file "${target_name}.exports")
70    add_custom_command(OUTPUT ${native_export_file}
71      COMMAND sed -e "s/^/_/" < ${export_file} > ${native_export_file}
72      DEPENDS ${export_file}
73      VERBATIM
74      COMMENT "Creating export file for ${target_name}")
75    set_property(TARGET ${target_name} APPEND_STRING PROPERTY
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    add_custom_command(OUTPUT ${native_export_file}
85      COMMAND echo "{" > ${native_export_file}
86      COMMAND grep -q "[[:alnum:]]" ${export_file} && echo "  global:" >> ${native_export_file} || :
87      COMMAND sed -e "s/$/;/" -e "s/^/    /" < ${export_file} >> ${native_export_file}
88      COMMAND echo "  local: *;" >> ${native_export_file}
89      COMMAND echo "};" >> ${native_export_file}
90      DEPENDS ${export_file}
91      VERBATIM
92      COMMENT "Creating export file for ${target_name}")
93    if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
94      set_property(TARGET ${target_name} APPEND_STRING PROPERTY
95                   LINK_FLAGS "  -Wl,-M,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
96    else()
97      set_property(TARGET ${target_name} APPEND_STRING PROPERTY
98                   LINK_FLAGS "  -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
99    endif()
100  else()
101    set(native_export_file "${target_name}.def")
102
103    add_custom_command(OUTPUT ${native_export_file}
104      COMMAND ${PYTHON_EXECUTABLE} -c "import sys;print(''.join(['EXPORTS\\n']+sys.stdin.readlines(),))"
105        < ${export_file} > ${native_export_file}
106      DEPENDS ${export_file}
107      VERBATIM
108      COMMENT "Creating export file for ${target_name}")
109    set(export_file_linker_flag "${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
110    if(MSVC)
111      set(export_file_linker_flag "/DEF:\"${export_file_linker_flag}\"")
112    endif()
113    set_property(TARGET ${target_name} APPEND_STRING PROPERTY
114                 LINK_FLAGS " ${export_file_linker_flag}")
115  endif()
116
117  add_custom_target(${target_name}_exports DEPENDS ${native_export_file})
118  set_target_properties(${target_name}_exports PROPERTIES FOLDER "Misc")
119
120  get_property(srcs TARGET ${target_name} PROPERTY SOURCES)
121  foreach(src ${srcs})
122    get_filename_component(extension ${src} EXT)
123    if(extension STREQUAL ".cpp")
124      set(first_source_file ${src})
125      break()
126    endif()
127  endforeach()
128
129  # Force re-linking when the exports file changes. Actually, it
130  # forces recompilation of the source file. The LINK_DEPENDS target
131  # property only works for makefile-based generators.
132  # FIXME: This is not safe because this will create the same target
133  # ${native_export_file} in several different file:
134  # - One where we emitted ${target_name}_exports
135  # - One where we emitted the build command for the following object.
136  # set_property(SOURCE ${first_source_file} APPEND PROPERTY
137  #   OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${native_export_file})
138
139  set_property(DIRECTORY APPEND
140    PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${native_export_file})
141
142  add_dependencies(${target_name} ${target_name}_exports)
143
144  # Add dependency to *_exports later -- CMake issue 14747
145  list(APPEND LLVM_COMMON_DEPENDS ${target_name}_exports)
146  set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)
147endfunction(add_llvm_symbol_exports)
148
149if(NOT WIN32 AND NOT APPLE)
150  execute_process(
151    COMMAND ${CMAKE_C_COMPILER} -Wl,--version
152    OUTPUT_VARIABLE stdout
153    ERROR_QUIET
154    )
155  if("${stdout}" MATCHES "GNU gold")
156    set(LLVM_LINKER_IS_GOLD ON)
157  endif()
158endif()
159
160function(add_link_opts target_name)
161  # Don't use linker optimizations in debug builds since it slows down the
162  # linker in a context where the optimizations are not important.
163  if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
164
165    # Pass -O3 to the linker. This enabled different optimizations on different
166    # linkers.
167    if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|SunOS|AIX" OR WIN32))
168      set_property(TARGET ${target_name} APPEND_STRING PROPERTY
169                   LINK_FLAGS " -Wl,-O3")
170    endif()
171
172    if(LLVM_LINKER_IS_GOLD)
173      # With gold gc-sections is always safe.
174      set_property(TARGET ${target_name} APPEND_STRING PROPERTY
175                   LINK_FLAGS " -Wl,--gc-sections")
176      # Note that there is a bug with -Wl,--icf=safe so it is not safe
177      # to enable. See https://sourceware.org/bugzilla/show_bug.cgi?id=17704.
178    endif()
179
180    if(NOT LLVM_NO_DEAD_STRIP)
181      if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
182        # ld64's implementation of -dead_strip breaks tools that use plugins.
183        set_property(TARGET ${target_name} APPEND_STRING PROPERTY
184                     LINK_FLAGS " -Wl,-dead_strip")
185      elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
186        set_property(TARGET ${target_name} APPEND_STRING PROPERTY
187                     LINK_FLAGS " -Wl,-z -Wl,discard-unused=sections")
188      elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD)
189        # Object files are compiled with -ffunction-data-sections.
190        # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks
191        # tools that use plugins. Always pass --gc-sections once we require
192        # a newer linker.
193        set_property(TARGET ${target_name} APPEND_STRING PROPERTY
194                     LINK_FLAGS " -Wl,--gc-sections")
195      endif()
196    endif()
197  endif()
198endfunction(add_link_opts)
199
200# Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}.
201# Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more,
202# or a certain builder, for eaxample, msbuild.exe, would be confused.
203function(set_output_directory target)
204  cmake_parse_arguments(ARG "" "BINARY_DIR;LIBRARY_DIR" "" ${ARGN})
205
206  # module_dir -- corresponding to LIBRARY_OUTPUT_DIRECTORY.
207  # It affects output of add_library(MODULE).
208  if(WIN32 OR CYGWIN)
209    # DLL platform
210    set(module_dir ${ARG_BINARY_DIR})
211  else()
212    set(module_dir ${ARG_LIBRARY_DIR})
213  endif()
214  if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
215    foreach(build_mode ${CMAKE_CONFIGURATION_TYPES})
216      string(TOUPPER "${build_mode}" CONFIG_SUFFIX)
217      if(ARG_BINARY_DIR)
218        string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} bi ${ARG_BINARY_DIR})
219        set_target_properties(${target} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${bi})
220      endif()
221      if(ARG_LIBRARY_DIR)
222        string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} li ${ARG_LIBRARY_DIR})
223        set_target_properties(${target} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li})
224      endif()
225      if(module_dir)
226        string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} mi ${module_dir})
227        set_target_properties(${target} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${mi})
228      endif()
229    endforeach()
230  else()
231    if(ARG_BINARY_DIR)
232      set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ARG_BINARY_DIR})
233    endif()
234    if(ARG_LIBRARY_DIR)
235      set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${ARG_LIBRARY_DIR})
236    endif()
237    if(module_dir)
238      set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${module_dir})
239    endif()
240  endif()
241endfunction()
242
243# If on Windows and building with MSVC, add the resource script containing the
244# VERSIONINFO data to the project.  This embeds version resource information
245# into the output .exe or .dll.
246# TODO: Enable for MinGW Windows builds too.
247#
248function(add_windows_version_resource_file OUT_VAR)
249  set(sources ${ARGN})
250  if (MSVC)
251    set(resource_file ${LLVM_SOURCE_DIR}/resources/windows_version_resource.rc)
252    if(EXISTS ${resource_file})
253      set(sources ${sources} ${resource_file})
254      source_group("Resource Files" ${resource_file})
255      set(windows_resource_file ${resource_file} PARENT_SCOPE)
256    endif()
257  endif(MSVC)
258
259  set(${OUT_VAR} ${sources} PARENT_SCOPE)
260endfunction(add_windows_version_resource_file)
261
262# set_windows_version_resource_properties(name resource_file...
263#   VERSION_MAJOR int
264#     Optional major version number (defaults to LLVM_VERSION_MAJOR)
265#   VERSION_MINOR int
266#     Optional minor version number (defaults to LLVM_VERSION_MINOR)
267#   VERSION_PATCHLEVEL int
268#     Optional patchlevel version number (defaults to LLVM_VERSION_PATCH)
269#   VERSION_STRING
270#     Optional version string (defaults to PACKAGE_VERSION)
271#   PRODUCT_NAME
272#     Optional product name string (defaults to "LLVM")
273#   )
274function(set_windows_version_resource_properties name resource_file)
275  cmake_parse_arguments(ARG
276    ""
277    "VERSION_MAJOR;VERSION_MINOR;VERSION_PATCHLEVEL;VERSION_STRING;PRODUCT_NAME"
278    ""
279    ${ARGN})
280
281  if (NOT DEFINED ARG_VERSION_MAJOR)
282    set(ARG_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
283  endif()
284
285  if (NOT DEFINED ARG_VERSION_MINOR)
286    set(ARG_VERSION_MINOR ${LLVM_VERSION_MINOR})
287  endif()
288
289  if (NOT DEFINED ARG_VERSION_PATCHLEVEL)
290    set(ARG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH})
291  endif()
292
293  if (NOT DEFINED ARG_VERSION_STRING)
294    set(ARG_VERSION_STRING ${PACKAGE_VERSION})
295  endif()
296
297  if (NOT DEFINED ARG_PRODUCT_NAME)
298    set(ARG_PRODUCT_NAME "LLVM")
299  endif()
300
301  set_property(SOURCE ${resource_file}
302               PROPERTY COMPILE_FLAGS /nologo)
303  set_property(SOURCE ${resource_file}
304               PROPERTY COMPILE_DEFINITIONS
305               "RC_VERSION_FIELD_1=${ARG_VERSION_MAJOR}"
306               "RC_VERSION_FIELD_2=${ARG_VERSION_MINOR}"
307               "RC_VERSION_FIELD_3=${ARG_VERSION_PATCHLEVEL}"
308               "RC_VERSION_FIELD_4=0"
309               "RC_FILE_VERSION=\"${ARG_VERSION_STRING}\""
310               "RC_INTERNAL_NAME=\"${name}\""
311               "RC_PRODUCT_NAME=\"${ARG_PRODUCT_NAME}\""
312               "RC_PRODUCT_VERSION=\"${ARG_VERSION_STRING}\"")
313endfunction(set_windows_version_resource_properties)
314
315# llvm_add_library(name sources...
316#   SHARED;STATIC
317#     STATIC by default w/o BUILD_SHARED_LIBS.
318#     SHARED by default w/  BUILD_SHARED_LIBS.
319#   OBJECT
320#     Also create an OBJECT library target. Default if STATIC && SHARED.
321#   MODULE
322#     Target ${name} might not be created on unsupported platforms.
323#     Check with "if(TARGET ${name})".
324#   DISABLE_LLVM_LINK_LLVM_DYLIB
325#     Do not link this library to libLLVM, even if
326#     LLVM_LINK_LLVM_DYLIB is enabled.
327#   OUTPUT_NAME name
328#     Corresponds to OUTPUT_NAME in target properties.
329#   DEPENDS targets...
330#     Same semantics as add_dependencies().
331#   LINK_COMPONENTS components...
332#     Same as the variable LLVM_LINK_COMPONENTS.
333#   LINK_LIBS lib_targets...
334#     Same semantics as target_link_libraries().
335#   ADDITIONAL_HEADERS
336#     May specify header files for IDE generators.
337#   SONAME
338#     Should set SONAME link flags and create symlinks
339#   PLUGIN_TOOL
340#     The tool (i.e. cmake target) that this plugin will link against
341#   )
342function(llvm_add_library name)
343  cmake_parse_arguments(ARG
344    "MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME"
345    "OUTPUT_NAME;PLUGIN_TOOL"
346    "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS"
347    ${ARGN})
348  list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
349  if(ARG_ADDITIONAL_HEADERS)
350    # Pass through ADDITIONAL_HEADERS.
351    set(ARG_ADDITIONAL_HEADERS ADDITIONAL_HEADERS ${ARG_ADDITIONAL_HEADERS})
352  endif()
353  if(ARG_OBJLIBS)
354    set(ALL_FILES ${ARG_OBJLIBS})
355  else()
356    llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS})
357  endif()
358
359  if(ARG_MODULE)
360    if(ARG_SHARED OR ARG_STATIC)
361      message(WARNING "MODULE with SHARED|STATIC doesn't make sense.")
362    endif()
363    # Plugins that link against a tool are allowed even when plugins in general are not
364    if(NOT LLVM_ENABLE_PLUGINS AND NOT (ARG_PLUGIN_TOOL AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS))
365      message(STATUS "${name} ignored -- Loadable modules not supported on this platform.")
366      return()
367    endif()
368  else()
369    if(ARG_PLUGIN_TOOL)
370      message(WARNING "PLUGIN_TOOL without MODULE doesn't make sense.")
371    endif()
372    if(BUILD_SHARED_LIBS AND NOT ARG_STATIC)
373      set(ARG_SHARED TRUE)
374    endif()
375    if(NOT ARG_SHARED)
376      set(ARG_STATIC TRUE)
377    endif()
378  endif()
379
380  # Generate objlib
381  if((ARG_SHARED AND ARG_STATIC) OR ARG_OBJECT)
382    # Generate an obj library for both targets.
383    set(obj_name "obj.${name}")
384    add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL
385      ${ALL_FILES}
386      )
387    llvm_update_compile_flags(${obj_name})
388    set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>")
389
390    # Do add_dependencies(obj) later due to CMake issue 14747.
391    list(APPEND objlibs ${obj_name})
392
393    set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
394  endif()
395
396  if(ARG_SHARED AND ARG_STATIC)
397    # static
398    set(name_static "${name}_static")
399    if(ARG_OUTPUT_NAME)
400      set(output_name OUTPUT_NAME "${ARG_OUTPUT_NAME}")
401    endif()
402    # DEPENDS has been appended to LLVM_COMMON_LIBS.
403    llvm_add_library(${name_static} STATIC
404      ${output_name}
405      OBJLIBS ${ALL_FILES} # objlib
406      LINK_LIBS ${ARG_LINK_LIBS}
407      LINK_COMPONENTS ${ARG_LINK_COMPONENTS}
408      )
409    # FIXME: Add name_static to anywhere in TARGET ${name}'s PROPERTY.
410    set(ARG_STATIC)
411  endif()
412
413  if(ARG_MODULE)
414    add_library(${name} MODULE ${ALL_FILES})
415    llvm_setup_rpath(${name})
416  elseif(ARG_SHARED)
417    add_windows_version_resource_file(ALL_FILES ${ALL_FILES})
418    add_library(${name} SHARED ${ALL_FILES})
419
420    llvm_setup_rpath(${name})
421
422  else()
423    add_library(${name} STATIC ${ALL_FILES})
424  endif()
425
426  setup_dependency_debugging(${name} ${LLVM_COMMON_DEPENDS})
427
428  if(DEFINED windows_resource_file)
429    set_windows_version_resource_properties(${name} ${windows_resource_file})
430    set(windows_resource_file ${windows_resource_file} PARENT_SCOPE)
431  endif()
432
433  set_output_directory(${name} BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR} LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
434  # $<TARGET_OBJECTS> doesn't require compile flags.
435  if(NOT obj_name)
436    llvm_update_compile_flags(${name})
437  endif()
438  add_link_opts( ${name} )
439  if(ARG_OUTPUT_NAME)
440    set_target_properties(${name}
441      PROPERTIES
442      OUTPUT_NAME ${ARG_OUTPUT_NAME}
443      )
444  endif()
445
446  if(ARG_MODULE)
447    set_target_properties(${name} PROPERTIES
448      PREFIX ""
449      SUFFIX ${LLVM_PLUGIN_EXT}
450      )
451  endif()
452
453  if(ARG_SHARED)
454    if(WIN32)
455      set_target_properties(${name} PROPERTIES
456        PREFIX ""
457        )
458    endif()
459
460    # Set SOVERSION on shared libraries that lack explicit SONAME
461    # specifier, on *nix systems that are not Darwin.
462    if(UNIX AND NOT APPLE AND NOT ARG_SONAME)
463      set_target_properties(${name}
464        PROPERTIES
465		# Concatenate the version numbers since ldconfig expects exactly
466		# one component indicating the ABI version, while LLVM uses
467		# major+minor for that.
468        SOVERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_MINOR}
469        VERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX})
470    endif()
471  endif()
472
473  if(ARG_MODULE OR ARG_SHARED)
474    # Do not add -Dname_EXPORTS to the command-line when building files in this
475    # target. Doing so is actively harmful for the modules build because it
476    # creates extra module variants, and not useful because we don't use these
477    # macros.
478    set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
479
480    if (LLVM_EXPORTED_SYMBOL_FILE)
481      add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
482    endif()
483  endif()
484
485  if(ARG_SHARED AND UNIX)
486    if(NOT APPLE AND ARG_SONAME)
487      get_target_property(output_name ${name} OUTPUT_NAME)
488      if(${output_name} STREQUAL "output_name-NOTFOUND")
489        set(output_name ${name})
490      endif()
491      set(library_name ${output_name}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX})
492      set(api_name ${output_name}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX})
493      set_target_properties(${name} PROPERTIES OUTPUT_NAME ${library_name})
494      llvm_install_library_symlink(${api_name} ${library_name} SHARED
495        COMPONENT ${name}
496        ALWAYS_GENERATE)
497      llvm_install_library_symlink(${output_name} ${library_name} SHARED
498        COMPONENT ${name}
499        ALWAYS_GENERATE)
500    endif()
501  endif()
502
503  if(ARG_MODULE AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS AND ARG_PLUGIN_TOOL AND (WIN32 OR CYGWIN))
504    # On DLL platforms symbols are imported from the tool by linking against it.
505    set(llvm_libs ${ARG_PLUGIN_TOOL})
506  elseif (DEFINED LLVM_LINK_COMPONENTS OR DEFINED ARG_LINK_COMPONENTS)
507    if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
508      set(llvm_libs LLVM)
509    else()
510      llvm_map_components_to_libnames(llvm_libs
511       ${ARG_LINK_COMPONENTS}
512       ${LLVM_LINK_COMPONENTS}
513       )
514    endif()
515  else()
516    # Components have not been defined explicitly in CMake, so add the
517    # dependency information for this library as defined by LLVMBuild.
518    #
519    # It would be nice to verify that we have the dependencies for this library
520    # name, but using get_property(... SET) doesn't suffice to determine if a
521    # property has been set to an empty value.
522    get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
523  endif()
524
525  if(ARG_STATIC)
526    set(libtype INTERFACE)
527  else()
528    # We can use PRIVATE since SO knows its dependent libs.
529    set(libtype PRIVATE)
530  endif()
531
532  target_link_libraries(${name} ${libtype}
533      ${ARG_LINK_LIBS}
534      ${lib_deps}
535      ${llvm_libs}
536      )
537
538  if(LLVM_COMMON_DEPENDS)
539    add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
540    # Add dependencies also to objlibs.
541    # CMake issue 14747 --  add_dependencies() might be ignored to objlib's user.
542    foreach(objlib ${objlibs})
543      add_dependencies(${objlib} ${LLVM_COMMON_DEPENDS})
544    endforeach()
545  endif()
546
547  if(ARG_SHARED OR ARG_MODULE)
548    llvm_externalize_debuginfo(${name})
549  endif()
550endfunction()
551
552macro(add_llvm_library name)
553  cmake_parse_arguments(ARG
554    "SHARED;BUILDTREE_ONLY"
555    ""
556    ""
557    ${ARGN})
558  if( BUILD_SHARED_LIBS OR ARG_SHARED )
559    llvm_add_library(${name} SHARED ${ARG_UNPARSED_ARGUMENTS})
560  else()
561    llvm_add_library(${name} ${ARG_UNPARSED_ARGUMENTS})
562  endif()
563
564  # Libraries that are meant to only be exposed via the build tree only are
565  # never installed and are only exported as a target in the special build tree
566  # config file.
567  if (NOT ARG_BUILDTREE_ONLY)
568    set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
569  endif()
570
571  if( EXCLUDE_FROM_ALL )
572    set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
573  elseif(ARG_BUILDTREE_ONLY)
574    set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name})
575  else()
576    if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO" OR
577        (LLVM_LINK_LLVM_DYLIB AND ${name} STREQUAL "LLVM"))
578      set(install_dir lib${LLVM_LIBDIR_SUFFIX})
579      if(ARG_SHARED OR BUILD_SHARED_LIBS)
580        if(WIN32 OR CYGWIN OR MINGW)
581          set(install_type RUNTIME)
582          set(install_dir bin)
583        else()
584          set(install_type LIBRARY)
585        endif()
586      else()
587        set(install_type ARCHIVE)
588      endif()
589
590      if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
591          NOT LLVM_DISTRIBUTION_COMPONENTS)
592        set(export_to_llvmexports EXPORT LLVMExports)
593        set_property(GLOBAL PROPERTY LLVM_HAS_EXPORTS True)
594      endif()
595
596      install(TARGETS ${name}
597              ${export_to_llvmexports}
598              ${install_type} DESTINATION ${install_dir}
599              COMPONENT ${name})
600
601      if (NOT CMAKE_CONFIGURATION_TYPES)
602        add_custom_target(install-${name}
603                          DEPENDS ${name}
604                          COMMAND "${CMAKE_COMMAND}"
605                                  -DCMAKE_INSTALL_COMPONENT=${name}
606                                  -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
607      endif()
608    endif()
609    set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
610  endif()
611  set_target_properties(${name} PROPERTIES FOLDER "Libraries")
612endmacro(add_llvm_library name)
613
614macro(add_llvm_loadable_module name)
615  llvm_add_library(${name} MODULE ${ARGN})
616  if(NOT TARGET ${name})
617    # Add empty "phony" target
618    add_custom_target(${name})
619  else()
620    if( EXCLUDE_FROM_ALL )
621      set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
622    else()
623      if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
624        if(WIN32 OR CYGWIN)
625          # DLL platform
626          set(dlldir "bin")
627        else()
628          set(dlldir "lib${LLVM_LIBDIR_SUFFIX}")
629        endif()
630
631        if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
632            NOT LLVM_DISTRIBUTION_COMPONENTS)
633          set(export_to_llvmexports EXPORT LLVMExports)
634          set_property(GLOBAL PROPERTY LLVM_HAS_EXPORTS True)
635        endif()
636
637        install(TARGETS ${name}
638                ${export_to_llvmexports}
639                LIBRARY DESTINATION ${dlldir}
640                ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
641      endif()
642      set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
643    endif()
644  endif()
645
646  set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
647endmacro(add_llvm_loadable_module name)
648
649
650macro(add_llvm_executable name)
651  cmake_parse_arguments(ARG "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH" "" "DEPENDS" ${ARGN})
652  llvm_process_sources( ALL_FILES ${ARG_UNPARSED_ARGUMENTS} )
653
654  list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
655
656  # Generate objlib
657  if(LLVM_ENABLE_OBJLIB)
658    # Generate an obj library for both targets.
659    set(obj_name "obj.${name}")
660    add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL
661      ${ALL_FILES}
662      )
663    llvm_update_compile_flags(${obj_name})
664    set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>")
665
666    set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
667  endif()
668
669  add_windows_version_resource_file(ALL_FILES ${ALL_FILES})
670
671  if(XCODE)
672    # Note: the dummy.cpp source file provides no definitions. However,
673    # it forces Xcode to properly link the static library.
674    list(APPEND ALL_FILES "${LLVM_MAIN_SRC_DIR}/cmake/dummy.cpp")
675  endif()
676
677  if( EXCLUDE_FROM_ALL )
678    add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
679  else()
680    add_executable(${name} ${ALL_FILES})
681  endif()
682
683  setup_dependency_debugging(${name} ${LLVM_COMMON_DEPENDS})
684
685  if(NOT ARG_NO_INSTALL_RPATH)
686    llvm_setup_rpath(${name})
687  endif()
688
689  if(DEFINED windows_resource_file)
690    set_windows_version_resource_properties(${name} ${windows_resource_file})
691  endif()
692
693  # $<TARGET_OBJECTS> doesn't require compile flags.
694  if(NOT LLVM_ENABLE_OBJLIB)
695    llvm_update_compile_flags(${name})
696  endif()
697  add_link_opts( ${name} )
698
699  # Do not add -Dname_EXPORTS to the command-line when building files in this
700  # target. Doing so is actively harmful for the modules build because it
701  # creates extra module variants, and not useful because we don't use these
702  # macros.
703  set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
704
705  if (LLVM_EXPORTED_SYMBOL_FILE)
706    add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
707  endif(LLVM_EXPORTED_SYMBOL_FILE)
708
709  if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
710    set(USE_SHARED USE_SHARED)
711  endif()
712
713  set(EXCLUDE_FROM_ALL OFF)
714  set_output_directory(${name} BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR} LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
715  llvm_config( ${name} ${USE_SHARED} ${LLVM_LINK_COMPONENTS} )
716  if( LLVM_COMMON_DEPENDS )
717    add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
718  endif( LLVM_COMMON_DEPENDS )
719
720  if(NOT ARG_IGNORE_EXTERNALIZE_DEBUGINFO)
721    llvm_externalize_debuginfo(${name})
722  endif()
723  if (PTHREAD_LIB)
724    # libpthreads overrides some standard library symbols, so main
725    # executable must be linked with it in order to provide consistent
726    # API for all shared libaries loaded by this executable.
727    target_link_libraries(${name} ${PTHREAD_LIB})
728  endif()
729endmacro(add_llvm_executable name)
730
731function(export_executable_symbols target)
732  if (LLVM_EXPORTED_SYMBOL_FILE)
733    # The symbol file should contain the symbols we want the executable to
734    # export
735    set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
736  elseif (LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)
737    # Extract the symbols to export from the static libraries that the
738    # executable links against.
739    set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
740    set(exported_symbol_file ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${target}.symbols)
741    # We need to consider not just the direct link dependencies, but also the
742    # transitive link dependencies. Do this by starting with the set of direct
743    # dependencies, then the dependencies of those dependencies, and so on.
744    get_target_property(new_libs ${target} LINK_LIBRARIES)
745    set(link_libs ${new_libs})
746    while(NOT "${new_libs}" STREQUAL "")
747      foreach(lib ${new_libs})
748        if(TARGET ${lib})
749          get_target_property(lib_type ${lib} TYPE)
750          if("${lib_type}" STREQUAL "STATIC_LIBRARY")
751            list(APPEND static_libs ${lib})
752          else()
753            list(APPEND other_libs ${lib})
754          endif()
755          get_target_property(transitive_libs ${lib} INTERFACE_LINK_LIBRARIES)
756          foreach(transitive_lib ${transitive_libs})
757            list(FIND link_libs ${transitive_lib} idx)
758            if(TARGET ${transitive_lib} AND idx EQUAL -1)
759              list(APPEND newer_libs ${transitive_lib})
760              list(APPEND link_libs ${transitive_lib})
761            endif()
762          endforeach(transitive_lib)
763        endif()
764      endforeach(lib)
765      set(new_libs ${newer_libs})
766      set(newer_libs "")
767    endwhile()
768    if (MSVC)
769      set(mangling microsoft)
770    else()
771      set(mangling itanium)
772    endif()
773    add_custom_command(OUTPUT ${exported_symbol_file}
774                       COMMAND ${PYTHON_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py --mangling=${mangling} ${static_libs} -o ${exported_symbol_file}
775                       WORKING_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR}
776                       DEPENDS ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py ${static_libs}
777                       VERBATIM
778                       COMMENT "Generating export list for ${target}")
779    add_llvm_symbol_exports( ${target} ${exported_symbol_file} )
780    # If something links against this executable then we want a
781    # transitive link against only the libraries whose symbols
782    # we aren't exporting.
783    set_target_properties(${target} PROPERTIES INTERFACE_LINK_LIBRARIES "${other_libs}")
784    # The default import library suffix that cmake uses for cygwin/mingw is
785    # ".dll.a", but for clang.exe that causes a collision with libclang.dll,
786    # where the import libraries of both get named libclang.dll.a. Use a suffix
787    # of ".exe.a" to avoid this.
788    if(CYGWIN OR MINGW)
789      set_target_properties(${target} PROPERTIES IMPORT_SUFFIX ".exe.a")
790    endif()
791  elseif(NOT (WIN32 OR CYGWIN))
792    # On Windows auto-exporting everything doesn't work because of the limit on
793    # the size of the exported symbol table, but on other platforms we can do
794    # it without any trouble.
795    set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
796    if (APPLE)
797      set_property(TARGET ${target} APPEND_STRING PROPERTY
798        LINK_FLAGS " -rdynamic")
799    endif()
800  endif()
801endfunction()
802
803if(NOT LLVM_TOOLCHAIN_TOOLS)
804  set (LLVM_TOOLCHAIN_TOOLS
805    llvm-ar
806    llvm-ranlib
807    llvm-lib
808    llvm-objdump
809    )
810endif()
811
812macro(add_llvm_tool name)
813  if( NOT LLVM_BUILD_TOOLS )
814    set(EXCLUDE_FROM_ALL ON)
815  endif()
816  add_llvm_executable(${name} ${ARGN})
817
818  if ( ${name} IN_LIST LLVM_TOOLCHAIN_TOOLS OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
819    if( LLVM_BUILD_TOOLS )
820      if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
821          NOT LLVM_DISTRIBUTION_COMPONENTS)
822        set(export_to_llvmexports EXPORT LLVMExports)
823        set_property(GLOBAL PROPERTY LLVM_HAS_EXPORTS True)
824      endif()
825
826      install(TARGETS ${name}
827              ${export_to_llvmexports}
828              RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR}
829              COMPONENT ${name})
830
831      if (NOT CMAKE_CONFIGURATION_TYPES)
832        add_custom_target(install-${name}
833                          DEPENDS ${name}
834                          COMMAND "${CMAKE_COMMAND}"
835                                  -DCMAKE_INSTALL_COMPONENT=${name}
836                                  -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
837      endif()
838    endif()
839  endif()
840  if( LLVM_BUILD_TOOLS )
841    set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
842  endif()
843  set_target_properties(${name} PROPERTIES FOLDER "Tools")
844endmacro(add_llvm_tool name)
845
846
847macro(add_llvm_example name)
848  if( NOT LLVM_BUILD_EXAMPLES )
849    set(EXCLUDE_FROM_ALL ON)
850  endif()
851  add_llvm_executable(${name} ${ARGN})
852  if( LLVM_BUILD_EXAMPLES )
853    install(TARGETS ${name} RUNTIME DESTINATION examples)
854  endif()
855  set_target_properties(${name} PROPERTIES FOLDER "Examples")
856endmacro(add_llvm_example name)
857
858# This is a macro that is used to create targets for executables that are needed
859# for development, but that are not intended to be installed by default.
860macro(add_llvm_utility name)
861  if ( NOT LLVM_BUILD_UTILS )
862    set(EXCLUDE_FROM_ALL ON)
863  endif()
864
865  add_llvm_executable(${name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN})
866  set_target_properties(${name} PROPERTIES FOLDER "Utils")
867  if( LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS )
868    install (TARGETS ${name}
869      RUNTIME DESTINATION bin
870      COMPONENT ${name})
871    if (NOT CMAKE_CONFIGURATION_TYPES)
872      add_custom_target(install-${name}
873                        DEPENDS ${name}
874                        COMMAND "${CMAKE_COMMAND}"
875                                -DCMAKE_INSTALL_COMPONENT=${name}
876                                -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
877    endif()
878  endif()
879endmacro(add_llvm_utility name)
880
881
882macro(add_llvm_target target_name)
883  include_directories(BEFORE
884    ${CMAKE_CURRENT_BINARY_DIR}
885    ${CMAKE_CURRENT_SOURCE_DIR})
886  add_llvm_library(LLVM${target_name} ${ARGN})
887  set( CURRENT_LLVM_TARGET LLVM${target_name} )
888endmacro(add_llvm_target)
889
890function(canonicalize_tool_name name output)
891  string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" nameStrip ${name})
892  string(REPLACE "-" "_" nameUNDERSCORE ${nameStrip})
893  string(TOUPPER ${nameUNDERSCORE} nameUPPER)
894  set(${output} "${nameUPPER}" PARENT_SCOPE)
895endfunction(canonicalize_tool_name)
896
897# Custom add_subdirectory wrapper
898# Takes in a project name (i.e. LLVM), the subdirectory name, and an optional
899# path if it differs from the name.
900macro(add_llvm_subdirectory project type name)
901  set(add_llvm_external_dir "${ARGN}")
902  if("${add_llvm_external_dir}" STREQUAL "")
903    set(add_llvm_external_dir ${name})
904  endif()
905  canonicalize_tool_name(${name} nameUPPER)
906  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}/CMakeLists.txt)
907    # Treat it as in-tree subproject.
908    option(${project}_${type}_${nameUPPER}_BUILD
909           "Whether to build ${name} as part of ${project}" On)
910    mark_as_advanced(${project}_${type}_${name}_BUILD)
911    if(${project}_${type}_${nameUPPER}_BUILD)
912      add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir} ${add_llvm_external_dir})
913      # Don't process it in add_llvm_implicit_projects().
914      set(${project}_${type}_${nameUPPER}_BUILD OFF)
915    endif()
916  else()
917    set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR
918      "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}"
919      CACHE PATH "Path to ${name} source directory")
920    set(${project}_${type}_${nameUPPER}_BUILD_DEFAULT ON)
921    if(NOT LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR OR NOT EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR})
922      set(${project}_${type}_${nameUPPER}_BUILD_DEFAULT OFF)
923    endif()
924    if("${LLVM_EXTERNAL_${nameUPPER}_BUILD}" STREQUAL "OFF")
925      set(${project}_${type}_${nameUPPER}_BUILD_DEFAULT OFF)
926    endif()
927    option(${project}_${type}_${nameUPPER}_BUILD
928      "Whether to build ${name} as part of LLVM"
929      ${${project}_${type}_${nameUPPER}_BUILD_DEFAULT})
930    if (${project}_${type}_${nameUPPER}_BUILD)
931      if(EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR})
932        add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir})
933      elseif(NOT "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}" STREQUAL "")
934        message(WARNING "Nonexistent directory for ${name}: ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}")
935      endif()
936      # FIXME: It'd be redundant.
937      set(${project}_${type}_${nameUPPER}_BUILD Off)
938    endif()
939  endif()
940endmacro()
941
942# Add external project that may want to be built as part of llvm such as Clang,
943# lld, and Polly. This adds two options. One for the source directory of the
944# project, which defaults to ${CMAKE_CURRENT_SOURCE_DIR}/${name}. Another to
945# enable or disable building it with everything else.
946# Additional parameter can be specified as the name of directory.
947macro(add_llvm_external_project name)
948  add_llvm_subdirectory(LLVM TOOL ${name} ${ARGN})
949endmacro()
950
951macro(add_llvm_tool_subdirectory name)
952  add_llvm_external_project(${name})
953endmacro(add_llvm_tool_subdirectory)
954
955function(get_project_name_from_src_var var output)
956  string(REGEX MATCH "LLVM_EXTERNAL_(.*)_SOURCE_DIR"
957         MACHED_TOOL "${var}")
958  if(MACHED_TOOL)
959    set(${output} ${CMAKE_MATCH_1} PARENT_SCOPE)
960  else()
961    set(${output} PARENT_SCOPE)
962  endif()
963endfunction()
964
965function(create_subdirectory_options project type)
966  file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
967  foreach(dir ${sub-dirs})
968    if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt")
969      canonicalize_tool_name(${dir} name)
970      option(${project}_${type}_${name}_BUILD
971           "Whether to build ${name} as part of ${project}" On)
972      mark_as_advanced(${project}_${type}_${name}_BUILD)
973    endif()
974  endforeach()
975endfunction(create_subdirectory_options)
976
977function(create_llvm_tool_options)
978  create_subdirectory_options(LLVM TOOL)
979endfunction(create_llvm_tool_options)
980
981function(llvm_add_implicit_projects project)
982  set(list_of_implicit_subdirs "")
983  file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
984  foreach(dir ${sub-dirs})
985    if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt")
986      canonicalize_tool_name(${dir} name)
987      if (${project}_TOOL_${name}_BUILD)
988        get_filename_component(fn "${dir}" NAME)
989        list(APPEND list_of_implicit_subdirs "${fn}")
990      endif()
991    endif()
992  endforeach()
993
994  foreach(external_proj ${list_of_implicit_subdirs})
995    add_llvm_subdirectory(${project} TOOL "${external_proj}" ${ARGN})
996  endforeach()
997endfunction(llvm_add_implicit_projects)
998
999function(add_llvm_implicit_projects)
1000  llvm_add_implicit_projects(LLVM)
1001endfunction(add_llvm_implicit_projects)
1002
1003# Generic support for adding a unittest.
1004function(add_unittest test_suite test_name)
1005  if( NOT LLVM_BUILD_TESTS )
1006    set(EXCLUDE_FROM_ALL ON)
1007  endif()
1008
1009  include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
1010  include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include)
1011  if (NOT LLVM_ENABLE_THREADS)
1012    list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0)
1013  endif ()
1014
1015  if (SUPPORTS_VARIADIC_MACROS_FLAG)
1016    list(APPEND LLVM_COMPILE_FLAGS "-Wno-variadic-macros")
1017  endif ()
1018  # Some parts of gtest rely on this GNU extension, don't warn on it.
1019  if(SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
1020    list(APPEND LLVM_COMPILE_FLAGS "-Wno-gnu-zero-variadic-macro-arguments")
1021  endif()
1022
1023  set(LLVM_REQUIRES_RTTI OFF)
1024
1025  list(APPEND LLVM_LINK_COMPONENTS Support) # gtest needs it for raw_ostream
1026  add_llvm_executable(${test_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${ARGN})
1027  set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
1028  set_output_directory(${test_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir})
1029  # libpthreads overrides some standard library symbols, so main
1030  # executable must be linked with it in order to provide consistent
1031  # API for all shared libaries loaded by this executable.
1032  target_link_libraries(${test_name} gtest_main gtest ${PTHREAD_LIB})
1033
1034  add_dependencies(${test_suite} ${test_name})
1035  get_target_property(test_suite_folder ${test_suite} FOLDER)
1036  if (NOT ${test_suite_folder} STREQUAL "NOTFOUND")
1037    set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}")
1038  endif ()
1039endfunction()
1040
1041function(llvm_add_go_executable binary pkgpath)
1042  cmake_parse_arguments(ARG "ALL" "" "DEPENDS;GOFLAGS" ${ARGN})
1043
1044  if(LLVM_BINDINGS MATCHES "go")
1045    # FIXME: This should depend only on the libraries Go needs.
1046    get_property(llvmlibs GLOBAL PROPERTY LLVM_LIBS)
1047    set(binpath ${CMAKE_BINARY_DIR}/bin/${binary}${CMAKE_EXECUTABLE_SUFFIX})
1048    set(cc "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
1049    set(cxx "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
1050    set(cppflags "")
1051    get_property(include_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
1052    foreach(d ${include_dirs})
1053      set(cppflags "${cppflags} -I${d}")
1054    endforeach(d)
1055    set(ldflags "${CMAKE_EXE_LINKER_FLAGS}")
1056    add_custom_command(OUTPUT ${binpath}
1057      COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "go=${GO_EXECUTABLE}" "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}" "packages=${LLVM_GO_PACKAGES}"
1058              ${ARG_GOFLAGS} build -o ${binpath} ${pkgpath}
1059      DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX}
1060              ${llvmlibs} ${ARG_DEPENDS}
1061      COMMENT "Building Go executable ${binary}"
1062      VERBATIM)
1063    if (ARG_ALL)
1064      add_custom_target(${binary} ALL DEPENDS ${binpath})
1065    else()
1066      add_custom_target(${binary} DEPENDS ${binpath})
1067    endif()
1068  endif()
1069endfunction()
1070
1071# This function canonicalize the CMake variables passed by names
1072# from CMake boolean to 0/1 suitable for passing into Python or C++,
1073# in place.
1074function(llvm_canonicalize_cmake_booleans)
1075  foreach(var ${ARGN})
1076    if(${var})
1077      set(${var} 1 PARENT_SCOPE)
1078    else()
1079      set(${var} 0 PARENT_SCOPE)
1080    endif()
1081  endforeach()
1082endfunction(llvm_canonicalize_cmake_booleans)
1083
1084# This function provides an automatic way to 'configure'-like generate a file
1085# based on a set of common and custom variables, specifically targeting the
1086# variables needed for the 'lit.site.cfg' files. This function bundles the
1087# common variables that any Lit instance is likely to need, and custom
1088# variables can be passed in.
1089function(configure_lit_site_cfg input output)
1090  foreach(c ${LLVM_TARGETS_TO_BUILD})
1091    set(TARGETS_BUILT "${TARGETS_BUILT} ${c}")
1092  endforeach(c)
1093  set(TARGETS_TO_BUILD ${TARGETS_BUILT})
1094
1095  set(SHLIBEXT "${LTDL_SHLIB_EXT}")
1096
1097  # Configuration-time: See Unit/lit.site.cfg.in
1098  if (CMAKE_CFG_INTDIR STREQUAL ".")
1099    set(LLVM_BUILD_MODE ".")
1100  else ()
1101    set(LLVM_BUILD_MODE "%(build_mode)s")
1102  endif ()
1103
1104  # They below might not be the build tree but provided binary tree.
1105  set(LLVM_SOURCE_DIR ${LLVM_MAIN_SRC_DIR})
1106  set(LLVM_BINARY_DIR ${LLVM_BINARY_DIR})
1107  string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_TOOLS_DIR ${LLVM_TOOLS_BINARY_DIR})
1108  string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_LIBS_DIR  ${LLVM_LIBRARY_DIR})
1109
1110  # SHLIBDIR points the build tree.
1111  string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} SHLIBDIR "${LLVM_SHLIB_OUTPUT_INTDIR}")
1112
1113  set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
1114  # FIXME: "ENABLE_SHARED" doesn't make sense, since it is used just for
1115  # plugins. We may rename it.
1116  if(LLVM_ENABLE_PLUGINS)
1117    set(ENABLE_SHARED "1")
1118  else()
1119    set(ENABLE_SHARED "0")
1120  endif()
1121
1122  if(LLVM_ENABLE_ASSERTIONS AND NOT MSVC_IDE)
1123    set(ENABLE_ASSERTIONS "1")
1124  else()
1125    set(ENABLE_ASSERTIONS "0")
1126  endif()
1127
1128  set(HOST_OS ${CMAKE_SYSTEM_NAME})
1129  set(HOST_ARCH ${CMAKE_SYSTEM_PROCESSOR})
1130
1131  set(HOST_CC "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
1132  set(HOST_CXX "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
1133  set(HOST_LDFLAGS "${CMAKE_EXE_LINKER_FLAGS}")
1134
1135  set(LIT_SITE_CFG_IN_HEADER  "## Autogenerated from ${input}\n## Do not edit!")
1136
1137  configure_file(${input} ${output} @ONLY)
1138endfunction()
1139
1140# A raw function to create a lit target. This is used to implement the testuite
1141# management functions.
1142function(add_lit_target target comment)
1143  cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN})
1144  set(LIT_ARGS "${ARG_ARGS} ${LLVM_LIT_ARGS}")
1145  separate_arguments(LIT_ARGS)
1146  if (NOT CMAKE_CFG_INTDIR STREQUAL ".")
1147    list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR})
1148  endif ()
1149  if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
1150    # reset cache after erraneous r283029
1151    # TODO: remove this once all buildbots run
1152    if (LIT_COMMAND STREQUAL "${PYTHON_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py")
1153      unset(LIT_COMMAND CACHE)
1154    endif()
1155    set (LIT_COMMAND "${PYTHON_EXECUTABLE};${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py"
1156         CACHE STRING "Command used to spawn llvm-lit")
1157  else()
1158    find_program(LIT_COMMAND NAMES llvm-lit lit.py lit)
1159  endif ()
1160  list(APPEND LIT_COMMAND ${LIT_ARGS})
1161  foreach(param ${ARG_PARAMS})
1162    list(APPEND LIT_COMMAND --param ${param})
1163  endforeach()
1164  if (ARG_UNPARSED_ARGUMENTS)
1165    add_custom_target(${target}
1166      COMMAND ${LIT_COMMAND} ${ARG_UNPARSED_ARGUMENTS}
1167      COMMENT "${comment}"
1168      USES_TERMINAL
1169      )
1170  else()
1171    add_custom_target(${target}
1172      COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, no tools built.")
1173    message(STATUS "${target} does nothing.")
1174  endif()
1175  if (ARG_DEPENDS)
1176    add_dependencies(${target} ${ARG_DEPENDS})
1177  endif()
1178
1179  # Tests should be excluded from "Build Solution".
1180  set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON)
1181endfunction()
1182
1183# A function to add a set of lit test suites to be driven through 'check-*' targets.
1184function(add_lit_testsuite target comment)
1185  cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN})
1186
1187  # EXCLUDE_FROM_ALL excludes the test ${target} out of check-all.
1188  if(NOT EXCLUDE_FROM_ALL)
1189    # Register the testsuites, params and depends for the global check rule.
1190    set_property(GLOBAL APPEND PROPERTY LLVM_LIT_TESTSUITES ${ARG_UNPARSED_ARGUMENTS})
1191    set_property(GLOBAL APPEND PROPERTY LLVM_LIT_PARAMS ${ARG_PARAMS})
1192    set_property(GLOBAL APPEND PROPERTY LLVM_LIT_DEPENDS ${ARG_DEPENDS})
1193    set_property(GLOBAL APPEND PROPERTY LLVM_LIT_EXTRA_ARGS ${ARG_ARGS})
1194  endif()
1195
1196  # Produce a specific suffixed check rule.
1197  add_lit_target(${target} ${comment}
1198    ${ARG_UNPARSED_ARGUMENTS}
1199    PARAMS ${ARG_PARAMS}
1200    DEPENDS ${ARG_DEPENDS}
1201    ARGS ${ARG_ARGS}
1202    )
1203endfunction()
1204
1205function(add_lit_testsuites project directory)
1206  if (NOT CMAKE_CONFIGURATION_TYPES)
1207    cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN})
1208
1209    # Search recursively for test directories by assuming anything not
1210    # in a directory called Inputs contains tests.
1211    file(GLOB_RECURSE to_process LIST_DIRECTORIES true ${directory}/*)
1212    foreach(lit_suite ${to_process})
1213      if(NOT IS_DIRECTORY ${lit_suite})
1214        continue()
1215      endif()
1216      string(FIND ${lit_suite} Inputs is_inputs)
1217      string(FIND ${lit_suite} Output is_output)
1218      if (NOT (is_inputs EQUAL -1 AND is_output EQUAL -1))
1219        continue()
1220      endif()
1221
1222      # Create a check- target for the directory.
1223      string(REPLACE ${directory} "" name_slash ${lit_suite})
1224      if (name_slash)
1225        string(REPLACE "/" "-" name_slash ${name_slash})
1226        string(REPLACE "\\" "-" name_dashes ${name_slash})
1227        string(TOLOWER "${project}${name_dashes}" name_var)
1228        add_lit_target("check-${name_var}" "Running lit suite ${lit_suite}"
1229          ${lit_suite}
1230          PARAMS ${ARG_PARAMS}
1231          DEPENDS ${ARG_DEPENDS}
1232          ARGS ${ARG_ARGS}
1233        )
1234      endif()
1235    endforeach()
1236  endif()
1237endfunction()
1238
1239function(llvm_install_library_symlink name dest type)
1240  cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
1241  foreach(path ${CMAKE_MODULE_PATH})
1242    if(EXISTS ${path}/LLVMInstallSymlink.cmake)
1243      set(INSTALL_SYMLINK ${path}/LLVMInstallSymlink.cmake)
1244      break()
1245    endif()
1246  endforeach()
1247
1248  set(component ${ARG_COMPONENT})
1249  if(NOT component)
1250    set(component ${name})
1251  endif()
1252
1253  set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX})
1254  set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX})
1255
1256  set(output_dir lib${LLVM_LIBDIR_SUFFIX})
1257  if(WIN32 AND "${type}" STREQUAL "SHARED")
1258    set(output_dir bin)
1259  endif()
1260
1261  install(SCRIPT ${INSTALL_SYMLINK}
1262          CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
1263          COMPONENT ${component})
1264
1265  if (NOT CMAKE_CONFIGURATION_TYPES AND NOT ARG_ALWAYS_GENERATE)
1266    add_custom_target(install-${name}
1267                      DEPENDS ${name} ${dest} install-${dest}
1268                      COMMAND "${CMAKE_COMMAND}"
1269                              -DCMAKE_INSTALL_COMPONENT=${name}
1270                              -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
1271  endif()
1272endfunction()
1273
1274function(llvm_install_symlink name dest)
1275  cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
1276  foreach(path ${CMAKE_MODULE_PATH})
1277    if(EXISTS ${path}/LLVMInstallSymlink.cmake)
1278      set(INSTALL_SYMLINK ${path}/LLVMInstallSymlink.cmake)
1279      break()
1280    endif()
1281  endforeach()
1282
1283  if(ARG_COMPONENT)
1284    set(component ${ARG_COMPONENT})
1285  else()
1286    if(ARG_ALWAYS_GENERATE)
1287      set(component ${dest})
1288    else()
1289      set(component ${name})
1290    endif()
1291  endif()
1292
1293  set(full_name ${name}${CMAKE_EXECUTABLE_SUFFIX})
1294  set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX})
1295
1296  install(SCRIPT ${INSTALL_SYMLINK}
1297          CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})"
1298          COMPONENT ${component})
1299
1300  if (NOT CMAKE_CONFIGURATION_TYPES AND NOT ARG_ALWAYS_GENERATE)
1301    add_custom_target(install-${name}
1302                      DEPENDS ${name} ${dest} install-${dest}
1303                      COMMAND "${CMAKE_COMMAND}"
1304                              -DCMAKE_INSTALL_COMPONENT=${name}
1305                              -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
1306  endif()
1307endfunction()
1308
1309function(add_llvm_tool_symlink link_name target)
1310  cmake_parse_arguments(ARG "ALWAYS_GENERATE" "OUTPUT_DIR" "" ${ARGN})
1311  set(dest_binary "$<TARGET_FILE:${target}>")
1312
1313  # This got a bit gross... For multi-configuration generators the target
1314  # properties return the resolved value of the string, not the build system
1315  # expression. To reconstruct the platform-agnostic path we have to do some
1316  # magic. First we grab one of the types, and a type-specific path. Then from
1317  # the type-specific path we find the last occurrence of the type in the path,
1318  # and replace it with CMAKE_CFG_INTDIR. This allows the build step to be type
1319  # agnostic again.
1320  if(NOT ARG_OUTPUT_DIR)
1321    # If you're not overriding the OUTPUT_DIR, we can make the link relative in
1322    # the same directory.
1323    if(UNIX)
1324      set(dest_binary "$<TARGET_FILE_NAME:${target}>")
1325    endif()
1326    if(CMAKE_CONFIGURATION_TYPES)
1327      list(GET CMAKE_CONFIGURATION_TYPES 0 first_type)
1328      string(TOUPPER ${first_type} first_type_upper)
1329      set(first_type_suffix _${first_type_upper})
1330    endif()
1331    get_target_property(target_type ${target} TYPE)
1332    if(${target_type} STREQUAL "STATIC_LIBRARY")
1333      get_target_property(ARG_OUTPUT_DIR ${target} ARCHIVE_OUTPUT_DIRECTORY${first_type_suffix})
1334    elseif(UNIX AND ${target_type} STREQUAL "SHARED_LIBRARY")
1335      get_target_property(ARG_OUTPUT_DIR ${target} LIBRARY_OUTPUT_DIRECTORY${first_type_suffix})
1336    else()
1337      get_target_property(ARG_OUTPUT_DIR ${target} RUNTIME_OUTPUT_DIRECTORY${first_type_suffix})
1338    endif()
1339    if(CMAKE_CONFIGURATION_TYPES)
1340      string(FIND "${ARG_OUTPUT_DIR}" "/${first_type}/" type_start REVERSE)
1341      string(SUBSTRING "${ARG_OUTPUT_DIR}" 0 ${type_start} path_prefix)
1342      string(SUBSTRING "${ARG_OUTPUT_DIR}" ${type_start} -1 path_suffix)
1343      string(REPLACE "/${first_type}/" "/${CMAKE_CFG_INTDIR}/"
1344             path_suffix ${path_suffix})
1345      set(ARG_OUTPUT_DIR ${path_prefix}${path_suffix})
1346    endif()
1347  endif()
1348
1349  if(UNIX)
1350    set(LLVM_LINK_OR_COPY create_symlink)
1351  else()
1352    set(LLVM_LINK_OR_COPY copy)
1353  endif()
1354
1355  set(output_path "${ARG_OUTPUT_DIR}/${link_name}${CMAKE_EXECUTABLE_SUFFIX}")
1356
1357  set(target_name ${link_name})
1358  if(TARGET ${link_name})
1359    set(target_name ${link_name}-link)
1360  endif()
1361
1362
1363  if(ARG_ALWAYS_GENERATE)
1364    set_property(DIRECTORY APPEND PROPERTY
1365      ADDITIONAL_MAKE_CLEAN_FILES ${dest_binary})
1366    add_custom_command(TARGET ${target} POST_BUILD
1367      COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${dest_binary}" "${output_path}")
1368  else()
1369    add_custom_command(OUTPUT ${output_path}
1370                     COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${dest_binary}" "${output_path}"
1371                     DEPENDS ${target})
1372    add_custom_target(${target_name} ALL DEPENDS ${target} ${output_path})
1373    set_target_properties(${target_name} PROPERTIES FOLDER Tools)
1374
1375    # Make sure both the link and target are toolchain tools
1376    if (${link_name} IN_LIST LLVM_TOOLCHAIN_TOOLS AND ${target} IN_LIST LLVM_TOOLCHAIN_TOOLS)
1377      set(TOOL_IS_TOOLCHAIN ON)
1378    endif()
1379
1380    if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS)
1381      llvm_install_symlink(${link_name} ${target})
1382    endif()
1383  endif()
1384endfunction()
1385
1386function(llvm_externalize_debuginfo name)
1387  if(NOT LLVM_EXTERNALIZE_DEBUGINFO)
1388    return()
1389  endif()
1390
1391  if(NOT LLVM_EXTERNALIZE_DEBUGINFO_SKIP_STRIP)
1392    set(strip_command COMMAND xcrun strip -Sxl $<TARGET_FILE:${name}>)
1393  endif()
1394
1395  if(APPLE)
1396    if(CMAKE_CXX_FLAGS MATCHES "-flto"
1397      OR CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} MATCHES "-flto")
1398
1399      set(lto_object ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${name}-lto.o)
1400      set_property(TARGET ${name} APPEND_STRING PROPERTY
1401        LINK_FLAGS " -Wl,-object_path_lto,${lto_object}")
1402    endif()
1403    add_custom_command(TARGET ${name} POST_BUILD
1404      COMMAND xcrun dsymutil $<TARGET_FILE:${name}>
1405      ${strip_command}
1406      )
1407  else()
1408    message(FATAL_ERROR "LLVM_EXTERNALIZE_DEBUGINFO isn't implemented for non-darwin platforms!")
1409  endif()
1410endfunction()
1411
1412function(llvm_setup_rpath name)
1413  if(CMAKE_INSTALL_RPATH)
1414    return()
1415  endif()
1416
1417  if(LLVM_INSTALL_PREFIX AND NOT (LLVM_INSTALL_PREFIX STREQUAL CMAKE_INSTALL_PREFIX))
1418    set(extra_libdir ${LLVM_LIBRARY_DIR})
1419  elseif(LLVM_BUILD_LIBRARY_DIR)
1420    set(extra_libdir ${LLVM_LIBRARY_DIR})
1421  endif()
1422
1423  if (APPLE)
1424    set(_install_name_dir INSTALL_NAME_DIR "@rpath")
1425    set(_install_rpath "@loader_path/../lib" ${extra_libdir})
1426  elseif(UNIX)
1427    set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
1428    if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
1429      set_property(TARGET ${name} APPEND_STRING PROPERTY
1430                   LINK_FLAGS " -Wl,-z,origin ")
1431    elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND NOT LLVM_LINKER_IS_GOLD)
1432      # $ORIGIN is not interpreted at link time by ld.bfd
1433      set_property(TARGET ${name} APPEND_STRING PROPERTY
1434                   LINK_FLAGS " -Wl,-rpath-link,${LLVM_LIBRARY_OUTPUT_INTDIR} ")
1435    endif()
1436  else()
1437    return()
1438  endif()
1439
1440  set_target_properties(${name} PROPERTIES
1441                        BUILD_WITH_INSTALL_RPATH On
1442                        INSTALL_RPATH "${_install_rpath}"
1443                        ${_install_name_dir})
1444endfunction()
1445
1446function(setup_dependency_debugging name)
1447  if(NOT LLVM_DEPENDENCY_DEBUGGING)
1448    return()
1449  endif()
1450
1451  if("intrinsics_gen" IN_LIST ARGN)
1452    return()
1453  endif()
1454
1455  set(deny_attributes_gen "(deny file* (literal \"${LLVM_BINARY_DIR}/include/llvm/IR/Attributes.gen\"))")
1456  set(deny_intrinsics_gen "(deny file* (literal \"${LLVM_BINARY_DIR}/include/llvm/IR/Intrinsics.gen\"))")
1457
1458  set(sandbox_command "sandbox-exec -p '(version 1) (allow default) ${deny_attributes_gen} ${deny_intrinsics_gen}'")
1459  set_target_properties(${name} PROPERTIES RULE_LAUNCH_COMPILE ${sandbox_command})
1460endfunction()
1461