Skip to content

Commit fe6604d

Browse files
committed
Reapply "[cmake] Refactor clang unittest cmake"
This reapplies 5ffd9bd (llvm#133545) with fixes. The BUILD_SHARED_LIBS=ON build was fixed by adding missing LLVM dependencies to the InterpTests binary in unittests/AST/ByteCode/CMakeLists.txt .
1 parent f475ccd commit fe6604d

File tree

28 files changed

+166
-289
lines changed

28 files changed

+166
-289
lines changed

clang/unittests/AST/ByteCode/CMakeLists.txt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@ add_clang_unittest(InterpTests
22
BitcastBuffer.cpp
33
Descriptor.cpp
44
toAPValue.cpp
5-
)
6-
7-
clang_target_link_libraries(InterpTests
8-
PRIVATE
5+
CLANG_LIBS
96
clangAST
107
clangASTMatchers
118
clangBasic
129
clangFrontend
1310
clangSerialization
1411
clangTooling
15-
)
16-
17-
target_link_libraries(InterpTests
18-
PRIVATE
12+
LINK_LIBS
1913
clangTesting
20-
)
14+
LLVM_COMPONENTS
15+
FrontendOpenMP
16+
Support
17+
TargetParser
18+
)

clang/unittests/AST/CMakeLists.txt

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
set(LLVM_LINK_COMPONENTS
2-
FrontendOpenMP
3-
Support
4-
TargetParser
5-
)
6-
7-
81
add_subdirectory(ByteCode)
92

103
add_clang_unittest(ASTTests
@@ -43,22 +36,20 @@ add_clang_unittest(ASTTests
4336
TemplateNameTest.cpp
4437
TypePrinterTest.cpp
4538
UnresolvedSetTest.cpp
46-
)
47-
48-
clang_target_link_libraries(ASTTests
49-
PRIVATE
39+
CLANG_LIBS
5040
clangAST
5141
clangASTMatchers
5242
clangBasic
5343
clangFrontend
5444
clangLex
5545
clangSerialization
5646
clangTooling
57-
)
58-
59-
target_link_libraries(ASTTests
60-
PRIVATE
47+
LINK_LIBS
6148
clangTesting
6249
LLVMTestingAnnotations
6350
LLVMTestingSupport
64-
)
51+
LLVM_COMPONENTS
52+
FrontendOpenMP
53+
Support
54+
TargetParser
55+
)
Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
1-
set(LLVM_LINK_COMPONENTS
2-
FrontendOpenMP
3-
Support
4-
TargetParser
5-
)
6-
71
add_clang_unittest(ASTMatchersTests
82
ASTMatchersInternalTest.cpp
93
ASTMatchersNodeTest.cpp
104
ASTMatchersNarrowingTest.cpp
115
ASTMatchersTraversalTest.cpp
126
GtestMatchersTest.cpp
13-
)
14-
15-
clang_target_link_libraries(ASTMatchersTests
16-
PRIVATE
7+
CLANG_LIBS
178
clangAST
189
clangASTMatchers
1910
clangBasic
2011
clangFrontend
2112
clangSerialization
2213
clangTooling
23-
)
24-
25-
target_link_libraries(ASTMatchersTests
26-
PRIVATE
14+
LINK_LIBS
2715
clangTesting
2816
LLVMTestingSupport
29-
)
17+
LLVM_COMPONENTS
18+
FrontendOpenMP
19+
Support
20+
TargetParser
21+
)
3022

