Improve gtest dependency.
@@ -12,8 +12,15 @@ if("${CMAKE_VERSION}" VERSION_LESS "3.11" AND POLICY CMP0037)
set_policy(CMP0037 OLD)
endif()
+set(GTEST_VERSION 1.8.1)
+
+find_package(GTest ${GTEST_VERSION})
+
+if(NOT GTEST_FOUND)
include(ExternalProject)
+ find_package(Threads REQUIRED)
+
if(MINGW)
set(GTEST_DISABLE_PTHREADS ON)
else()
@@ -23,7 +30,7 @@ endif()
# Import Google Test Framework
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
- GIT_TAG release-1.8.1
+ GIT_TAG release-${GTEST_VERSION}
CMAKE_ARGS -Dgmock_build_tests=OFF
-Dgtest_build_samples=OFF
-Dgtest_build_tests=OFF
@@ -33,8 +40,9 @@ ExternalProject_Add(googletest
-DINSTALL_GTEST=OFF
-DBUILD_GMOCK=ON
PREFIX "${CMAKE_CURRENT_BINARY_DIR}"
- UPDATE_COMMAND "" # Disable update step
- INSTALL_COMMAND "" # Disable install step
+ UPDATE_COMMAND ""
+ INSTALL_COMMAND ""
+ TEST_COMMAND ""
)
# Google Test include and binary directories
@@ -54,20 +62,27 @@ else()
set(GTEST_LIBS_SUFFIX "a")
endif()
-set(GTEST_LIBS
+ # Define Paths
+ set(GTEST_INCLUDE_DIRS
+ "${GTEST_INCLUDE_DIR}"
+ "${GMOCK_INCLUDE_DIR}"
+ )
+
+ set(GTEST_LIBRARIES
"${GTEST_LIBS_DIR}/libgtest.${GTEST_LIBS_SUFFIX}"
"${GMOCK_LIBS_DIR}/libgmock.${GTEST_LIBS_SUFFIX}"
+ "${CMAKE_THREAD_LIBS_INIT}"
)
+endif()
target_include_directories(gtest
SYSTEM INTERFACE
- ${GTEST_INCLUDE_DIR}
- ${GMOCK_INCLUDE_DIR}
+ ${GTEST_INCLUDE_DIRS}
)
target_link_libraries(gtest
INTERFACE
- ${GTEST_LIBS}
+ ${GTEST_LIBRARIES}
)
add_dependencies(gtest googletest)
