diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -693,6 +693,10 @@ "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/third-party/unittest/CMakeLists.txt b/third-party/unittest/CMakeLists.txt --- a/third-party/unittest/CMakeLists.txt +++ b/third-party/unittest/CMakeLists.txt @@ -65,12 +65,25 @@ endif () target_include_directories(llvm_gtest - PUBLIC googletest/include googlemock/include + PUBLIC $ + $ + $ + $ PRIVATE googletest googlemock ) add_subdirectory(UnitTestMain) +if (LLVM_INSTALL_GTEST) + export(TARGETS llvm_gtest llvm_gtest_main LLVMTestingSupport FILE LLVMGTestConfig.cmake) + install(TARGETS llvm_gtest llvm_gtest_main LLVMTestingSupport EXPORT LLVMGTestConfig + ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT llvm_gtest) + install(EXPORT LLVMGTestConfig DESTINATION ${LLVM_INSTALL_PACKAGE_DIR} COMPONENT llvm_gtest) + add_llvm_install_targets(install-llvm_gtest COMPONENT llvm_gtest DEPENDS llvm_gtest LLVMGTestConfig.cmake) + 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