]> git.donarmstrong.com Git - kiibohd-controller.git/blob - LoadFile/FindLibUSB-1.0.cmake
Merge pull request #71 from glguy/pr-cli-history
[kiibohd-controller.git] / LoadFile / FindLibUSB-1.0.cmake
1 # Attempts to find libusb-1.0
2 #
3 #  LIBUSB_FOUND - system has libusb
4 #  LIBUSB_INCLUDE_DIRS - the libusb include directory
5 #  LIBUSB_LIBRARIES - Link these to use libusb
6 #  LIBUSB_DEFINITIONS - Compiler switches required for using libusb
7 #
8 #  Adapted from cmake-modules Google Code project
9 #
10 #  Copyright (c) 2006 Andreas Schneider <mail@cynapses.org>
11 #
12 #  (Changes for libusb) Copyright (c) 2014 Jacob Alexander <haata@kiibohd.com>
13 #
14 # Redistribution and use is allowed according to the terms of the New BSD license.
15 #
16 # CMake-Modules Project New BSD License
17 #
18 # Redistribution and use in source and binary forms, with or without
19 # modification, are permitted provided that the following conditions are met:
20 #
21 # * Redistributions of source code must retain the above copyright notice, this
22 #   list of conditions and the following disclaimer.
23 #
24 # * Redistributions in binary form must reproduce the above copyright notice,
25 #   this list of conditions and the following disclaimer in the
26 #   documentation and/or other materials provided with the distribution.
27 #
28 # * Neither the name of the CMake-Modules Project nor the names of its
29 #   contributors may be used to endorse or promote products derived from this
30 #   software without specific prior written permission.
31 #
32 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
33 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
36 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38 #  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
39 # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #
43
44
45 if ( LIBUSB_LIBRARIES AND LIBUSB_INCLUDE_DIRS )
46         # in cache already
47         set( LIBUSB_FOUND TRUE )
48 else ()
49         find_path( LIBUSB_INCLUDE_DIR
50                 NAMES
51                         libusb.h
52                 PATHS
53                         /usr/include
54                         /usr/local/include
55                         /opt/local/include
56                         /sw/include
57                         /include
58                 PATH_SUFFIXES
59                         libusb-1.0
60         )
61
62         find_library( LIBUSB_LIBRARY
63                 NAMES
64                         usb-1.0
65                 PATHS
66                         /usr/lib
67                         /usr/local/lib
68                         /opt/local/lib
69                         /sw/lib
70                         /lib
71         )
72
73         set( LIBUSB_INCLUDE_DIRS ${LIBUSB_INCLUDE_DIR} )
74         set( LIBUSB_LIBRARIES ${LIBUSB_LIBRARY} )
75
76         if ( LIBUSB_INCLUDE_DIRS AND LIBUSB_LIBRARIES )
77                  set( LIBUSB_FOUND TRUE )
78         endif ()
79
80         if ( LIBUSB_FOUND )
81                 if ( NOT LIBUSB_FIND_QUIETLY )
82                         message( STATUS "Found libusb:" )
83                         message( STATUS " - Includes: ${LIBUSB_INCLUDE_DIRS}" )
84                         message( STATUS " - Libraries: ${LIBUSB_LIBRARIES}" )
85                 endif ()
86         else ()
87                 if ( LIBUSB_FIND_REQUIRED )
88                         message( FATAL_ERROR "Could not find libusb-1.0" )
89                 endif ()
90         endif ()
91
92         # show the LIBUSB_INCLUDE_DIRS and LIBUSB_LIBRARIES variables only in the advanced view
93         mark_as_advanced( LIBUSB_INCLUDE_DIRS LIBUSB_LIBRARIES )
94
95 endif ()
96