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

Conversation

rnk
Copy link
Collaborator

@rnk rnk commented Apr 3, 2025

This reapplies 5ffd9bd (#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 .

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 .
@rnk rnk requested a review from cyndyishida as a code owner April 3, 2025 03:49
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang-format clang:modules C++20 modules and Clang Header Modules clang:dataflow Clang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.html labels Apr 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 3, 2025

@llvm/pr-subscribers-clang-format
@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Reid Kleckner (rnk)

Changes

This reapplies 5ffd9bd (#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 .


Patch is 22.08 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/134195.diff

28 Files Affected:

  • (modified) clang/unittests/AST/ByteCode/CMakeLists.txt (+7-9)
  • (modified) clang/unittests/AST/CMakeLists.txt (+7-16)
  • (modified) clang/unittests/ASTMatchers/CMakeLists.txt (+7-15)
  • (modified) clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt (+5-13)
  • (modified) clang/unittests/Analysis/CMakeLists.txt (+5-13)
  • (modified) clang/unittests/Analysis/FlowSensitive/CMakeLists.txt (+5-13)
  • (modified) clang/unittests/Basic/CMakeLists.txt (+5-13)
  • (modified) clang/unittests/CMakeLists.txt (+28-4)
  • (modified) clang/unittests/CodeGen/CMakeLists.txt (+5-10)
  • (modified) clang/unittests/CrossTU/CMakeLists.txt (+3-9)
  • (modified) clang/unittests/DirectoryWatcher/CMakeLists.txt (+3-8)
  • (modified) clang/unittests/Driver/CMakeLists.txt (+7-12)
  • (modified) clang/unittests/Format/CMakeLists.txt (+3-8)
  • (modified) clang/unittests/Frontend/CMakeLists.txt (+4-8)
  • (modified) clang/unittests/Index/CMakeLists.txt (+4-9)
  • (modified) clang/unittests/InstallAPI/CMakeLists.txt (+3-6)
  • (modified) clang/unittests/Interpreter/CMakeLists.txt (+12-13)
  • (modified) clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt (+9-11)
  • (modified) clang/unittests/Lex/CMakeLists.txt (+4-12)
  • (modified) clang/unittests/Rewrite/CMakeLists.txt (+3-7)
  • (modified) clang/unittests/Sema/CMakeLists.txt (+5-13)
  • (modified) clang/unittests/Serialization/CMakeLists.txt (+6-11)
  • (modified) clang/unittests/StaticAnalyzer/CMakeLists.txt (+5-13)
  • (modified) clang/unittests/Support/CMakeLists.txt (+3-8)
  • (modified) clang/unittests/Tooling/CMakeLists.txt (+11-17)
  • (modified) clang/unittests/Tooling/Syntax/CMakeLists.txt (+5-10)
  • (modified) clang/unittests/libclang/CMakeLists.txt (+1-4)
  • (modified) clang/unittests/libclang/CrashTests/CMakeLists.txt (+1-4)
diff --git a/clang/unittests/AST/ByteCode/CMakeLists.txt b/clang/unittests/AST/ByteCode/CMakeLists.txt
index b862fb4834fbd..1469cd6b2a8ea 100644
--- a/clang/unittests/AST/ByteCode/CMakeLists.txt
+++ b/clang/unittests/AST/ByteCode/CMakeLists.txt
@@ -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
+  )
diff --git a/clang/unittests/AST/CMakeLists.txt b/clang/unittests/AST/CMakeLists.txt
index bfa6082a6ffa4..f27d34e8a0719 100644
--- a/clang/unittests/AST/CMakeLists.txt
+++ b/clang/unittests/AST/CMakeLists.txt
@@ -1,10 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
-  Support
-  TargetParser
-  )
-
-
 add_subdirectory(ByteCode)
 
 add_clang_unittest(ASTTests
@@ -43,10 +36,7 @@ add_clang_unittest(ASTTests
   TemplateNameTest.cpp
   TypePrinterTest.cpp
   UnresolvedSetTest.cpp
-  )
-
-clang_target_link_libraries(ASTTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangASTMatchers
   clangBasic
@@ -54,11 +44,12 @@ clang_target_link_libraries(ASTTests
   clangLex
   clangSerialization
   clangTooling
-  )
-
-target_link_libraries(ASTTests
-  PRIVATE
+  LINK_LIBS
   clangTesting
   LLVMTestingAnnotations
   LLVMTestingSupport
-)
+  LLVM_COMPONENTS
+  FrontendOpenMP
+  Support
+  TargetParser
+  )
diff --git a/clang/unittests/ASTMatchers/CMakeLists.txt b/clang/unittests/ASTMatchers/CMakeLists.txt
index 6a1e629d81b65..47bd5c108bb5a 100644
--- a/clang/unittests/ASTMatchers/CMakeLists.txt
+++ b/clang/unittests/ASTMatchers/CMakeLists.txt
@@ -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)
diff --git a/clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt b/clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt
index 6d0e12bcb0759..b6db7ce62afe7 100644
--- a/clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt
+++ b/clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt
@@ -1,16 +1,8 @@
-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
@@ -18,9 +10,9 @@ clang_target_link_libraries(DynamicASTMatchersTests
   clangFrontend
   clangSerialization
   clangTooling
-  )
-
-target_link_libraries(DynamicASTMatchersTests
-  PRIVATE
+  LINK_LIBS
   clangTesting
+  LLVM_COMPONENTS
+  FrontendOpenMP
+  Support
   )
