git repos / blockattack-game

blame: source/misc/cmake/LibFindMacros.cmake

normal view · raw

5614ab55 sago007 2016-01-17 13:44 1
# Version 2.2
5614ab55 sago007 2016-01-17 13:44 2
# Public Domain, originally written by Lasse Kärkkäinen <tronic>
5614ab55 sago007 2016-01-17 13:44 3
# Maintained at https://github.com/Tronic/cmake-modules
5614ab55 sago007 2016-01-17 13:44 4
# Please send your improvements as pull requests on Github.
5614ab55 sago007 2016-01-17 13:44 5
5614ab55 sago007 2016-01-17 13:44 6
# Find another package and make it a dependency of the current package.
5614ab55 sago007 2016-01-17 13:44 7
# This also automatically forwards the "REQUIRED" argument.
5614ab55 sago007 2016-01-17 13:44 8
# Usage: libfind_package(<prefix> <another package> [extra args to find_package])
5614ab55 sago007 2016-01-17 13:44 9
macro (libfind_package PREFIX PKG)
5614ab55 sago007 2016-01-17 13:44 10
  set(${PREFIX}_args ${PKG} ${ARGN})
5614ab55 sago007 2016-01-17 13:44 11
  if (${PREFIX}_FIND_REQUIRED)
5614ab55 sago007 2016-01-17 13:44 12
    set(${PREFIX}_args ${${PREFIX}_args} REQUIRED)
5614ab55 sago007 2016-01-17 13:44 13
  endif()
5614ab55 sago007 2016-01-17 13:44 14
  find_package(${${PREFIX}_args})
5614ab55 sago007 2016-01-17 13:44 15
  set(${PREFIX}_DEPENDENCIES ${${PREFIX}_DEPENDENCIES};${PKG})
5614ab55 sago007 2016-01-17 13:44 16
  unset(${PREFIX}_args)
5614ab55 sago007 2016-01-17 13:44 17
endmacro()
5614ab55 sago007 2016-01-17 13:44 18
5614ab55 sago007 2016-01-17 13:44 19
# A simple wrapper to make pkg-config searches a bit easier.
5614ab55 sago007 2016-01-17 13:44 20
# Works the same as CMake's internal pkg_check_modules but is always quiet.
5614ab55 sago007 2016-01-17 13:44 21
macro (libfind_pkg_check_modules)
5614ab55 sago007 2016-01-17 13:44 22
  find_package(PkgConfig QUIET)
5614ab55 sago007 2016-01-17 13:44 23
  if (PKG_CONFIG_FOUND)
5614ab55 sago007 2016-01-17 13:44 24
    pkg_check_modules(${ARGN} QUIET)
5614ab55 sago007 2016-01-17 13:44 25
  endif()
5614ab55 sago007 2016-01-17 13:44 26
endmacro()
5614ab55 sago007 2016-01-17 13:44 27
5614ab55 sago007 2016-01-17 13:44 28
# Avoid useless copy&pasta by doing what most simple libraries do anyway:
5614ab55 sago007 2016-01-17 13:44 29
# pkg-config, find headers, find library.
5614ab55 sago007 2016-01-17 13:44 30
# Usage: libfind_pkg_detect(<prefix> <pkg-config args> FIND_PATH <name> [other args] FIND_LIBRARY <name> [other args])
5614ab55 sago007 2016-01-17 13:44 31
# E.g. libfind_pkg_detect(SDL2 sdl2 FIND_PATH SDL.h PATH_SUFFIXES SDL2 FIND_LIBRARY SDL2)
5614ab55 sago007 2016-01-17 13:44 32
function (libfind_pkg_detect PREFIX)
5614ab55 sago007 2016-01-17 13:44 33
  # Parse arguments
5614ab55 sago007 2016-01-17 13:44 34
  set(argname pkgargs)
5614ab55 sago007 2016-01-17 13:44 35
  foreach (i ${ARGN})
5614ab55 sago007 2016-01-17 13:44 36
    if ("${i}" STREQUAL "FIND_PATH")
