Skip to content

[clang] Merge gtest binaries into AllClangUnitTests #134196

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 12 commits into from
Apr 29, 2025
53 changes: 51 additions & 2 deletions clang/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ if(CLANG_BUILT_STANDALONE)
endif()
endif()

# add_clang_unittest(test_name file1.cpp file2.cpp)
# add_distinct_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_name)'.
function(add_clang_unittest test_name)
function(add_distinct_clang_unittest test_name)
cmake_parse_arguments(ARG
""
""
Expand Down Expand Up @@ -47,6 +47,33 @@ function(add_clang_unittest test_name)
target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBS})
endfunction()

define_property(GLOBAL PROPERTY CLANG_UNITTEST_SRCS)
define_property(GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS)
define_property(GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS)
define_property(GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS)

# add_clang_unittest(test_name file1.cpp file2.cpp)
#
# Adds unittests to the combined AllClangUnitTests binary. The unittest binary
# is defined after adding all unittest subdirectories.
function(add_clang_unittest test_name)
cmake_parse_arguments(ARG
""
""
"CLANG_LIBS;LINK_LIBS;LLVM_COMPONENTS"
${ARGN})

file(RELATIVE_PATH src_prefix "${CMAKE_CURRENT_FUNCTION_LIST_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
set(srcs_prefixed)
foreach(src ${ARG_UNPARSED_ARGUMENTS})
set(srcs_prefixed ${srcs_prefixed} "${src_prefix}/${src}")
endforeach()
set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_SRCS ${srcs_prefixed})
set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_CLANG_LIBS ${ARG_CLANG_LIBS})
set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_LINK_LIBS ${ARG_LINK_LIBS})
set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS ${ARG_LLVM_COMPONENTS})
endfunction()

add_subdirectory(Basic)
add_subdirectory(Lex)
add_subdirectory(Parse)
Expand Down Expand Up @@ -77,3 +104,25 @@ add_subdirectory(Index)
add_subdirectory(InstallAPI)
add_subdirectory(Serialization)
add_subdirectory(Support)


# If we're doing a single merged clang unit test binary, add that target after
# all the previous subdirectories have been processed.
get_property(SRCS GLOBAL PROPERTY CLANG_UNITTEST_SRCS)
get_property(CLANG_LIBS GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS)
get_property(LINK_LIBS GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS)
get_property(LLVM_COMPONENTS GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS)
add_distinct_clang_unittest(AllClangUnitTests
${SRCS}
CLANG_LIBS
${CLANG_LIBS}
LINK_LIBS
${LINK_LIBS}
LLVM_COMPONENTS
${LLVM_COMPONENTS}
)

# The Tooling library has some internal headers. Make those work. If we like
# the merged clang unit test binary, we can udpate the include paths and make
# this the default.
include_directories(Tooling)
2 changes: 1 addition & 1 deletion clang/unittests/Driver/ModuleCacheTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using namespace clang::driver;

namespace {

TEST(ModuleCacheTest, GetTargetAndMode) {
TEST(DriverModuleCacheTest, GetTargetAndMode) {
SmallString<128> Buf;
Driver::getDefaultModuleCachePath(Buf);
StringRef Path = Buf;
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_clang_unittest(ClangReplInterpreterTests
add_distinct_clang_unittest(ClangReplInterpreterTests
IncrementalCompilerBuilderTest.cpp
IncrementalProcessingTest.cpp
InterpreterTest.cpp
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set(LLVM_REQUIRES_EH ON)
set(LLVM_REQUIRES_RTTI ON)

add_clang_unittest(ClangReplInterpreterExceptionTests
add_distinct_clang_unittest(ClangReplInterpreterExceptionTests
InterpreterExceptionTest.cpp
EXPORT_SYMBOLS

Expand Down
13 changes: 4 additions & 9 deletions clang/unittests/Parse/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
set(LLVM_LINK_COMPONENTS
Support
)
add_clang_unittest(ParseTests
ParseHLSLRootSignatureTest.cpp
)
clang_target_link_libraries(ParseTests
PRIVATE
CLANG_LIBS
clangAST
clangBasic
clangLex
clangParse
clangSema
)
target_link_libraries(ParseTests
PRIVATE
LINK_LIBS
LLVMTestingAnnotations
LLVMTestingSupport
clangTesting
LLVM_COMPONENTS
Support
)
Loading