summaryrefslogtreecommitdiff
path: root/externals/find-modules/FindCatch2.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'externals/find-modules/FindCatch2.cmake')
-rw-r--r--externals/find-modules/FindCatch2.cmake49
1 files changed, 49 insertions, 0 deletions
diff --git a/externals/find-modules/FindCatch2.cmake b/externals/find-modules/FindCatch2.cmake
new file mode 100644
index 000000000..ce1d40bae
--- /dev/null
+++ b/externals/find-modules/FindCatch2.cmake
@@ -0,0 +1,49 @@
1
2find_package(PkgConfig QUIET)
3pkg_check_modules(PC_Catch2 QUIET Catch2)
4
5find_path(Catch2_INCLUDE_DIR
6 NAMES catch.hpp
7 PATHS ${PC_Catch2_INCLUDE_DIRS} ${CONAN_CATCH2_ROOT}
8 PATH_SUFFIXES catch2
9)
10
11if(Catch2_INCLUDE_DIR)
12 file(STRINGS "${Catch2_INCLUDE_DIR}/catch.hpp" _Catch2_version_lines
13 REGEX "#define[ \t]+CATCH_VERSION_(MAJOR|MINOR|PATCH)")
14 string(REGEX REPLACE ".*CATCH_VERSION_MAJOR +\([0-9]+\).*" "\\1" _Catch2_version_major "${_Catch2_version_lines}")
15 string(REGEX REPLACE ".*CATCH_VERSION_MINOR +\([0-9]+\).*" "\\1" _Catch2_version_minor "${_Catch2_version_lines}")
16 string(REGEX REPLACE ".*CATCH_VERSION_PATCH +\([0-9]+\).*" "\\1" _Catch2_version_patch "${_Catch2_version_lines}")
17 set(Catch2_VERSION "${_Catch2_version_major}.${_Catch2_version_minor}.${_Catch2_version_patch}")
18 unset(_Catch2_version_major)
19 unset(_Catch2_version_minor)
20 unset(_Catch2_version_patch)
21 unset(_Catch2_version_lines)
22endif()
23
24include(FindPackageHandleStandardArgs)
25find_package_handle_standard_args(Catch2
26 FOUND_VAR Catch2_FOUND
27 REQUIRED_VARS
28 Catch2_INCLUDE_DIR
29 Catch2_VERSION
30 VERSION_VAR Catch2_VERSION
31)
32
33if(Catch2_FOUND)
34 set(Catch2_INCLUDE_DIRS ${Catch2_INCLUDE_DIR})
35 set(Catch2_DEFINITIONS ${PC_Catch2_CFLAGS_OTHER})
36endif()
37
38if(Catch2_FOUND AND NOT TARGET Catch2::Catch2)
39 add_library(Catch2::Catch2 UNKNOWN IMPORTED)
40 set_target_properties(Catch2::Catch2 PROPERTIES
41 IMPORTED_LOCATION "${Catch2_LIBRARY}"
42 INTERFACE_COMPILE_OPTIONS "${PC_Catch2_CFLAGS_OTHER}"
43 INTERFACE_INCLUDE_DIRECTORIES "${Catch2_INCLUDE_DIR}"
44 )
45endif()
46
47mark_as_advanced(
48 Catch2_INCLUDE_DIR
49)