FindCatch2.cmake 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # SPDX-FileCopyrightText: 2020 yuzu Emulator Project
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. find_package(PkgConfig QUIET)
  4. pkg_check_modules(PC_Catch2 QUIET Catch2)
  5. find_path(Catch2_INCLUDE_DIR
  6. NAMES catch.hpp
  7. PATHS ${PC_Catch2_INCLUDE_DIRS} ${CONAN_CATCH2_ROOT}
  8. PATH_SUFFIXES catch2
  9. )
  10. if(Catch2_INCLUDE_DIR)
  11. file(STRINGS "${Catch2_INCLUDE_DIR}/catch.hpp" _Catch2_version_lines
  12. REGEX "#define[ \t]+CATCH_VERSION_(MAJOR|MINOR|PATCH)")
  13. string(REGEX REPLACE ".*CATCH_VERSION_MAJOR +\([0-9]+\).*" "\\1" _Catch2_version_major "${_Catch2_version_lines}")
  14. string(REGEX REPLACE ".*CATCH_VERSION_MINOR +\([0-9]+\).*" "\\1" _Catch2_version_minor "${_Catch2_version_lines}")
  15. string(REGEX REPLACE ".*CATCH_VERSION_PATCH +\([0-9]+\).*" "\\1" _Catch2_version_patch "${_Catch2_version_lines}")
  16. set(Catch2_VERSION "${_Catch2_version_major}.${_Catch2_version_minor}.${_Catch2_version_patch}")
  17. unset(_Catch2_version_major)
  18. unset(_Catch2_version_minor)
  19. unset(_Catch2_version_patch)
  20. unset(_Catch2_version_lines)
  21. endif()
  22. include(FindPackageHandleStandardArgs)
  23. find_package_handle_standard_args(Catch2
  24. FOUND_VAR Catch2_FOUND
  25. REQUIRED_VARS
  26. Catch2_INCLUDE_DIR
  27. Catch2_VERSION
  28. VERSION_VAR Catch2_VERSION
  29. )
  30. if(Catch2_FOUND)
  31. set(Catch2_INCLUDE_DIRS ${Catch2_INCLUDE_DIR})
  32. set(Catch2_DEFINITIONS ${PC_Catch2_CFLAGS_OTHER})
  33. endif()
  34. if(Catch2_FOUND AND NOT TARGET Catch2::Catch2)
  35. add_library(Catch2::Catch2 UNKNOWN IMPORTED)
  36. set_target_properties(Catch2::Catch2 PROPERTIES
  37. IMPORTED_LOCATION "${Catch2_LIBRARY}"
  38. INTERFACE_COMPILE_OPTIONS "${PC_Catch2_CFLAGS_OTHER}"
  39. INTERFACE_INCLUDE_DIRECTORIES "${Catch2_INCLUDE_DIR}"
  40. )
  41. endif()
  42. mark_as_advanced(
  43. Catch2_INCLUDE_DIR
  44. )