5614ab55 sago007 2016-01-17 13:44 37
      set(argname pathargs)
5614ab55 sago007 2016-01-17 13:44 38
    elseif ("${i}" STREQUAL "FIND_LIBRARY")
5614ab55 sago007 2016-01-17 13:44 39
      set(argname libraryargs)
5614ab55 sago007 2016-01-17 13:44 40
    else()
5614ab55 sago007 2016-01-17 13:44 41
      set(${argname} ${${argname}} ${i})
5614ab55 sago007 2016-01-17 13:44 42
    endif()
5614ab55 sago007 2016-01-17 13:44 43
  endforeach()
5614ab55 sago007 2016-01-17 13:44 44
  if (NOT pkgargs)
5614ab55 sago007 2016-01-17 13:44 45
    message(FATAL_ERROR "libfind_pkg_detect requires at least a pkg_config package name to be passed.")
5614ab55 sago007 2016-01-17 13:44 46
  endif()
5614ab55 sago007 2016-01-17 13:44 47
  # Find library
5614ab55 sago007 2016-01-17 13:44 48
  libfind_pkg_check_modules(${PREFIX}_PKGCONF ${pkgargs})
5614ab55 sago007 2016-01-17 13:44 49
  if (pathargs)
5614ab55 sago007 2016-01-17 13:44 50
    find_path(${PREFIX}_INCLUDE_DIR NAMES ${pathargs} HINTS ${${PREFIX}_PKGCONF_INCLUDE_DIRS})
5614ab55 sago007 2016-01-17 13:44 51
  endif()
5614ab55 sago007 2016-01-17 13:44 52
  if (libraryargs)
5614ab55 sago007 2016-01-17 13:44 53
    find_library(${PREFIX}_LIBRARY NAMES ${libraryargs} HINTS ${${PREFIX}_PKGCONF_LIBRARY_DIRS})
5614ab55 sago007 2016-01-17 13:44 54
  endif()
5614ab55 sago007 2016-01-17 13:44 55
endfunction()
5614ab55 sago007 2016-01-17 13:44 56
5614ab55 sago007 2016-01-17 13:44 57
# Extracts a version #define from a version.h file, output stored to <PREFIX>_VERSION.
5614ab55 sago007 2016-01-17 13:44 58
# Usage: libfind_version_header(Foobar foobar/version.h FOOBAR_VERSION_STR)
5614ab55 sago007 2016-01-17 13:44 59
# Fourth argument "QUIET" may be used for silently testing different define names.
5614ab55 sago007 2016-01-17 13:44 60
# This function does nothing if the version variable is already defined.
5614ab55 sago007 2016-01-17 13:44 61
function (libfind_version_header PREFIX VERSION_H DEFINE_NAME)
5614ab55 sago007 2016-01-17 13:44 62
  # Skip processing if we already have a version or if the include dir was not found
5614ab55 sago007 2016-01-17 13:44 63
  if (${PREFIX}_VERSION OR NOT ${PREFIX}_INCLUDE_DIR)
5614ab55 sago007 2016-01-17 13:44 64
    return()
5614ab55 sago007 2016-01-17 13:44 65
  endif()
5614ab55 sago007 2016-01-17 13:44 66
  set(quiet ${${PREFIX}_FIND_QUIETLY})
5614ab55 sago007 2016-01-17 13:44 67
  # Process optional arguments
5614ab55 sago007 2016-01-17 13:44 68
  foreach(arg ${ARGN})
5614ab55 sago007 2016-01-17 13:44 69
    if (arg STREQUAL "QUIET")
5614ab55 sago007 2016-01-17 13:44 70
      set(quiet TRUE)
5614ab55 sago007 2016-01-17 13:44 71
    else()
5614ab55 sago007 2016-01-17 13:44 72
      message(AUTHOR_WARNING "Unknown argument ${arg} to libfind_version_header ignored.")
5614ab55 sago007 2016-01-17 13:44 73
    endif()
5614ab55 sago007 2016-01-17 13:44 74
  endforeach()
