[llvm] 0807986 - Add install targets for gtest

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 10 17:29:32 PST 2023


Author: Tom Stellard
Date: 2023-03-10T17:22:33-08:00
New Revision: 0807986303f5d498cee32d42c242940d00617ad9

URL: https://github.com/llvm/llvm-project/commit/0807986303f5d498cee32d42c242940d00617ad9
DIFF: https://github.com/llvm/llvm-project/commit/0807986303f5d498cee32d42c242940d00617ad9.diff

LOG: Add install targets for gtest

Stand-alone builds need an installed version of gtest in order to run
the unittests.

Reviewed By: mgorny, kwk

Differential Revision: https://reviews.llvm.org/D137890

Added: 
    

Modified: 
    llvm/CMakeLists.txt
    llvm/lib/Testing/Annotations/CMakeLists.txt
    llvm/lib/Testing/Support/CMakeLists.txt
    third-party/unittest/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index ba73ebaeaf4a..bd23d6657829 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -720,6 +720,10 @@ option(LLVM_BUILD_TESTS
   "Build LLVM unit tests. If OFF, just generate build targets." OFF)
 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
 
+option(LLVM_INSTALL_GTEST
+  "Install the llvm gtest library.  This should be on if you want to do
+   stand-alone builds of the other projects and run their unit tests." OFF)
+
 option(LLVM_BUILD_BENCHMARKS "Add LLVM benchmark targets to the list of default
 targets. If OFF, benchmarks still could be built using Benchmarks target." OFF)
 option(LLVM_INCLUDE_BENCHMARKS "Generate benchmark targets. If OFF, benchmarks can't be built." ON)

diff  --git a/llvm/lib/Testing/Annotations/CMakeLists.txt b/llvm/lib/Testing/Annotations/CMakeLists.txt
index 75e006207edb..1d8dba8b6a41 100644
--- a/llvm/lib/Testing/Annotations/CMakeLists.txt
+++ b/llvm/lib/Testing/Annotations/CMakeLists.txt
@@ -1,11 +1,14 @@
 # Do not build unittest libraries automatically, they will be pulled in
 # by unittests if these are built.
-set(EXCLUDE_FROM_ALL ON)
+if (NOT ${LLVM_INSTALL_GTEST})
+  set (BUILDTREE_ONLY BUILDTREE_ONLY)
+  set(EXCLUDE_FROM_ALL ON)
+endif()
 
 add_llvm_library(LLVMTestingAnnotations
   Annotations.cpp
 
-  BUILDTREE_ONLY
+  ${BUILDTREE_ONLY}
 
   ADDITIONAL_HEADER_DIRS
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Testing/Support

diff  --git a/llvm/lib/Testing/Support/CMakeLists.txt b/llvm/lib/Testing/Support/CMakeLists.txt
index 766c64b6fdd6..6955271239ca 100644
--- a/llvm/lib/Testing/Support/CMakeLists.txt
+++ b/llvm/lib/Testing/Support/CMakeLists.txt
@@ -1,12 +1,15 @@
 # Do not build unittest libraries automatically, they will be pulled in
 # by unittests if these are built.
-set(EXCLUDE_FROM_ALL ON)
+if (NOT ${LLVM_INSTALL_GTEST})
+  set (BUILDTREE_ONLY BUILDTREE_ONLY)
+  set(EXCLUDE_FROM_ALL ON)
+endif()
 
 add_llvm_library(LLVMTestingSupport
   Error.cpp
   SupportHelpers.cpp
 
-  BUILDTREE_ONLY
+  ${BUILDTREE_ONLY}
 
   ADDITIONAL_HEADER_DIRS
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Testing/Support

diff  --git a/third-party/unittest/CMakeLists.txt b/third-party/unittest/CMakeLists.txt
index 302e9e0e8440..74a523b6dfcc 100644
--- a/third-party/unittest/CMakeLists.txt
+++ b/third-party/unittest/CMakeLists.txt
@@ -40,7 +40,13 @@ endif()
 
 # Do not build unittest libraries automatically, they will be pulled in
 # by unittests if these are built.
+
+set(BUILDTREE_ONLY BUILDTREE_ONLY)
 set(EXCLUDE_FROM_ALL ON)
+if (LLVM_INSTALL_GTEST)
+  set(EXCLUDE_FROM_ALL OFF)
+  set(BUILDTREE_ONLY "")
+endif ()
 
 add_llvm_library(llvm_gtest
   googletest/src/gtest-all.cc
@@ -53,7 +59,7 @@ add_llvm_library(llvm_gtest
   Support # Depends on llvm::raw_ostream
 
   # This is a library meant only for the build tree.
-  BUILDTREE_ONLY
+  ${BUILDTREE_ONLY}
 )
 
 # The googletest and googlemock sources don't presently use the 'override'
@@ -69,12 +75,22 @@ if (NOT LLVM_ENABLE_THREADS)
 endif ()
 
 target_include_directories(llvm_gtest
-  PUBLIC googletest/include googlemock/include
+  PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/googletest/include>
+         $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/googlemock/include>
+         $<INSTALL_INTERFACE:include/llvm-gtest/>
+         $<INSTALL_INTERFACE:include/llvm-gmock/>
   PRIVATE googletest googlemock
   )
 
 add_subdirectory(UnitTestMain)
 
+if (LLVM_INSTALL_GTEST)
+  install(TARGETS llvm_gtest llvm_gtest_main LLVMTestingSupport LLVMTestingAnnotations
+	  ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT llvm_gtest)
+  install(DIRECTORY googletest/include/gtest/ DESTINATION include/llvm-gtest/gtest/ COMPONENT llvm_gtest)
+  install(DIRECTORY googlemock/include/gmock/ DESTINATION include/llvm-gmock/gmock/ COMPONENT llvm_gtest)
+endif()
+
 # When LLVM_LINK_LLVM_DYLIB is enabled, libLLVM.so is added to the interface
 # link libraries for gtest and gtest_main.  This means that any target, like
 # unittests for example, that links against gtest will be forced to link


        


More information about the llvm-commits mailing list