@@ -48,7 +48,6 @@ if (BUILD_TESTS)
4848
4949 else ()
5050 # Download gtest from official github repository:
51- message (STATUS "GoogleTest: using GTest from official repository" )
5251 set (GTEST_SUBMOD "${CMAKE_SOURCE_DIR} /vendor/googletest" )
5352 set (GTEST_PREFIX "${CMAKE_BINARY_DIR} /gtest" )
5453 set (GTEST_LOCATION "${GTEST_PREFIX} /src/GTestExternal-build/googlemock/gtest" )
@@ -57,21 +56,24 @@ if (BUILD_TESTS)
5756 set (GTEST_MAINLIB "${GTEST_LOCATION} /${LIBPREFIX} gtest_main${LIBSUFFIX} " )
5857
5958 # check whether the submodule has been initialized
60- file (GLOB gtest_files "${GTEST_SUBMOD} /*" )
61- list (LENGTH gtest_files gtest_file_cnt)
59+ file (GLOB gtest_files "${GTEST_SUBMOD} /*" )
60+ list (LENGTH gtest_files gtest_file_cnt)
6261 set (git_res 0)
6362 if (gtest_file_cnt EQUAL 0)
6463 # we first need to initialize the submodule
65- message (STATUS "GoogleTest: Fetching submodule into vendor/googletest" )
66- execute_process (COMMAND git submodule update --init vendor/googletest
64+ message (STATUS "GoogleTest: using GTest from official repository" )
65+ message (STATUS "GoogleTest: Fetching submodule into ${GTEST_SUBMOD} " )
66+ execute_process (COMMAND git submodule update --init ${GTEST_SUBMOD}
6767 TIMEOUT 10
6868 RESULT_VARIABLE git_res
6969 OUTPUT_VARIABLE git_out
7070 ERROR_VARIABLE git_err
7171 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} )
7272 endif ()
7373
74- if (git_res EQUAL 0)
74+ file (GLOB gtest_git_files "${GTEST_SUBMOD} /.git*" )
75+ list (LENGTH gtest_git_files gtest_git_file_cnt)
76+ if (NOT gtest_git_file_cnt EQUAL 0 AND git_res EQUAL 0)
7577 # checkout desired version
7678 message (STATUS "GoogleTest: Checking out commit ${GTEST_GIT_TAG} " )
7779 execute_process (COMMAND git checkout -q ${GTEST_GIT_TAG}
@@ -82,7 +84,7 @@ if (BUILD_TESTS)
8284 if (NOT git_res EQUAL 0)
8385 # try to fetch latest commit from origin
8486 message (STATUS "GoogleTest: Checkout failed, trying to fetch latest commit" )
85- execute_process (COMMAND git submodule update --remote vendor/googletest
87+ execute_process (COMMAND git submodule update --remote ${GTEST_SUBMOD}
8688 TIMEOUT 10
8789 RESULT_VARIABLE git_res
8890 OUTPUT_VARIABLE git_out
@@ -100,6 +102,8 @@ if (BUILD_TESTS)
100102 message (WARNING "GoogleTest: Failed to checkout commit ${GTEST_GIT_TAG} : ${git_err} " )
101103 endif ()
102104 endif ()
105+ elseif (NOT gtest_file_cnt EQUAL 0)
106+ message (STATUS "GoogleTest: using GTest available in ${GTEST_SUBMOD} " )
103107 endif ()
104108
105109
0 commit comments