Index: cmake/modules/AddLLVM.cmake =================================================================== --- cmake/modules/AddLLVM.cmake +++ cmake/modules/AddLLVM.cmake @@ -547,7 +547,7 @@ if( EXCLUDE_FROM_ALL ) set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON) - elseif(NOT _is_gtest) + else() if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO") set(install_dir lib${LLVM_LIBDIR_SUFFIX}) if(ARG_SHARED OR BUILD_SHARED_LIBS) @@ -561,6 +561,10 @@ set(install_type ARCHIVE) endif() + if( _is_gtest ) + set(install_dir "${install_dir}/llvm") + endif() + install(TARGETS ${name} EXPORT LLVMExports ${install_type} DESTINATION ${install_dir} @@ -576,7 +580,12 @@ endif() set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) endif() - set_target_properties(${name} PROPERTIES FOLDER "Libraries") + + if( NOT _is_gtest ) + set_target_properties(${name} PROPERTIES FOLDER "Libraries") + else() + set_target_properties(${name} PROPERTIES FOLDER "Internal use libraries") + endif() endmacro(add_llvm_library name) macro(add_llvm_loadable_module name) Index: utils/unittest/CMakeLists.txt =================================================================== --- utils/unittest/CMakeLists.txt +++ utils/unittest/CMakeLists.txt @@ -17,34 +17,55 @@ googletest ) -if(WIN32) - add_definitions(-DGTEST_OS_WINDOWS=1) -endif() +# Define conditionally to avoid breaking revdeps that explicitly include +# this directory to obtain gtest target (exported now) +if( NOT TARGET gtest ) + if(WIN32) + add_definitions(-DGTEST_OS_WINDOWS=1) + endif() -if(SUPPORTS_NO_VARIADIC_MACROS_FLAG) - add_definitions("-Wno-variadic-macros") -endif() + if(SUPPORTS_NO_VARIADIC_MACROS_FLAG) + add_definitions("-Wno-variadic-macros") + endif() -set(LLVM_REQUIRES_RTTI 1) -add_definitions( -DGTEST_HAS_RTTI=0 ) + set(LLVM_REQUIRES_RTTI 1) + add_definitions( -DGTEST_HAS_RTTI=0 ) -if (NOT LLVM_ENABLE_THREADS) - add_definitions( -DGTEST_HAS_PTHREAD=0 ) -endif() + if (NOT LLVM_ENABLE_THREADS) + add_definitions( -DGTEST_HAS_PTHREAD=0 ) + endif() -find_library(PTHREAD_LIBRARY_PATH pthread) -if (PTHREAD_LIBRARY_PATH) - list(APPEND LIBS pthread) -endif() + find_library(PTHREAD_LIBRARY_PATH pthread) + if (PTHREAD_LIBRARY_PATH) + list(APPEND LIBS pthread) + endif() -add_llvm_library(gtest - googletest/src/gtest-all.cc + add_llvm_library(gtest + googletest/src/gtest-all.cc - LINK_LIBS - ${LIBS} + LINK_LIBS + ${LIBS} - LINK_COMPONENTS - Support # Depends on llvm::raw_ostream -) + LINK_COMPONENTS + Support # Depends on llvm::raw_ostream + ) + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY googletest/include/ + DESTINATION include/llvm-gtest + COMPONENT llvm-gtest-headers + FILES_MATCHING + PATTERN "*.h" + ) + + if (NOT CMAKE_CONFIGURATION_TYPES) + add_custom_target(installgtesthdrs + DEPENDS ${name} + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=llvm-gtest-headers + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") + endif() + endif() +endif() add_subdirectory(UnitTestMain) Index: utils/unittest/UnitTestMain/CMakeLists.txt =================================================================== --- utils/unittest/UnitTestMain/CMakeLists.txt +++ utils/unittest/UnitTestMain/CMakeLists.txt @@ -1,9 +1,13 @@ -add_llvm_library(gtest_main - TestMain.cpp +# Define conditionally to avoid breaking revdeps that explicitly include +# this directory to obtain gtest target (exported now) +if( NOT TARGET gtest_main ) + add_llvm_library(gtest_main + TestMain.cpp - LINK_LIBS - gtest + LINK_LIBS + gtest - LINK_COMPONENTS - Support # Depends on llvm::cl - ) + LINK_COMPONENTS + Support # Depends on llvm::cl + ) +endif()