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