diff --git a/CMakeLists.txt b/CMakeLists.txt index 1499775b..43a6201d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,10 @@ project(googletest-distribution LANGUAGES CXX ) +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) + set(PROJECT_IS_TOP_LEVEL TRUE) +endif() + if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX) set(CMAKE_CXX_EXTENSIONS OFF) endif() @@ -22,7 +26,7 @@ include(GNUInstallDirs) # Note that googlemock target already builds googletest. option(BUILD_GMOCK "Builds the googlemock subproject" ON) -option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ON) +option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ${PROJECT_IS_TOP_LEVEL}) option(GTEST_HAS_ABSL "Use Abseil and RE2. Requires Abseil and RE2 to be separately added to the build." OFF) if(GTEST_HAS_ABSL) @@ -40,7 +44,7 @@ else() add_subdirectory( googletest ) endif() -if(INSTALL_GTEST) +if(PROJECT_IS_TOP_LEVEL) set(CPACK_PACKAGE_NAME "GTest") # same as the name in `find_package` set(CPACK_PACKAGE_VENDOR "Google") set(CPACK_GENERATOR "TGZ")