-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate_find_module.template
93 lines (79 loc) · 2.25 KB
/
generate_find_module.template
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
90
91
92
#
# Finds $name and populates variables and imported targets
#
# Hints:
# ${name}_ROOT
# ${name}_INCLUDEDIR
# ${name}_LIBRARYDIR
# ${name}_NO_SYSTEM_PATHS
#
# Variables:
# ${name}_FOUND
# ${name}_INCLUDE_DIR
# ${name}_LIBRARY
#
# Targets:
# ${target}
#
set(INCLUDE_SEARCH_PATHS)
set(LIBRARY_SEARCH_PATHS)
if(${name}_ROOT)
list(APPEND INCLUDE_SEARCH_PATHS $${${name}_ROOT}/include)
list(APPEND LIBRARY_SEARCH_PATHS $${${name}_ROOT}/lib)
endif()
if(${name}_INCLUDEDIR)
list(APPEND INCLUDE_SEARCH_PATHS $${${name}_INCLUDEDIR})
endif()
if(${name}_LIBRARYDIR)
list(APPEND LIBRARY_SEARCH_PATHS $${${name}_LIBRARYDIR})
endif()
find_package(PkgConfig)
pkg_check_modules(PC_${name} QUIET ${package})
list(APPEND INCLUDE_SEARCH_PATHS $${PC_${name}_INCLUDE_DIRS})
list(APPEND LIBRARY_SEARCH_PATHS $${PC_${name}_LIBRARY_DIRS})
set(${name}_VERSION $${PC_${name}_VERSION})
if(${name}_NO_SYSTEM_PATHS)
find_path(${name}_INCLUDE_DIR
NAMES ${include}
PATHS
$${INCLUDE_SEARCH_PATHS}
$${CMAKE_INCLUDE_PATH}
$${CMAKE_SYSTEM_INCLUDE_PATH}
$${CMAKE_INSTALL_PREFIX}/include
NO_DEFAULT_PATH)
find_library(${name}_LIBRARY
NAMES ${lib}
PATHS
$${LIBRARY_SEARCH_PATHS}
$${CMAKE_LIBRARY_PATH}
$${CMAKE_SYSTEM_LIBRARY_PATH}
$${CMAKE_INSTALL_PREFIX}/lib
NO_DEFAULT_PATH)
else()
find_path(${name}_INCLUDE_DIR
NAMES ${include}
PATHS $${INCLUDE_SEARCH_PATHS})
find_library(${name}_LIBRARY
NAMES ${lib}
PATHS $${LIBRARY_SEARCH_PATHS})
endif()
mark_as_advanced(
${name}_INCLUDE_DIR
${name}_LIBRARY)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(${name}
FOUND_VAR ${name}_FOUND
REQUIRED_VARS
${name}_LIBRARY
${name}_INCLUDE_DIR
VERSION_VAR ${name}_VERSION)
if(${name}_FOUND)
set(${name}_LIBRARIES $${${name}_LIBRARY})
set(${name}_INCLUDE_DIRS $${${name}_INCLUDE_DIR})
if(NOT TARGET ${target})
add_library(${target} UNKNOWN IMPORTED)
set_target_properties(${target} PROPERTIES
IMPORTED_LOCATION $${${name}_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES $${${name}_INCLUDE_DIR})
endif()
endif()