Skip to content

Commit 9cb222e

Browse files
committed
[cmake] Make gtest include directories a part of the library interface
This applies the same fix that D84748 did for macro definitions. Appropriate include path is now automatically set for all libraries which link against gtest targets, which avoids the need to set include_directories in various parts of the project. Differential Revision: https://reviews.llvm.org/D86616
1 parent 2668256 commit 9cb222e

File tree

7 files changed

+6
-35
lines changed

7 files changed

+6
-35
lines changed

flang/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
135135
if (FLANG_INCLUDE_TESTS)
136136
set(UNITTEST_DIR ${LLVM_BUILD_MAIN_SRC_DIR}/utils/unittest)
137137
if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
138-
if (TARGET gtest)
139-
# LLVM Doesn't export gtest's include directorys, so do that here
140-
set_target_properties(gtest
141-
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
142-
"${UNITTEST_DIR}/googletest/include;${UNITTEST_DIR}/googlemock/include"
143-
)
144-
else()
138+
if (NOT TARGET gtest)
145139
add_library(gtest
146140
${UNITTEST_DIR}/googletest/src/gtest-all.cc
147141
${UNITTEST_DIR}/googlemock/src/gmock-all.cc

libc/benchmarks/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ function(add_libc_benchmark_unittest target_name)
5353
EXCLUDE_FROM_ALL
5454
${LIBC_BENCHMARKS_UNITTEST_SRCS}
5555
)
56-
target_include_directories(${target_name}
57-
PRIVATE
58-
${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include
59-
${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include
60-
)
6156
target_link_libraries(${target_name}
6257
PRIVATE
6358
gtest_main

lldb/unittests/TestingSupport/Symbol/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,3 @@ set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL ON)
22
add_lldb_library(lldbSymbolHelpers
33
YAMLModuleTester.cpp
44
)
5-
6-
target_include_directories(lldbSymbolHelpers PUBLIC
7-
${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include
8-
${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include)

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,9 +1401,6 @@ function(add_unittest test_suite test_name)
14011401
set(EXCLUDE_FROM_ALL ON)
14021402
endif()
14031403
1404-
include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
1405-
include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include)
1406-
14071404
if (SUPPORTS_VARIADIC_MACROS_FLAG)
14081405
list(APPEND LLVM_COMPILE_FLAGS "-Wno-variadic-macros")
14091406
endif ()

llvm/lib/Testing/Support/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@ add_llvm_library(LLVMTestingSupport
1212
Support
1313
)
1414

15-
include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
16-
include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include)
1715
target_link_libraries(LLVMTestingSupport PRIVATE gtest)

llvm/utils/unittest/CMakeLists.txt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@
1111
#
1212
# Project-wide settings
1313

14-
# Where gtest's .h files can be found.
15-
include_directories(
16-
googletest/include
17-
googletest
18-
googlemock/include
19-
googlemock
20-
)
21-
2214
if(WIN32)
2315
add_definitions(-DGTEST_OS_WINDOWS=1)
2416
endif()
@@ -76,6 +68,11 @@ if (NOT LLVM_ENABLE_THREADS)
7668
target_compile_definitions(gtest PUBLIC GTEST_HAS_PTHREAD=0)
7769
endif ()
7870

71+
target_include_directories(gtest
72+
PUBLIC googletest/include googlemock/include
73+
PRIVATE googletest googlemock
74+
)
75+
7976
add_subdirectory(UnitTestMain)
8077

8178
# When LLVM_LINK_LLVM_DYLIB is enabled, libLLVM.so is added to the interface

polly/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ if (NOT DEFINED LLVM_MAIN_SRC_DIR)
3030
if (NOT TARGET gtest)
3131
add_subdirectory(${UNITTEST_DIR} utils/unittest)
3232
endif()
33-
34-
# LLVM Doesn't export gtest's include directorys, so do that here
35-
set_target_properties(gtest
36-
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
37-
"${UNITTEST_DIR}/googletest/include;${UNITTEST_DIR}/googlemock/include"
38-
)
3933
set(POLLY_GTEST_AVAIL 1)
4034
endif()
4135

0 commit comments

Comments
 (0)