5614ab55 sago007 2016-01-17 13:44 75
  # Read the header and parse for version number
5614ab55 sago007 2016-01-17 13:44 76
  set(filename "${${PREFIX}_INCLUDE_DIR}/${VERSION_H}")
5614ab55 sago007 2016-01-17 13:44 77
  if (NOT EXISTS ${filename})
5614ab55 sago007 2016-01-17 13:44 78
    if (NOT quiet)
5614ab55 sago007 2016-01-17 13:44 79
      message(AUTHOR_WARNING "Unable to find ${${PREFIX}_INCLUDE_DIR}/${VERSION_H}")
5614ab55 sago007 2016-01-17 13:44 80
    endif()
5614ab55 sago007 2016-01-17 13:44 81
    return()
5614ab55 sago007 2016-01-17 13:44 82
  endif()
5614ab55 sago007 2016-01-17 13:44 83
  file(READ "${filename}" header)
5614ab55 sago007 2016-01-17 13:44 84
  string(REGEX REPLACE ".*#[ \t]*define[ \t]*${DEFINE_NAME}[ \t]*\"([^\n]*)\".*" "\\1" match "${header}")
5614ab55 sago007 2016-01-17 13:44 85
  # No regex match?
5614ab55 sago007 2016-01-17 13:44 86
  if (match STREQUAL header)
5614ab55 sago007 2016-01-17 13:44 87
    if (NOT quiet)
5614ab55 sago007 2016-01-17 13:44 88
      message(AUTHOR_WARNING "Unable to find \#define ${DEFINE_NAME} \"<version>\" from ${${PREFIX}_INCLUDE_DIR}/${VERSION_H}")
5614ab55 sago007 2016-01-17 13:44 89
    endif()
5614ab55 sago007 2016-01-17 13:44 90
    return()
5614ab55 sago007 2016-01-17 13:44 91
  endif()
5614ab55 sago007 2016-01-17 13:44 92
  # Export the version string
5614ab55 sago007 2016-01-17 13:44 93
  set(${PREFIX}_VERSION "${match}" PARENT_SCOPE)
5614ab55 sago007 2016-01-17 13:44 94
endfunction()
5614ab55 sago007 2016-01-17 13:44 95
5614ab55 sago007 2016-01-17 13:44 96
# Do the final processing once the paths have been detected.
5614ab55 sago007 2016-01-17 13:44 97
# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
5614ab55 sago007 2016-01-17 13:44 98
# all the variables, each of which contain one include directory.
5614ab55 sago007 2016-01-17 13:44 99
# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
5614ab55 sago007 2016-01-17 13:44 100
# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
5614ab55 sago007 2016-01-17 13:44 101
# Also handles errors in case library detection was required, etc.
5614ab55 sago007 2016-01-17 13:44 102
function (libfind_process PREFIX)
5614ab55 sago007 2016-01-17 13:44 103
  # Skip processing if already processed during this configuration run
5614ab55 sago007 2016-01-17 13:44 104
  if (${PREFIX}_FOUND)
5614ab55 sago007 2016-01-17 13:44 105
    return()
5614ab55 sago007 2016-01-17 13:44 106
  endif()
5614ab55 sago007 2016-01-17 13:44 107
5614ab55 sago007 2016-01-17 13:44 108
  set(found TRUE)  # Start with the assumption that the package was found
5614ab55 sago007 2016-01-17 13:44 109
5614ab55 sago007 2016-01-17 13:44 110
  # Did we find any files? Did we miss includes? These are for formatting better error messages.
5614ab55 sago007 2016-01-17 13:44 111
  set(some_files FALSE)
5614ab55 sago007 2016-01-17 13:44 112
  set(missing_headers FALSE)
5614ab55 sago007 2016-01-17 13:44 113
5614ab55 sago007 2016-01-17 13:44 114
  # Shorthands for some variables that we need often
5614ab55 sago007 2016-01-17 13:44 115
  set(quiet ${${PREFIX}_FIND_QUIETLY})
