Back to home page

EIC code displayed by LXR

 
 

    


Warning, /jana2/src/python/externals/pybind11-2.10.3/tools/FindCatch.cmake is written in an unsupported language. File is not indexed.

0001 # - Find the Catch test framework or download it (single header)
0002 #
0003 # This is a quick module for internal use. It assumes that Catch is
0004 # REQUIRED and that a minimum version is provided (not EXACT). If
0005 # a suitable version isn't found locally, the single header file
0006 # will be downloaded and placed in the build dir: PROJECT_BINARY_DIR.
0007 #
0008 # This code sets the following variables:
0009 #  CATCH_INCLUDE_DIR      - path to catch.hpp
0010 #  CATCH_VERSION          - version number
0011 
0012 option(DOWNLOAD_CATCH "Download catch2 if not found")
0013 
0014 if(NOT Catch_FIND_VERSION)
0015   message(FATAL_ERROR "A version number must be specified.")
0016 elseif(Catch_FIND_REQUIRED)
0017   message(FATAL_ERROR "This module assumes Catch is not required.")
0018 elseif(Catch_FIND_VERSION_EXACT)
0019   message(FATAL_ERROR "Exact version numbers are not supported, only minimum.")
0020 endif()
0021 
0022 # Extract the version number from catch.hpp
0023 function(_get_catch_version)
0024   file(
0025     STRINGS "${CATCH_INCLUDE_DIR}/catch.hpp" version_line
0026     REGEX "Catch v.*"
0027     LIMIT_COUNT 1)
0028   if(version_line MATCHES "Catch v([0-9]+)\\.([0-9]+)\\.([0-9]+)")
0029     set(CATCH_VERSION
0030         "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}"
0031         PARENT_SCOPE)
0032   endif()
0033 endfunction()
0034 
0035 # Download the single-header version of Catch
0036 function(_download_catch version destination_dir)
0037   message(STATUS "Downloading catch v${version}...")
0038   set(url https://github.com/philsquared/Catch/releases/download/v${version}/catch.hpp)
0039   file(DOWNLOAD ${url} "${destination_dir}/catch.hpp" STATUS status)
0040   list(GET status 0 error)
0041   if(error)
0042     message(FATAL_ERROR "Could not download ${url}")
0043   endif()
0044   set(CATCH_INCLUDE_DIR
0045       "${destination_dir}"
0046       CACHE INTERNAL "")
0047 endfunction()
0048 
0049 # Look for catch locally
0050 find_path(
0051   CATCH_INCLUDE_DIR
0052   NAMES catch.hpp
0053   PATH_SUFFIXES catch2)
0054 if(CATCH_INCLUDE_DIR)
0055   _get_catch_version()
0056 endif()
0057 
0058 # Download the header if it wasn't found or if it's outdated
0059 if(NOT CATCH_VERSION OR CATCH_VERSION VERSION_LESS ${Catch_FIND_VERSION})
0060   if(DOWNLOAD_CATCH)
0061     _download_catch(${Catch_FIND_VERSION} "${PROJECT_BINARY_DIR}/catch/")
0062     _get_catch_version()
0063   else()
0064     set(CATCH_FOUND FALSE)
0065     return()
0066   endif()
0067 endif()
0068 
0069 add_library(Catch2::Catch2 IMPORTED INTERFACE)
0070 set_property(TARGET Catch2::Catch2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CATCH_INCLUDE_DIR}")
0071 
0072 set(CATCH_FOUND TRUE)