build: cmake: support passing a custom source folder for GoogleTest (#5157)

This commit is contained in:
Kévin Petit 2023-03-18 01:05:12 +00:00 committed by GitHub
parent 8e6563b913
commit 44bc9bd2af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -56,7 +56,9 @@ if (NOT ${SPIRV_SKIP_TESTS})
if (TARGET gmock)
message(STATUS "Google Mock already configured")
else()
set(GMOCK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
if (NOT GMOCK_DIR)
set(GMOCK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
endif()
if(EXISTS ${GMOCK_DIR})
if(MSVC)
# Our tests use ::testing::Combine. Work around a compiler
@ -73,7 +75,7 @@ if (NOT ${SPIRV_SKIP_TESTS})
# gtest requires special defines for building as a shared
# library, simply always build as static.
push_variable(BUILD_SHARED_LIBS 0)
add_subdirectory(${GMOCK_DIR} EXCLUDE_FROM_ALL)
add_subdirectory(${GMOCK_DIR} ${CMAKE_CURRENT_BINARY_DIR}/googletest EXCLUDE_FROM_ALL)
pop_variable(BUILD_SHARED_LIBS)
endif()
endif()