5614ab55 sago007 2016-01-17 13:44 116
  set(required ${${PREFIX}_FIND_REQUIRED})
5614ab55 sago007 2016-01-17 13:44 117
  set(exactver ${${PREFIX}_FIND_VERSION_EXACT})
5614ab55 sago007 2016-01-17 13:44 118
  set(findver "${${PREFIX}_FIND_VERSION}")
5614ab55 sago007 2016-01-17 13:44 119
  set(version "${${PREFIX}_VERSION}")
5614ab55 sago007 2016-01-17 13:44 120
5614ab55 sago007 2016-01-17 13:44 121
  # Lists of config option names (all, includes, libs)
5614ab55 sago007 2016-01-17 13:44 122
  unset(configopts)
5614ab55 sago007 2016-01-17 13:44 123
  set(includeopts ${${PREFIX}_PROCESS_INCLUDES})
5614ab55 sago007 2016-01-17 13:44 124
  set(libraryopts ${${PREFIX}_PROCESS_LIBS})
5614ab55 sago007 2016-01-17 13:44 125
5614ab55 sago007 2016-01-17 13:44 126
  # Process deps to add to 
5614ab55 sago007 2016-01-17 13:44 127
  foreach (i ${PREFIX} ${${PREFIX}_DEPENDENCIES})
5614ab55 sago007 2016-01-17 13:44 128
    if (DEFINED ${i}_INCLUDE_OPTS OR DEFINED ${i}_LIBRARY_OPTS)
5614ab55 sago007 2016-01-17 13:44 129
      # The package seems to export option lists that we can use, woohoo!
5614ab55 sago007 2016-01-17 13:44 130
      list(APPEND includeopts ${${i}_INCLUDE_OPTS})
5614ab55 sago007 2016-01-17 13:44 131
      list(APPEND libraryopts ${${i}_LIBRARY_OPTS})
5614ab55 sago007 2016-01-17 13:44 132
    else()
5614ab55 sago007 2016-01-17 13:44 133
      # If plural forms don't exist or they equal singular forms
5614ab55 sago007 2016-01-17 13:44 134
      if ((NOT DEFINED ${i}_INCLUDE_DIRS AND NOT DEFINED ${i}_LIBRARIES) OR
5614ab55 sago007 2016-01-17 13:44 135
          ({i}_INCLUDE_DIR STREQUAL ${i}_INCLUDE_DIRS AND ${i}_LIBRARY STREQUAL ${i}_LIBRARIES))
5614ab55 sago007 2016-01-17 13:44 136
        # Singular forms can be used
5614ab55 sago007 2016-01-17 13:44 137
        if (DEFINED ${i}_INCLUDE_DIR)
5614ab55 sago007 2016-01-17 13:44 138
          list(APPEND includeopts ${i}_INCLUDE_DIR)
5614ab55 sago007 2016-01-17 13:44 139
        endif()
5614ab55 sago007 2016-01-17 13:44 140
        if (DEFINED ${i}_LIBRARY)
5614ab55 sago007 2016-01-17 13:44 141
          list(APPEND libraryopts ${i}_LIBRARY)
5614ab55 sago007 2016-01-17 13:44 142
        endif()
5614ab55 sago007 2016-01-17 13:44 143
      else()
5614ab55 sago007 2016-01-17 13:44 144
        # Oh no, we don't know the option names
5614ab55 sago007 2016-01-17 13:44 145
        message(FATAL_ERROR "We couldn't determine config variable names for ${i} includes and libs. Aieeh!")
5614ab55 sago007 2016-01-17 13:44 146
      endif()
5614ab55 sago007 2016-01-17 13:44 147
    endif()
5614ab55 sago007 2016-01-17 13:44 148
  endforeach()
5614ab55 sago007 2016-01-17 13:44 149
  
5614ab55 sago007 2016-01-17 13:44 150
  if (includeopts)
5614ab55 sago007 2016-01-17 13:44 151
    list(REMOVE_DUPLICATES includeopts)
5614ab55 sago007 2016-01-17 13:44 152
  endif()
