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
|
#
# Copyright 2014 Ettus Research LLC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
########################################################################
# When "find_package" is provided with UHD and a version, this file is
# called to try to determine if the requested version matches that
# provided by this UHD install. All version checking is done herein.
########################################################################
# set that this file was found, for use in GNU Radio's FindUHD.cmake.
# Have to use the ENV, since this file might not allow CACHE changes.
set(ENV{UHD_CONFIG_VERSION_USED} TRUE)
# version values as set in cmake/Modules/UHDVersion.cmake, placed
# statically in here to avoid using Python all over again.
SET(MAJOR_VERSION @TRIMMED_VERSION_MAJOR@)
SET(API_VERSION @TRIMMED_VERSION_API@)
SET(ABI_VERSION @TRIMMED_VERSION_ABI@)
SET(PATCH_VERSION @TRIMMED_VERSION_PATCH@)
SET(DEVEL_VERSION @UHD_VERSION_DEVEL@)
SET(PACKAGE_VERSION @TRIMMED_UHD_VERSION@)
SET(ENV{UHD_PACKAGE_VERSION} ${PACKAGE_VERSION})
# There is a bug in CMake whereby calling "find_package(FOO)" within
# "find_package(FOO)" results in the version being checked in the
# second version no matter if it was set. To get around this, check
# "PACKAGE_FIND_VERSION" and if empty set return variables to TRUE to
# make CMake happy. Not the best solution, but it does the trick.
IF(NOT PACKAGE_FIND_VERSION)
SET(PACKAGE_VERSION_COMPATIBLE TRUE)
SET(PACKAGE_VERSION_EXACT TRUE)
RETURN()
ENDIF(NOT PACKAGE_FIND_VERSION)
# Development branches of UHD don't have a patch version. This is a hack
# to add a fake patch version that should be higher than anything the user
# requests.
IF(DEVEL_VERSION)
SET(PACKAGE_VERSION "${MAJOR_VERSION}.${API_VERSION}.${ABI_VERSION}.999")
ENDIF(DEVEL_VERSION)
# assume incorrect versioning by default
SET(PACKAGE_VERSION_COMPATIBLE FALSE)
SET(PACKAGE_VERSION_EXACT FALSE)
# do not use ABI for now
SET(UHD_USE_ABI FALSE)
# leave the ABI checking in, for now, just in case it is wanted in the
# future. This code works nicely to find the ABI compatibility
# version from <uhd/version.hpp>.
IF(UHD_USE_ABI)
# find ABI compatible version from <uhd/version.hpp>
SET(UHD_INCLUDE_HINTS)
SET(UHD_DIR $ENV{UHD_DIR})
IF(UHD_DIR)
LIST(APPEND UHD_INCLUDE_HINTS ${UHD_DIR}/include)
ENDIF()
INCLUDE(FindPkgConfig)
IF(PKG_CONFIG_FOUND)
IF(NOT ${CMAKE_VERSION} VERSION_LESS "2.8.0")
SET(UHD_QUIET "QUIET")
ENDIF()
IF(PACKAGE_VERSION_EXACT)
PKG_CHECK_MODULES(PC_UHD ${UHD_QUIET} uhd=${UHD_FIND_VERSION})
ELSE()
PKG_CHECK_MODULES(PC_UHD ${UHD_QUIET} uhd>=${UHD_FIND_VERSION})
ENDIF()
IF(PC_UHD_FOUND)
LIST(APPEND UHD_INCLUDE_HINTS ${PC_UHD_INCLUDEDIR})
ENDIF()
ENDIF()
LIST(APPEND UHD_INCLUDE_HINTS ${CMAKE_INSTALL_PREFIX}/include)
# Verify that <uhd/config.hpp> and libuhd are available, and, if a
# version is provided, that UHD meets the version requirements -- no
# matter what pkg-config might think.
FIND_PATH(
UHD_INCLUDE_DIR
NAMES uhd/version.hpp
HINTS ${UHD_INCLUDE_HINTS}
PATHS /usr/local/include
/usr/include
)
IF(UHD_INCLUDE_DIR)
# extract the UHD API version from the installed header
FILE(STRINGS "${UHD_INCLUDE_DIR}/uhd/version.hpp"
UHD_STRING_VERSION REGEX "UHD_VERSION_ABI_STRING")
STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+"
UHD_ABI_VERSION_CONCISE ${UHD_STRING_VERSION})
# convert UHD_FIND_VERSION into concise #.#.# format for comparison
STRING(REGEX REPLACE "([^\\.]*)\\.([^\\.]*)\\.([^\\.]*)"
"\\1.\\2.\\3" UHD_ABI_VERSION_TMP ${UHD_ABI_VERSION_CONCISE})
STRING(REPLACE "0" "" UHD_ABI_MAJOR ${CMAKE_MATCH_1})
STRING(REPLACE "0" "" UHD_ABI_MINOR ${CMAKE_MATCH_2})
STRING(REPLACE "0" "" UHD_ABI_PATCH ${CMAKE_MATCH_3})
# fix the case where the version number is "000"
IF(NOT UHD_ABI_MAJOR)
SET(UHD_ABI_MAJOR "0")
ENDIF()
IF(NOT UHD_ABI_MINOR)
SET(UHD_ABI_MINOR "0")
ENDIF()
IF(NOT UHD_ABI_PATCH)
SET(UHD_ABI_PATCH "0")
ENDIF()
SET(UHD_ABI_VERSION_CONCISE ${UHD_ABI_MAJOR}.${UHD_ABI_MINOR}.${UHD_ABI_PATCH})
ELSE(UHD_INCLUDE_DIR)
# no header found ... not a good sign! Assume ABI version is the
# same as that known internally here. Let UHDConfig.cmake fail if
# it cannot find <uhd/config.hpp> or "libuhd" ...
SET(UHD_ABI_VERSION_CONCISE ${PACKAGE_VERSION})
ENDIF(UHD_INCLUDE_DIR)
# check for ABI compatibility, both:
# ACTUAL VERSION >= DESIRED VERSION >= ABI VERSION
IF(NOT ${PACKAGE_FIND_VERSION} VERSION_LESS ${UHD_ABI_VERSION_CONCISE} AND
NOT ${PACKAGE_FIND_VERSION} VERSION_GREATER ${PACKAGE_VERSION})
SET(PACKAGE_VERSION_COMPATIBLE TRUE)
ENDIF()
ELSE(UHD_USE_ABI)
# use API only, and assume compatible of requested <= actual
# which is the same as "not >"
IF(NOT ${PACKAGE_FIND_VERSION} VERSION_GREATER ${PACKAGE_VERSION})
SET(PACKAGE_VERSION_COMPATIBLE TRUE)
ENDIF()
ENDIF(UHD_USE_ABI)
# check for exact version
IF(${PACKAGE_FIND_VERSION} VERSION_EQUAL ${PACKAGE_VERSION})
SET(PACKAGE_VERSION_EXACT TRUE)
ENDIF()
# Undo our patch-version-number hack
SET(PACKAGE_VERSION @TRIMMED_UHD_VERSION@)
|