|
| 1 | +# https://github.com/myriadrf/LimeSuite/blob/master/cmake/Modules/Findlibusb-1.0.cmake |
| 2 | +# - Try to find libusb-1.0 |
| 3 | +# Once done this will define |
| 4 | +# |
| 5 | +# LIBUSB_1_FOUND - system has libusb |
| 6 | +# LIBUSB_1_INCLUDE_DIRS - the libusb include directory |
| 7 | +# LIBUSB_1_LIBRARIES - Link these to use libusb |
| 8 | +# LIBUSB_1_DEFINITIONS - Compiler switches required for using libusb |
| 9 | +# |
| 10 | +# Adapted from cmake-modules Google Code project |
| 11 | +# |
| 12 | +# Copyright (c) 2006 Andreas Schneider <[email protected]> |
| 13 | +# |
| 14 | +# (Changes for libusb) Copyright (c) 2008 Kyle Machulis <[email protected]> |
| 15 | +# |
| 16 | +# Redistribution and use is allowed according to the terms of the New BSD license. |
| 17 | +# |
| 18 | +# CMake-Modules Project New BSD License |
| 19 | +# |
| 20 | +# Redistribution and use in source and binary forms, with or without |
| 21 | +# modification, are permitted provided that the following conditions are met: |
| 22 | +# |
| 23 | +# * Redistributions of source code must retain the above copyright notice, this |
| 24 | +# list of conditions and the following disclaimer. |
| 25 | +# |
| 26 | +# * Redistributions in binary form must reproduce the above copyright notice, |
| 27 | +# this list of conditions and the following disclaimer in the |
| 28 | +# documentation and/or other materials provided with the distribution. |
| 29 | +# |
| 30 | +# * Neither the name of the CMake-Modules Project nor the names of its |
| 31 | +# contributors may be used to endorse or promote products derived from this |
| 32 | +# software without specific prior written permission. |
| 33 | +# |
| 34 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 35 | +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 36 | +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 37 | +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 38 | +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 39 | +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 40 | +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 41 | +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 42 | +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 43 | +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 44 | +# |
| 45 | + |
| 46 | + |
| 47 | +if (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) |
| 48 | + # in cache already |
| 49 | + set(LIBUSB_FOUND TRUE) |
| 50 | +else (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) |
| 51 | + find_path(LIBUSB_1_INCLUDE_DIR |
| 52 | + NAMES |
| 53 | + libusb.h |
| 54 | + PATHS |
| 55 | + /usr/include |
| 56 | + /usr/local/include |
| 57 | + /opt/local/include |
| 58 | + /sw/include |
| 59 | + PATH_SUFFIXES |
| 60 | + libusb-1.0 |
| 61 | + ) |
| 62 | + |
| 63 | + set(LIBUSB_1_LIBRARY_NAME usb-1.0) |
| 64 | + if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") |
| 65 | + set(LIBUSB_1_LIBRARY_NAME usb) |
| 66 | + endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") |
| 67 | + |
| 68 | +if(NOT bananapi-r2) |
| 69 | + find_library(LIBUSB_1_LIBRARY |
| 70 | + NAMES ${LIBUSB_1_LIBRARY_NAME} |
| 71 | + PATHS |
| 72 | + /usr/lib |
| 73 | + /usr/local/lib |
| 74 | + /opt/local/lib |
| 75 | + /sw/lib |
| 76 | + ) |
| 77 | +endif(NOT bananapi-r2) |
| 78 | + |
| 79 | +#bananapi-r2 ubuntu 16.04 has wrong libusb-1.0.so path |
| 80 | +#when compiling on bananapi-r2 run cmake with -DBananapi-r2=YES argument like so: |
| 81 | +# $(builddir)/cmake -Dbananapi-r2=YES ../ |
| 82 | +if(bananapi-r2) |
| 83 | + message(STATUS "DEBUG --->>>> BANANAPI") |
| 84 | + find_library(LIBUSB_1_LIBRARY |
| 85 | + NAMES ${LIBUSB_1_LIBRARY_NAME} |
| 86 | + PATHS |
| 87 | + /lib/arm-linux-gnueabihf/ |
| 88 | + /usr/lib/arm-linux-gnueabihf/ |
| 89 | + NO_DEFAULT_PATH |
| 90 | + ) |
| 91 | +endif(bananapi-r2) |
| 92 | + |
| 93 | + set(LIBUSB_1_INCLUDE_DIRS |
| 94 | + ${LIBUSB_1_INCLUDE_DIR} |
| 95 | + ) |
| 96 | + set(LIBUSB_1_LIBRARIES |
| 97 | + ${LIBUSB_1_LIBRARY} |
| 98 | +) |
| 99 | + |
| 100 | + if (LIBUSB_1_INCLUDE_DIRS AND LIBUSB_1_LIBRARIES) |
| 101 | + set(LIBUSB_1_FOUND TRUE) |
| 102 | + endif (LIBUSB_1_INCLUDE_DIRS AND LIBUSB_1_LIBRARIES) |
| 103 | + |
| 104 | + if (LIBUSB_1_FOUND) |
| 105 | + if (NOT libusb_1_FIND_QUIETLY) |
| 106 | + message(STATUS "Found libusb-1.0:") |
| 107 | + message(STATUS " - Includes: ${LIBUSB_1_INCLUDE_DIRS}") |
| 108 | + message(STATUS " - Libraries: ${LIBUSB_1_LIBRARIES}") |
| 109 | + endif (NOT libusb_1_FIND_QUIETLY) |
| 110 | + else (LIBUSB_1_FOUND) |
| 111 | + if (libusb_1_FIND_REQUIRED) |
| 112 | + message(FATAL_ERROR "Could not find libusb") |
| 113 | + endif (libusb_1_FIND_REQUIRED) |
| 114 | + endif (LIBUSB_1_FOUND) |
| 115 | + |
| 116 | + # show the LIBUSB_1_INCLUDE_DIRS and LIBUSB_1_LIBRARIES variables only in the advanced view |
| 117 | + mark_as_advanced(LIBUSB_1_INCLUDE_DIRS LIBUSB_1_LIBRARIES) |
| 118 | + |
| 119 | +endif (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) |
0 commit comments