Fix SOURCE_DIR in HandleGTest.cmake (#703)

* Fix SOURCE_DIR in HandleGTest.cmake

If benchmark added as cmake subproject, HandleGTest throws an error as  does return absolute source dir.
Change it to , so it will be refering to it's own source dir.
This commit is contained in:
Olzhas Kaiyrakhmet 2018-10-13 16:51:51 +09:00 committed by Eric
parent 8503dfe537
commit 609752306f
1 changed files with 25 additions and 18 deletions

View File

@ -75,12 +75,10 @@ macro(build_external_gtest)
endforeach()
endmacro(build_external_gtest)
if (BENCHMARK_ENABLE_GTEST_TESTS)
if (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/googletest)
set(GTEST_ROOT "${CMAKE_SOURCE_DIR}/googletest")
macro(build_gtest_from_dir)
set(INSTALL_GTEST OFF CACHE INTERNAL "")
set(INSTALL_GMOCK OFF CACHE INTERNAL "")
add_subdirectory(${CMAKE_SOURCE_DIR}/googletest)
add_subdirectory(${GTEST_ROOT} build)
set(GTEST_BOTH_LIBRARIES gtest gmock gmock_main)
foreach(HEADER test mock)
# CMake 2.8 and older don't respect INTERFACE_INCLUDE_DIRECTORIES, so we
@ -96,6 +94,15 @@ if (BENCHMARK_ENABLE_GTEST_TESTS)
endif()
list(APPEND GTEST_INCLUDE_DIRS ${HEADER_PATH_${HEADER}})
endforeach()
endmacro()
if (BENCHMARK_ENABLE_GTEST_TESTS)
if (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/googletest)
set(GTEST_ROOT "${CMAKE_SOURCE_DIR}/googletest")
build_gtest_from_dir()
elseif (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
set(GTEST_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/googletest")
build_gtest_from_dir()
elseif(BENCHMARK_DOWNLOAD_DEPENDENCIES)
build_external_gtest()
else()