blob: 3c682aef07f3d7fb2a98657a5d6dcbe9da371ed3 [file] [log] [blame]
Austin Schuh36244a12019-09-21 17:52:38 -07001# Downloads and unpacks googletest at configure time. Based on the instructions
2# at https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project
3
4# Download the latest googletest from Github master
5configure_file(
6 ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt.in
7 ${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt
8)
9
10# Configure and build the downloaded googletest source
11execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
12 RESULT_VARIABLE result
13 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
14if(result)
15 message(FATAL_ERROR "CMake step for googletest failed: ${result}")
16endif()
17
18execute_process(COMMAND ${CMAKE_COMMAND} --build .
19 RESULT_VARIABLE result
20 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download)
21if(result)
22 message(FATAL_ERROR "Build step for googletest failed: ${result}")
23endif()
24
25# Prevent overriding the parent project's compiler/linker settings on Windows
26set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
27
28# Add googletest directly to our build. This defines the gtest and gtest_main
29# targets.
30add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
31 ${CMAKE_BINARY_DIR}/googletest-build
32 EXCLUDE_FROM_ALL)