find_package(Threads REQUIRED) # Enable ExternalProject CMake module include(ExternalProject) # Download and install GoogleTest ExternalProject_Add( gtest # URL file:// # PREFIX GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG master SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" CMAKE_CACHE_ARGS # -DBUILD_SHARED_LIBS:BOOL=ON CMAKE_ARGS -Dgtest_force_shared_crt=ON INSTALL_COMMAND "" TEST_COMMAND "" ) # Get GTest source and binary directories from CMake project ExternalProject_Get_Property(gtest source_dir binary_dir) # Create a libgtest target to be used as a dependency by test programs add_library(libgtest IMPORTED STATIC GLOBAL) add_dependencies(libgtest gtest) # Set libgtest properties set_target_properties(libgtest PROPERTIES "IMPORTED_LOCATION" "${binary_dir}/lib/Release/gtest.lib" "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}" ) # Create a libgmock target to be used as a dependency by test programs add_library(libgmock IMPORTED STATIC GLOBAL) add_dependencies(libgmock gmock) # Set libgmock properties set_target_properties(libgmock PROPERTIES "IMPORTED_LOCATION" "${binary_dir}/lib/Release/gmock.lib" "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}" ) # I couldn't make it work with INTERFACE_INCLUDE_DIRECTORIES include_directories("${source_dir}/googletest/include" "${source_dir}/googlemock/include")