| 1 |
add_custom_target(ClangUnitTests) |
| 2 |
set_target_properties(ClangUnitTests PROPERTIES FOLDER "Clang/Tests") |
| 3 |
|
| 4 |
if(CLANG_BUILT_STANDALONE) |
| 5 |
# LLVMTesting* libraries are needed for some of the unittests. |
| 6 |
if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Testing/Annotations |
| 7 |
AND NOT TARGET LLVMTestingAnnotations) |
| 8 |
add_subdirectory(${LLVM_MAIN_SRC_DIR}/lib/Testing/Annotations |
| 9 |
lib/Testing/Annotations) |
| 10 |
endif() |
| 11 |
if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Testing/Support |
| 12 |
AND NOT TARGET LLVMTestingSupport) |
| 13 |
add_subdirectory(${LLVM_MAIN_SRC_DIR}/lib/Testing/Support |
| 14 |
lib/Testing/Support) |
| 15 |
endif() |
| 16 |
endif() |
| 17 |
|
| 18 |
# add_distinct_clang_unittest(test_name file1.cpp file2.cpp) |
| 19 |
# |
| 20 |
# Will compile the list of files together and link against the clang |
| 21 |
# Produces a binary named 'basename(test_name)'. |
| 22 |
function(add_distinct_clang_unittest test_name) |
| 23 |
cmake_parse_arguments(ARG |
| 24 |
"" |
| 25 |
"" |
| 26 |
"CLANG_LIBS;LINK_LIBS;LLVM_COMPONENTS" |
| 27 |
${ARGN}) |
| 28 |
|
| 29 |
if (NOT ${test_name} MATCHES "Tests$") |
| 30 |
message(FATAL_ERROR "Unit test name must end with 'Tests' for lit to find it.") |
| 31 |
endif() |
| 32 |
|
| 33 |
# LLVM_COMPONENTS is for LLVM_LINK_COMPONENTS deps, and must be before |
| 34 |
# add_unittest. |
| 35 |
list(APPEND LLVM_LINK_COMPONENTS ${ARG_LLVM_COMPONENTS}) |
| 36 |
|
| 37 |
add_unittest(ClangUnitTests ${test_name} ${ARG_UNPARSED_ARGUMENTS}) |
| 38 |
|
| 39 |
# Clang libs either come from the entire dylib, or individual libraries. |
| 40 |
if (CLANG_LINK_CLANG_DYLIB) |
| 41 |
list(APPEND ARG_LINK_LIBS clang-cpp) |
| 42 |
else() |
| 43 |
list(APPEND ARG_LINK_LIBS ${ARG_CLANG_LIBS}) |
| 44 |
endif() |
| 45 |
|
| 46 |
# LINK_LIBS is for normal library dependencies. |
| 47 |
target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBS}) |
| 48 |
endfunction() |
| 49 |
|
| 50 |
set(doc_opts BRIEF_DOCS "<internal setting>" FULL_DOCS "<internal settings>") |
| 51 |
define_property(GLOBAL PROPERTY CLANG_UNITTEST_SRCS ${doc_opts}) |
| 52 |
define_property(GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS ${doc_opts}) |
| 53 |
define_property(GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS ${doc_opts}) |
| 54 |
define_property(GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS ${doc_opts}) |
| 55 |
|
| 56 |
# add_clang_unittest(test_name file1.cpp file2.cpp) |
| 57 |
# |
| 58 |
# Adds unittests to the combined AllClangUnitTests binary. The unittest binary |
| 59 |
# is defined after adding all unittest subdirectories. |
| 60 |
function(add_clang_unittest test_name) |
| 61 |
cmake_parse_arguments(ARG |
| 62 |
"" |
| 63 |
"" |
| 64 |
"CLANG_LIBS;LINK_LIBS;LLVM_COMPONENTS" |
| 65 |
${ARGN}) |
| 66 |
|
| 67 |
file(RELATIVE_PATH src_prefix "${CMAKE_CURRENT_FUNCTION_LIST_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") |
| 68 |
set(srcs_prefixed) |
| 69 |
foreach(src ${ARG_UNPARSED_ARGUMENTS}) |
| 70 |
set(srcs_prefixed ${srcs_prefixed} "${src_prefix}/${src}") |
| 71 |
endforeach() |
| 72 |
set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_SRCS ${srcs_prefixed}) |
| 73 |
set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_CLANG_LIBS ${ARG_CLANG_LIBS}) |
| 74 |
set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_LINK_LIBS ${ARG_LINK_LIBS}) |
| 75 |
set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS ${ARG_LLVM_COMPONENTS}) |
| 76 |
endfunction() |
| 77 |
|
| 78 |
add_subdirectory(Basic) |
| 79 |
add_subdirectory(Lex) |
| 80 |
add_subdirectory(Parse) |
| 81 |
add_subdirectory(Driver) |
| 82 |
add_subdirectory(DependencyScanning) |
| 83 |
if(CLANG_ENABLE_STATIC_ANALYZER) |
| 84 |
add_subdirectory(Analysis) |
| 85 |
add_subdirectory(StaticAnalyzer) |
| 86 |
endif() |
| 87 |
add_subdirectory(ASTMatchers) |
| 88 |
add_subdirectory(AST) |
| 89 |
add_subdirectory(CrossTU) |
| 90 |
add_subdirectory(Tooling) |
| 91 |
add_subdirectory(Format) |
| 92 |
add_subdirectory(Frontend) |
| 93 |
add_subdirectory(Rewrite) |
| 94 |
add_subdirectory(Sema) |
| 95 |
add_subdirectory(CodeGen) |
| 96 |
if(HAVE_CLANG_REPL_SUPPORT) |
| 97 |
add_subdirectory(Interpreter) |
| 98 |
endif() |
| 99 |
# FIXME: libclang unit tests are disabled on Windows due |
| 100 |
# to failures, mostly in libclang.VirtualFileOverlay_*. |
| 101 |
if(NOT WIN32 AND CLANG_TOOL_LIBCLANG_BUILD) |
| 102 |
add_subdirectory(libclang) |
| 103 |
endif() |
| 104 |
add_subdirectory(DirectoryWatcher) |
| 105 |
add_subdirectory(Index) |
| 106 |
add_subdirectory(InstallAPI) |
| 107 |
add_subdirectory(Serialization) |
| 108 |
add_subdirectory(Support) |
| 109 |
if (CLANG_ENABLE_CIR) |
| 110 |
add_subdirectory(CIR) |
| 111 |
endif() |
| 112 |
|
| 113 |
# If we're doing a single merged clang unit test binary, add that target after |
| 114 |
# all the previous subdirectories have been processed. |
| 115 |
get_property(SRCS GLOBAL PROPERTY CLANG_UNITTEST_SRCS) |
| 116 |
get_property(CLANG_LIBS GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS) |
| 117 |
get_property(LINK_LIBS GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS) |
| 118 |
get_property(LLVM_COMPONENTS GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS) |
| 119 |
add_distinct_clang_unittest(AllClangUnitTests |
| 120 |
${SRCS} |
| 121 |
AllClangUnitTests.cpp |
| 122 |
CLANG_LIBS |
| 123 |
${CLANG_LIBS} |
| 124 |
LINK_LIBS |
| 125 |
${LINK_LIBS} |
| 126 |
LLVM_COMPONENTS |
| 127 |
${LLVM_COMPONENTS} |
| 128 |
) |
| 129 |
|
| 130 |
# The Tooling library has some internal headers. Make those work. If we like |
| 131 |
# the merged clang unit test binary, we can update the include paths and make |
| 132 |
# this the default. |
| 133 |
include_directories(Tooling) |