1# Integrates googletest at configure time. Based on the instructions at 2# https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project 3 4# Set up the external googletest project, downloading the latest from Github 5# master if requested. 6configure_file( 7 ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt.in 8 ${CMAKE_BINARY_DIR}/googletest-external/CMakeLists.txt 9) 10 11set(ABSL_SAVE_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) 12set(ABSL_SAVE_CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 13if (BUILD_SHARED_LIBS) 14 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 15 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_CREATE_SHARED_LIBRARY=1") 16endif() 17 18# Configure and build the googletest source. 19execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . 20 RESULT_VARIABLE result 21 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-external ) 22if(result) 23 message(FATAL_ERROR "CMake step for googletest failed: ${result}") 24endif() 25 26execute_process(COMMAND ${CMAKE_COMMAND} --build . 27 RESULT_VARIABLE result 28 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-external) 29if(result) 30 message(FATAL_ERROR "Build step for googletest failed: ${result}") 31endif() 32 33set(CMAKE_CXX_FLAGS ${ABSL_SAVE_CMAKE_CXX_FLAGS}) 34set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ABSL_SAVE_CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 35 36# Prevent overriding the parent project's compiler/linker settings on Windows 37set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 38 39# Add googletest directly to our build. This defines the gtest and gtest_main 40# targets. 41add_subdirectory(${absl_gtest_src_dir} ${absl_gtest_build_dir} EXCLUDE_FROM_ALL) 42