Skip to content

Revert "[cmake] Refactor clang unittest cmake" #134022

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 2, 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
12 changes: 9 additions & 3 deletions clang/unittests/AST/ByteCode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ add_clang_unittest(InterpTests
BitcastBuffer.cpp
Descriptor.cpp
toAPValue.cpp
CLANG_LIBS
)

clang_target_link_libraries(InterpTests
PRIVATE
clangAST
clangASTMatchers
clangBasic
clangFrontend
clangSerialization
clangTooling
LINK_LIBS
clangTesting
)

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


add_subdirectory(ByteCode)

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

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

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

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

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

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

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

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

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

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

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

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

target_link_libraries(ClangAnalysisTests
PRIVATE
clangTesting
LLVMTestingSupport
LLVM_COMPONENTS
FrontendOpenMP
Support
)

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

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

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

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

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

clang_target_link_libraries(BasicTests
PRIVATE
clangBasic
clangLex
LINK_LIBS
LLVMTestingSupport
LLVM_COMPONENTS
Support
)

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

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

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

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

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

add_clang_unittest(CrossTUTests
CrossTranslationUnitTest.cpp
CLANG_LIBS
)

clang_target_link_libraries(CrossTUTests
PRIVATE
clangAST
clangBasic
clangCrossTU
clangFrontend
clangSerialization
clangTooling
LLVM_COMPONENTS
Support
)
11 changes: 8 additions & 3 deletions clang/unittests/DirectoryWatcher/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
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
LINK_LIBS
)

target_link_libraries(DirectoryWatcherTests
PRIVATE
LLVMTestingSupport
clangDirectoryWatcher
LLVM_COMPONENTS
Support
)

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

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

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