Debian Codegraph @

cmake_modules/FindUSB1.cmake

raw
1 # - Try to find libusb-1.0
2 # Once done this will define
3 #
4 # USB1_FOUND - system has libusb-1.0
5 # USB1_INCLUDE_DIRS - the libusb-1.0 include directories
6 # USB1_LIBRARIES - Link these to use libusb-1.0
7 # USB1_DEFINITIONS - Compiler switches required for using libusb-1.0
8 #
9 # USB1_HAS_LIBUSB_ERROR_NAME - defined when libusb-1.0 has libusb_error_name()
10
11 #=============================================================================
12 # Copyright (c) 2017 Pino Toscano <[email protected]>
13 #
14 # Redistribution and use in source and binary forms, with or without
15 # modification, are permitted provided that the following conditions
16 # are met:
17 #
18 # 1. Redistributions of source code must retain the copyright
19 # notice, this list of conditions and the following disclaimer.
20 # 2. Redistributions in binary form must reproduce the copyright
21 # notice, this list of conditions and the following disclaimer in the
22 # documentation and/or other materials provided with the distribution.
23 # 3. The name of the author may not be used to endorse or promote products
24 # derived from this software without specific prior written permission.
25 #
26 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #=============================================================================
37
38 find_package(PkgConfig)
39 pkg_check_modules(PC_LIBUSB1 QUIET libusb-1.0)
40
41 find_path(USB1_INCLUDE_DIR
42 NAMES
43 libusb.h
44 HINTS
45 ${PC_LIBUSB1_INCLUDE_DIRS}
46 PATH_SUFFIXES
47 libusb-1.0
48 )
49
50 find_library(USB1_LIBRARY
51 NAMES
52 ${PC_LIBUSB1_LIBRARIES}
53 usb-1.0
54 HINTS
55 ${PC_LIBUSB1_LIBRARY_DIRS}
56 )
57
58 set(USB1_INCLUDE_DIRS ${USB1_INCLUDE_DIR})
59 set(USB1_LIBRARIES ${USB1_LIBRARY})
60
61 include(FindPackageHandleStandardArgs)
62 find_package_handle_standard_args(USB1
63 FOUND_VAR
64 USB1_FOUND
65 REQUIRED_VARS
66 USB1_LIBRARY
67 USB1_INCLUDE_DIR
68 VERSION_VAR
69 PC_LIBUSB1_VERSION
70 )
71
72 mark_as_advanced(USB1_INCLUDE_DIRS USB1_LIBRARIES)
73
74 if(USB1_FOUND)
75 include(CheckCXXSourceCompiles)
76 include(CMakePushCheckState)
77 cmake_push_check_state(RESET)
78 set(CMAKE_REQUIRED_INCLUDES ${USB1_INCLUDE_DIRS})
79 set(CMAKE_REQUIRED_LIBRARIES ${USB1_LIBRARIES})
80 check_cxx_source_compiles("#include <libusb.h>
81 int main() { libusb_error_name(0); return 0; }" USB1_HAS_LIBUSB_ERROR_NAME)
82 cmake_pop_check_state()
83 endif()