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")
93 # Using ${export_file} in add_custom_command directly confuses cmd.exe.
94 file(TO_NATIVE_PATH ${export_file} export_file_backslashes)
96 add_custom_command(OUTPUT ${native_export_file}
97 COMMAND ${CMAKE_COMMAND} -E echo "EXPORTS" > ${native_export_file}
98 COMMAND ${CAT} ${export_file_backslashes} >> ${native_export_file}
99 DEPENDS ${export_file}
101 COMMENT "Creating export file for ${target_name}")
103 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
104 LINK_FLAGS " ${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
106 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
107 LINK_FLAGS " /DEF:${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
111 add_custom_target(${target_name}_exports DEPENDS ${native_export_file})
112 set_target_properties(${target_name}_exports PROPERTIES FOLDER "Misc")
114 get_property(srcs TARGET ${target_name} PROPERTY SOURCES)
116 get_filename_component(extension ${src} EXT)
117 if(extension STREQUAL ".cpp")
118 set(first_source_file ${src})
123 # Force re-linking when the exports file changes. Actually, it
124 # forces recompilation of the source file. The LINK_DEPENDS target
125 # property only works for makefile-based generators.
126 # FIXME: This is not safe because this will create the same target
127 # ${native_export_file} in several different file:
128 # - One where we emitted ${target_name}_exports
129 # - One where we emitted the build command for the following object.
130 # set_property(SOURCE ${first_source_file} APPEND PROPERTY
131 # OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${native_export_file})
133 set_property(DIRECTORY APPEND
134 PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${native_export_file})
136 add_dependencies(${target_name} ${target_name}_exports)
138 # Add dependency to *_exports later -- CMake issue 14747
139 list(APPEND LLVM_COMMON_DEPENDS ${target_name}_exports)
140 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)
141 endfunction(add_llvm_symbol_exports)
143 function(add_dead_strip target_name)
144 if(NOT LLVM_NO_DEAD_STRIP)
145 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
146 # ld64's implementation of -dead_strip breaks tools that use plugins.
147 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
148 LINK_FLAGS " -Wl,-dead_strip")
150 # Object files are compiled with -ffunction-data-sections.
151 # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks
152 # tools that use plugins. Always pass --gc-sections once we require
154 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
155 LINK_FLAGS " -Wl,--gc-sections")
158 endfunction(add_dead_strip)
160 # Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}.
161 # Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more,
162 # or a certain builder, for eaxample, msbuild.exe, would be confused.
163 function(set_output_directory target bindir libdir)
164 # Do nothing if *_OUTPUT_INTDIR is empty.
165 if("${bindir}" STREQUAL "")
169 # moddir -- corresponding to LIBRARY_OUTPUT_DIRECTORY.
170 # It affects output of add_library(MODULE).
173 set(moddir ${bindir})
175 set(moddir ${libdir})
177 if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
178 foreach(build_mode ${CMAKE_CONFIGURATION_TYPES})
179 string(TOUPPER "${build_mode}" CONFIG_SUFFIX)
180 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} bi ${bindir})
181 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} li ${libdir})
182 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} mi ${moddir})
183 set_target_properties(${target} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${bi})
184 set_target_properties(${target} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li})
185 set_target_properties(${target} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${mi})
188 set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${bindir})
189 set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${libdir})
190 set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${moddir})
194 # llvm_add_library(name sources...
196 # STATIC by default w/o BUILD_SHARED_LIBS.
197 # SHARED by default w/ BUILD_SHARED_LIBS.
199 # Target ${name} might not be created on unsupported platforms.
200 # Check with "if(TARGET ${name})".
202 # Corresponds to OUTPUT_NAME in target properties.
204 # Same semantics as add_dependencies().
205 # LINK_COMPONENTS components...
206 # Same as the variable LLVM_LINK_COMPONENTS.
207 # LINK_LIBS lib_targets...
208 # Same semantics as target_link_libraries().
210 # May specify header files for IDE generators.
212 function(llvm_add_library name)
213 cmake_parse_arguments(ARG
214 "MODULE;SHARED;STATIC"
216 "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS"
218 list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
219 if(ARG_ADDITIONAL_HEADERS)
220 # Pass through ADDITIONAL_HEADERS.
221 set(ARG_ADDITIONAL_HEADERS ADDITIONAL_HEADERS ${ARG_ADDITIONAL_HEADERS})
224 set(ALL_FILES ${ARG_OBJLIBS})
226 llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS})
230 if(ARG_SHARED OR ARG_STATIC)
231 message(WARNING "MODULE with SHARED|STATIC doesn't make sense.")
233 if(NOT LLVM_ENABLE_PLUGINS)
234 message(STATUS "${name} ignored -- Loadable modules not supported on this platform.")
238 if(BUILD_SHARED_LIBS AND NOT ARG_STATIC)
247 if(ARG_SHARED AND ARG_STATIC)
248 # Generate an obj library for both targets.
249 set(obj_name "obj.${name}")
250 add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL
253 llvm_update_compile_flags(${obj_name})
254 set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>")
256 # Do add_dependencies(obj) later due to CMake issue 14747.
257 list(APPEND objlibs ${obj_name})
259 set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
262 if(ARG_SHARED AND ARG_STATIC)
264 set(name_static "${name}_static")
266 set(output_name OUTPUT_NAME "${ARG_OUTPUT_NAME}")
268 # DEPENDS has been appended to LLVM_COMMON_LIBS.
269 llvm_add_library(${name_static} STATIC
271 OBJLIBS ${ALL_FILES} # objlib
272 LINK_LIBS ${ARG_LINK_LIBS}
273 LINK_COMPONENTS ${ARG_LINK_COMPONENTS}
275 # FIXME: Add name_static to anywhere in TARGET ${name}'s PROPERTY.
280 add_library(${name} MODULE ${ALL_FILES})
282 add_library(${name} SHARED ${ALL_FILES})
284 add_library(${name} STATIC ${ALL_FILES})
286 set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR})
287 llvm_update_compile_flags(${name})
288 add_dead_strip( ${name} )
290 set_target_properties(${name}
292 OUTPUT_NAME ${ARG_OUTPUT_NAME}
297 set_target_properties(${name} PROPERTIES
299 SUFFIX ${LLVM_PLUGIN_EXT}
305 set_target_properties(${name} PROPERTIES
310 set_target_properties(${name}
312 IMPORT_SUFFIX ".imp")
316 if(ARG_MODULE OR ARG_SHARED)
317 # Do not add -Dname_EXPORTS to the command-line when building files in this
318 # target. Doing so is actively harmful for the modules build because it
319 # creates extra module variants, and not useful because we don't use these
321 set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
323 if (LLVM_EXPORTED_SYMBOL_FILE)
324 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
328 # Add the explicit dependency information for this library.
330 # It would be nice to verify that we have the dependencies for this library
331 # name, but using get_property(... SET) doesn't suffice to determine if a
332 # property has been set to an empty value.
333 get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
335 llvm_map_components_to_libnames(llvm_libs
336 ${ARG_LINK_COMPONENTS}
337 ${LLVM_LINK_COMPONENTS}
340 if(CMAKE_VERSION VERSION_LESS 2.8.12)
341 # Link libs w/o keywords, assuming PUBLIC.
342 target_link_libraries(${name}
348 target_link_libraries(${name} INTERFACE
353 elseif((CYGWIN OR WIN32) AND ARG_SHARED)
354 # Win32's import library may be unaware of its dependent libs.
355 target_link_libraries(${name} PRIVATE
360 elseif(ARG_SHARED AND BUILD_SHARED_LIBS)
361 # FIXME: It may be PRIVATE since SO knows its dependent libs.
362 target_link_libraries(${name} PUBLIC
369 target_link_libraries(${name} PRIVATE
376 if(LLVM_COMMON_DEPENDS)
377 add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
378 # Add dependencies also to objlibs.
379 # CMake issue 14747 -- add_dependencies() might be ignored to objlib's user.
380 foreach(objlib ${objlibs})
381 add_dependencies(${objlib} ${LLVM_COMMON_DEPENDS})
386 macro(add_llvm_library name)
387 if( BUILD_SHARED_LIBS )
388 llvm_add_library(${name} SHARED ${ARGN})
390 llvm_add_library(${name} ${ARGN})
392 set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
394 if( EXCLUDE_FROM_ALL )
395 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
397 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO")
398 install(TARGETS ${name}
400 RUNTIME DESTINATION bin
401 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
402 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
404 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
406 set_target_properties(${name} PROPERTIES FOLDER "Libraries")
407 endmacro(add_llvm_library name)
409 macro(add_llvm_loadable_module name)
410 llvm_add_library(${name} MODULE ${ARGN})
411 if(NOT TARGET ${name})
412 # Add empty "phony" target
413 add_custom_target(${name})
415 if( EXCLUDE_FROM_ALL )
416 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
418 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
423 set(dlldir "lib${LLVM_LIBDIR_SUFFIX}")
425 install(TARGETS ${name}
427 LIBRARY DESTINATION ${dlldir}
428 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
430 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
434 set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
435 endmacro(add_llvm_loadable_module name)
438 macro(add_llvm_executable name)
439 llvm_process_sources( ALL_FILES ${ARGN} )
440 if( EXCLUDE_FROM_ALL )
441 add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
443 add_executable(${name} ${ALL_FILES})
445 llvm_update_compile_flags(${name})
446 add_dead_strip( ${name} )
448 # Do not add -Dname_EXPORTS to the command-line when building files in this
449 # target. Doing so is actively harmful for the modules build because it
450 # creates extra module variants, and not useful because we don't use these
452 set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
454 if (LLVM_EXPORTED_SYMBOL_FILE)
455 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
456 endif(LLVM_EXPORTED_SYMBOL_FILE)
458 set(EXCLUDE_FROM_ALL OFF)
459 set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR})
460 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
461 if( LLVM_COMMON_DEPENDS )
462 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
463 endif( LLVM_COMMON_DEPENDS )
464 endmacro(add_llvm_executable name)
467 set (LLVM_TOOLCHAIN_TOOLS
472 macro(add_llvm_tool name)
473 if( NOT LLVM_BUILD_TOOLS )
474 set(EXCLUDE_FROM_ALL ON)
476 add_llvm_executable(${name} ${ARGN})
478 list(FIND LLVM_TOOLCHAIN_TOOLS ${name} LLVM_IS_${name}_TOOLCHAIN_TOOL)
479 if (LLVM_IS_${name}_TOOLCHAIN_TOOL GREATER -1 OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
480 if( LLVM_BUILD_TOOLS )
481 install(TARGETS ${name}
483 RUNTIME DESTINATION bin)
486 if( LLVM_BUILD_TOOLS )
487 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
489 set_target_properties(${name} PROPERTIES FOLDER "Tools")
490 endmacro(add_llvm_tool name)
493 macro(add_llvm_example name)
494 if( NOT LLVM_BUILD_EXAMPLES )
495 set(EXCLUDE_FROM_ALL ON)
497 add_llvm_executable(${name} ${ARGN})
498 if( LLVM_BUILD_EXAMPLES )
499 install(TARGETS ${name} RUNTIME DESTINATION examples)
501 set_target_properties(${name} PROPERTIES FOLDER "Examples")
502 endmacro(add_llvm_example name)
505 macro(add_llvm_utility name)
506 add_llvm_executable(${name} ${ARGN})
507 set_target_properties(${name} PROPERTIES FOLDER "Utils")
508 endmacro(add_llvm_utility name)
511 macro(add_llvm_target target_name)
512 include_directories(BEFORE
513 ${CMAKE_CURRENT_BINARY_DIR}
514 ${CMAKE_CURRENT_SOURCE_DIR})
515 add_llvm_library(LLVM${target_name} ${ARGN})
516 set( CURRENT_LLVM_TARGET LLVM${target_name} )
517 endmacro(add_llvm_target)
519 # Add external project that may want to be built as part of llvm such as Clang,
520 # lld, and Polly. This adds two options. One for the source directory of the
521 # project, which defaults to ${CMAKE_CURRENT_SOURCE_DIR}/${name}. Another to
522 # enable or disable building it with everything else.
523 # Additional parameter can be specified as the name of directory.
524 macro(add_llvm_external_project name)
525 set(add_llvm_external_dir "${ARGN}")
526 if("${add_llvm_external_dir}" STREQUAL "")
527 set(add_llvm_external_dir ${name})
529 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}")
530 string(REPLACE "-" "_" nameUNDERSCORE ${name})
531 string(TOUPPER ${nameUNDERSCORE} nameUPPER)
532 set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}"
533 CACHE PATH "Path to ${name} source directory")
534 if (NOT ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} STREQUAL ""
535 AND EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}/CMakeLists.txt)
536 option(LLVM_EXTERNAL_${nameUPPER}_BUILD
537 "Whether to build ${name} as part of LLVM" ON)
538 if (LLVM_EXTERNAL_${nameUPPER}_BUILD)
539 add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir})
542 endmacro(add_llvm_external_project)
544 macro(add_llvm_tool_subdirectory name)
545 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
546 add_subdirectory(${name})
547 endmacro(add_llvm_tool_subdirectory)
549 macro(ignore_llvm_tool_subdirectory name)
550 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
551 endmacro(ignore_llvm_tool_subdirectory)
553 function(add_llvm_implicit_external_projects)
554 set(list_of_implicit_subdirs "")
555 file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
556 foreach(dir ${sub-dirs})
557 if(IS_DIRECTORY "${dir}")
558 list(FIND LLVM_IMPLICIT_PROJECT_IGNORE "${dir}" tool_subdir_ignore)
559 if( tool_subdir_ignore EQUAL -1
560 AND EXISTS "${dir}/CMakeLists.txt")
561 get_filename_component(fn "${dir}" NAME)
562 list(APPEND list_of_implicit_subdirs "${fn}")
567 foreach(external_proj ${list_of_implicit_subdirs})
568 add_llvm_external_project("${external_proj}")
570 endfunction(add_llvm_implicit_external_projects)
572 # Generic support for adding a unittest.
573 function(add_unittest test_suite test_name)
574 if( NOT LLVM_BUILD_TESTS )
575 set(EXCLUDE_FROM_ALL ON)
578 # Visual Studio 2012 only supports up to 8 template parameters in
579 # std::tr1::tuple by default, but gtest requires 10
580 if (MSVC AND MSVC_VERSION EQUAL 1700)
581 list(APPEND LLVM_COMPILE_DEFINITIONS _VARIADIC_MAX=10)
584 include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
585 if (NOT LLVM_ENABLE_THREADS)
586 list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0)
589 if (SUPPORTS_NO_VARIADIC_MACROS_FLAG)
590 list(APPEND LLVM_COMPILE_FLAGS "-Wno-variadic-macros")
593 set(LLVM_REQUIRES_RTTI OFF)
595 add_llvm_executable(${test_name} ${ARGN})
596 set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
597 set_output_directory(${test_name} ${outdir} ${outdir})
598 target_link_libraries(${test_name}
601 LLVMSupport # gtest needs it for raw_ostream.
604 add_dependencies(${test_suite} ${test_name})
605 get_target_property(test_suite_folder ${test_suite} FOLDER)
606 if (NOT ${test_suite_folder} STREQUAL "NOTFOUND")
607 set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}")
611 # This function provides an automatic way to 'configure'-like generate a file
612 # based on a set of common and custom variables, specifically targeting the
613 # variables needed for the 'lit.site.cfg' files. This function bundles the
614 # common variables that any Lit instance is likely to need, and custom
615 # variables can be passed in.
616 function(configure_lit_site_cfg input output)
617 foreach(c ${LLVM_TARGETS_TO_BUILD})
618 set(TARGETS_BUILT "${TARGETS_BUILT} ${c}")
620 set(TARGETS_TO_BUILD ${TARGETS_BUILT})
622 set(SHLIBEXT "${LTDL_SHLIB_EXT}")
624 # Configuration-time: See Unit/lit.site.cfg.in
625 if (CMAKE_CFG_INTDIR STREQUAL ".")
626 set(LLVM_BUILD_MODE ".")
628 set(LLVM_BUILD_MODE "%(build_mode)s")
631 # They below might not be the build tree but provided binary tree.
632 set(LLVM_SOURCE_DIR ${LLVM_MAIN_SRC_DIR})
633 set(LLVM_BINARY_DIR ${LLVM_BINARY_DIR})
634 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_TOOLS_DIR ${LLVM_TOOLS_BINARY_DIR})
635 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_LIBS_DIR ${LLVM_LIBRARY_DIR})
637 # SHLIBDIR points the build tree.
638 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} SHLIBDIR "${LLVM_SHLIB_OUTPUT_INTDIR}")
640 set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
641 # FIXME: "ENABLE_SHARED" doesn't make sense, since it is used just for
642 # plugins. We may rename it.
643 if(LLVM_ENABLE_PLUGINS)
644 set(ENABLE_SHARED "1")
646 set(ENABLE_SHARED "0")
649 if(LLVM_ENABLE_ASSERTIONS AND NOT MSVC_IDE)
650 set(ENABLE_ASSERTIONS "1")
652 set(ENABLE_ASSERTIONS "0")
655 set(HOST_OS ${CMAKE_SYSTEM_NAME})
656 set(HOST_ARCH ${CMAKE_SYSTEM_PROCESSOR})
658 set(HOST_CC "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
659 set(HOST_CXX "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
660 set(HOST_LDFLAGS "${CMAKE_EXE_LINKER_FLAGS}")
662 configure_file(${input} ${output} @ONLY)
665 # A raw function to create a lit target. This is used to implement the testuite
666 # management functions.
667 function(add_lit_target target comment)
668 parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN})
669 set(LIT_ARGS "${ARG_ARGS} ${LLVM_LIT_ARGS}")
670 separate_arguments(LIT_ARGS)
671 if (NOT CMAKE_CFG_INTDIR STREQUAL ".")
672 list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR})
674 if (LLVM_MAIN_SRC_DIR)
675 set (LIT_COMMAND ${PYTHON_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
677 find_program(LIT_COMMAND llvm-lit)
679 list(APPEND LIT_COMMAND ${LIT_ARGS})
680 foreach(param ${ARG_PARAMS})
681 list(APPEND LIT_COMMAND --param ${param})
684 add_custom_target(${target}
685 COMMAND ${LIT_COMMAND} ${ARG_DEFAULT_ARGS}
688 add_dependencies(${target} ${ARG_DEPENDS})
690 add_custom_target(${target}
691 COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, no tools built.")
692 message(STATUS "${target} does nothing.")
695 # Tests should be excluded from "Build Solution".
696 set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON)
699 # A function to add a set of lit test suites to be driven through 'check-*' targets.
700 function(add_lit_testsuite target comment)
701 parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN})
703 # EXCLUDE_FROM_ALL excludes the test ${target} out of check-all.
704 if(NOT EXCLUDE_FROM_ALL)
705 # Register the testsuites, params and depends for the global check rule.
706 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_TESTSUITES ${ARG_DEFAULT_ARGS})
707 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_PARAMS ${ARG_PARAMS})
708 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_DEPENDS ${ARG_DEPENDS})
709 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_EXTRA_ARGS ${ARG_ARGS})
712 # Produce a specific suffixed check rule.
713 add_lit_target(${target} ${comment}
716 DEPENDS ${ARG_DEPENDS}