diff --git a/clang/unittests/Analysis/CMakeLists.txt b/clang/unittests/Analysis/CMakeLists.txt
index cfea57f53f033..059a74843155c 100644
--- a/clang/unittests/Analysis/CMakeLists.txt
+++ b/clang/unittests/Analysis/CMakeLists.txt
@@ -1,8 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
-  Support
-  )
-
 add_clang_unittest(ClangAnalysisTests
   CFGDominatorTree.cpp
   CFGTest.cpp
@@ -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
@@ -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)
diff --git a/clang/unittests/Analysis/FlowSensitive/CMakeLists.txt b/clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
index 6c01ae8fc2e54..4ac563143cd68 100644
--- a/clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
+++ b/clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
@@ -1,8 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
-  Support
-  )
-
 add_clang_unittest(ClangAnalysisFlowSensitiveTests
   ArenaTest.cpp
   ASTOpsTest.cpp
@@ -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
@@ -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
   )
diff --git a/clang/unittests/Basic/CMakeLists.txt b/clang/unittests/Basic/CMakeLists.txt
index 3844ba49add8d..e818bd3e2c372 100644
--- a/clang/unittests/Basic/CMakeLists.txt
+++ b/clang/unittests/Basic/CMakeLists.txt
@@ -1,7 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  Support
-  )
-
 add_clang_unittest(BasicTests
   CharInfoTest.cpp
   DarwinSDKInfoTest.cpp
@@ -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
+  )
diff --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt
index 9b3ce8aa7de73..f3823ba309420 100644
--- a/clang/unittests/CMakeLists.txt
+++ b/clang/unittests/CMakeLists.txt
@@ -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)
diff --git a/clang/unittests/CodeGen/CMakeLists.txt b/clang/unittests/CodeGen/CMakeLists.txt
index a437f441568f2..f5bcecb0b08a3 100644
--- a/clang/unittests/CodeGen/CMakeLists.txt
+++ b/clang/unittests/CodeGen/CMakeLists.txt
@@ -1,18 +1,9 @@
-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
@@ -20,4 +11,8 @@ clang_target_link_libraries(ClangCodeGenTests
   clangLex
   clangParse
   clangSerialization
+  LLVM_COMPONENTS
+  Core
+  Support
+  TargetParser
   )
diff --git a/clang/unittests/CrossTU/CMakeLists.txt b/clang/unittests/CrossTU/CMakeLists.txt
index 222b7e83dc38c..ee81c57ca1dce 100644
--- a/clang/unittests/CrossTU/CMakeLists.txt
+++ b/clang/unittests/CrossTU/CMakeLists.txt
@@ -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
   )
diff --git a/clang/unittests/DirectoryWatcher/CMakeLists.txt b/clang/unittests/DirectoryWatcher/CMakeLists.txt
index 38882c9ec2162..58e0aee2d1076 100644
--- a/clang/unittests/DirectoryWatcher/CMakeLists.txt
+++ b/clang/unittests/DirectoryWatcher/CMakeLists.txt
@@ -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()
diff --git a/clang/unittests/Driver/CMakeLists.txt b/clang/unittests/Driver/CMakeLists.txt
index efdd07ea23889..fa0e87c3318df 100644
--- a/clang/unittests/Driver/CMakeLists.txt
+++ b/clang/unittests/Driver/CMakeLists.txt
@@ -1,11 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  ${LLVM_TARGETS_TO_BUILD}
-  MC
-  Option
-  Support
-  TargetParser
-  )
-
 add_clang_unittest(ClangDriverTests
   DistroTest.cpp
   DXCModeTest.cpp
@@ -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
   )
