1 include(LLVMParseArguments)
2 include(LLVMProcessSources)
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
12 # targets can use to 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)
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 if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI))
30 list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0)
31 if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
32 list(APPEND LLVM_COMPILE_FLAGS "-fno-rtti")
34 list(APPEND LLVM_COMPILE_FLAGS "/GR-")
39 # - LLVM_COMPILE_FLAGS is list.
40 # - PROPERTY COMPILE_FLAGS is string.
41 string(REPLACE ";" " " target_compile_flags "${LLVM_COMPILE_FLAGS}")
44 foreach(fn ${sources})
45 get_filename_component(suf ${fn} EXT)
46 if("${suf}" STREQUAL ".cpp")
47 set_property(SOURCE ${fn} APPEND_STRING PROPERTY
48 COMPILE_FLAGS "${target_compile_flags}")
52 # Update target props, since all sources are C++.
53 set_property(TARGET ${name} APPEND_STRING PROPERTY
54 COMPILE_FLAGS "${target_compile_flags}")
57 set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS ${LLVM_COMPILE_DEFINITIONS})
60 function(add_llvm_symbol_exports target_name export_file)
61 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
62 set(native_export_file "${target_name}.exports")
63 add_custom_command(OUTPUT ${native_export_file}
64 COMMAND sed -e "s/^/_/" < ${export_file} > ${native_export_file}
65 DEPENDS ${export_file}
67 COMMENT "Creating export file for ${target_name}")
68 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
69 LINK_FLAGS " -Wl,-exported_symbols_list,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
70 elseif(LLVM_HAVE_LINK_VERSION_SCRIPT)
71 # Gold and BFD ld require a version script rather than a plain list.
72 set(native_export_file "${target_name}.exports")
73 # FIXME: Don't write the "local:" line on OpenBSD.
74 add_custom_command(OUTPUT ${native_export_file}
75 COMMAND echo "{" > ${native_export_file}
76 COMMAND grep -q "[[:alnum:]]" ${export_file} && echo " global:" >> ${native_export_file} || :
77 COMMAND sed -e "s/$/;/" -e "s/^/ /" < ${export_file} >> ${native_export_file}
78 COMMAND echo " local: *;" >> ${native_export_file}
79 COMMAND echo "};" >> ${native_export_file}
80 DEPENDS ${export_file}
82 COMMENT "Creating export file for ${target_name}")
83 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
84 LINK_FLAGS " -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
86 set(native_export_file "${target_name}.def")
89 set(export_file_nativeslashes ${export_file})
90 if(WIN32 AND NOT CYGWIN)
92 # Convert ${export_file} to native format (backslashes) for "type"
93 # Does not use file(TO_NATIVE_PATH) as it doesn't create a native
94 # path but a build-system specific format (see CMake bug
95 # http://public.kitware.com/Bug/print_bug_page.php?bug_id=5939 )
96 string(REPLACE / \\ export_file_nativeslashes ${export_file})
99 add_custom_command(OUTPUT ${native_export_file}
100 COMMAND ${CMAKE_COMMAND} -E echo "EXPORTS" > ${native_export_file}
101 COMMAND ${CAT} ${export_file_nativeslashes} >> ${native_export_file}
102 DEPENDS ${export_file}
104 COMMENT "Creating export file for ${target_name}")
105 set(export_file_linker_flag "${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
107 set(export_file_linker_flag "/DEF:${export_file_linker_flag}")
109 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
110 LINK_FLAGS " ${export_file_linker_flag}")
113 add_custom_target(${target_name}_exports DEPENDS ${native_export_file})
114 set_target_properties(${target_name}_exports PROPERTIES FOLDER "Misc")
116 get_property(srcs TARGET ${target_name} PROPERTY SOURCES)
118 get_filename_component(extension ${src} EXT)
119 if(extension STREQUAL ".cpp")
120 set(first_source_file ${src})
125 # Force re-linking when the exports file changes. Actually, it
126 # forces recompilation of the source file. The LINK_DEPENDS target
127 # property only works for makefile-based generators.
128 # FIXME: This is not safe because this will create the same target
129 # ${native_export_file} in several different file:
130 # - One where we emitted ${target_name}_exports
131 # - One where we emitted the build command for the following object.
132 # set_property(SOURCE ${first_source_file} APPEND PROPERTY
133 # OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${native_export_file})
135 set_property(DIRECTORY APPEND
136 PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${native_export_file})
138 add_dependencies(${target_name} ${target_name}_exports)
140 # Add dependency to *_exports later -- CMake issue 14747
141 list(APPEND LLVM_COMMON_DEPENDS ${target_name}_exports)
142 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)
143 endfunction(add_llvm_symbol_exports)
145 function(add_link_opts target_name)
146 # Pass -O3 to the linker. This enabled different optimizations on different
148 if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32))
149 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
150 LINK_FLAGS " -Wl,-O3")
153 if(NOT LLVM_NO_DEAD_STRIP)
154 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
155 # ld64's implementation of -dead_strip breaks tools that use plugins.
156 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
157 LINK_FLAGS " -Wl,-dead_strip")
159 # Object files are compiled with -ffunction-data-sections.
160 # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks
161 # tools that use plugins. Always pass --gc-sections once we require
163 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
164 LINK_FLAGS " -Wl,--gc-sections")
167 endfunction(add_link_opts)
169 # Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}.
170 # Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more,
171 # or a certain builder, for eaxample, msbuild.exe, would be confused.
172 function(set_output_directory target bindir libdir)
173 # Do nothing if *_OUTPUT_INTDIR is empty.
174 if("${bindir}" STREQUAL "")
178 # moddir -- corresponding to LIBRARY_OUTPUT_DIRECTORY.
179 # It affects output of add_library(MODULE).
182 set(moddir ${bindir})
184 set(moddir ${libdir})
186 if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
187 foreach(build_mode ${CMAKE_CONFIGURATION_TYPES})
188 string(TOUPPER "${build_mode}" CONFIG_SUFFIX)
189 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} bi ${bindir})
190 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} li ${libdir})
191 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} mi ${moddir})
192 set_target_properties(${target} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${bi})
193 set_target_properties(${target} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li})
194 set_target_properties(${target} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${mi})
197 set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${bindir})
198 set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${libdir})
199 set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${moddir})
203 # llvm_add_library(name sources...
205 # STATIC by default w/o BUILD_SHARED_LIBS.
206 # SHARED by default w/ BUILD_SHARED_LIBS.
208 # Target ${name} might not be created on unsupported platforms.
209 # Check with "if(TARGET ${name})".
211 # Corresponds to OUTPUT_NAME in target properties.
213 # Same semantics as add_dependencies().
214 # LINK_COMPONENTS components...
215 # Same as the variable LLVM_LINK_COMPONENTS.
216 # LINK_LIBS lib_targets...
217 # Same semantics as target_link_libraries().
219 # May specify header files for IDE generators.
221 function(llvm_add_library name)
222 cmake_parse_arguments(ARG
223 "MODULE;SHARED;STATIC"
225 "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS"
227 list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
228 if(ARG_ADDITIONAL_HEADERS)
229 # Pass through ADDITIONAL_HEADERS.
230 set(ARG_ADDITIONAL_HEADERS ADDITIONAL_HEADERS ${ARG_ADDITIONAL_HEADERS})
233 set(ALL_FILES ${ARG_OBJLIBS})
235 llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS})
239 if(ARG_SHARED OR ARG_STATIC)
240 message(WARNING "MODULE with SHARED|STATIC doesn't make sense.")
242 if(NOT LLVM_ENABLE_PLUGINS)
243 message(STATUS "${name} ignored -- Loadable modules not supported on this platform.")
247 if(BUILD_SHARED_LIBS AND NOT ARG_STATIC)
256 if(ARG_SHARED AND ARG_STATIC)
257 # Generate an obj library for both targets.
258 set(obj_name "obj.${name}")
259 add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL
262 llvm_update_compile_flags(${obj_name})
263 set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>")
265 # Do add_dependencies(obj) later due to CMake issue 14747.
266 list(APPEND objlibs ${obj_name})
268 set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
271 if(ARG_SHARED AND ARG_STATIC)
273 set(name_static "${name}_static")
275 set(output_name OUTPUT_NAME "${ARG_OUTPUT_NAME}")
277 # DEPENDS has been appended to LLVM_COMMON_LIBS.
278 llvm_add_library(${name_static} STATIC
280 OBJLIBS ${ALL_FILES} # objlib
281 LINK_LIBS ${ARG_LINK_LIBS}
282 LINK_COMPONENTS ${ARG_LINK_COMPONENTS}
284 # FIXME: Add name_static to anywhere in TARGET ${name}'s PROPERTY.
289 add_library(${name} MODULE ${ALL_FILES})
291 add_library(${name} SHARED ${ALL_FILES})
293 add_library(${name} STATIC ${ALL_FILES})
295 set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR})
296 llvm_update_compile_flags(${name})
297 add_link_opts( ${name} )
299 set_target_properties(${name}
301 OUTPUT_NAME ${ARG_OUTPUT_NAME}
306 set_target_properties(${name} PROPERTIES
308 SUFFIX ${LLVM_PLUGIN_EXT}
314 set_target_properties(${name} PROPERTIES
319 set_target_properties(${name}
321 IMPORT_SUFFIX ".imp")
325 if(ARG_MODULE OR ARG_SHARED)
326 # Do not add -Dname_EXPORTS to the command-line when building files in this
327 # target. Doing so is actively harmful for the modules build because it
328 # creates extra module variants, and not useful because we don't use these
330 set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
332 if (LLVM_EXPORTED_SYMBOL_FILE)
333 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
337 # Add the explicit dependency information for this library.
339 # It would be nice to verify that we have the dependencies for this library
340 # name, but using get_property(... SET) doesn't suffice to determine if a
341 # property has been set to an empty value.
342 get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
344 llvm_map_components_to_libnames(llvm_libs
345 ${ARG_LINK_COMPONENTS}
346 ${LLVM_LINK_COMPONENTS}
349 if(CMAKE_VERSION VERSION_LESS 2.8.12)
350 # Link libs w/o keywords, assuming PUBLIC.
351 target_link_libraries(${name}
357 target_link_libraries(${name} INTERFACE
362 elseif((CYGWIN OR WIN32) AND ARG_SHARED)
363 # Win32's import library may be unaware of its dependent libs.
364 target_link_libraries(${name} PRIVATE
369 elseif(ARG_SHARED AND BUILD_SHARED_LIBS)
370 # FIXME: It may be PRIVATE since SO knows its dependent libs.
371 target_link_libraries(${name} PUBLIC
378 target_link_libraries(${name} PRIVATE
385 if(LLVM_COMMON_DEPENDS)
386 add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
387 # Add dependencies also to objlibs.
388 # CMake issue 14747 -- add_dependencies() might be ignored to objlib's user.
389 foreach(objlib ${objlibs})
390 add_dependencies(${objlib} ${LLVM_COMMON_DEPENDS})
395 macro(add_llvm_library name)
396 if( BUILD_SHARED_LIBS )
397 llvm_add_library(${name} SHARED ${ARGN})
399 llvm_add_library(${name} ${ARGN})
401 set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
403 if( EXCLUDE_FROM_ALL )
404 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
406 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO")
407 install(TARGETS ${name}
409 RUNTIME DESTINATION bin
410 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
411 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
413 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
415 set_target_properties(${name} PROPERTIES FOLDER "Libraries")
416 endmacro(add_llvm_library name)
418 macro(add_llvm_loadable_module name)
419 llvm_add_library(${name} MODULE ${ARGN})
420 if(NOT TARGET ${name})
421 # Add empty "phony" target
422 add_custom_target(${name})
424 if( EXCLUDE_FROM_ALL )
425 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
427 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
432 set(dlldir "lib${LLVM_LIBDIR_SUFFIX}")
434 install(TARGETS ${name}
436 LIBRARY DESTINATION ${dlldir}
437 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
439 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
443 set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
444 endmacro(add_llvm_loadable_module name)
447 macro(add_llvm_executable name)
448 llvm_process_sources( ALL_FILES ${ARGN} )
449 if( EXCLUDE_FROM_ALL )
450 add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
452 add_executable(${name} ${ALL_FILES})
454 llvm_update_compile_flags(${name})
455 add_link_opts( ${name} )
457 # Do not add -Dname_EXPORTS to the command-line when building files in this
458 # target. Doing so is actively harmful for the modules build because it
459 # creates extra module variants, and not useful because we don't use these
461 set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
463 if (LLVM_EXPORTED_SYMBOL_FILE)
464 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
465 endif(LLVM_EXPORTED_SYMBOL_FILE)
467 set(EXCLUDE_FROM_ALL OFF)
468 set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR})
469 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
470 if( LLVM_COMMON_DEPENDS )
471 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
472 endif( LLVM_COMMON_DEPENDS )
473 endmacro(add_llvm_executable name)
476 set (LLVM_TOOLCHAIN_TOOLS
481 macro(add_llvm_tool name)
482 if( NOT LLVM_BUILD_TOOLS )
483 set(EXCLUDE_FROM_ALL ON)
485 add_llvm_executable(${name} ${ARGN})
487 list(FIND LLVM_TOOLCHAIN_TOOLS ${name} LLVM_IS_${name}_TOOLCHAIN_TOOL)
488 if (LLVM_IS_${name}_TOOLCHAIN_TOOL GREATER -1 OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
489 if( LLVM_BUILD_TOOLS )
490 install(TARGETS ${name}
492 RUNTIME DESTINATION bin)
495 if( LLVM_BUILD_TOOLS )
496 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
498 set_target_properties(${name} PROPERTIES FOLDER "Tools")
499 endmacro(add_llvm_tool name)
502 macro(add_llvm_example name)
503 if( NOT LLVM_BUILD_EXAMPLES )
504 set(EXCLUDE_FROM_ALL ON)
506 add_llvm_executable(${name} ${ARGN})
507 if( LLVM_BUILD_EXAMPLES )
508 install(TARGETS ${name} RUNTIME DESTINATION examples)
510 set_target_properties(${name} PROPERTIES FOLDER "Examples")
511 endmacro(add_llvm_example name)
514 macro(add_llvm_utility name)
515 add_llvm_executable(${name} ${ARGN})
516 set_target_properties(${name} PROPERTIES FOLDER "Utils")
517 endmacro(add_llvm_utility name)
520 macro(add_llvm_target target_name)
521 include_directories(BEFORE
522 ${CMAKE_CURRENT_BINARY_DIR}
523 ${CMAKE_CURRENT_SOURCE_DIR})
524 add_llvm_library(LLVM${target_name} ${ARGN})
525 set( CURRENT_LLVM_TARGET LLVM${target_name} )
526 endmacro(add_llvm_target)
528 # Add external project that may want to be built as part of llvm such as Clang,
529 # lld, and Polly. This adds two options. One for the source directory of the
530 # project, which defaults to ${CMAKE_CURRENT_SOURCE_DIR}/${name}. Another to
531 # enable or disable building it with everything else.
532 # Additional parameter can be specified as the name of directory.
533 macro(add_llvm_external_project name)
534 set(add_llvm_external_dir "${ARGN}")
535 if("${add_llvm_external_dir}" STREQUAL "")
536 set(add_llvm_external_dir ${name})
538 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}")
539 string(REPLACE "-" "_" nameUNDERSCORE ${name})
540 string(TOUPPER ${nameUNDERSCORE} nameUPPER)
541 set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}"
542 CACHE PATH "Path to ${name} source directory")
543 if (NOT ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} STREQUAL ""
544 AND EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}/CMakeLists.txt)
545 option(LLVM_EXTERNAL_${nameUPPER}_BUILD
546 "Whether to build ${name} as part of LLVM" ON)
547 if (LLVM_EXTERNAL_${nameUPPER}_BUILD)
548 add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir})
551 endmacro(add_llvm_external_project)
553 macro(add_llvm_tool_subdirectory name)
554 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
555 add_subdirectory(${name})
556 endmacro(add_llvm_tool_subdirectory)
558 macro(ignore_llvm_tool_subdirectory name)
559 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
560 endmacro(ignore_llvm_tool_subdirectory)
562 function(add_llvm_implicit_external_projects)
563 set(list_of_implicit_subdirs "")
564 file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
565 foreach(dir ${sub-dirs})
566 if(IS_DIRECTORY "${dir}")
567 list(FIND LLVM_IMPLICIT_PROJECT_IGNORE "${dir}" tool_subdir_ignore)
568 if( tool_subdir_ignore EQUAL -1
569 AND EXISTS "${dir}/CMakeLists.txt")
570 get_filename_component(fn "${dir}" NAME)
571 list(APPEND list_of_implicit_subdirs "${fn}")
576 foreach(external_proj ${list_of_implicit_subdirs})
577 add_llvm_external_project("${external_proj}")
579 endfunction(add_llvm_implicit_external_projects)
581 # Generic support for adding a unittest.
582 function(add_unittest test_suite test_name)
583 if( NOT LLVM_BUILD_TESTS )
584 set(EXCLUDE_FROM_ALL ON)
587 # Visual Studio 2012 only supports up to 8 template parameters in
588 # std::tr1::tuple by default, but gtest requires 10
589 if (MSVC AND MSVC_VERSION EQUAL 1700)
590 list(APPEND LLVM_COMPILE_DEFINITIONS _VARIADIC_MAX=10)
593 include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
594 if (NOT LLVM_ENABLE_THREADS)
595 list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0)
598 if (SUPPORTS_NO_VARIADIC_MACROS_FLAG)
599 list(APPEND LLVM_COMPILE_FLAGS "-Wno-variadic-macros")
602 set(LLVM_REQUIRES_RTTI OFF)
604 add_llvm_executable(${test_name} ${ARGN})
605 set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
606 set_output_directory(${test_name} ${outdir} ${outdir})
607 target_link_libraries(${test_name}
610 LLVMSupport # gtest needs it for raw_ostream.
613 add_dependencies(${test_suite} ${test_name})
614 get_target_property(test_suite_folder ${test_suite} FOLDER)
615 if (NOT ${test_suite_folder} STREQUAL "NOTFOUND")
616 set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}")
620 # This function provides an automatic way to 'configure'-like generate a file
621 # based on a set of common and custom variables, specifically targeting the
622 # variables needed for the 'lit.site.cfg' files. This function bundles the
623 # common variables that any Lit instance is likely to need, and custom
624 # variables can be passed in.
625 function(configure_lit_site_cfg input output)
626 foreach(c ${LLVM_TARGETS_TO_BUILD})
627 set(TARGETS_BUILT "${TARGETS_BUILT} ${c}")
629 set(TARGETS_TO_BUILD ${TARGETS_BUILT})
631 set(SHLIBEXT "${LTDL_SHLIB_EXT}")
633 # Configuration-time: See Unit/lit.site.cfg.in
634 if (CMAKE_CFG_INTDIR STREQUAL ".")
635 set(LLVM_BUILD_MODE ".")
637 set(LLVM_BUILD_MODE "%(build_mode)s")
640 # They below might not be the build tree but provided binary tree.
641 set(LLVM_SOURCE_DIR ${LLVM_MAIN_SRC_DIR})
642 set(LLVM_BINARY_DIR ${LLVM_BINARY_DIR})
643 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_TOOLS_DIR ${LLVM_TOOLS_BINARY_DIR})
644 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_LIBS_DIR ${LLVM_LIBRARY_DIR})
646 # SHLIBDIR points the build tree.
647 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} SHLIBDIR "${LLVM_SHLIB_OUTPUT_INTDIR}")
649 set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
650 # FIXME: "ENABLE_SHARED" doesn't make sense, since it is used just for
651 # plugins. We may rename it.
652 if(LLVM_ENABLE_PLUGINS)
653 set(ENABLE_SHARED "1")
655 set(ENABLE_SHARED "0")
658 if(LLVM_ENABLE_ASSERTIONS AND NOT MSVC_IDE)
659 set(ENABLE_ASSERTIONS "1")
661 set(ENABLE_ASSERTIONS "0")
664 set(HOST_OS ${CMAKE_SYSTEM_NAME})
665 set(HOST_ARCH ${CMAKE_SYSTEM_PROCESSOR})
667 set(HOST_CC "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
668 set(HOST_CXX "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
669 set(HOST_LDFLAGS "${CMAKE_EXE_LINKER_FLAGS}")
671 configure_file(${input} ${output} @ONLY)
674 # A raw function to create a lit target. This is used to implement the testuite
675 # management functions.
676 function(add_lit_target target comment)
677 parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN})
678 set(LIT_ARGS "${ARG_ARGS} ${LLVM_LIT_ARGS}")
679 separate_arguments(LIT_ARGS)
680 if (NOT CMAKE_CFG_INTDIR STREQUAL ".")
681 list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR})
683 if (LLVM_MAIN_SRC_DIR)
684 set (LIT_COMMAND ${PYTHON_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
686 find_program(LIT_COMMAND llvm-lit)
688 list(APPEND LIT_COMMAND ${LIT_ARGS})
689 foreach(param ${ARG_PARAMS})
690 list(APPEND LIT_COMMAND --param ${param})
693 add_custom_target(${target}
694 COMMAND ${LIT_COMMAND} ${ARG_DEFAULT_ARGS}
697 add_dependencies(${target} ${ARG_DEPENDS})
699 add_custom_target(${target}
700 COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, no tools built.")
701 message(STATUS "${target} does nothing.")
704 # Tests should be excluded from "Build Solution".
705 set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON)
708 # A function to add a set of lit test suites to be driven through 'check-*' targets.
709 function(add_lit_testsuite target comment)
710 parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN})
712 # EXCLUDE_FROM_ALL excludes the test ${target} out of check-all.
713 if(NOT EXCLUDE_FROM_ALL)
714 # Register the testsuites, params and depends for the global check rule.
715 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_TESTSUITES ${ARG_DEFAULT_ARGS})
716 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_PARAMS ${ARG_PARAMS})
717 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_DEPENDS ${ARG_DEPENDS})
718 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_EXTRA_ARGS ${ARG_ARGS})
721 # Produce a specific suffixed check rule.
722 add_lit_target(${target} ${comment}
725 DEPENDS ${ARG_DEPENDS}