ENH: Added FindPackageMessage module

- Defines FIND_PACKAGE_MESSAGE function to help display
    find result messages only once
  - Added use of it to FindPackageHandleStandardArgs
  - Added use of it to FindQt4, and FindX11
  - This cleans up repeated messages in big projects
This commit is contained in:
Brad King 2008-03-17 11:10:42 -04:00
parent 98e06794dd
commit 7a888b68da
4 changed files with 50 additions and 7 deletions

View File

@ -17,6 +17,7 @@
# be "Could NOT find LibXml2", if you don't like this message you can specify
# your own custom failure message there.
INCLUDE(FindPackageMessage)
FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FAIL_MSG _VAR1 )
IF("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
@ -27,22 +28,25 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FAIL_MSG _VAR1 )
STRING(TOUPPER ${_NAME} _NAME_UPPER)
SET(DETAILS "")
SET(${_NAME_UPPER}_FOUND TRUE)
IF(NOT ${_VAR1})
SET(${_NAME_UPPER}_FOUND FALSE)
ELSE(NOT ${_VAR1})
SET(DETAILS "${DETAILS}[${${_VAR1}}]")
ENDIF(NOT ${_VAR1})
# check if all passed variables are valid
FOREACH(_CURRENT_VAR ${ARGN})
IF(NOT ${_CURRENT_VAR})
SET(${_NAME_UPPER}_FOUND FALSE)
ELSE(NOT ${_CURRENT_VAR})
SET(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]")
ENDIF(NOT ${_CURRENT_VAR})
ENDFOREACH(_CURRENT_VAR)
IF (${_NAME_UPPER}_FOUND)
IF (NOT ${_NAME}_FIND_QUIETLY)
MESSAGE(STATUS "Found ${_NAME}: ${${_VAR1}}")
ENDIF (NOT ${_NAME}_FIND_QUIETLY)
FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_VAR1}}" "${DETAILS}")
ELSE (${_NAME_UPPER}_FOUND)
IF (${_NAME}_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "${_FAIL_MESSAGE}")

View File

@ -0,0 +1,35 @@
# FIND_PACKAGE_MESSAGE(<name> "message for user" "find result details")
#
# This macro is intended to be used in FindXXX.cmake modules files.
# It will print a message once for each unique find result.
# This is useful for telling the user where a package was found.
# The first argument specifies the name (XXX) of the package.
# The second argument specifies the message to display.
# The third argument lists details about the find result so that
# if they change the message will be displayed again.
# The macro also obeys the QUIET argument to the find_package command.
#
# Example:
#
# IF(X11_FOUND)
# FIND_PACKAGE_MESSAGE(X11 "Found X11: ${X11_X11_LIB}"
# "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]")
# ELSE(X11_FOUND)
# ...
# ENDIF(X11_FOUND)
FUNCTION(FIND_PACKAGE_MESSAGE pkg msg details)
# Avoid printing a message repeatedly for the same find result.
IF(NOT ${pkg}_FIND_QUIETLY)
SET(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg})
IF(NOT "${details}" STREQUAL "${${DETAILS_VAR}}")
# The message has not yet been printed.
MESSAGE(STATUS "${msg}")
# Save the find details in the cache to avoid printing the same
# message again.
SET("${DETAILS_VAR}" "${details}"
CACHE INTERNAL "Details about finding ${pkg}")
ENDIF(NOT "${details}" STREQUAL "${${DETAILS_VAR}}")
ENDIF(NOT ${pkg}_FIND_QUIETLY)
ENDFUNCTION(FIND_PACKAGE_MESSAGE)

View File

@ -1232,9 +1232,9 @@ IF (QT4_QMAKE_FOUND)
# if the includes,libraries,moc,uic and rcc are found then we have it
IF( QT_LIBRARY_DIR AND QT_INCLUDE_DIR AND QT_MOC_EXECUTABLE AND QT_UIC_EXECUTABLE AND QT_RCC_EXECUTABLE)
SET( QT4_FOUND "YES" )
IF( NOT Qt4_FIND_QUIETLY)
MESSAGE(STATUS "Found Qt-Version ${QTVERSION}")
ENDIF( NOT Qt4_FIND_QUIETLY)
INCLUDE(FindPackageMessage)
FIND_PACKAGE_MESSAGE(Qt4 "Found Qt-Version ${QTVERSION}"
"[${QT_LIBRARY_DIR}][${QT_INCLUDE_DIR}][${QT_MOC_EXECUTABLE}][${QT_UIC_EXECUTABLE}][${QT_RCC_EXECUTABLE}]")
ELSE( QT_LIBRARY_DIR AND QT_INCLUDE_DIR AND QT_MOC_EXECUTABLE AND QT_UIC_EXECUTABLE AND QT_RCC_EXECUTABLE)
SET( QT4_FOUND "NO")
SET(QT_QMAKE_EXECUTABLE "${QT_QMAKE_EXECUTABLE}-NOTFOUND" CACHE FILEPATH "Invalid qmake found" FORCE)

View File

@ -127,6 +127,7 @@ IF (UNIX)
GET_FILENAME_COMPONENT(X11_LIBRARY_DIR ${X11_X11_LIB} PATH)
ENDIF(X11_X11_LIB)
SET(X11_INCLUDE_DIR) # start with empty list
IF(X11_X11_INCLUDE_PATH)
SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_X11_INCLUDE_PATH})
ENDIF(X11_X11_INCLUDE_PATH)
@ -145,6 +146,7 @@ IF (UNIX)
SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xshape_INCLUDE_PATH})
ENDIF(X11_Xshape_INCLUDE_PATH)
SET(X11_LIBRARIES) # start with empty list
IF(X11_X11_LIB)
SET(X11_LIBRARIES ${X11_LIBRARIES} ${X11_X11_LIB})
ENDIF(X11_X11_LIB)
@ -354,7 +356,9 @@ IF (UNIX)
# Build the final list of libraries.
SET(X11_LIBRARIES ${X11_X_PRE_LIBS} ${X11_LIBRARIES} ${X11_X_EXTRA_LIBS})
MESSAGE(STATUS "Found X11: ${X11_X11_LIB}")
INCLUDE(FindPackageMessage)
FIND_PACKAGE_MESSAGE(X11 "Found X11: ${X11_X11_LIB}"
"[${X11_X11_LIB}][${X11_INCLUDE_DIR}]")
ELSE (X11_FOUND)
IF (X11_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find X11")