Debian Codegraph @

cmake/FindCheck.cmake

raw
1 # Copyright 2022 Timo Röhling <[email protected]>
2 # SPDX-License-Identifier: FSFAP
3 #
4 # Copying and distribution of this file, with or without modification, are
5 # permitted in any medium without royalty provided the copyright notice and
6 # this notice are preserved. This file is offered as-is, without any warranty.
7 #
8 include(FindPackageHandleStandardArgs)
9 find_package(Check CONFIG QUIET)
10 if(TARGET Check::check)
11 find_package_handle_standard_args(Check CONFIG_MODE)
12 else()
13 find_package(PkgConfig QUIET)
14 if(PkgConfig_FOUND)
15 pkg_search_module(PC_CHECK QUIET check)
16 pkg_search_module(PC_SUBUNIT QUIET libsubunit)
17 endif()
18 find_path(Check_INCLUDE_DIR check.h HINTS ${PC_CHECK_INCLUDE_DIRS})
19 find_library(
20 Check_LIBRARY
21 NAMES check_pic check
22 HINTS ${PC_CHECK_LIBRARY_DIRS}
23 )
24 find_library(Check_subunit_LIBRARY subunit HINTS ${PC_SUBUNIT_LIBRARY_DIRS})
25 find_library(Check_m_LIBRARY m)
26 find_library(Check_rt_LIBRARY rt)
27 find_package(Threads REQUIRED)
28 find_package_handle_standard_args(
29 Check
30 FOUND_VAR Check_FOUND
31 REQUIRED_VARS Check_INCLUDE_DIR Check_LIBRARY
32 )
33 if(Check_FOUND AND NOT TARGET Check::check)
34 set(Check_DEPS "Threads::Threads")
35 if(Check_subunit_LIBRARY)
36 list(APPEND Check_DEPS "${Check_subunit_LIBRARY}")
37 endif()
38 if(Check_m_LIBRARY)
39 list(APPEND Check_DEPS "${Check_m_LIBRARY}")
40 endif()
41 if(Check_rt_LIBRARY)
42 list(APPEND Check_DEPS "${Check_rt_LIBRARY}")
43 endif()
44 add_library(Check::check UNKNOWN IMPORTED)
45 set_target_properties(
46 Check::check
47 PROPERTIES IMPORTED_LOCATION "${Check_LIBRARY}"
48 INTERFACE_INCLUDE_DIRECTORIES "${Check_INCLUDE_DIR}"
49 INTERFACE_LINK_LIBRARIES "${Check_DEPS}"
50 )
51 endif()
52 endif()