1 # Copyright Raimar Sandner 2012–2014. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt)
5 #! \brief Improved versions of %CMake's `find_package`
8 #! \brief Works the same as `find_package`, but forwards the "REQUIRED" and "QUIET" arguments
9 #! used for the current package.
11 #! For this to work, the first parameter must be the prefix of the current package, then the
12 #! prefix of the new package etc, which are passed to `find_package`.
13 macro (libfind_package PREFIX)
14 set (LIBFIND_PACKAGE_ARGS ${ARGN})
15 if (${PREFIX}_FIND_QUIETLY)
16 set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET)
17 endif (${PREFIX}_FIND_QUIETLY)
18 if (${PREFIX}_FIND_REQUIRED)
19 set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
20 endif (${PREFIX}_FIND_REQUIRED)
21 find_package(${LIBFIND_PACKAGE_ARGS})
22 endmacro (libfind_package)
26 #! \brief Do the final processing once the paths have been detected.
28 #! If include dirs are needed, `${PREFIX}_PROCESS_INCLUDES` should be set to contain
29 #! all the variables, each of which contain one include directory.
30 #! Ditto for `${PREFIX}_PROCESS_LIBS` and library files.
31 #! Will set `${PREFIX}_FOUND`, `${PREFIX}_INCLUDE_DIRS` and `${PREFIX}_LIBRARIES`.
32 #! Also handles errors in case library detection was required, etc.
33 macro (libfind_process PREFIX)
34 # Skip processing if already processed during this run
35 if (NOT ${PREFIX}_FOUND)
36 # Start with the assumption that the library was found
37 set (${PREFIX}_FOUND TRUE)
39 # Process all includes and set _FOUND to false if any are missing
40 foreach (i ${${PREFIX}_PROCESS_INCLUDES})
42 set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
43 mark_as_advanced(${i})
45 set (${PREFIX}_FOUND FALSE)
49 # Process all libraries and set _FOUND to false if any are missing
50 foreach (i ${${PREFIX}_PROCESS_LIBS})
52 set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
53 mark_as_advanced(${i})
55 set (${PREFIX}_FOUND FALSE)
59 # Print message and/or exit on fatal error
61 if (NOT ${PREFIX}_FIND_QUIETLY)
62 message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
63 endif (NOT ${PREFIX}_FIND_QUIETLY)
64 else (${PREFIX}_FOUND)
65 if (${PREFIX}_FIND_REQUIRED)
66 foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
67 message("${i}=${${i}}")
69 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.")
70 endif (${PREFIX}_FIND_REQUIRED)
71 endif (${PREFIX}_FOUND)
72 endif (NOT ${PREFIX}_FOUND)
73 endmacro (libfind_process)