Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame^] | 1 | # 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 |
| 5 | configure_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 |
| 11 | execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . |
| 12 | RESULT_VARIABLE result |
| 13 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download ) |
| 14 | if(result) |
| 15 | message(FATAL_ERROR "CMake step for googletest failed: ${result}") |
| 16 | endif() |
| 17 | |
| 18 | execute_process(COMMAND ${CMAKE_COMMAND} --build . |
| 19 | RESULT_VARIABLE result |
| 20 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download) |
| 21 | if(result) |
| 22 | message(FATAL_ERROR "Build step for googletest failed: ${result}") |
| 23 | endif() |
| 24 | |
| 25 | # Prevent overriding the parent project's compiler/linker settings on Windows |
| 26 | set(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. |
| 30 | add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src |
| 31 | ${CMAKE_BINARY_DIR}/googletest-build |
| 32 | EXCLUDE_FROM_ALL) |