-
Notifications
You must be signed in to change notification settings - Fork 257
/
FindInstPatch.cmake
89 lines (73 loc) · 2.73 KB
/
FindInstPatch.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#[=======================================================================[.rst:
FindInstPatch
-------
Finds the InstPatch library.
Imported Targets
^^^^^^^^^^^^^^^^
This module provides the following imported targets, if found:
``InstPatch::libinstpatch``
The InstPatch library
Result Variables
^^^^^^^^^^^^^^^^
This will define the following variables:
``InstPatch_FOUND``
True if the system has the InstPatch library.
``InstPatch_VERSION``
The version of the InstPatch library which was found.
#]=======================================================================]
# Use pkg-config if available
find_package(PkgConfig QUIET)
pkg_check_modules(PC_INSTPATCH QUIET libinstpatch-1.0)
# Find the headers and library
find_path(
InstPatch_INCLUDE_DIR
NAMES "libinstpatch/libinstpatch.h"
HINTS "${PC_INSTPATCH_INCLUDEDIR}"
PATH_SUFFIXES "libinstpatch-1" "libinstpatch-2")
find_library(
InstPatch_LIBRARY
NAMES "instpatch-1.0" "instpatch-2"
HINTS "${PC_INSTPATCH_LIBDIR}")
# Get version from pkg-config or read the config header
if(PC_INSTPATCH_VERSION)
set(InstPatch_VERSION "${PC_INSTPATCH_VERSION}")
elseif(InstPatch_INCLUDE_DIR)
file(READ "${InstPatch_INCLUDE_DIR}/libinstpatch/version.h" _version_h)
string(REGEX MATCH
"#define[ \t]+IPATCH_VERSION[ \t]+\"([0-9]+.[0-9]+.[0-9]+)\""
_instpatch_version_re "${_version_h}")
set(InstPatch_VERSION "${CMAKE_MATCH_1}")
endif()
# Handle transitive dependencies
if(PC_INSTPATCH_FOUND)
get_target_properties_from_pkg_config("${InstPatch_LIBRARY}" "PC_INSTPATCH"
"_instpatch")
else()
if(NOT TARGET GLib2::gobject-2
OR NOT TARGET GLib2::gthread-2
OR NOT TARGET GLib2::glib-2)
find_package(GLib2 QUIET)
endif()
if(NOT TARGET SndFile::sndfile)
find_package(SndFile QUIET)
endif()
set(_instpatch_link_libraries "GLib2::gobject-2" "GLib2::gthread-2"
"GLib2::glib-2" "SndFile::sndfile")
endif()
# Forward the result to CMake
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
InstPatch
REQUIRED_VARS "InstPatch_LIBRARY" "InstPatch_INCLUDE_DIR"
VERSION_VAR "InstPatch_VERSION")
if(InstPatch_FOUND AND NOT TARGET InstPatch::libinstpatch)
add_library(InstPatch::libinstpatch UNKNOWN IMPORTED)
set_target_properties(
InstPatch::libinstpatch
PROPERTIES IMPORTED_LOCATION "${InstPatch_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${_instpatch_compile_options}"
INTERFACE_INCLUDE_DIRECTORIES "${InstPatch_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${_instpatch_link_libraries}"
INTERFACE_LINK_DIRECTORIES "${_instpatch_link_directories}")
endif()
mark_as_advanced(InstPatch_INCLUDE_DIR InstPatch_LIBRARY)