| 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 |
set(PHMAP_SAVE_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) |
| 11 |
set(PHMAP_SAVE_CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) |
| 12 |
|
| 13 |
# Configure and build the downloaded googletest source |
| 14 |
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . |
| 15 |
RESULT_VARIABLE result |
| 16 |
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download ) |
| 17 |
|
| 18 |
if(result) |
| 19 |
message(FATAL_ERROR "CMake step for googletest failed: ${result}") |
| 20 |
endif() |
| 21 |
|
| 22 |
execute_process(COMMAND ${CMAKE_COMMAND} --build . |
| 23 |
RESULT_VARIABLE result |
| 24 |
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download) |
| 25 |
|
| 26 |
if(result) |
| 27 |
message(FATAL_ERROR "Build step for googletest failed: ${result}") |
| 28 |
endif() |
| 29 |
|
| 30 |
set(CMAKE_CXX_FLAGS ${PHMAP_SAVE_CMAKE_CXX_FLAGS}) |
| 31 |
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PHMAP_SAVE_CMAKE_RUNTIME_OUTPUT_DIRECTORY}) |
| 32 |
|
| 33 |
# Prevent overriding the parent project's compiler/linker settings on Windows |
| 34 |
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) |
| 35 |
|
| 36 |
# Add googletest directly to our build. This defines the gtest and gtest_main |
| 37 |
# targets. |
| 38 |
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src |
| 39 |
${CMAKE_BINARY_DIR}/googletest-build |
| 40 |
EXCLUDE_FROM_ALL) |