PageRenderTime 111ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 35ms app.codeStats 1ms

/CMakeModules/MacroLogFeature.cmake

http://github.com/tomahawk-player/tomahawk
CMake | 157 lines | 90 code | 35 blank | 32 comment | 0 complexity | 5678c8fe8cd97688cf9d37bee2b3a545 MD5 | raw file
  1# This file defines the Feature Logging macros.
  2#
  3# MACRO_LOG_FEATURE(VAR FEATURE DESCRIPTION URL [REQUIRED [MIN_VERSION [COMMENTS]]])
  4#   Logs the information so that it can be displayed at the end
  5#   of the configure run
  6#   VAR : TRUE or FALSE, indicating whether the feature is supported
  7#   FEATURE: name of the feature, e.g. "libjpeg"
  8#   DESCRIPTION: description what this feature provides
  9#   URL: home page
 10#   REQUIRED: TRUE or FALSE, indicating whether the featue is required
 11#   MIN_VERSION: minimum version number. empty string if unneeded
 12#   COMMENTS: More info you may want to provide.  empty string if unnecessary
 13#
 14# MACRO_DISPLAY_FEATURE_LOG()
 15#   Call this to display the collected results.
 16#   Exits CMake with a FATAL error message if a required feature is missing
 17#
 18# Example:
 19#
 20# INCLUDE(MacroLogFeature)
 21#
 22# FIND_PACKAGE(JPEG)
 23# MACRO_LOG_FEATURE(JPEG_FOUND "libjpeg" "Support JPEG images" "http://www.ijg.org" TRUE "3.2a" "")
 24# ...
 25# MACRO_DISPLAY_FEATURE_LOG()
 26
 27# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
 28# Copyright (c) 2006, Allen Winter, <winter@kde.org>
 29# Copyright (c) 2009, Sebastian Trueg, <trueg@kde.org>
 30#
 31# Redistribution and use is allowed according to the terms of the BSD license.
 32# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
 33
 34IF (NOT _macroLogFeatureAlreadyIncluded)
 35   SET(_file ${CMAKE_BINARY_DIR}/MissingRequirements.txt)
 36   IF (EXISTS ${_file})
 37      FILE(REMOVE ${_file})
 38   ENDIF (EXISTS ${_file})
 39
 40   SET(_file ${CMAKE_BINARY_DIR}/EnabledFeatures.txt)
 41   IF (EXISTS ${_file})
 42      FILE(REMOVE ${_file})
 43   ENDIF (EXISTS ${_file})
 44
 45   SET(_file ${CMAKE_BINARY_DIR}/DisabledFeatures.txt)
 46   IF (EXISTS ${_file})
 47      FILE(REMOVE ${_file})
 48  ENDIF (EXISTS ${_file})
 49
 50  SET(_macroLogFeatureAlreadyIncluded TRUE)
 51
 52  INCLUDE(FeatureSummary)
 53
 54ENDIF (NOT _macroLogFeatureAlreadyIncluded)
 55
 56
 57MACRO(MACRO_LOG_FEATURE _var _package _description _url ) # _required _minvers _comments)
 58
 59   STRING(TOUPPER "${ARGV4}" _required)
 60   SET(_minvers "${ARGV5}")
 61   SET(_comments "${ARGV6}")
 62
 63   IF (${_var})
 64     SET(_LOGFILENAME ${CMAKE_BINARY_DIR}/EnabledFeatures.txt)
 65   ELSE (${_var})
 66     IF ("${_required}" STREQUAL "TRUE")
 67       SET(_LOGFILENAME ${CMAKE_BINARY_DIR}/MissingRequirements.txt)
 68     ELSE ("${_required}" STREQUAL "TRUE")
 69       SET(_LOGFILENAME ${CMAKE_BINARY_DIR}/DisabledFeatures.txt)
 70     ENDIF ("${_required}" STREQUAL "TRUE")
 71   ENDIF (${_var})
 72
 73   SET(_logtext "   * ${_package}")
 74
 75   IF (NOT ${_var})
 76      IF (${_minvers} MATCHES ".*")
 77        SET(_logtext "${_logtext} (${_minvers} or higher)")
 78      ENDIF (${_minvers} MATCHES ".*")
 79      SET(_logtext "${_logtext}  <${_url}>\n     ")
 80   ELSE (NOT ${_var})
 81     SET(_logtext "${_logtext} - ")
 82   ENDIF (NOT ${_var})
 83
 84   SET(_logtext "${_logtext}${_description}")
 85
 86   IF (NOT ${_var})
 87      IF (${_comments} MATCHES ".*")
 88        SET(_logtext "${_logtext}\n     ${_comments}")
 89      ENDIF (${_comments} MATCHES ".*")
 90#      SET(_logtext "${_logtext}\n") #double-space missing features?
 91   ENDIF (NOT ${_var})
 92
 93   FILE(APPEND "${_LOGFILENAME}" "${_logtext}\n")
 94
 95   IF(COMMAND SET_PACKAGE_INFO)  # in FeatureSummary.cmake since CMake 2.8.3
 96     SET_PACKAGE_PROPERTIES("${_package}" PROPERTIES DESCRIPTION "\"${_description}\"" URL "${_url}" PURPOSE "\"${_comments}\"")
 97   ENDIF(COMMAND SET_PACKAGE_INFO)
 98
 99ENDMACRO(MACRO_LOG_FEATURE)
