Skip to content

Commit 8897331

Browse files
committed
Simplify the Clang unittest function in the CMake build, and make it
match the LLVM implemenation. This also simplifies the name management and splits the custom library management out from the unittest specific management. It finally drops the dependency on parsing cmake arguments. llvm-svn: 158894
1 parent 1313d98 commit 8897331

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

clang/unittests/CMakeLists.txt

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
include(LLVMParseArguments)
2-
3-
# add_clang_unittest(test_dirname file1.cpp file2.cpp ...
4-
# [USED_LIBS lib1 lib2])
1+
# add_clang_unittest(test_dirname file1.cpp file2.cpp)
52
#
63
# Will compile the list of files together and link against the clang
7-
# libraries in the USED_LIBS. Produces a binary named
8-
# 'basename(test_dirname)Tests'.
9-
function(add_clang_unittest)
10-
parse_arguments(CLANG_UNITTEST "USED_LIBS" "" ${ARGN})
11-
list(GET CLANG_UNITTEST_DEFAULT_ARGS 0 test_dirname)
12-
list(REMOVE_AT CLANG_UNITTEST_DEFAULT_ARGS 0)
13-
4+
# Produces a binary named 'basename(test_dirname)'.
5+
function(add_clang_unittest test_dirname)
146
string(REGEX MATCH "([^/]+)$" test_name ${test_dirname})
157
if (CMAKE_BUILD_TYPE)
168
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
@@ -22,10 +14,16 @@ function(add_clang_unittest)
2214
if( NOT LLVM_BUILD_TESTS )
2315
set(EXCLUDE_FROM_ALL ON)
2416
endif()
25-
add_clang_executable(${test_name}Tests ${CLANG_UNITTEST_DEFAULT_ARGS})
26-
target_link_libraries(${test_name}Tests ${CLANG_UNITTEST_USED_LIBS})
27-
add_dependencies(ClangUnitTests ${test_name}Tests)
28-
set_target_properties(${test_name}Tests PROPERTIES FOLDER "Clang tests")
17+
18+
add_clang_executable(${test_name} ${ARGN})
19+
target_link_libraries(${test_name}
20+
gtest
21+
gtest_main
22+
LLVMSupport # gtest needs it for raw_ostream.
23+
)
24+
25+
add_dependencies(ClangUnitTests ${test_name})
26+
set_target_properties(${test_name} PROPERTIES FOLDER "Clang tests")
2927
endfunction()
3028

3129
add_custom_target(ClangUnitTests)
@@ -48,27 +46,37 @@ if(SUPPORTS_NO_VARIADIC_MACROS_FLAG)
4846
add_definitions("-Wno-variadic-macros")
4947
endif()
5048

51-
add_clang_unittest(Basic
49+
add_clang_unittest(BasicTests
5250
Basic/FileManagerTest.cpp
5351
Basic/SourceManagerTest.cpp
54-
USED_LIBS gtest gtest_main clangLex
55-
)
52+
)
53+
target_link_libraries(BasicTests
54+
clangLex
55+
)
5656

57-
add_clang_unittest(Lex
57+
add_clang_unittest(LexTests
5858
Lex/LexerTest.cpp
59-
USED_LIBS gtest gtest_main clangLex
60-
)
59+
)
60+
target_link_libraries(LexTests
61+
clangLex
62+
)
6163

62-
add_clang_unittest(Frontend
64+
add_clang_unittest(FrontendTests
6365
Frontend/FrontendActionTest.cpp
64-
USED_LIBS gtest gtest_main clangFrontend
65-
)
66+
)
67+
target_link_libraries(FrontendTests
68+
clangFrontend
69+
)
6670

67-
add_clang_unittest(Tooling
71+
add_clang_unittest(ToolingTests
6872
Tooling/CompilationDatabaseTest.cpp
6973
Tooling/ToolingTest.cpp
7074
Tooling/RecursiveASTVisitorTest.cpp
7175
Tooling/RefactoringTest.cpp
7276
Tooling/RewriterTest.cpp
73-
USED_LIBS gtest gtest_main clangAST clangTooling clangRewrite
74-
)
77+
)
78+
target_link_libraries(ToolingTests
79+
clangAST
80+
clangTooling
81+
clangRewrite
82+
)

0 commit comments

Comments
 (0)