The CMake\'s ExternalProject allows to define how to an external project is going to be downloaded, configured, built and installed. All whose steps are going to be performed at
Since CMake 3.14 and up wards, this how you use FetchContent
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.0
)
FetchContent_MakeAvailable(googletest)
Then to build your test
test/CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(${PROJECT_NAME}_test)
# Tests for mu_project
file(GLOB_RECURSE TEST_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
)
add_executable(${PROJECT_NAME}_test ${TEST_SOURCES})
target_link_libraries(${PROJECT_NAME}_test gtest gmock_main)
# Register the tests
add_test(NAME ${PROJECT_NAME}_test
COMMAND ${PROJECT_NAME}_test)
enable_testing()
You're now good to go