5614ab55 sago007 2016-01-17 13:44 153
  
5614ab55 sago007 2016-01-17 13:44 154
  if (libraryopts)
5614ab55 sago007 2016-01-17 13:44 155
    list(REMOVE_DUPLICATES libraryopts)
5614ab55 sago007 2016-01-17 13:44 156
  endif()
5614ab55 sago007 2016-01-17 13:44 157
5614ab55 sago007 2016-01-17 13:44 158
  string(REGEX REPLACE ".*[ ;]([^ ;]*(_INCLUDE_DIRS|_LIBRARIES))" "\\1" tmp "${includeopts} ${libraryopts}")
5614ab55 sago007 2016-01-17 13:44 159
  if (NOT tmp STREQUAL "${includeopts} ${libraryopts}")
5614ab55 sago007 2016-01-17 13:44 160
    message(AUTHOR_WARNING "Plural form ${tmp} found in config options of ${PREFIX}. This works as before but is now deprecated. Please only use singular forms INCLUDE_DIR and LIBRARY, and update your find scripts for LibFindMacros > 2.0 automatic dependency system (most often you can simply remove the PROCESS variables entirely).")
5614ab55 sago007 2016-01-17 13:44 161
  endif()
5614ab55 sago007 2016-01-17 13:44 162
5614ab55 sago007 2016-01-17 13:44 163
  # Include/library names separated by spaces (notice: not CMake lists)
5614ab55 sago007 2016-01-17 13:44 164
  unset(includes)
5614ab55 sago007 2016-01-17 13:44 165
  unset(libs)
5614ab55 sago007 2016-01-17 13:44 166
5614ab55 sago007 2016-01-17 13:44 167
  # Process all includes and set found false if any are missing
5614ab55 sago007 2016-01-17 13:44 168
  foreach (i ${includeopts})
5614ab55 sago007 2016-01-17 13:44 169
    list(APPEND configopts ${i})
5614ab55 sago007 2016-01-17 13:44 170
    if (NOT "${${i}}" STREQUAL "${i}-NOTFOUND")
5614ab55 sago007 2016-01-17 13:44 171
      list(APPEND includes "${${i}}")
5614ab55 sago007 2016-01-17 13:44 172
    else()
5614ab55 sago007 2016-01-17 13:44 173
      set(found FALSE)
5614ab55 sago007 2016-01-17 13:44 174
      set(missing_headers TRUE)
5614ab55 sago007 2016-01-17 13:44 175
    endif()
5614ab55 sago007 2016-01-17 13:44 176
  endforeach()
5614ab55 sago007 2016-01-17 13:44 177
5614ab55 sago007 2016-01-17 13:44 178
  # Process all libraries and set found false if any are missing
5614ab55 sago007 2016-01-17 13:44 179
  foreach (i ${libraryopts})
5614ab55 sago007 2016-01-17 13:44 180
    list(APPEND configopts ${i})
5614ab55 sago007 2016-01-17 13:44 181
    if (NOT "${${i}}" STREQUAL "${i}-NOTFOUND")
5614ab55 sago007 2016-01-17 13:44 182
      list(APPEND libs "${${i}}")
5614ab55 sago007 2016-01-17 13:44 183
    else()
5614ab55 sago007 2016-01-17 13:44 184
      set (found FALSE)
5614ab55 sago007 2016-01-17 13:44 185
    endif()
5614ab55 sago007 2016-01-17 13:44 186
  endforeach()
5614ab55 sago007 2016-01-17 13:44 187
5614ab55 sago007 2016-01-17 13:44 188
  # Version checks
5614ab55 sago007 2016-01-17 13:44 189
  if (found AND findver)
5614ab55 sago007 2016-01-17 13:44 190
    if (NOT version)
5614ab55 sago007 2016-01-17 13:44 191
      message(WARNING "The find module for ${PREFIX} does not provide version information, so we'll just assume that it is OK. Please fix the module or remove package version requirements to get rid of this warning.")