diff --git a/clang/unittests/Format/CMakeLists.txt b/clang/unittests/Format/CMakeLists.txt
index 71f5886d946c8..5bd6a17182d29 100644
--- a/clang/unittests/Format/CMakeLists.txt
+++ b/clang/unittests/Format/CMakeLists.txt
@@ -1,7 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  Support
-  )
-
 add_clang_unittest(FormatTests
   BracesInserterTest.cpp
   BracesRemoverTest.cpp
@@ -36,12 +32,11 @@ add_clang_unittest(FormatTests
   SortIncludesTest.cpp
   UsingDeclarationsSorterTest.cpp
   TokenAnnotatorTest.cpp
-  )
-
-clang_target_link_libraries(FormatTests
-  PRIVATE
+  CLANG_LIBS
   clangBasic
   clangFormat
   clangRewrite
   clangToolingCore
+  LLVM_COMPONENTS
+  Support
   )
diff --git a/clang/unittests/Frontend/CMakeLists.txt b/clang/unittests/Frontend/CMakeLists.txt
index 3c94846243870..bbf0396014fa9 100644
--- a/clang/unittests/Frontend/CMakeLists.txt
+++ b/clang/unittests/Frontend/CMakeLists.txt
@@ -1,8 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  Support
-  TargetParser
-  )
-
 add_clang_unittest(FrontendTests
   ASTUnitTest.cpp
   CompilerInvocationTest.cpp
@@ -17,9 +12,7 @@ add_clang_unittest(FrontendTests
   OutputStreamTest.cpp
   TextDiagnosticTest.cpp
   UtilsTest.cpp
-  )
-clang_target_link_libraries(FrontendTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangBasic
   clangFrontend
@@ -29,4 +22,7 @@ clang_target_link_libraries(FrontendTests
   clangFrontendTool
   clangSerialization
   clangTooling
+  LLVM_COMPONENTS
+  Support
+  TargetParser
   )
diff --git a/clang/unittests/Index/CMakeLists.txt b/clang/unittests/Index/CMakeLists.txt
index ea940e9d7a9ef..15e9ba0643eaf 100644
--- a/clang/unittests/Index/CMakeLists.txt
+++ b/clang/unittests/Index/CMakeLists.txt
@@ -1,14 +1,6 @@
-set(LLVM_LINK_COMPONENTS
-  ${LLVM_TARGETS_TO_BUILD}
-  Support
-  )
-
 add_clang_unittest(IndexTests
   IndexTests.cpp
-  )
-
-clang_target_link_libraries(IndexTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangBasic
   clangFrontend
@@ -16,4 +8,7 @@ clang_target_link_libraries(IndexTests
   clangLex
   clangSerialization
   clangTooling
+  LLVM_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  Support
   )
diff --git a/clang/unittests/InstallAPI/CMakeLists.txt b/clang/unittests/InstallAPI/CMakeLists.txt
index 4255001ff51f1..c174fa3f87161 100644
--- a/clang/unittests/InstallAPI/CMakeLists.txt
+++ b/clang/unittests/InstallAPI/CMakeLists.txt
@@ -1,11 +1,8 @@
 add_clang_unittest(InstallAPITests
   HeaderFileTest.cpp
   FileListTest.cpp
-  )
-
-clang_target_link_libraries(InstallAPITests
-  PRIVATE
+  CLANG_LIBS
   clangInstallAPI 
+  LINK_LIBS
+  LLVMTestingSupport
   )
-
-target_link_libraries(InstallAPITests PRIVATE LLVMTestingSupport)
diff --git a/clang/unittests/Interpreter/CMakeLists.txt b/clang/unittests/Interpreter/CMakeLists.txt
index 95378f9cfe737..9df1a4b03da47 100644
--- a/clang/unittests/Interpreter/CMakeLists.txt
+++ b/clang/unittests/Interpreter/CMakeLists.txt
@@ -1,12 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  ${LLVM_TARGETS_TO_BUILD}
-  Core
-  MC
-  OrcJIT
-  Support
-  TargetParser
-  )
-
 add_clang_unittest(ClangReplInterpreterTests
   IncrementalCompilerBuilderTest.cpp
   IncrementalProcessingTest.cpp
@@ -15,16 +6,24 @@ add_clang_unittest(ClangReplInterpreterTests
   CodeCompletionTest.cpp
 
   EXPORT_SYMBOLS
-  )
-  
-target_link_libraries(ClangReplInterpreterTests PUBLIC LLVMTestingSupport)
 
-clang_target_link_libraries(ClangReplInterpreterTests PRIVATE
+  CLANG_LIBS
   clangAST
   clangBasic
   clangInterpreter
   clangFrontend
   clangSema
+
+  LINK_LIBS
+  LLVMTestingSupport
+
+  LLVM_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  Core
+  MC
+  OrcJIT
+  Support
+  TargetParser
   )
 
 # Exceptions on Windows are not yet supported.
diff --git a/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt b/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
index 24ae9cd78b5ca..eb366a860661c 100644
--- a/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
+++ b/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
@@ -3,24 +3,22 @@
 set(LLVM_REQUIRES_EH ON)
 set(LLVM_REQUIRES_RTTI ON)
 
-set(LLVM_LINK_COMPONENTS
-  ${LLVM_TARGETS_TO_BUILD}
-  Core
-  OrcJIT
-  Support
-  )
-
 add_clang_unittest(ClangReplInterpreterExceptionTests
   InterpreterExceptionTest.cpp
-
   EXPORT_SYMBOLS
-  )
 
-llvm_update_compile_flags(ClangReplInterpreterExceptionTests)
-target_link_libraries(ClangReplInterpreterExceptionTests PUBLIC
+  CLANG_LIBS
   clangAST
   clangBasic
   clangInterpreter
   clangFrontend
+
+  LLVM_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  Core
+  OrcJIT
+  Support
   )
+
+llvm_update_compile_flags(ClangReplInterpreterExceptionTests)
 add_dependencies(ClangReplInterpreterExceptionTests clang-resource-headers)
diff --git a/clang/unittests/Lex/CMakeLists.txt b/clang/unittests/Lex/CMakeLists.txt
index 5ec93946594b7..96ca6dda9cd85 100644
--- a/clang/unittests/Lex/CMakeLists.txt
+++ b/clang/unittests/Lex/CMakeLists.txt
@@ -1,7 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  Support
-  )
-
 add_clang_unittest(LexTests
   DependencyDirectivesScannerTest.cpp
   HeaderMapTest.cpp
@@ -13,19 +9,15 @@ add_clang_unittest(LexTests
   PPConditionalDirectiveRecordTest.cpp
   PPDependencyDirectivesTest.cpp
   PPMemoryAllocationsTest.cpp
-  )
-
-clang_target_link_libraries(LexTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangBasic
   clangLex
   clangParse
   clangSema
-  )
-
-target_link_libraries(LexTests
-  PRIVATE
+  LINK_LIBS
   LLVMTestingAnnotations
   LLVMTestingSupport
+  LLVM_COMPONENTS
+  Support
   )
diff --git a/clang/unittests/Rewrite/CMakeLists.txt b/clang/unittests/Rewrite/CMakeLists.txt
index 3c5e2f8e5354b..498613254e72b 100644
--- a/clang/unittests/Rewrite/CMakeLists.txt
+++ b/clang/unittests/Rewrite/CMakeLists.txt
@@ -1,14 +1,10 @@
-set(LLVM_LINK_COMPONENTS
-  Support
-  )
-
 add_clang_unittest(RewriteTests
   RewriterTest.cpp
-  )
-clang_target_link_libraries(RewriteTests
-  PRIVATE
+  CLANG_LIBS
   clangFrontend
   clangRewrite
   clangSerialization
   clangTooling
+  LLVM_COMPONENTS
+  Support
   )
diff --git a/clang/unittests/Sema/CMakeLists.txt b/clang/unittests/Sema/CMakeLists.txt
index 17d39408000a4..acc76c932afeb 100644
--- a/clang/unittests/Sema/CMakeLists.txt
+++ b/clang/unittests/Sema/CMakeLists.txt
@@ -1,8 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
-  Support
-  )
-
 add_clang_unittest(SemaTests
   ExternalSemaSourceTest.cpp
   CodeCompleteTest.cpp
@@ -10,10 +5,7 @@ add_clang_unittest(SemaTests
   GslOwnerPointerInference.cpp
   SemaLookupTest.cpp
   SemaNoloadLookupTest.cpp
-  )
-
-clang_target_link_libraries(SemaTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangASTMatchers
   clangBasic
@@ -22,11 +14,11 @@ clang_target_link_libraries(SemaTests
   clangSema
   clangSerialization
   clangTooling
-  )
-
-target_link_libraries(SemaTests
-  PRIVATE
+  LINK_LIBS
   LLVMTestingAnnotations
   LLVMTestingSupport
   clangTesting
+  LLVM_COMPONENTS
+  FrontendOpenMP
+  Support
   )
diff --git a/clang/unittests/Serialization/CMakeLists.txt b/clang/unittests/Serialization/CMakeLists.txt
index e7005b5d511eb..6782e6b4d7330 100644
--- a/clang/unittests/Serialization/CMakeLists.txt
+++ b/clang/unittests/Serialization/CMakeLists.txt
@@ -1,10 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  BitReader
-  BitstreamReader
-  FrontendOpenMP
-  Support
-  )
-
 add_clang_unittest(SerializationTests
   ForceCheckFileInputTest.cpp
   InMemoryModuleCacheTest.cpp
@@ -14,10 +7,7 @@ add_clang_unittest(SerializationTests
   LoadSpecLazilyTest.cpp
   SourceLocationEncodingTest.cpp
   VarDeclConstantInitTest.cpp
-  )
-
-clang_target_link_libraries(SerializationTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangBasic
   clangFrontend
@@ -26,4 +16,9 @@ clang_target_link_libraries(SerializationTests
   clangSerialization
   clangTooling
   clangASTMatchers
+  LLVM_COMPONENTS
+  BitReader
+  BitstreamReader
+  FrontendOpenMP
+  Support
   )
diff --git a/clang/unittests/StaticAnalyzer/CMakeLists.txt b/clang/unittests/StaticAnalyzer/CMakeLists.txt
index 3b01a4e9e5327..143b7eedbfe05 100644
--- a/clang/unittests/StaticAnalyzer/CMakeLists.txt
+++ b/clang/unittests/StaticAnalyzer/CMakeLists.txt
@@ -1,8 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
-  Support
-  )
-
 add_clang_unittest(StaticAnalysisTests
   AnalyzerOptionsTest.cpp
   APSIntTypeTest.cpp
@@ -25,10 +20,7 @@ add_clang_unittest(StaticAnalysisTests
   SValTest.cpp
   TestReturnValueUnderConstruction.cpp
   Z3CrosscheckOracleTest.cpp
-  )
-
-clang_target_link_libraries(StaticAnalysisTests
-  PRIVATE
+  CLANG_LIBS
   clangBasic
   clangAnalysis
   clangAST
@@ -39,9 +31,9 @@ clang_target_link_libraries(StaticAnalysisTests
   clangStaticAnalyzerCore
   clangStaticAnalyzerFrontend
   clangTooling
-  )
-
-target_link_libraries(StaticAnalysisTests
-  PRIVATE
+  LINK_LIBS
   clangTesting
+  LLVM_COMPONENTS
+  FrontendOpenMP
+  Support
   )
diff --git a/clang/unittests/Support/CMakeLists.txt b/clang/unittests/Support/CMakeLists.txt
index 22be5ed18cc7a..d0ce4f6d10617 100644
--- a/clang/unittests/Support/CMakeLists.txt
+++ b/clang/unittests/Support/CMakeLists.txt
@@ -1,15 +1,10 @@
-set(LLVM_LINK_COMPONENTS
-  Support
-  )
-
 add_clang_unittest(ClangSupportTests
   TimeProfilerTest.cpp
-  )
-
-clang_target_link_libraries(ClangSupportTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangBasic
   clangFrontend
   clangSerialization
+  LLVM_COMPONENTS
+  Support
   )
diff --git a/clang/unittests/Tooling/CMakeLists.txt b/clang/unittests/Tooling/CMakeLists.txt
index 401978c31863c..106c6b9dc38bd 100644
--- a/clang/unittests/Tooling/CMakeLists.txt
+++ b/clang/unittests/Tooling/CMakeLists.txt
@@ -1,13 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  ${LLVM_TARGETS_TO_BUILD}
-  MC
-  Option
-  FrontendOpenMP
-  Support
-  TargetParser
-  )
-
-
 add_clang_unittest(ToolingTests
   ASTSelectionTest.cpp
   CastExprTest.cpp
@@ -69,10 +59,8 @@ add_clang_unittest(ToolingTests
   StencilTest.cpp
   ToolingTest.cpp
   TransformerTest.cpp
-  )
 
-clang_target_link_libraries(ToolingTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangASTMatchers
   clangBasi...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Apr 3, 2025

@llvm/pr-subscribers-clang-modules

Author: Reid Kleckner (rnk)

Changes

This reapplies 5ffd9bd (#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 .


Patch is 22.08 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/134195.diff

28 Files Affected:

  • (modified) clang/unittests/AST/ByteCode/CMakeLists.txt (+7-9)
  • (modified) clang/unittests/AST/CMakeLists.txt (+7-16)
  • (modified) clang/unittests/ASTMatchers/CMakeLists.txt (+7-15)
  • (modified) clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt (+5-13)
  • (modified) clang/unittests/Analysis/CMakeLists.txt (+5-13)
  • (modified) clang/unittests/Analysis/FlowSensitive/CMakeLists.txt (+5-13)
  • (modified) clang/unittests/Basic/CMakeLists.txt (+5-13)
  • (modified) clang/unittests/CMakeLists.txt (+28-4)
  • (modified) clang/unittests/CodeGen/CMakeLists.txt (+5-10)
  • (modified) clang/unittests/CrossTU/CMakeLists.txt (+3-9)
  • (modified) clang/unittests/DirectoryWatcher/CMakeLists.txt (+3-8)
  • (modified) clang/unittests/Driver/CMakeLists.txt (+7-12)
  • (modified) clang/unittests/Format/CMakeLists.txt (+3-8)
  • (modified) clang/unittests/Frontend/CMakeLists.txt (+4-8)
  • (modified) clang/unittests/Index/CMakeLists.txt (+4-9)
  • (modified) clang/unittests/InstallAPI/CMakeLists.txt (+3-6)
  • (modified) clang/unittests/Interpreter/CMakeLists.txt (+12-13)
  • (modified) clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt (+9-11)
  • (modified) clang/unittests/Lex/CMakeLists.txt (+4-12)
  • (modified) clang/unittests/Rewrite/CMakeLists.txt (+3-7)
  • (modified) clang/unittests/Sema/CMakeLists.txt (+5-13)
  • (modified) clang/unittests/Serialization/CMakeLists.txt (+6-11)
  • (modified) clang/unittests/StaticAnalyzer/CMakeLists.txt (+5-13)
  • (modified) clang/unittests/Support/CMakeLists.txt (+3-8)
  • (modified) clang/unittests/Tooling/CMakeLists.txt (+11-17)
  • (modified) clang/unittests/Tooling/Syntax/CMakeLists.txt (+5-10)
  • (modified) clang/unittests/libclang/CMakeLists.txt (+1-4)
  • (modified) clang/unittests/libclang/CrashTests/CMakeLists.txt (+1-4)
diff --git a/clang/unittests/AST/ByteCode/CMakeLists.txt b/clang/unittests/AST/ByteCode/CMakeLists.txt
index b862fb4834fbd..1469cd6b2a8ea 100644
--- a/clang/unittests/AST/ByteCode/CMakeLists.txt
+++ b/clang/unittests/AST/ByteCode/CMakeLists.txt
@@ -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
+  )
diff --git a/clang/unittests/AST/CMakeLists.txt b/clang/unittests/AST/CMakeLists.txt
index bfa6082a6ffa4..f27d34e8a0719 100644
--- a/clang/unittests/AST/CMakeLists.txt
+++ b/clang/unittests/AST/CMakeLists.txt
@@ -1,10 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
-  Support
-  TargetParser
-  )
-
-
 add_subdirectory(ByteCode)
 
 add_clang_unittest(ASTTests
@@ -43,10 +36,7 @@ add_clang_unittest(ASTTests
   TemplateNameTest.cpp
   TypePrinterTest.cpp
   UnresolvedSetTest.cpp
-  )
-
-clang_target_link_libraries(ASTTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangASTMatchers
   clangBasic
@@ -54,11 +44,12 @@ clang_target_link_libraries(ASTTests
   clangLex
   clangSerialization
   clangTooling
-  )
-
-target_link_libraries(ASTTests
-  PRIVATE
+  LINK_LIBS
   clangTesting
   LLVMTestingAnnotations
   LLVMTestingSupport
-)
+  LLVM_COMPONENTS
+  FrontendOpenMP
+  Support
+  TargetParser
+  )
diff --git a/clang/unittests/ASTMatchers/CMakeLists.txt b/clang/unittests/ASTMatchers/CMakeLists.txt
index 6a1e629d81b65..47bd5c108bb5a 100644
--- a/clang/unittests/ASTMatchers/CMakeLists.txt
+++ b/clang/unittests/ASTMatchers/CMakeLists.txt
@@ -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)
diff --git a/clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt b/clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt
index 6d0e12bcb0759..b6db7ce62afe7 100644
--- a/clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt
+++ b/clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt
@@ -1,16 +1,8 @@
-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
@@ -18,9 +10,9 @@ clang_target_link_libraries(DynamicASTMatchersTests
   clangFrontend
   clangSerialization
   clangTooling
-  )
-
-target_link_libraries(DynamicASTMatchersTests
-  PRIVATE
+  LINK_LIBS
   clangTesting
+  LLVM_COMPONENTS
+  FrontendOpenMP
+  Support
   )
diff --git a/clang/unittests/Analysis/CMakeLists.txt b/clang/unittests/Analysis/CMakeLists.txt
index cfea57f53f033..059a74843155c 100644
--- a/clang/unittests/Analysis/CMakeLists.txt
+++ b/clang/unittests/Analysis/CMakeLists.txt
@@ -1,8 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
-  Support
-  )
-
 add_clang_unittest(ClangAnalysisTests
   CFGDominatorTree.cpp
   CFGTest.cpp
@@ -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
@@ -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)
diff --git a/clang/unittests/Analysis/FlowSensitive/CMakeLists.txt b/clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
index 6c01ae8fc2e54..4ac563143cd68 100644
--- a/clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
+++ b/clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
@@ -1,8 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
-  Support
-  )
-
 add_clang_unittest(ClangAnalysisFlowSensitiveTests
   ArenaTest.cpp
   ASTOpsTest.cpp
@@ -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
@@ -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
   )
diff --git a/clang/unittests/Basic/CMakeLists.txt b/clang/unittests/Basic/CMakeLists.txt
index 3844ba49add8d..e818bd3e2c372 100644
--- a/clang/unittests/Basic/CMakeLists.txt
+++ b/clang/unittests/Basic/CMakeLists.txt
@@ -1,7 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  Support
-  )
-
 add_clang_unittest(BasicTests
   CharInfoTest.cpp
   DarwinSDKInfoTest.cpp
@@ -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
+  )
diff --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt
index 9b3ce8aa7de73..f3823ba309420 100644
--- a/clang/unittests/CMakeLists.txt
+++ b/clang/unittests/CMakeLists.txt
@@ -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)
diff --git a/clang/unittests/CodeGen/CMakeLists.txt b/clang/unittests/CodeGen/CMakeLists.txt
index a437f441568f2..f5bcecb0b08a3 100644
--- a/clang/unittests/CodeGen/CMakeLists.txt
+++ b/clang/unittests/CodeGen/CMakeLists.txt
@@ -1,18 +1,9 @@
-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
@@ -20,4 +11,8 @@ clang_target_link_libraries(ClangCodeGenTests
   clangLex
   clangParse
   clangSerialization
+  LLVM_COMPONENTS
+  Core
+  Support
+  TargetParser
   )
diff --git a/clang/unittests/CrossTU/CMakeLists.txt b/clang/unittests/CrossTU/CMakeLists.txt
index 222b7e83dc38c..ee81c57ca1dce 100644
--- a/clang/unittests/CrossTU/CMakeLists.txt
+++ b/clang/unittests/CrossTU/CMakeLists.txt
@@ -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
   )
diff --git a/clang/unittests/DirectoryWatcher/CMakeLists.txt b/clang/unittests/DirectoryWatcher/CMakeLists.txt
index 38882c9ec2162..58e0aee2d1076 100644
--- a/clang/unittests/DirectoryWatcher/CMakeLists.txt
+++ b/clang/unittests/DirectoryWatcher/CMakeLists.txt
@@ -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()
diff --git a/clang/unittests/Driver/CMakeLists.txt b/clang/unittests/Driver/CMakeLists.txt
index efdd07ea23889..fa0e87c3318df 100644
--- a/clang/unittests/Driver/CMakeLists.txt
+++ b/clang/unittests/Driver/CMakeLists.txt
@@ -1,11 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  ${LLVM_TARGETS_TO_BUILD}
-  MC
-  Option
-  Support
-  TargetParser
-  )
-
 add_clang_unittest(ClangDriverTests
   DistroTest.cpp
   DXCModeTest.cpp
@@ -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
   )
