[flang-commits] [flang] 9cb222e - [cmake] Make gtest include directories a part of the library interface

Pavel Labath via flang-commits flang-commits at lists.llvm.org
Thu Aug 27 06:36:07 PDT 2020


Author: Pavel Labath
Date: 2020-08-27T15:35:57+02:00
New Revision: 9cb222e749e8392517a138cf6645a7c220d671c8

URL: https://github.com/llvm/llvm-project/commit/9cb222e749e8392517a138cf6645a7c220d671c8
DIFF: https://github.com/llvm/llvm-project/commit/9cb222e749e8392517a138cf6645a7c220d671c8.diff

LOG: [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

Added: 
    

Modified: 
    flang/CMakeLists.txt
    libc/benchmarks/CMakeLists.txt
    lldb/unittests/TestingSupport/Symbol/CMakeLists.txt
    llvm/cmake/modules/AddLLVM.cmake
    llvm/lib/Testing/Support/CMakeLists.txt
    llvm/utils/unittest/CMakeLists.txt
    polly/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 73c2db55e8f8..03440b72ec8c 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -135,13 +135,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   if (FLANG_INCLUDE_TESTS)
     set(UNITTEST_DIR ${LLVM_BUILD_MAIN_SRC_DIR}/utils/unittest)
     if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
-      if (TARGET gtest)
-        # LLVM Doesn't export gtest's include directorys, so do that here
-        set_target_properties(gtest
-          PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
-          "${UNITTEST_DIR}/googletest/include;${UNITTEST_DIR}/googlemock/include"
-          )
-      else()
+      if (NOT TARGET gtest)
         add_library(gtest
           ${UNITTEST_DIR}/googletest/src/gtest-all.cc
           ${UNITTEST_DIR}/googlemock/src/gmock-all.cc

diff  --git a/libc/benchmarks/CMakeLists.txt b/libc/benchmarks/CMakeLists.txt
index 6f3cfdb64a5f..2275dad7f653 100644
--- a/libc/benchmarks/CMakeLists.txt
+++ b/libc/benchmarks/CMakeLists.txt
@@ -53,11 +53,6 @@ function(add_libc_benchmark_unittest target_name)
     EXCLUDE_FROM_ALL
     ${LIBC_BENCHMARKS_UNITTEST_SRCS}
   )
-  target_include_directories(${target_name}
-    PRIVATE
-    ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include
-    ${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include
-  )
   target_link_libraries(${target_name}
     PRIVATE
     gtest_main

diff  --git a/lldb/unittests/TestingSupport/Symbol/CMakeLists.txt b/lldb/unittests/TestingSupport/Symbol/CMakeLists.txt
index 3faec7c8030b..38a518682853 100644
--- a/lldb/unittests/TestingSupport/Symbol/CMakeLists.txt
+++ b/lldb/unittests/TestingSupport/Symbol/CMakeLists.txt
@@ -2,7 +2,3 @@ set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL ON)
 add_lldb_library(lldbSymbolHelpers
   YAMLModuleTester.cpp
   )
-
-target_include_directories(lldbSymbolHelpers PUBLIC
-  ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include
-  ${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include)

diff  --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 1689d36171c3..a40cf17426fe 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1401,9 +1401,6 @@ function(add_unittest test_suite test_name)
     set(EXCLUDE_FROM_ALL ON)
   endif()
 
-  include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
-  include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include)
-
   if (SUPPORTS_VARIADIC_MACROS_FLAG)
     list(APPEND LLVM_COMPILE_FLAGS "-Wno-variadic-macros")
   endif ()

diff  --git a/llvm/lib/Testing/Support/CMakeLists.txt b/llvm/lib/Testing/Support/CMakeLists.txt
index 4f5345c1dc57..ed2fd8ae43b2 100644
--- a/llvm/lib/Testing/Support/CMakeLists.txt
+++ b/llvm/lib/Testing/Support/CMakeLists.txt
@@ -12,6 +12,4 @@ add_llvm_library(LLVMTestingSupport
   Support
   )
 
-include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
-include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include)
 target_link_libraries(LLVMTestingSupport PRIVATE gtest)

diff  --git a/llvm/utils/unittest/CMakeLists.txt b/llvm/utils/unittest/CMakeLists.txt
index 14c780342b60..43c8fafdfc4c 100644
--- a/llvm/utils/unittest/CMakeLists.txt
+++ b/llvm/utils/unittest/CMakeLists.txt
@@ -11,14 +11,6 @@
 #
 # Project-wide settings
 
-# Where gtest's .h files can be found.
-include_directories(
-  googletest/include
-  googletest
-  googlemock/include
-  googlemock
-  )
-
 if(WIN32)
   add_definitions(-DGTEST_OS_WINDOWS=1)
 endif()
@@ -76,6 +68,11 @@ if (NOT LLVM_ENABLE_THREADS)
   target_compile_definitions(gtest PUBLIC GTEST_HAS_PTHREAD=0)
 endif ()
 
+target_include_directories(gtest
+  PUBLIC googletest/include googlemock/include
+  PRIVATE googletest googlemock
+  )
+
 add_subdirectory(UnitTestMain)
 
 # When LLVM_LINK_LLVM_DYLIB is enabled, libLLVM.so is added to the interface

diff  --git a/polly/CMakeLists.txt b/polly/CMakeLists.txt
index 0f5f71bba9d9..fe7f6b78b479 100644
--- a/polly/CMakeLists.txt
+++ b/polly/CMakeLists.txt
@@ -30,12 +30,6 @@ if (NOT DEFINED LLVM_MAIN_SRC_DIR)
     if (NOT TARGET gtest)
       add_subdirectory(${UNITTEST_DIR} utils/unittest)
     endif()
-
-    # LLVM Doesn't export gtest's include directorys, so do that here
-    set_target_properties(gtest
-      PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
-      "${UNITTEST_DIR}/googletest/include;${UNITTEST_DIR}/googlemock/include"
-      )
     set(POLLY_GTEST_AVAIL 1)
   endif()
 


        


More information about the flang-commits mailing list