1# Download and unpack a third-party library at configure time 2# The original code is at the README of google-test: 3# https://github.com/google/googletest/tree/master/googletest 4function(get_third_party name) 5 configure_file( 6 "${PROJECT_SOURCE_DIR}/third_party/${name}.cmake" 7 "${CMAKE_CURRENT_BINARY_DIR}/${name}-download/CMakeLists.txt") 8 execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . 9 RESULT_VARIABLE result 10 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${name}-download") 11 if(result) 12 message(FATAL_ERROR "CMake step for ${name} failed: ${result}") 13 endif() 14 execute_process(COMMAND ${CMAKE_COMMAND} --build . 15 RESULT_VARIABLE result 16 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${name}-download") 17 if(result) 18 message(FATAL_ERROR "Build step for ${name} failed: ${result}") 19 endif() 20endfunction() 21