diff options
author | Ryan Volz <ryan.volz@gmail.com> | 2021-03-29 13:10:11 -0400 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-06-04 06:21:34 -0400 |
commit | fe764daff876b71021d886e8af052135afced730 (patch) | |
tree | 3314c2e7cdbd5d57cd424b7b742d71d6c9f3cfa1 /cmake | |
parent | 8248f074ea9891e5a61f103b814eab2c838b6dfd (diff) |
gr-iio: cmake: Standardize Find*.cmake modules and use targets.
This standardizes the CMake Find module names for libiio and libad9361
to use the pkg-config names and what the projects use internally as
their CMake "project" names. The CMake variables that are set in the
Find modules are also changed to match, per CMake convention.
This also adds and uses targets for libiio::iio and libad9361::ad9361,
removing the need for extra steps like setting a local include directory
for libiio on the gnuradio-iio target (PR #4465).
I also added pkg-config checks for added search breadth and headed off
Windows problems by adding the not-searched "libiio" and "libad9361"
library names that are used there.
Signed-off-by: Ryan Volz <ryan.volz@gmail.com>
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/Modules/FindAD9361.cmake | 52 | ||||
-rw-r--r-- | cmake/Modules/FindIIO.cmake | 52 | ||||
-rw-r--r-- | cmake/Modules/Findlibad9361.cmake | 99 | ||||
-rw-r--r-- | cmake/Modules/Findlibiio.cmake | 99 |
4 files changed, 198 insertions, 104 deletions
diff --git a/cmake/Modules/FindAD9361.cmake b/cmake/Modules/FindAD9361.cmake deleted file mode 100644 index b17798c27b..0000000000 --- a/cmake/Modules/FindAD9361.cmake +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright 2021 Horden Engineering -# Author: Adam Horden <adam.horden@horden.engineering> -# -# This file is part of GNU Radio -# -# SPDX-License-Identifier: GPL-3.0-or-later -# - -# - Find libad9361 -# Find the native libad9361 includes and library -# -# LIBAD9361_FOUND - True if libad9361 is found. -# LIBAD9361_INCLUDE_DIR - Where to find ad9361.h. -# LIBAD9361_LIBRARIES - List of libraries when using libad9361. - -set(LIBAD9361_NAMES ad9361) -find_library(LIBAD9361_LIBRARY - NAMES ${LIBAD9361_NAMES} - PATHS /usr/lib - /usr/lib64 - /usr/local/lib - /usr/local/lib64 - /opt/local/lib - /opt/local/lib64 -) - -find_path(LIBAD9361_INCLUDE_DIR ad9361.h - /usr/include - /usr/local/include - /opt/local/include -) - -if (LIBAD9361_INCLUDE_DIR AND LIBAD9361_LIBRARY) - set(LIBAD9361_FOUND TRUE) - set(LIBAD9361_INCLUDE_DIRS ${LIBAD9361_INCLUDE_DIR}) - set(LIBAD9361_LIBRARIES ${LIBAD9361_LIBRARY}) -else () - set(LIBAD9361_FOUND FALSE) - set(LIBAD9361_INCLUDE_DIR "") - set(LIBAD9361_INCLUDE_DIRS "") - set(LIBAD9361_LIBRARY "") - set(LIBAD9361_LIBRARIES "") -endif () - -if (LIBAD9361_FOUND) - message(STATUS "Found libad9361 library: ${LIBAD9361_LIBRARIES}") -endif () - -mark_as_advanced( - LIBAD9361_INCLUDE_DIRS - LIBAD9361_LIBRARIES -) diff --git a/cmake/Modules/FindIIO.cmake b/cmake/Modules/FindIIO.cmake deleted file mode 100644 index a14c216984..0000000000 --- a/cmake/Modules/FindIIO.cmake +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright 2021 Horden Engineering -# Author: Adam Horden <adam.horden@horden.engineering> -# -# This file is part of GNU Radio -# -# SPDX-License-Identifier: GPL-3.0-or-later -# - -# - Find libiio -# Find the native libiio includes and library -# -# LIBIIO_FOUND - True if libiio is found. -# LIBIIO_INCLUDE_DIR - Where to find iio.h. -# LIBIIO_LIBRARIES - List of libraries when using libiio. - -set(LIBIIO_NAMES iio) -find_library(LIBIIO_LIBRARY - NAMES ${LIBIIO_NAMES} - PATHS /usr/lib - /usr/lib64 - /usr/local/lib - /usr/local/lib64 - /opt/local/lib - /opt/local/lib64 -) - -find_path(LIBIIO_INCLUDE_DIR iio.h - /usr/include - /usr/local/include - /opt/local/include -) - -if (LIBIIO_INCLUDE_DIR AND LIBIIO_LIBRARY) - set(LIBIIO_FOUND TRUE) - set(LIBIIO_INCLUDE_DIRS ${LIBIIO_INCLUDE_DIR}) - set(LIBIIO_LIBRARIES ${LIBIIO_LIBRARY}) -else () - set(LIBIIO_FOUND FALSE) - set(LIBIIO_INCLUDE_DIR "") - set(LIBIIO_INCLUDE_DIRS "") - set(LIBIIO_LIBRARY "") - set(LIBIIO_LIBRARIES "") -endif () - -if (LIBIIO_FOUND) - message(STATUS "Found libiio library: ${LIBIIO_LIBRARIES}") -endif () - -mark_as_advanced( - LIBIIO_INCLUDE_DIRS - LIBIIO_LIBRARIES -) diff --git a/cmake/Modules/Findlibad9361.cmake b/cmake/Modules/Findlibad9361.cmake new file mode 100644 index 0000000000..653ca345fc --- /dev/null +++ b/cmake/Modules/Findlibad9361.cmake @@ -0,0 +1,99 @@ +# Copyright 2021 Horden Engineering +# Author: Adam Horden <adam.horden@horden.engineering> +# +# This file is part of GNU Radio +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +#[=======================================================================[.rst: +Findlibad9361 +------------- + +Find the libad9361-iio includes and library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``libad9361::ad9361`` + The ad9361 library + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``libad9361_FOUND`` + True if the system has libad9361. +``libad9361_VERSION`` + The version of libad9361 that was found. +``libad9361_INCLUDE_DIRS`` + Include directories needed to use libad9361. +``libad9361_LIBRARIES`` + Libraries needed to link to libad9361. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``libad9361_INCLUDE_DIR`` + The directory containing ``ad9361.h``. +``libad9361_LIBRARY`` + The path to the ad9361 library. + +#]=======================================================================] + + +find_package(PkgConfig) +pkg_check_modules(PC_libad9361 QUIET libad9361) + +find_path(libad9361_INCLUDE_DIR + NAMES ad9361.h + HINTS ${PC_libiio_INCLUDE_DIRS} + PATHS /usr/include + /usr/local/include + /opt/local/include +) + +find_library(libad9361_LIBRARY + NAMES ad9361 libad9361 + HINTS ${PC_libad9361_LIBRARY_DIRS} + PATHS /usr/lib + /usr/lib64 + /usr/local/lib + /usr/local/lib64 + /opt/local/lib + /opt/local/lib64 +) + +# only way we have to get version is to rely on pkg-config +set(libad9361_VERSION ${PC_libad9361_VERSION}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(libad9361 + REQUIRED_VARS + libad9361_LIBRARY + libad9361_INCLUDE_DIR + VERSION_VAR libad9361_VERSION +) + +if(libad9361_FOUND) + set(libad9361_INCLUDE_DIRS ${libad9361_INCLUDE_DIR}) + set(libad9361_LIBRARIES ${libad9361_LIBRARY}) +endif() + +if(libad9361_FOUND AND NOT TARGET libad9361::ad9361) + add_library(libad9361::ad9361 UNKNOWN IMPORTED) + set_target_properties(libad9361::ad9361 PROPERTIES + IMPORTED_LOCATION "${libad9361_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${libad9361_INCLUDE_DIR}" + ) +endif() + +mark_as_advanced( + libad9361_INCLUDE_DIR + libad9361_LIBRARY +) diff --git a/cmake/Modules/Findlibiio.cmake b/cmake/Modules/Findlibiio.cmake new file mode 100644 index 0000000000..1074315e79 --- /dev/null +++ b/cmake/Modules/Findlibiio.cmake @@ -0,0 +1,99 @@ +# Copyright 2021 Horden Engineering +# Author: Adam Horden <adam.horden@horden.engineering> +# +# This file is part of GNU Radio +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +#[=======================================================================[.rst: +Findlibiio +---------- + +Find the native libiio includes and library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``libbio::iio`` + The iio library + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``libiio_FOUND`` + True if the system has libiio. +``libiio_VERSION`` + The version of libiio that was found. +``libiio_INCLUDE_DIRS`` + Include directories needed to use libiio. +``libiio_LIBRARIES`` + Libraries needed to link to libiio. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``libiio_INCLUDE_DIR`` + The directory containing ``iio.h``. +``libiio_LIBRARY`` + The path to the iio library. + +#]=======================================================================] + + +find_package(PkgConfig) +pkg_check_modules(PC_libiio QUIET libiio) + +find_path(libiio_INCLUDE_DIR + NAMES iio.h + HINTS ${PC_libiio_INCLUDE_DIRS} + PATHS /usr/include + /usr/local/include + /opt/local/include +) + +find_library(libiio_LIBRARY + NAMES iio libiio + HINTS ${PC_libiio_LIBRARY_DIRS} + PATHS /usr/lib + /usr/lib64 + /usr/local/lib + /usr/local/lib64 + /opt/local/lib + /opt/local/lib64 +) + +# only way we have to get version is to rely on pkg-config +set(libiio_VERSION ${PC_libiio_VERSION}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(libiio + REQUIRED_VARS + libiio_LIBRARY + libiio_INCLUDE_DIR + VERSION_VAR libiio_VERSION +) + +if(libiio_FOUND) + set(libiio_INCLUDE_DIRS ${libiio_INCLUDE_DIR}) + set(libiio_LIBRARIES ${libiio_LIBRARY}) +endif() + +if(libiio_FOUND AND NOT TARGET libiio::iio) + add_library(libiio::iio UNKNOWN IMPORTED) + set_target_properties(libiio::iio PROPERTIES + IMPORTED_LOCATION "${libiio_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${libiio_INCLUDE_DIR}" + ) +endif() + +mark_as_advanced( + libiio_INCLUDE_DIR + libiio_LIBRARY +) |