Add PROJECT_IS_TOP_LEVEL variable, to decide whether need to install/package

This commit is contained in:
zjyhjqs 2024-09-30 00:56:14 +08:00
parent 3d4a95e32e
commit 35a66c88dc

View File

@ -11,6 +11,10 @@ project(googletest-distribution
LANGUAGES CXX 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) if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
endif() endif()
@ -22,7 +26,7 @@ include(GNUInstallDirs)
# Note that googlemock target already builds googletest. # Note that googlemock target already builds googletest.
option(BUILD_GMOCK "Builds the googlemock subproject" ON) 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) option(GTEST_HAS_ABSL "Use Abseil and RE2. Requires Abseil and RE2 to be separately added to the build." OFF)
if(GTEST_HAS_ABSL) if(GTEST_HAS_ABSL)
@ -40,7 +44,7 @@ else()
add_subdirectory( googletest ) add_subdirectory( googletest )
endif() endif()
if(INSTALL_GTEST) if(PROJECT_IS_TOP_LEVEL)
set(CPACK_PACKAGE_NAME "GTest") # same as the name in `find_package` set(CPACK_PACKAGE_NAME "GTest") # same as the name in `find_package`
set(CPACK_PACKAGE_VENDOR "Google") set(CPACK_PACKAGE_VENDOR "Google")
set(CPACK_GENERATOR "TGZ") set(CPACK_GENERATOR "TGZ")