C++QED  2.100.2 (v2 Milestone 10 Development branch)
a framework for simulating open quantum dynamics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Modules Pages
LibFindMacros.cmake
1 # Copyright Raimar Sandner 2012–2014. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt)
2 
3 #! \file
4 #! \ingroup Helpers
5 #! \brief Improved versions of %CMake's `find_package`
6 
7 #! \ingroup Helpers
8 #! \brief Works the same as `find_package`, but forwards the "REQUIRED" and "QUIET" arguments
9 #! used for the current package.
10 #!
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)
23 
24 
25 #! \ingroup Helpers
26 #! \brief Do the final processing once the paths have been detected.
27 #!
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)
38 
39  # Process all includes and set _FOUND to false if any are missing
40  foreach (i ${${PREFIX}_PROCESS_INCLUDES})
41  if (${i})
42  set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
43  mark_as_advanced(${i})
44  else (${i})
45  set (${PREFIX}_FOUND FALSE)
46  endif (${i})
47  endforeach (i)
48 
49  # Process all libraries and set _FOUND to false if any are missing
50  foreach (i ${${PREFIX}_PROCESS_LIBS})
51  if (${i})
52  set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
53  mark_as_advanced(${i})
54  else (${i})
55  set (${PREFIX}_FOUND FALSE)
56  endif (${i})
57  endforeach (i)
58 
59  # Print message and/or exit on fatal error
60  if (${PREFIX}_FOUND)
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}}")
68  endforeach (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)
74 
75