5614ab55 sago007 2016-01-17 13:44 192
    elseif (version VERSION_LESS findver OR (exactver AND NOT version VERSION_EQUAL findver))
5614ab55 sago007 2016-01-17 13:44 193
      set(found FALSE)
5614ab55 sago007 2016-01-17 13:44 194
      set(version_unsuitable TRUE)
5614ab55 sago007 2016-01-17 13:44 195
    endif()
5614ab55 sago007 2016-01-17 13:44 196
  endif()
5614ab55 sago007 2016-01-17 13:44 197
5614ab55 sago007 2016-01-17 13:44 198
  # If all-OK, hide all config options, export variables, print status and exit
5614ab55 sago007 2016-01-17 13:44 199
  if (found)
5614ab55 sago007 2016-01-17 13:44 200
    foreach (i ${configopts})
5614ab55 sago007 2016-01-17 13:44 201
      mark_as_advanced(${i})
5614ab55 sago007 2016-01-17 13:44 202
    endforeach()
5614ab55 sago007 2016-01-17 13:44 203
    if (NOT quiet)
5614ab55 sago007 2016-01-17 13:44 204
      message(STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
5614ab55 sago007 2016-01-17 13:44 205
      if (LIBFIND_DEBUG)
5614ab55 sago007 2016-01-17 13:44 206
        message(STATUS "  ${PREFIX}_DEPENDENCIES=${${PREFIX}_DEPENDENCIES}")
5614ab55 sago007 2016-01-17 13:44 207
        message(STATUS "  ${PREFIX}_INCLUDE_OPTS=${includeopts}")
5614ab55 sago007 2016-01-17 13:44 208
        message(STATUS "  ${PREFIX}_INCLUDE_DIRS=${includes}")
5614ab55 sago007 2016-01-17 13:44 209
        message(STATUS "  ${PREFIX}_LIBRARY_OPTS=${libraryopts}")
5614ab55 sago007 2016-01-17 13:44 210
        message(STATUS "  ${PREFIX}_LIBRARIES=${libs}")
5614ab55 sago007 2016-01-17 13:44 211
      endif()
5614ab55 sago007 2016-01-17 13:44 212
      set (${PREFIX}_INCLUDE_OPTS ${includeopts} PARENT_SCOPE)
5614ab55 sago007 2016-01-17 13:44 213
      set (${PREFIX}_LIBRARY_OPTS ${libraryopts} PARENT_SCOPE)
5614ab55 sago007 2016-01-17 13:44 214
      set (${PREFIX}_INCLUDE_DIRS ${includes} PARENT_SCOPE)
5614ab55 sago007 2016-01-17 13:44 215
      set (${PREFIX}_LIBRARIES ${libs} PARENT_SCOPE)
5614ab55 sago007 2016-01-17 13:44 216
      set (${PREFIX}_FOUND TRUE PARENT_SCOPE)
5614ab55 sago007 2016-01-17 13:44 217
    endif()
5614ab55 sago007 2016-01-17 13:44 218
    return()    
5614ab55 sago007 2016-01-17 13:44 219
  endif()
5614ab55 sago007 2016-01-17 13:44 220
5614ab55 sago007 2016-01-17 13:44 221
  # Format messages for debug info and the type of error
5614ab55 sago007 2016-01-17 13:44 222
  set(vars "Relevant CMake configuration variables:\n")
5614ab55 sago007 2016-01-17 13:44 223
  foreach (i ${configopts})
5614ab55 sago007 2016-01-17 13:44 224
    mark_as_advanced(CLEAR ${i})
5614ab55 sago007 2016-01-17 13:44 225
    set(val ${${i}})
5614ab55 sago007 2016-01-17 13:44 226
    if ("${val}" STREQUAL "${i}-NOTFOUND")
5614ab55 sago007 2016-01-17 13:44 227
      set (val "<not found>")
5614ab55 sago007 2016-01-17 13:44 228
    elseif (val AND NOT EXISTS ${val})
5614ab55 sago007 2016-01-17 13:44 229
      set (val "${val}  (does not exist)")
5614ab55 sago007 2016-01-17 13:44 230
    else()
5614ab55 sago007 2016-01-17 13:44 231
      set(some_files TRUE)
5614ab55 sago007 2016-01-17 13:44 232
    endif()
5614ab55 sago007 2016-01-17 13:44 233
    set(vars "${vars}  ${i}=${val}\n")
5614ab55 sago007 2016-01-17 13:44 234
  endforeach()
5614ab55 sago007 2016-01-17 13:44 235
  set(vars "${vars}You may use CMake GUI, cmake -D or ccmake to modify the values. Delete CMakeCache.txt to discard all values and force full re-detection if necessary.\n")
5614ab55 sago007 2016-01-17 13:44 236
  if (version_unsuitable)
5614ab55 sago007 2016-01-17 13:44 237
    set(msg "${PREFIX} ${${PREFIX}_VERSION} was found but")
5614ab55 sago007 2016-01-17 13:44 238
    if (exactver)
5614ab55 sago007 2016-01-17 13:44 239
      set(msg "${msg} only version ${findver} is acceptable.")
5614ab55 sago007 2016-01-17 13:44 240
    else()
5614ab55 sago007 2016-01-17 13:44 241
      set(msg "${msg} version ${findver} is the minimum requirement.")
5614ab55 sago007 2016-01-17 13:44 242
    endif()
5614ab55 sago007 2016-01-17 13:44 243
  else()
5614ab55 sago007 2016-01-17 13:44 244
    if (missing_headers)
5614ab55 sago007 2016-01-17 13:44 245
      set(msg "We could not find development headers for ${PREFIX}. Do you have the necessary dev package installed?")
5614ab55 sago007 2016-01-17 13:44 246
    elseif (some_files)
5614ab55 sago007 2016-01-17 13:44 247
      set(msg "We only found some files of ${PREFIX}, not all of them. Perhaps your installation is incomplete or maybe we just didn't look in the right place?")
5614ab55 sago007 2016-01-17 13:44 248
      if(findver)
5614ab55 sago007 2016-01-17 13:44 249
        set(msg "${msg} This could also be caused by incompatible version (if it helps, at least ${PREFIX} ${findver} should work).")
5614ab55 sago007 2016-01-17 13:44 250
      endif()
5614ab55 sago007 2016-01-17 13:44 251
    else()
5614ab55 sago007 2016-01-17 13:44 252
      set(msg "We were unable to find package ${PREFIX}.")
5614ab55 sago007 2016-01-17 13:44 253
    endif()
5614ab55 sago007 2016-01-17 13:44 254
  endif()
5614ab55 sago007 2016-01-17 13:44 255
5614ab55 sago007 2016-01-17 13:44 256
  # Fatal error out if REQUIRED
5614ab55 sago007 2016-01-17 13:44 257
  if (required)
5614ab55 sago007 2016-01-17 13:44 258
    set(msg "REQUIRED PACKAGE NOT FOUND\n${msg} This package is REQUIRED and you need to install it or adjust CMake configuration in order to continue building ${CMAKE_PROJECT_NAME}.")
5614ab55 sago007 2016-01-17 13:44 259
    message(FATAL_ERROR "${msg}\n${vars}")
5614ab55 sago007 2016-01-17 13:44 260
  endif()
5614ab55 sago007 2016-01-17 13:44 261
  # Otherwise just print a nasty warning
5614ab55 sago007 2016-01-17 13:44 262
  if (NOT quiet)
5614ab55 sago007 2016-01-17 13:44 263
    message(WARNING "WARNING: MISSING PACKAGE\n${msg} This package is NOT REQUIRED and you may ignore this warning but by doing so you may miss some functionality of ${CMAKE_PROJECT_NAME}. \n${vars}")
5614ab55 sago007 2016-01-17 13:44 264
  endif()
5614ab55 sago007 2016-01-17 13:44 265
endfunction()
5614ab55 sago007 2016-01-17 13:44 266
5614ab55 sago007 2016-01-17 13:44 267
1970-01-01 00:00 268