Skip to content

Reapply "[cmake] Refactor clang unittest cmake" #134195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions clang/unittests/AST/ByteCode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ add_clang_unittest(InterpTests
BitcastBuffer.cpp
Descriptor.cpp
toAPValue.cpp
)

clang_target_link_libraries(InterpTests
PRIVATE
CLANG_LIBS
clangAST
clangASTMatchers
clangBasic
clangFrontend
clangSerialization
clangTooling
)

target_link_libraries(InterpTests
PRIVATE
LINK_LIBS
clangTesting
)
LLVM_COMPONENTS
FrontendOpenMP
Support
TargetParser
)
23 changes: 7 additions & 16 deletions clang/unittests/AST/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
set(LLVM_LINK_COMPONENTS
FrontendOpenMP
Support
TargetParser
)


add_subdirectory(ByteCode)

add_clang_unittest(ASTTests
Expand Down Expand Up @@ -43,22 +36,20 @@ add_clang_unittest(ASTTests
TemplateNameTest.cpp
TypePrinterTest.cpp
UnresolvedSetTest.cpp
)

clang_target_link_libraries(ASTTests
PRIVATE
CLANG_LIBS
clangAST
clangASTMatchers
clangBasic
clangFrontend
clangLex
clangSerialization
clangTooling
)

target_link_libraries(ASTTests
PRIVATE
LINK_LIBS
clangTesting
LLVMTestingAnnotations
LLVMTestingSupport
)
LLVM_COMPONENTS
FrontendOpenMP
Support
TargetParser
)
22 changes: 7 additions & 15 deletions clang/unittests/ASTMatchers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
set(LLVM_LINK_COMPONENTS
FrontendOpenMP
Support
TargetParser
)

add_clang_unittest(ASTMatchersTests
ASTMatchersInternalTest.cpp
ASTMatchersNodeTest.cpp
ASTMatchersNarrowingTest.cpp
ASTMatchersTraversalTest.cpp
GtestMatchersTest.cpp
)

clang_target_link_libraries(ASTMatchersTests
PRIVATE
CLANG_LIBS
clangAST
clangASTMatchers
clangBasic
clangFrontend
clangSerialization
clangTooling
)

target_link_libraries(ASTMatchersTests
PRIVATE
LINK_LIBS
clangTesting
LLVMTestingSupport
)
LLVM_COMPONENTS
FrontendOpenMP
Support
TargetParser
)

add_subdirectory(Dynamic)
18 changes: 5 additions & 13 deletions clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
set(LLVM_LINK_COMPONENTS
FrontendOpenMP
Support
)

add_clang_unittest(DynamicASTMatchersTests
VariantValueTest.cpp
ParserTest.cpp
RegistryTest.cpp
)

clang_target_link_libraries(DynamicASTMatchersTests
PRIVATE
CLANG_LIBS
clangAST
clangASTMatchers
clangBasic
clangDynamicASTMatchers
clangFrontend
clangSerialization
clangTooling
)

target_link_libraries(DynamicASTMatchersTests
PRIVATE
LINK_LIBS
clangTesting
LLVM_COMPONENTS
FrontendOpenMP
Support
)
18 changes: 5 additions & 13 deletions clang/unittests/Analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
set(LLVM_LINK_COMPONENTS
FrontendOpenMP
Support
)

