forked from robotology/yarp-devices-forcetorque
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStandardFindModule.cmake
206 lines (180 loc) · 8.73 KB
/
StandardFindModule.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#.rst:
# StandardFindModule
# ------------------
#
# Try to find a package using a cmake config file, or pkgconfig
#
#
# ::
#
# standard_find_module(<name>
# <pkgconfig name>
# [NOT_REQUIRED]
# [QUIET]
# [SKIP_CMAKE_CONFIG]
# [SKIP_PKG_CONFIG])
#
# If the package is found, the following variables (where possible)
# are created:
#
# ::
#
# <name>_FOUND - System has <name>
# <name>_INCLUDE_DIRS - <name> include directory
# <name>_LIBRARIES - <name> libraries
# <name>_DEFINITIONS - Additional compiler flags for <name>
# <name>_VERSION - <name> version
# <name>_MAJOR_VERSION - <name> major version
# <name>_MINOR_VERSION - <name> minor version
# <name>_PATCH_VERSION - <name> patch version
# <name>_TWEAK_VERSION - <name> tweak version
# <name>_VERSION_COUNT - Number of version components, 0 to 4
#
# For each library that requires to be linked (i.e. "-llib") it creates
#
# ::
#
# <name>_<LIB>_LIBRARY_RELEASE (cached, advanced)
# <name>_<LIB>_LIBRARY_DEBUG (cached, advanced, and empty by default)
# <name>_<LIB>_LIBRARY
# <name>_<LIB>_LIBRARY_FOUND
#
# In a FindXXX.cmake module, this macro can be used at the beginning.
# The NOT_REQUIRED can be added to avoid failing if the package was not
# found, but pkg-config is installed.
# The `QUIET` argument can be used to hide the output from
# `find_package_handle_standard_args`.
# If <name>_FOUND is FALSE at the end, more "custom" searches can be
# used (for windows, etc.)
#
# If SKIP_CMAKE_CONFIG or SKIP_PKG_CONFIG are set, the relative step
# is skipped
#
# If one of the variables STANDARD_FIND_MODULE_DEBUG or
# STANDARD_FIND_MODULE_DEBUG_<name> is TRUE, prints more useful debug
# output
#=============================================================================
# Copyright 2012-2013 iCub Facility, Istituto Italiano di Tecnologia
# Authors: Daniele E. Domenichelli <[email protected]>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
if(DEFINED __STANDARD_FIND_MODULE_INCLUDED)
return()
endif()
set(__STANDARD_FIND_MODULE_INCLUDED TRUE)
include(FindPackageHandleStandardArgs)
include(CMakeParseArguments)
include(SelectLibraryConfigurations)
include(ExtractVersion)
macro(STANDARD_FIND_MODULE _name _pkgconfig_name)
string(TOUPPER ${_name} _NAME)
cmake_parse_arguments(_OPT_${_NAME} "NOT_REQUIRED;SKIP_CMAKE_CONFIG;SKIP_PKG_CONFIG;QUIET" "" "" ${ARGN})
# Try to use CMake Config file to locate the package
if(NOT _OPT_${_NAME}_SKIP_CMAKE_CONFIG)
# Disable package cache when not done automatically by CMake
# This is a workaround for CMake bug #14849
unset(_standard_find_module_registryArgs)
if(NOT CMAKE_REQUIRED_VERSION VERSION_LESS 3.1)
message(AUTHOR_WARNING "Disabling cmake cache is supported since CMake 3.1. You can remove this check")
endif()
if(CMAKE_VERSION VERSION_LESS 3.1)
if(CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY)
list(APPEND _standard_find_module_registryArgs NO_CMAKE_PACKAGE_REGISTRY)
endif()
if(CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY)
list(APPEND _standard_find_module_registryArgs NO_CMAKE_SYSTEM_PACKAGE_REGISTRY)
endif()
endif()
set(_${_name}_FIND_QUIETLY ${${_name}_FIND_QUIETLY})
find_package(${_name} QUIET NO_MODULE ${_standard_find_module_registryArgs})
set(${_name}_FIND_QUIETLY ${_${_name}_FIND_QUIETLY})
mark_as_advanced(${_name}_DIR)
if(${_name}_FOUND)
set(_${_name}_FIND_QUIETLY ${${_name}_FIND_QUIETLY})
set(${_name}_FIND_QUIETLY ${_OPT_${_NAME}_QUIET})
find_package_handle_standard_args(${_name} DEFAULT_MSG ${_name}_CONFIG)
set(${_name}_FIND_QUIETLY ${_${_name}_FIND_QUIETLY})
endif()
endif()
if(NOT ${_name}_FOUND AND NOT _OPT_${_NAME}_SKIP_PKG_CONFIG)
# No CMake Config file was found. Try using PkgConfig
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
if(${_name}_FIND_VERSION)
if(${_name}_FIND_VERSION_EXACT)
pkg_check_modules(_PC_${_NAME} QUIET ${_pkgconfig_name}=${${_name}_FIND_VERSION})
else(${_name}_FIND_VERSION_EXACT)
pkg_check_modules(_PC_${_NAME} QUIET ${_pkgconfig_name}>=${${_name}_FIND_VERSION})
endif(${_name}_FIND_VERSION_EXACT)
else(${_name}_FIND_VERSION)
pkg_check_modules(_PC_${_NAME} QUIET ${_pkgconfig_name})
endif(${_name}_FIND_VERSION)
if(_PC_${_NAME}_FOUND)
set(${_name}_INCLUDE_DIRS ${_PC_${_NAME}_INCLUDE_DIRS} CACHE PATH "${_name} include directory")
set(${_name}_DEFINITIONS ${_PC_${_NAME}_CFLAGS_OTHER} CACHE STRING "Additional compiler flags for ${_name}")
set(${_name}_LIBRARIES)
foreach(_library IN ITEMS ${_PC_${_NAME}_LIBRARIES})
string(TOUPPER ${_library} _LIBRARY)
find_library(${_name}_${_LIBRARY}_LIBRARY_RELEASE
NAMES ${_library}
PATHS ${_PC_${_NAME}_LIBRARY_DIRS})
list(APPEND ${_name}_LIBRARIES ${${_name}_${_LIBRARY}_LIBRARY_RELEASE})
select_library_configurations(${_name}_${_LIBRARY})
if(STANDARD_FIND_MODULE_DEBUG OR STANDARD_FIND_MODULE_DEBUG_${_name})
message(STATUS "${_name}_${_LIBRARY}_FOUND = ${${_name}_${_LIBRARY}_FOUND}")
message(STATUS "${_name}_${_LIBRARY}_LIBRARY_RELEASE = ${${_name}_${_LIBRARY}_LIBRARY_RELEASE}")
message(STATUS "${_name}_${_LIBRARY}_LIBRARY_DEBUG = ${${_name}_${_LIBRARY}_LIBRARY_DEBUG}")
message(STATUS "${_name}_${_LIBRARY}_LIBRARY = ${${_name}_${_LIBRARY}_LIBRARY}")
endif()
endforeach()
set(${_name}_VERSION ${_PC_${_NAME}_VERSION})
endif(_PC_${_NAME}_FOUND)
mark_as_advanced(${_name}_INCLUDE_DIRS
${_name}_DEFINITIONS)
# If NOT_REQUIRED unset the _FIND_REQUIRED variable and save it for later
if(_OPT_${_NAME}_NOT_REQUIRED AND DEFINED ${_name}_FIND_REQUIRED)
set(_${_name}_FIND_REQUIRED ${${_name}_FIND_REQUIRED})
set(_${_name}_FIND_QUIETLY ${${_name}_FIND_QUIETLY})
unset(${_name}_FIND_REQUIRED)
set(${_name}_FIND_QUIETLY 1)
endif()
set(_${_name}_FIND_QUIETLY ${${_name}_FIND_QUIETLY})
set(${_name}_FIND_QUIETLY ${_OPT_${_NAME}_QUIET})
find_package_handle_standard_args(${_name} DEFAULT_MSG ${_name}_LIBRARIES)
set(${_name}_FIND_QUIETLY ${_${_name}_FIND_QUIETLY})
# If NOT_REQUIRED reset the _FIND_REQUIRED variable
if(_OPT_${_NAME}_NOT_REQUIRED AND DEFINED _${_name}_FIND_REQUIRED)
set(${_name}_FIND_REQUIRED ${_${_name}_FIND_REQUIRED})
set(${_name}_FIND_QUIETLY ${_${_name}_FIND_QUIETLY})
endif()
endif()
endif()
# ${_name}_FOUND is uppercase after find_package_handle_standard_args
set(${_name}_FOUND ${${_NAME}_FOUND})
# Extract version numbers
if(${_name}_FOUND)
extract_version(${_name})
endif()
# Print some debug output if either STANDARD_FIND_MODULE_DEBUG
# or STANDARD_FIND_MODULE_DEBUG_${_name} is set to TRUE
if(STANDARD_FIND_MODULE_DEBUG OR STANDARD_FIND_MODULE_DEBUG_${_name})
message(STATUS "${_name}_FOUND = ${${_name}_FOUND}")
message(STATUS "${_name}_INCLUDE_DIRS = ${${_name}_INCLUDE_DIRS}")
message(STATUS "${_name}_LIBRARIES = ${${_name}_LIBRARIES}")
message(STATUS "${_name}_DEFINITIONS = ${${_name}_DEFINITIONS}")
message(STATUS "${_name}_VERSION = ${${_name}_VERSION}")
message(STATUS "${_name}_MAJOR_VERSION = ${${_name}_MAJOR_VERSION}")
message(STATUS "${_name}_MINOR_VERSION = ${${_name}_MINOR_VERSION}")
message(STATUS "${_name}_PATCH_VERSION = ${${_name}_PATCH_VERSION}")
message(STATUS "${_name}_TWEAK_VERSION = ${${_name}_TWEAK_VERSION}")
message(STATUS "${_name}_VERSION_COUNT = ${${_name}_VERSION_COUNT}")
endif()
endmacro()