1# 2# Copyright 2014 Ettus Research LLC 3# Copyright 2018 Ettus Research, a National Instruments Company 4# 5# SPDX-License-Identifier: GPL-3.0-or-later 6# 7 8######################################################################## 9# When "find_package" is provided with UHD and a version, this file is 10# called to try to determine if the requested version matches that 11# provided by this UHD install. All version checking is done herein. 12######################################################################## 13 14# set that this file was found, for use in GNU Radio's FindUHD.cmake. 15# Have to use the ENV, since this file might not allow CACHE changes. 16 17set(ENV{UHD_CONFIG_VERSION_USED} TRUE) 18 19# version values as set in cmake/Modules/UHDVersion.cmake, placed 20# statically in here to avoid using Python all over again. 21 22set(MAJOR_VERSION @UHD_VERSION_MAJOR@) 23set(API_VERSION @UHD_VERSION_API@) 24set(ABI_VERSION @UHD_VERSION_ABI@) 25set(PATCH_VERSION @UHD_VERSION_PATCH@) 26set(DEVEL_VERSION @UHD_VERSION_DEVEL@) 27 28set(PACKAGE_VERSION "@UHD_VERSION@") 29set(ENV{UHD_PACKAGE_VERSION} ${PACKAGE_VERSION}) 30 31# There is a bug in CMake whereby calling "find_package(FOO)" within 32# "find_package(FOO)" results in the version being checked in the 33# second version no matter if it was set. To get around this, check 34# "PACKAGE_FIND_VERSION" and if empty set return variables to TRUE to 35# make CMake happy. Not the best solution, but it does the trick. 36 37if(NOT PACKAGE_FIND_VERSION) 38 set(PACKAGE_VERSION_COMPATIBLE TRUE) 39 set(PACKAGE_VERSION_EXACT TRUE) 40 return() 41endif(NOT PACKAGE_FIND_VERSION) 42 43# Development branches of UHD don't have a patch version. This is a hack 44# to add a fake patch version that should be higher than anything the user 45# requests. 46if(DEVEL_VERSION) 47 set(PACKAGE_VERSION "${MAJOR_VERSION}.${API_VERSION}.${ABI_VERSION}.999") 48endif(DEVEL_VERSION) 49 50# assume incorrect versioning by default 51set(PACKAGE_VERSION_COMPATIBLE FALSE) 52set(PACKAGE_VERSION_EXACT FALSE) 53 54# do not use ABI for now 55set(UHD_USE_ABI FALSE) 56 57# leave the ABI checking in, for now, just in case it is wanted in the 58# future. This code works nicely to find the ABI compatibility 59# version from <uhd/version.hpp>. 60if(UHD_USE_ABI) 61 62 # find ABI compatible version from <uhd/version.hpp> 63 64 set(UHD_INCLUDE_HINTS) 65 set(UHD_DIR $ENV{UHD_DIR}) 66 67 if(UHD_DIR) 68 list(APPEND UHD_INCLUDE_HINTS ${UHD_DIR}/include) 69 endif() 70 71 include(FindPkgConfig) 72 if(PKG_CONFIG_FOUND) 73 if(NOT ${CMAKE_VERSION} VERSION_LESS "2.8.0") 74 set(UHD_QUIET "QUIET") 75 endif() 76 if(PACKAGE_VERSION_EXACT) 77 PKG_CHECK_MODULES(PC_UHD ${UHD_QUIET} uhd=${UHD_FIND_VERSION}) 78 else() 79 PKG_CHECK_MODULES(PC_UHD ${UHD_QUIET} uhd>=${UHD_FIND_VERSION}) 80 endif() 81 if(PC_UHD_FOUND) 82 list(APPEND UHD_INCLUDE_HINTS ${PC_UHD_INCLUDEDIR}) 83 endif() 84 endif() 85 86 list(APPEND UHD_INCLUDE_HINTS ${CMAKE_INSTALL_PREFIX}/include) 87 88 # Verify that <uhd/config.hpp> and libuhd are available, and, if a 89 # version is provided, that UHD meets the version requirements -- no 90 # matter what pkg-config might think. 91 92 find_path( 93 UHD_INCLUDE_DIR 94 NAMES uhd/version.hpp 95 HINTS ${UHD_INCLUDE_HINTS} 96 PATHS /usr/local/include 97 /usr/include 98 ) 99 100 if(UHD_INCLUDE_DIR) 101 102 # extract the UHD API version from the installed header 103 104 file(STRINGS "${UHD_INCLUDE_DIR}/uhd/version.hpp" 105 UHD_STRING_VERSION REGEX "UHD_VERSION_ABI_STRING") 106 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" 107 UHD_ABI_VERSION_CONCISE ${UHD_STRING_VERSION}) 108 109 # convert UHD_FIND_VERSION into concise #.#.# format for comparison 110 111 string(REGEX REPLACE "([^\\.]*)\\.([^\\.]*)\\.([^\\.]*)" 112 "\\1.\\2.\\3" UHD_ABI_VERSION_TMP ${UHD_ABI_VERSION_CONCISE}) 113 114 string(REPLACE "0" "" UHD_ABI_MAJOR ${CMAKE_MATCH_1}) 115 string(REPLACE "0" "" UHD_ABI_MINOR ${CMAKE_MATCH_2}) 116 string(REPLACE "0" "" UHD_ABI_PATCH ${CMAKE_MATCH_3}) 117 118 # fix the case where the version number is "000" 119 120 if(NOT UHD_ABI_MAJOR) 121 set(UHD_ABI_MAJOR "0") 122 endif() 123 if(NOT UHD_ABI_MINOR) 124 set(UHD_ABI_MINOR "0") 125 endif() 126 if(NOT UHD_ABI_PATCH) 127 set(UHD_ABI_PATCH "0") 128 endif() 129 130 set(UHD_ABI_VERSION_CONCISE ${UHD_ABI_MAJOR}.${UHD_ABI_MINOR}.${UHD_ABI_PATCH}) 131 132 else(UHD_INCLUDE_DIR) 133 134 # no header found ... not a good sign! Assume ABI version is the 135 # same as that known internally here. Let UHDConfig.cmake fail if 136 # it cannot find <uhd/config.hpp> or "libuhd" ... 137 138 set(UHD_ABI_VERSION_CONCISE ${PACKAGE_VERSION}) 139 140 endif(UHD_INCLUDE_DIR) 141 142 # check for ABI compatibility, both: 143 # ACTUAL VERSION >= DESIRED VERSION >= ABI VERSION 144 145 if(NOT ${PACKAGE_FIND_VERSION} VERSION_LESS ${UHD_ABI_VERSION_CONCISE} AND 146 NOT ${PACKAGE_FIND_VERSION} VERSION_GREATER ${PACKAGE_VERSION}) 147 set(PACKAGE_VERSION_COMPATIBLE TRUE) 148 endif() 149 150else(UHD_USE_ABI) 151 152 # use API only, and assume compatible of requested <= actual 153 # which is the same as "not >" 154 155 if(NOT ${PACKAGE_FIND_VERSION} VERSION_GREATER ${PACKAGE_VERSION}) 156 set(PACKAGE_VERSION_COMPATIBLE TRUE) 157 endif() 158 159endif(UHD_USE_ABI) 160 161# check for exact version 162 163if(${PACKAGE_FIND_VERSION} VERSION_EQUAL ${PACKAGE_VERSION}) 164 set(PACKAGE_VERSION_EXACT TRUE) 165endif() 166 167# Undo our patch-version-number hack 168set(PACKAGE_VERSION @UHD_VERSION@) 169