add_clang_unittest(ClangAnalysisTests
CFGDominatorTree.cpp
CFGTest.cpp
Expand All @@ -11,10 +6,7 @@ add_clang_unittest(ClangAnalysisTests
IntervalPartitionTest.cpp
MacroExpansionContextTest.cpp
UnsafeBufferUsageTest.cpp
)

clang_target_link_libraries(ClangAnalysisTests
PRIVATE
CLANG_LIBS
clangAST
clangASTMatchers
clangAnalysis
Expand All @@ -23,12 +15,12 @@ clang_target_link_libraries(ClangAnalysisTests
clangLex
clangSerialization
clangTooling
)

target_link_libraries(ClangAnalysisTests
PRIVATE
LINK_LIBS
clangTesting
LLVMTestingSupport
LLVM_COMPONENTS
FrontendOpenMP
Support
)

add_subdirectory(FlowSensitive)
18 changes: 5 additions & 13 deletions clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
set(LLVM_LINK_COMPONENTS
FrontendOpenMP
Support
)

add_clang_unittest(ClangAnalysisFlowSensitiveTests
ArenaTest.cpp
ASTOpsTest.cpp
Expand Down Expand Up @@ -30,10 +25,7 @@ add_clang_unittest(ClangAnalysisFlowSensitiveTests
UncheckedOptionalAccessModelTest.cpp
ValueTest.cpp
WatchedLiteralsSolverTest.cpp
)

clang_target_link_libraries(ClangAnalysisFlowSensitiveTests
PRIVATE
CLANG_LIBS
clangAST
clangASTMatchers
clangAnalysis
Expand All @@ -44,11 +36,11 @@ clang_target_link_libraries(ClangAnalysisFlowSensitiveTests
clangLex
clangSerialization
clangTooling
)

target_link_libraries(ClangAnalysisFlowSensitiveTests
PRIVATE
LINK_LIBS
clangTesting
LLVMTestingAnnotations
LLVMTestingSupport
LLVM_COMPONENTS
FrontendOpenMP
Support
)
18 changes: 5 additions & 13 deletions clang/unittests/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
set(LLVM_LINK_COMPONENTS
Support
)

add_clang_unittest(BasicTests
CharInfoTest.cpp
DarwinSDKInfoTest.cpp
Expand All @@ -12,15 +8,11 @@ add_clang_unittest(BasicTests
SanitizersTest.cpp
SarifTest.cpp
SourceManagerTest.cpp
)

clang_target_link_libraries(BasicTests
PRIVATE
CLANG_LIBS
clangBasic
clangLex
)

target_link_libraries(BasicTests
PRIVATE
LINK_LIBS
LLVMTestingSupport
)
LLVM_COMPONENTS
Support
)
32 changes: 28 additions & 4 deletions clang/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,36 @@ if(CLANG_BUILT_STANDALONE)
endif()
endif()

# add_clang_unittest(test_dirname file1.cpp file2.cpp)
# add_clang_unittest(test_name file1.cpp file2.cpp)
#
# Will compile the list of files together and link against the clang
# Produces a binary named 'basename(test_dirname)'.
function(add_clang_unittest test_dirname)
add_unittest(ClangUnitTests ${test_dirname} ${ARGN})
# Produces a binary named 'basename(test_name)'.
function(add_clang_unittest test_name)
cmake_parse_arguments(ARG
""
""
"CLANG_LIBS;LINK_LIBS;LLVM_COMPONENTS"
${ARGN})

if (NOT ${test_name} MATCHES "Tests$")
message(FATAL_ERROR "Unit test name must end with 'Tests' for lit to find it.")
endif()

# LLVM_COMPONENTS is for LLVM_LINK_COMPONENTS deps, and must be before
# add_unittest.
list(APPEND LLVM_LINK_COMPONENTS ${ARG_LLVM_COMPONENTS})

add_unittest(ClangUnitTests ${test_name} ${ARG_UNPARSED_ARGUMENTS})

# Clang libs either come from the entire dylib, or individual libraries.
if (CLANG_LINK_CLANG_DYLIB)
list(APPEND ARG_LINK_LIBS clang-cpp)
else()
list(APPEND ARG_LINK_LIBS ${ARG_CLANG_LIBS})
endif()

# LINK_LIBS is for normal library dependencies.
target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBS})
endfunction()

add_subdirectory(Basic)
Expand Down
15 changes: 5 additions & 10 deletions clang/unittests/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
set(LLVM_LINK_COMPONENTS
Core
Support
TargetParser
)

add_clang_unittest(ClangCodeGenTests
BufferSourceTest.cpp
CodeGenExternalTest.cpp
TBAAMetadataTest.cpp
CheckTargetFeaturesTest.cpp
)

clang_target_link_libraries(ClangCodeGenTests
PRIVATE
CLANG_LIBS
clangAST
clangBasic
clangCodeGen
clangFrontend
clangLex
clangParse
clangSerialization
LLVM_COMPONENTS
Core
Support
TargetParser
)
12 changes: 3 additions & 9 deletions clang/unittests/CrossTU/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
set(LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
Support
)

add_clang_unittest(CrossTUTests
CrossTranslationUnitTest.cpp
)

clang_target_link_libraries(CrossTUTests
PRIVATE
CLANG_LIBS
clangAST
clangBasic
clangCrossTU
clangFrontend
clangSerialization
clangTooling
LLVM_COMPONENTS
Support
)
11 changes: 3 additions & 8 deletions clang/unittests/DirectoryWatcher/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME STREQUAL Windows)

set(LLVM_LINK_COMPONENTS
Support
)

add_clang_unittest(DirectoryWatcherTests
DirectoryWatcherTest.cpp
)

target_link_libraries(DirectoryWatcherTests
PRIVATE
LINK_LIBS
LLVMTestingSupport
clangDirectoryWatcher
LLVM_COMPONENTS
Support
)

endif()
19 changes: 7 additions & 12 deletions clang/unittests/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
set(LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
MC
Option
Support
TargetParser
)

add_clang_unittest(ClangDriverTests
DistroTest.cpp
DXCModeTest.cpp
Expand All @@ -15,12 +7,15 @@ add_clang_unittest(ClangDriverTests
MultilibBuilderTest.cpp
MultilibTest.cpp
SanitizerArgsTest.cpp
)

clang_target_link_libraries(ClangDriverTests
PRIVATE
CLANG_LIBS
clangDriver
clangBasic
clangFrontend # For TextDiagnosticPrinter.
clangSerialization
LLVM_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
MC
Option
Support
TargetParser
)
Loading
Loading