100
101
102MACRO(MACRO_DISPLAY_FEATURE_LOG)
103   IF(COMMAND FEATURE_SUMMARY) # in FeatureSummary.cmake since CMake 2.8.3
104      FEATURE_SUMMARY(FILENAME ${CMAKE_CURRENT_BINARY_DIR}/FindPackageLog.txt
105                      WHAT ALL)
106   ENDIF(COMMAND FEATURE_SUMMARY)
107
108   SET(_missingFile ${CMAKE_BINARY_DIR}/MissingRequirements.txt)
109   SET(_enabledFile ${CMAKE_BINARY_DIR}/EnabledFeatures.txt)
110   SET(_disabledFile ${CMAKE_BINARY_DIR}/DisabledFeatures.txt)
111
112   IF (EXISTS ${_missingFile} OR EXISTS ${_enabledFile} OR EXISTS ${_disabledFile})
113     SET(_printSummary TRUE)
114   ENDIF (EXISTS ${_missingFile} OR EXISTS ${_enabledFile} OR EXISTS ${_disabledFile})
115
116   IF(_printSummary)
117     SET(_missingDeps 0)
118     IF (EXISTS ${_enabledFile})
119       FILE(READ ${_enabledFile} _enabled)
120       FILE(REMOVE ${_enabledFile})
121       SET(_summary "${_summary}\n-----------------------------------------------------------------------------\n-- The following external packages were located on your system.\n-- This installation will have the extra features provided by these packages.\n-----------------------------------------------------------------------------\n${_enabled}")
122     ENDIF (EXISTS ${_enabledFile})
123
124
125     IF (EXISTS ${_disabledFile})
126       SET(_missingDeps 1)
127       FILE(READ ${_disabledFile} _disabled)
128       FILE(REMOVE ${_disabledFile})
129       SET(_summary "${_summary}\n-----------------------------------------------------------------------------\n-- The following OPTIONAL packages could NOT be located on your system.\n-- Consider installing them to enable more features from this software.\n-----------------------------------------------------------------------------\n${_disabled}")
130     ENDIF (EXISTS ${_disabledFile})
131
132
133     IF (EXISTS ${_missingFile})
134       SET(_missingDeps 1)
135       FILE(READ ${_missingFile} _requirements)
136       SET(_summary "${_summary}\n-----------------------------------------------------------------------------\n-- The following REQUIRED packages could NOT be located on your system.\n-- You must install these packages before continuing.\n-----------------------------------------------------------------------------\n${_requirements}")
137       FILE(REMOVE ${_missingFile})
138       SET(_haveMissingReq 1)
139     ENDIF (EXISTS ${_missingFile})
140
141
142     IF (NOT ${_missingDeps})
143       SET(_summary "${_summary}\n-----------------------------------------------------------------------------\n-- Congratulations! All external packages have been found.")
144     ENDIF (NOT ${_missingDeps})
145
146
147     MESSAGE(${_summary})
148     MESSAGE("-----------------------------------------------------------------------------\n")
149
150
151     IF(_haveMissingReq)
152       MESSAGE(FATAL_ERROR "Exiting: Missing Requirements")
153     ENDIF(_haveMissingReq)
154
155   ENDIF(_printSummary)
156
157ENDMACRO(MACRO_DISPLAY_FEATURE_LOG)