File: FindRequiredPackage.cmake

package info (click to toggle)
broccoli-python 0.62-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 460 kB
  • ctags: 105
  • sloc: python: 407; sh: 202; makefile: 21
file content (44 lines) | stat: -rw-r--r-- 1,567 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# A wrapper macro around the standard CMake find_package macro that
# facilitates displaying better error messages by default, or even
# accepting custom error messages on a per package basis.
#
# If a package is not found, then the MISSING_PREREQS variable gets
# set to true and either a default or custom error message appended
# to MISSING_PREREQ_DESCS.
#
# The caller can use these variables to display a list of any missing
# packages and abort the build/configuration if there were any.
# 
# Use as follows:
#
# include(FindRequiredPackage)
# FindRequiredPackage(Perl)
# FindRequiredPackage(FLEX "You need to install flex (Fast Lexical Analyzer)")
#
# if (MISSING_PREREQS)
#    foreach (prereq ${MISSING_PREREQ_DESCS})
#        message(SEND_ERROR ${prereq})
#    endforeach ()
#    message(FATAL_ERROR "Configuration aborted due to missing prerequisites")
# endif ()

macro(FindRequiredPackage packageName)
    find_package(${packageName})
    string(TOUPPER ${packageName} canonPackageName)
    if (NOT ${canonPackageName}_FOUND)
        set(MISSING_PREREQS true)

        set(customDesc)
        foreach (descArg ${ARGN})
            set(customDesc "${customDesc} ${descArg}")
        endforeach ()

        if (customDesc)
            # append the custom error message that was provided as an argument
            list(APPEND MISSING_PREREQ_DESCS ${customDesc})
        else ()
            list(APPEND MISSING_PREREQ_DESCS
                 " Could not find prerequisite package '${packageName}'")
        endif ()
    endif ()
endmacro(FindRequiredPackage)