1
# http://performous.git.sourceforge.net
3
# Works the same as find_package, but forwards the "REQUIRED" argument used for
4
# the current package and always uses the "QUIET" flag. For this to work, the
5
# first parameter must be the prefix of the current package, then the prefix of
6
# the new package etc, which are passed to find_package.
7
macro (libfind_package PREFIX)
8
set (LIBFIND_PACKAGE_ARGS ${ARGN} QUIET)
9
if (${PREFIX}_FIND_REQUIRED)
10
set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
11
endif (${PREFIX}_FIND_REQUIRED)
12
find_package(${LIBFIND_PACKAGE_ARGS})
13
endmacro (libfind_package)
15
# Damn CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
16
# where they added pkg_check_modules. Consequently I need to support both in my scripts
17
# to avoid those deprecated warnings. Here's a helper that does just that.
18
# Works identically to pkg_check_modules, except that no checks are needed prior to use.
19
macro (libfind_pkg_check_modules PREFIX PKGNAME)
20
if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
22
pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
23
else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
24
find_package(PkgConfig)
26
pkg_check_modules(${PREFIX} ${PKGNAME})
27
endif (PKG_CONFIG_FOUND)
28
endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
29
endmacro (libfind_pkg_check_modules)
31
# Do the final processing once the paths have been detected.
32
# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
33
# all the variables, each of which contain one include directory.
34
# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
35
# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
36
# Also handles errors in case library detection was required, etc.
37
macro (libfind_process PREFIX)
38
# Skip processing if already processed during this run
39
if (NOT ${PREFIX}_FOUND)
40
# Start with the assumption that the library was found
41
set (${PREFIX}_FOUND TRUE)
43
# Process all includes and set _FOUND to false if any are missing
44
foreach (i ${${PREFIX}_PROCESS_INCLUDES})
46
set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
47
mark_as_advanced(${i})
49
set (${PREFIX}_FOUND FALSE)
53
# Process all libraries and set _FOUND to false if any are missing
54
foreach (i ${${PREFIX}_PROCESS_LIBS})
56
set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
57
mark_as_advanced(${i})
59
set (${PREFIX}_FOUND FALSE)
63
# Print message and/or exit on fatal error
65
if (NOT ${PREFIX}_FIND_QUIETLY)
66
message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
67
endif (NOT ${PREFIX}_FIND_QUIETLY)
68
else (${PREFIX}_FOUND)
69
if (${PREFIX}_FIND_REQUIRED)
70
foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
71
message("${i}=${${i}}")
73
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.")
74
endif (${PREFIX}_FIND_REQUIRED)
75
endif (${PREFIX}_FOUND)
76
endif (NOT ${PREFIX}_FOUND)
77
endmacro (libfind_process)