summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGravatar Hector Martin2009-08-20 03:42:52 +0200
committerGravatar Hector Martin2009-08-20 06:51:10 +0200
commit1a0c58e4062da7db73b4c08963f741cf016f6aa5 (patch)
treeb250f094e978d48622ecf652e28e9f3b68873893 /Modules
parentf4854f3fd725b5ba49cd5157d941783cffa08c04 (diff)
parent79ca4d9a3c3a82bb5a3f9be1ac7a2533c7a89b05 (diff)
downloadusbmuxd-1a0c58e4062da7db73b4c08963f741cf016f6aa5.tar.gz
usbmuxd-1a0c58e4062da7db73b4c08963f741cf016f6aa5.tar.bz2
Merge the two development histories
Diffstat (limited to 'Modules')
-rw-r--r--Modules/FindUSB.cmake31
-rw-r--r--Modules/LibFindMacros.cmake99
2 files changed, 130 insertions, 0 deletions
diff --git a/Modules/FindUSB.cmake b/Modules/FindUSB.cmake
new file mode 100644
index 0000000..d562b98
--- /dev/null
+++ b/Modules/FindUSB.cmake
@@ -0,0 +1,31 @@
1# - Try to find libusb-1.0
2# Once done, this will define
3#
4# USB_FOUND - system has libusb-1.0
5# USB_INCLUDE_DIRS - the libusb-1.0 include directories
6# USB_LIBRARIES - link these to use libusb-1.0
7
8include(LibFindMacros)
9
10# Dependencies
11
12# Use pkg-config to get hints about paths
13libfind_pkg_check_modules(USB_PKGCONF libusb-1.0)
14
15# Include dir
16find_path(USB_INCLUDE_DIR
17 NAMES libusb.h
18 PATHS ${USB_PKGCONF_INCLUDE_DIRS}
19)
20
21# Finally the library itself
22find_library(USB_LIBRARY
23 NAMES usb-1.0
24 PATHS ${USB_PKGCONF_LIBRARY_DIRS}
25)
26
27# Set the include dir variables and the libraries and let libfind_process do the rest.
28# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
29set(USB_PROCESS_INCLUDES USB_INCLUDE_DIR)
30set(USB_PROCESS_LIBS USB_LIBRARY)
31libfind_process(USB)
diff --git a/Modules/LibFindMacros.cmake b/Modules/LibFindMacros.cmake
new file mode 100644
index 0000000..795d6b7
--- /dev/null
+++ b/Modules/LibFindMacros.cmake
@@ -0,0 +1,99 @@
1# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments
2# used for the current package. For this to work, the first parameter must be the
3# prefix of the current package, then the prefix of the new package etc, which are
4# passed to find_package.
5macro (libfind_package PREFIX)
6 set (LIBFIND_PACKAGE_ARGS ${ARGN})
7 if (${PREFIX}_FIND_QUIETLY)
8 set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET)
9 endif (${PREFIX}_FIND_QUIETLY)
10 if (${PREFIX}_FIND_REQUIRED)
11 set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
12 endif (${PREFIX}_FIND_REQUIRED)
13 find_package(${LIBFIND_PACKAGE_ARGS})
14endmacro (libfind_package)
15
16# Damn CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
17# where they added pkg_check_modules. Consequently I need to support both in my scripts
18# to avoid those deprecated warnings. Here's a helper that does just that.
19# Works identically to pkg_check_modules, except that no checks are needed prior to use.
20macro (libfind_pkg_check_modules PREFIX PKGNAME)
21 if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
22 include(UsePkgConfig)
23 pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
24 else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
25 find_package(PkgConfig)
26 if (PKG_CONFIG_FOUND)
27 pkg_check_modules(${PREFIX} ${PKGNAME})
28 endif (PKG_CONFIG_FOUND)
29 endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
30endmacro (libfind_pkg_check_modules)
31
32# Do the final processing once the paths have been detected.
33# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
34# all the variables, each of which contain one include directory.
35# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
36# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
37# Also handles errors in case library detection was required, etc.
38macro (libfind_process PREFIX)
39 # Skip processing if already processed during this run
40 if (NOT ${PREFIX}_FOUND)
41 # Start with the assumption that the library was found
42 set (${PREFIX}_FOUND TRUE)
43
44 # Process all includes and set _FOUND to false if any are missing
45 foreach (i ${${PREFIX}_PROCESS_INCLUDES})
46 if (${i})
47 set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
48 mark_as_advanced(${i})
49 else (${i})
50 set (${PREFIX}_FOUND FALSE)
51 endif (${i})
52 endforeach (i)
53
54 # Process all libraries and set _FOUND to false if any are missing
55 foreach (i ${${PREFIX}_PROCESS_LIBS})
56 if (${i})
57 set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
58 mark_as_advanced(${i})
59 else (${i})
60 set (${PREFIX}_FOUND FALSE)
61 endif (${i})
62 endforeach (i)
63
64 # Print message and/or exit on fatal error
65 if (${PREFIX}_FOUND)
66 if (NOT ${PREFIX}_FIND_QUIETLY)
67 message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
68 endif (NOT ${PREFIX}_FIND_QUIETLY)
69 else (${PREFIX}_FOUND)
70 if (${PREFIX}_FIND_REQUIRED)
71 foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
72 message("${i}=${${i}}")
73 endforeach (i)
74 message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.")
75 endif (${PREFIX}_FIND_REQUIRED)
76 endif (${PREFIX}_FOUND)
77 endif (NOT ${PREFIX}_FOUND)
78endmacro (libfind_process)
79
80macro(libfind_library PREFIX basename)
81 set(TMP "")
82 if(MSVC80)
83 set(TMP -vc80)
84 endif(MSVC80)
85 if(MSVC90)
86 set(TMP -vc90)
87 endif(MSVC90)
88 set(${PREFIX}_LIBNAMES ${basename}${TMP})
89 if(${ARGC} GREATER 2)
90 set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2})
91 string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES})
92 set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP})
93 endif(${ARGC} GREATER 2)
94 find_library(${PREFIX}_LIBRARY
95 NAMES ${${PREFIX}_LIBNAMES}
96 PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}
97 )
98endmacro(libfind_library)
99