@@ -15,11 +15,11 @@ if(CLANG_BUILT_STANDALONE)
15
15
endif ()
16
16
endif ()
17
17
18
- # add_clang_unittest (test_name file1.cpp file2.cpp)
18
+ # add_distinct_clang_unittest (test_name file1.cpp file2.cpp)
19
19
#
20
20
# Will compile the list of files together and link against the clang
21
21
# Produces a binary named 'basename(test_name)'.
22
- function (add_clang_unittest test_name)
22
+ function (add_distinct_clang_unittest test_name)
23
23
cmake_parse_arguments (ARG
24
24
""
25
25
""
@@ -47,6 +47,34 @@ function(add_clang_unittest test_name)
47
47
target_link_libraries (${test_name} PRIVATE ${ARG_LINK_LIBS} )
48
48
endfunction ()
49
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
+
50
78
add_subdirectory (Basic)
51
79
add_subdirectory (CAS)
52
80
add_subdirectory (Lex)
@@ -78,3 +106,25 @@ add_subdirectory(Index)
78
106
add_subdirectory (InstallAPI)
79
107
add_subdirectory (Serialization)
80
108
add_subdirectory (Support)
109
+
110
+
111
+ # If we're doing a single merged clang unit test binary, add that target after
112
+ # all the previous subdirectories have been processed.
113
+ get_property (SRCS GLOBAL PROPERTY CLANG_UNITTEST_SRCS)
114
+ get_property (CLANG_LIBS GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS)
115
+ get_property (LINK_LIBS GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS)
116
+ get_property (LLVM_COMPONENTS GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS)
117
+ add_distinct_clang_unittest(AllClangUnitTests
118
+ ${SRCS}
119
+ CLANG_LIBS
120
+ ${CLANG_LIBS}
121
+ LINK_LIBS
122
+ ${LINK_LIBS}
123
+ LLVM_COMPONENTS
124
+ ${LLVM_COMPONENTS}
125
+ )
126
+
127
+ # The Tooling library has some internal headers. Make those work. If we like
128
+ # the merged clang unit test binary, we can update the include paths and make
129
+ # this the default.
130
+ include_directories (Tooling)
0 commit comments