3123
add_subdirectory(Dynamic)
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
set(LLVM_LINK_COMPONENTS
2-
FrontendOpenMP
3-
Support
4-
)
5-
61
add_clang_unittest(DynamicASTMatchersTests
72
VariantValueTest.cpp
83
ParserTest.cpp
94
RegistryTest.cpp
10-
)
11-
12-
clang_target_link_libraries(DynamicASTMatchersTests
13-
PRIVATE
5+
CLANG_LIBS
146
clangAST
157
clangASTMatchers
168
clangBasic
179
clangDynamicASTMatchers
1810
clangFrontend
1911
clangSerialization
2012
clangTooling
21-
)
22-
23-
target_link_libraries(DynamicASTMatchersTests
24-
PRIVATE
13+
LINK_LIBS
2514
clangTesting
15+
LLVM_COMPONENTS
16+
FrontendOpenMP
17+
Support
2618
)
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
set(LLVM_LINK_COMPONENTS
2-
FrontendOpenMP
3-
Support
4-
)
5-
61
add_clang_unittest(ClangAnalysisTests
72
CFGDominatorTree.cpp
83
CFGTest.cpp
@@ -11,10 +6,7 @@ add_clang_unittest(ClangAnalysisTests
116
IntervalPartitionTest.cpp
127
MacroExpansionContextTest.cpp
138
UnsafeBufferUsageTest.cpp
14-
)
15-
16-
clang_target_link_libraries(ClangAnalysisTests
17-
PRIVATE
9+
CLANG_LIBS
1810
clangAST
1911
clangASTMatchers
2012
clangAnalysis
@@ -23,12 +15,12 @@ clang_target_link_libraries(ClangAnalysisTests
2315
clangLex
2416
clangSerialization
2517
clangTooling
26-
)
27-
28-
target_link_libraries(ClangAnalysisTests
29-
PRIVATE
18+
LINK_LIBS
3019
clangTesting
3120
LLVMTestingSupport
21+
LLVM_COMPONENTS
22+
FrontendOpenMP
23+
Support
3224
)
3325

3426
add_subdirectory(FlowSensitive)

clang/unittests/Analysis/FlowSensitive/CMakeLists.txt

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
set(LLVM_LINK_COMPONENTS
2-
FrontendOpenMP
3-
Support
4-
)
5-
61
add_clang_unittest(ClangAnalysisFlowSensitiveTests
72
ArenaTest.cpp
83
ASTOpsTest.cpp
@@ -30,10 +25,7 @@ add_clang_unittest(ClangAnalysisFlowSensitiveTests
3025
UncheckedOptionalAccessModelTest.cpp
3126
ValueTest.cpp
3227
WatchedLiteralsSolverTest.cpp
33-
)
34-
35-
clang_target_link_libraries(ClangAnalysisFlowSensitiveTests
36-
PRIVATE
28+
CLANG_LIBS
3729
clangAST
3830
clangASTMatchers
3931
clangAnalysis
@@ -44,11 +36,11 @@ clang_target_link_libraries(ClangAnalysisFlowSensitiveTests
4436
clangLex
4537
clangSerialization
4638
clangTooling
47-
)
48-
49-
target_link_libraries(ClangAnalysisFlowSensitiveTests
50-
PRIVATE
39+
LINK_LIBS
5140
clangTesting
5241
LLVMTestingAnnotations
5342
LLVMTestingSupport
43+
LLVM_COMPONENTS
44+
FrontendOpenMP
45+
Support
5446
)

clang/unittests/Basic/CMakeLists.txt

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
set(LLVM_LINK_COMPONENTS
2-
Support
3-
)
4-
51
add_clang_unittest(BasicTests
62
CharInfoTest.cpp
73
DarwinSDKInfoTest.cpp
@@ -12,15 +8,11 @@ add_clang_unittest(BasicTests
128
SanitizersTest.cpp
139
SarifTest.cpp
1410
SourceManagerTest.cpp
15-
)
16-
17-
clang_target_link_libraries(BasicTests
18-
PRIVATE
11+
CLANG_LIBS
1912
clangBasic
2013
clangLex
21-
)
22-
23-
target_link_libraries(BasicTests
24-
PRIVATE
14+
LINK_LIBS
2515
LLVMTestingSupport
26-
)
16+
LLVM_COMPONENTS
17+
Support
18+
)

clang/unittests/CMakeLists.txt

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,36 @@ if(CLANG_BUILT_STANDALONE)
1515
endif()
1616
endif()
1717

18-
# add_clang_unittest(test_dirname file1.cpp file2.cpp)
18+
# add_clang_unittest(test_name file1.cpp file2.cpp)
1919
#
2020
# Will compile the list of files together and link against the clang
21-
# Produces a binary named 'basename(test_dirname)'.
22-
function(add_clang_unittest test_dirname)
23-
add_unittest(ClangUnitTests ${test_dirname} ${ARGN})
21+
# Produces a binary named 'basename(test_name)'.
22+
function(add_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})
2448
endfunction()
2549

2650
add_subdirectory(Basic)
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
set(LLVM_LINK_COMPONENTS
2-
Core
3-
Support
4-
TargetParser
5-
)
6-
71
add_clang_unittest(ClangCodeGenTests
82
BufferSourceTest.cpp
93
CodeGenExternalTest.cpp
104
TBAAMetadataTest.cpp
115
CheckTargetFeaturesTest.cpp
12-
)
13-
14-
clang_target_link_libraries(ClangCodeGenTests
15-
PRIVATE
6+
CLANG_LIBS
167
clangAST
178
clangBasic
189
clangCodeGen
1910
clangFrontend
2011
clangLex
2112
clangParse
2213
clangSerialization
14+
LLVM_COMPONENTS
15+
Core
16+
Support
17+
TargetParser
2318
)
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
set(LLVM_LINK_COMPONENTS
2-
${LLVM_TARGETS_TO_BUILD}
3-
Support
4-
)
5-
61
add_clang_unittest(CrossTUTests
72
CrossTranslationUnitTest.cpp
8-
)
9-
10-
clang_target_link_libraries(CrossTUTests
11-
PRIVATE
3+
CLANG_LIBS
124
clangAST
135
clangBasic
146
clangCrossTU
157
clangFrontend
168
clangSerialization
179
clangTooling
10+
LLVM_COMPONENTS
11+
Support
1812
)
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME STREQUAL Windows)
22

3-
set(LLVM_LINK_COMPONENTS
4-
Support
5-
)
6-
73
add_clang_unittest(DirectoryWatcherTests
84
DirectoryWatcherTest.cpp
9-
)
10-
11-
target_link_libraries(DirectoryWatcherTests
12-
PRIVATE
5+
LINK_LIBS
136
LLVMTestingSupport
147
clangDirectoryWatcher
8+
LLVM_COMPONENTS
9+
Support
1510
)
1611

1712
endif()

clang/unittests/Driver/CMakeLists.txt

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
set(LLVM_LINK_COMPONENTS
2-
${LLVM_TARGETS_TO_BUILD}
3-
MC
4-
Option
5-
Support
6-
TargetParser
7-
)
8-
91
add_clang_unittest(ClangDriverTests
102
DistroTest.cpp
113
DXCModeTest.cpp
@@ -15,12 +7,15 @@ add_clang_unittest(ClangDriverTests
157
MultilibBuilderTest.cpp
168
MultilibTest.cpp
179
SanitizerArgsTest.cpp
18-
)
19-
20-
clang_target_link_libraries(ClangDriverTests
21-
PRIVATE
10+
CLANG_LIBS
2211
clangDriver
2312
clangBasic
2413
clangFrontend # For TextDiagnosticPrinter.
2514
clangSerialization
15+
LLVM_COMPONENTS
16+
${LLVM_TARGETS_TO_BUILD}
17+
MC
18+
Option
19+
Support
20+
TargetParser
2621
)

0 commit comments

Comments
 (0)