github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/pybind11/tools/FindCatch.cmake (about) 1 # - Find the Catch test framework or download it (single header) 2 # 3 # This is a quick module for internal use. It assumes that Catch is 4 # REQUIRED and that a minimum version is provided (not EXACT). If 5 # a suitable version isn't found locally, the single header file 6 # will be downloaded and placed in the build dir: PROJECT_BINARY_DIR. 7 # 8 # This code sets the following variables: 9 # CATCH_INCLUDE_DIR - path to catch.hpp 10 # CATCH_VERSION - version number 11 12 option(DOWNLOAD_CATCH "Download catch2 if not found") 13 14 if(NOT Catch_FIND_VERSION) 15 message(FATAL_ERROR "A version number must be specified.") 16 elseif(Catch_FIND_REQUIRED) 17 message(FATAL_ERROR "This module assumes Catch is not required.") 18 elseif(Catch_FIND_VERSION_EXACT) 19 message(FATAL_ERROR "Exact version numbers are not supported, only minimum.") 20 endif() 21 22 # Extract the version number from catch.hpp 23 function(_get_catch_version) 24 file( 25 STRINGS "${CATCH_INCLUDE_DIR}/catch.hpp" version_line 26 REGEX "Catch v.*" 27 LIMIT_COUNT 1) 28 if(version_line MATCHES "Catch v([0-9]+)\\.([0-9]+)\\.([0-9]+)") 29 set(CATCH_VERSION 30 "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}" 31 PARENT_SCOPE) 32 endif() 33 endfunction() 34 35 # Download the single-header version of Catch 36 function(_download_catch version destination_dir) 37 message(STATUS "Downloading catch v${version}...") 38 set(url https://github.com/philsquared/Catch/releases/download/v${version}/catch.hpp) 39 file(DOWNLOAD ${url} "${destination_dir}/catch.hpp" STATUS status) 40 list(GET status 0 error) 41 if(error) 42 message(FATAL_ERROR "Could not download ${url}") 43 endif() 44 set(CATCH_INCLUDE_DIR 45 "${destination_dir}" 46 CACHE INTERNAL "") 47 endfunction() 48 49 # Look for catch locally 50 find_path( 51 CATCH_INCLUDE_DIR 52 NAMES catch.hpp 53 PATH_SUFFIXES catch2) 54 if(CATCH_INCLUDE_DIR) 55 _get_catch_version() 56 endif() 57 58 # Download the header if it wasn't found or if it's outdated 59 if(NOT CATCH_VERSION OR CATCH_VERSION VERSION_LESS ${Catch_FIND_VERSION}) 60 if(DOWNLOAD_CATCH) 61 _download_catch(${Catch_FIND_VERSION} "${PROJECT_BINARY_DIR}/catch/") 62 _get_catch_version() 63 else() 64 set(CATCH_FOUND FALSE) 65 return() 66 endif() 67 endif() 68 69 add_library(Catch2::Catch2 IMPORTED INTERFACE) 70 set_property(TARGET Catch2::Catch2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CATCH_INCLUDE_DIR}") 71 72 set(CATCH_FOUND TRUE)