diff --git a/clang/unittests/Format/CMakeLists.txt b/clang/unittests/Format/CMakeLists.txt
index 71f5886d946c8..5bd6a17182d29 100644
--- a/clang/unittests/Format/CMakeLists.txt
+++ b/clang/unittests/Format/CMakeLists.txt
@@ -1,7 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  Support
-  )
-
 add_clang_unittest(FormatTests
   BracesInserterTest.cpp
   BracesRemoverTest.cpp
@@ -36,12 +32,11 @@ add_clang_unittest(FormatTests
   SortIncludesTest.cpp
   UsingDeclarationsSorterTest.cpp
   TokenAnnotatorTest.cpp
-  )
-
-clang_target_link_libraries(FormatTests
-  PRIVATE
+  CLANG_LIBS
   clangBasic
   clangFormat
   clangRewrite
   clangToolingCore
+  LLVM_COMPONENTS
+  Support
   )
diff --git a/clang/unittests/Frontend/CMakeLists.txt b/clang/unittests/Frontend/CMakeLists.txt
index 3c94846243870..bbf0396014fa9 100644
--- a/clang/unittests/Frontend/CMakeLists.txt
+++ b/clang/unittests/Frontend/CMakeLists.txt
@@ -1,8 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  Support
-  TargetParser
-  )
-
 add_clang_unittest(FrontendTests
   ASTUnitTest.cpp
   CompilerInvocationTest.cpp
@@ -17,9 +12,7 @@ add_clang_unittest(FrontendTests
   OutputStreamTest.cpp
   TextDiagnosticTest.cpp
   UtilsTest.cpp
-  )
-clang_target_link_libraries(FrontendTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangBasic
   clangFrontend
@@ -29,4 +22,7 @@ clang_target_link_libraries(FrontendTests
   clangFrontendTool
   clangSerialization
   clangTooling
+  LLVM_COMPONENTS
+  Support
+  TargetParser
   )
diff --git a/clang/unittests/Index/CMakeLists.txt b/clang/unittests/Index/CMakeLists.txt
index ea940e9d7a9ef..15e9ba0643eaf 100644
--- a/clang/unittests/Index/CMakeLists.txt
+++ b/clang/unittests/Index/CMakeLists.txt
@@ -1,14 +1,6 @@
-set(LLVM_LINK_COMPONENTS
-  ${LLVM_TARGETS_TO_BUILD}
-  Support
-  )
-
 add_clang_unittest(IndexTests
   IndexTests.cpp
-  )
-
-clang_target_link_libraries(IndexTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangBasic
   clangFrontend
@@ -16,4 +8,7 @@ clang_target_link_libraries(IndexTests
   clangLex
   clangSerialization
   clangTooling
+  LLVM_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  Support
   )
diff --git a/clang/unittests/InstallAPI/CMakeLists.txt b/clang/unittests/InstallAPI/CMakeLists.txt
index 4255001ff51f1..c174fa3f87161 100644
--- a/clang/unittests/InstallAPI/CMakeLists.txt
+++ b/clang/unittests/InstallAPI/CMakeLists.txt
@@ -1,11 +1,8 @@
 add_clang_unittest(InstallAPITests
   HeaderFileTest.cpp
   FileListTest.cpp
-  )
-
-clang_target_link_libraries(InstallAPITests
-  PRIVATE
+  CLANG_LIBS
   clangInstallAPI 
+  LINK_LIBS
+  LLVMTestingSupport
   )
-
-target_link_libraries(InstallAPITests PRIVATE LLVMTestingSupport)
diff --git a/clang/unittests/Interpreter/CMakeLists.txt b/clang/unittests/Interpreter/CMakeLists.txt
index 95378f9cfe737..9df1a4b03da47 100644
--- a/clang/unittests/Interpreter/CMakeLists.txt
+++ b/clang/unittests/Interpreter/CMakeLists.txt
@@ -1,12 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  ${LLVM_TARGETS_TO_BUILD}
-  Core
-  MC
-  OrcJIT
-  Support
-  TargetParser
-  )
-
 add_clang_unittest(ClangReplInterpreterTests
   IncrementalCompilerBuilderTest.cpp
   IncrementalProcessingTest.cpp
@@ -15,16 +6,24 @@ add_clang_unittest(ClangReplInterpreterTests
   CodeCompletionTest.cpp
 
   EXPORT_SYMBOLS
-  )
-  
-target_link_libraries(ClangReplInterpreterTests PUBLIC LLVMTestingSupport)
 
-clang_target_link_libraries(ClangReplInterpreterTests PRIVATE
+  CLANG_LIBS
   clangAST
   clangBasic
   clangInterpreter
   clangFrontend
   clangSema
+
+  LINK_LIBS
+  LLVMTestingSupport
+
+  LLVM_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  Core
+  MC
+  OrcJIT
+  Support
+  TargetParser
   )
 
 # Exceptions on Windows are not yet supported.
diff --git a/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt b/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
index 24ae9cd78b5ca..eb366a860661c 100644
--- a/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
+++ b/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
@@ -3,24 +3,22 @@
 set(LLVM_REQUIRES_EH ON)
 set(LLVM_REQUIRES_RTTI ON)
 
-set(LLVM_LINK_COMPONENTS
-  ${LLVM_TARGETS_TO_BUILD}
-  Core
-  OrcJIT
-  Support
-  )
-
 add_clang_unittest(ClangReplInterpreterExceptionTests
   InterpreterExceptionTest.cpp
-
   EXPORT_SYMBOLS
-  )
 
-llvm_update_compile_flags(ClangReplInterpreterExceptionTests)
-target_link_libraries(ClangReplInterpreterExceptionTests PUBLIC
+  CLANG_LIBS
   clangAST
   clangBasic
   clangInterpreter
   clangFrontend
+
+  LLVM_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  Core
+  OrcJIT
+  Support
   )
+
+llvm_update_compile_flags(ClangReplInterpreterExceptionTests)
 add_dependencies(ClangReplInterpreterExceptionTests clang-resource-headers)
diff --git a/clang/unittests/Lex/CMakeLists.txt b/clang/unittests/Lex/CMakeLists.txt
index 5ec93946594b7..96ca6dda9cd85 100644
--- a/clang/unittests/Lex/CMakeLists.txt
+++ b/clang/unittests/Lex/CMakeLists.txt
@@ -1,7 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  Support
-  )
-
 add_clang_unittest(LexTests
   DependencyDirectivesScannerTest.cpp
   HeaderMapTest.cpp
@@ -13,19 +9,15 @@ add_clang_unittest(LexTests
   PPConditionalDirectiveRecordTest.cpp
   PPDependencyDirectivesTest.cpp
   PPMemoryAllocationsTest.cpp
-  )
-
-clang_target_link_libraries(LexTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangBasic
   clangLex
   clangParse
   clangSema
-  )
-
-target_link_libraries(LexTests
-  PRIVATE
+  LINK_LIBS
   LLVMTestingAnnotations
   LLVMTestingSupport
+  LLVM_COMPONENTS
+  Support
   )
diff --git a/clang/unittests/Rewrite/CMakeLists.txt b/clang/unittests/Rewrite/CMakeLists.txt
index 3c5e2f8e5354b..498613254e72b 100644
--- a/clang/unittests/Rewrite/CMakeLists.txt
+++ b/clang/unittests/Rewrite/CMakeLists.txt
@@ -1,14 +1,10 @@
-set(LLVM_LINK_COMPONENTS
-  Support
-  )
-
 add_clang_unittest(RewriteTests
   RewriterTest.cpp
-  )
-clang_target_link_libraries(RewriteTests
-  PRIVATE
+  CLANG_LIBS
   clangFrontend
   clangRewrite
   clangSerialization
   clangTooling
+  LLVM_COMPONENTS
+  Support
   )
diff --git a/clang/unittests/Sema/CMakeLists.txt b/clang/unittests/Sema/CMakeLists.txt
index 17d39408000a4..acc76c932afeb 100644
--- a/clang/unittests/Sema/CMakeLists.txt
+++ b/clang/unittests/Sema/CMakeLists.txt
@@ -1,8 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
-  Support
-  )
-
 add_clang_unittest(SemaTests
   ExternalSemaSourceTest.cpp
   CodeCompleteTest.cpp
@@ -10,10 +5,7 @@ add_clang_unittest(SemaTests
   GslOwnerPointerInference.cpp
   SemaLookupTest.cpp
   SemaNoloadLookupTest.cpp
-  )
-
-clang_target_link_libraries(SemaTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangASTMatchers
   clangBasic
@@ -22,11 +14,11 @@ clang_target_link_libraries(SemaTests
   clangSema
   clangSerialization
   clangTooling
-  )
-
-target_link_libraries(SemaTests
-  PRIVATE
+  LINK_LIBS
   LLVMTestingAnnotations
   LLVMTestingSupport
   clangTesting
+  LLVM_COMPONENTS
+  FrontendOpenMP
+  Support
   )
diff --git a/clang/unittests/Serialization/CMakeLists.txt b/clang/unittests/Serialization/CMakeLists.txt
index e7005b5d511eb..6782e6b4d7330 100644
--- a/clang/unittests/Serialization/CMakeLists.txt
+++ b/clang/unittests/Serialization/CMakeLists.txt
@@ -1,10 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  BitReader
-  BitstreamReader
-  FrontendOpenMP
-  Support
-  )
-
 add_clang_unittest(SerializationTests
   ForceCheckFileInputTest.cpp
   InMemoryModuleCacheTest.cpp
@@ -14,10 +7,7 @@ add_clang_unittest(SerializationTests
   LoadSpecLazilyTest.cpp
   SourceLocationEncodingTest.cpp
   VarDeclConstantInitTest.cpp
-  )
-
-clang_target_link_libraries(SerializationTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangBasic
   clangFrontend
@@ -26,4 +16,9 @@ clang_target_link_libraries(SerializationTests
   clangSerialization
   clangTooling
   clangASTMatchers
+  LLVM_COMPONENTS
+  BitReader
+  BitstreamReader
+  FrontendOpenMP
+  Support
   )
diff --git a/clang/unittests/StaticAnalyzer/CMakeLists.txt b/clang/unittests/StaticAnalyzer/CMakeLists.txt
index 3b01a4e9e5327..143b7eedbfe05 100644
--- a/clang/unittests/StaticAnalyzer/CMakeLists.txt
+++ b/clang/unittests/StaticAnalyzer/CMakeLists.txt
@@ -1,8 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
-  Support
-  )
-
 add_clang_unittest(StaticAnalysisTests
   AnalyzerOptionsTest.cpp
   APSIntTypeTest.cpp
@@ -25,10 +20,7 @@ add_clang_unittest(StaticAnalysisTests
   SValTest.cpp
   TestReturnValueUnderConstruction.cpp
   Z3CrosscheckOracleTest.cpp
-  )
-
-clang_target_link_libraries(StaticAnalysisTests
-  PRIVATE
+  CLANG_LIBS
   clangBasic
   clangAnalysis
   clangAST
@@ -39,9 +31,9 @@ clang_target_link_libraries(StaticAnalysisTests
   clangStaticAnalyzerCore
   clangStaticAnalyzerFrontend
   clangTooling
-  )
-
-target_link_libraries(StaticAnalysisTests
-  PRIVATE
+  LINK_LIBS
   clangTesting
+  LLVM_COMPONENTS
+  FrontendOpenMP
+  Support
   )
diff --git a/clang/unittests/Support/CMakeLists.txt b/clang/unittests/Support/CMakeLists.txt
index 22be5ed18cc7a..d0ce4f6d10617 100644
--- a/clang/unittests/Support/CMakeLists.txt
+++ b/clang/unittests/Support/CMakeLists.txt
@@ -1,15 +1,10 @@
-set(LLVM_LINK_COMPONENTS
-  Support
-  )
-
 add_clang_unittest(ClangSupportTests
   TimeProfilerTest.cpp
-  )
-
-clang_target_link_libraries(ClangSupportTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangBasic
   clangFrontend
   clangSerialization
+  LLVM_COMPONENTS
+  Support
   )
diff --git a/clang/unittests/Tooling/CMakeLists.txt b/clang/unittests/Tooling/CMakeLists.txt
index 401978c31863c..106c6b9dc38bd 100644
--- a/clang/unittests/Tooling/CMakeLists.txt
+++ b/clang/unittests/Tooling/CMakeLists.txt
@@ -1,13 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  ${LLVM_TARGETS_TO_BUILD}
-  MC
-  Option
-  FrontendOpenMP
-  Support
-  TargetParser
-  )
-
-
 add_clang_unittest(ToolingTests
   ASTSelectionTest.cpp
   CastExprTest.cpp
@@ -69,10 +59,8 @@ add_clang_unittest(ToolingTests
   StencilTest.cpp
   ToolingTest.cpp
   TransformerTest.cpp
-  )
 
-clang_target_link_libraries(ToolingTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangASTMatchers
   clangBasi...
[truncated]

@rnk rnk merged commit e3c0565 into llvm:main Apr 3, 2025
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:dataflow Clang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.html clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category clang-format
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants