From dfe9c95129b9ca05ea8ca98e69d973c9c40e5a4e Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 29 Aug 2010 17:07:39 +0200 Subject: Record all considered Config files and their versions. As suggested on cmake-devel, find_package in Config-mode now records all considered config-files and their versions in _CONSIDERED_CONFIGS and _CONSIDERED_VERSIONS respectively. Alex --- Source/cmFindPackageCommand.cxx | 76 +++++++++++++++++++++++++++++++++++------ Source/cmFindPackageCommand.h | 5 ++- 2 files changed, 70 insertions(+), 11 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index eb86014..b8dcb3d 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -156,6 +156,11 @@ cmFindPackageCommand::cmFindPackageCommand() "The full path to the configuration file is stored in the cmake " "variable _CONFIG." "\n" + "All configuration files which have been considered by CMake while " + "searching for an installation of the package with an appropriate " + "version are stored in the cmake variable _CONSIDERED_CONFIGS, " + "the associated versions in _CONSIDERED_VERSIONS. " + "\n" "If the package configuration file cannot be found CMake " "will generate an error describing the problem unless the QUIET " "argument is specified. If REQUIRED is specified and the package " @@ -618,7 +623,7 @@ void cmFindPackageCommand::SetModuleVariables(const std::string& components) // Store the list of components. std::string components_var = this->Name + "_FIND_COMPONENTS"; this->AddFindDefinition(components_var.c_str(), components.c_str()); - + if(this->Quiet) { // Tell the module that is about to be read that it should find @@ -721,6 +726,9 @@ bool cmFindPackageCommand::FindModule(bool& found) //---------------------------------------------------------------------------- bool cmFindPackageCommand::HandlePackageMode() { + this->ConsideredConfigFiles.clear(); + this->ConsideredVersions.clear(); + // Support old capitalization behavior. std::string upperDir = cmSystemTools::UpperCase(this->Name); std::string upperFound = cmSystemTools::UpperCase(this->Name); @@ -897,6 +905,35 @@ bool cmFindPackageCommand::HandlePackageMode() } #endif + std::string consideredConfigsVar = this->Name; + consideredConfigsVar += "_CONSIDERED_CONFIGS"; + std::string consideredVersionsVar = this->Name; + consideredVersionsVar += "_CONSIDERED_VERSIONS"; + + std::string consideredConfigFiles; + for(std::vector::const_iterator + it = this->ConsideredConfigFiles.begin(); + it != this->ConsideredConfigFiles.end(); ++it) + { + consideredConfigFiles += *it; + consideredConfigFiles += ";"; + } + + std::string consideredVersions; + for(std::vector::const_iterator + it = this->ConsideredVersions.begin(); + it != this->ConsideredVersions.end(); ++it) + { + consideredVersions += *it; + consideredVersions += ";"; + } + + this->Makefile->AddDefinition(consideredConfigsVar.c_str(), + consideredConfigFiles.c_str()); + + this->Makefile->AddDefinition(consideredVersionsVar.c_str(), + consideredVersions.c_str()); + return result; } @@ -1467,6 +1504,10 @@ bool cmFindPackageCommand::FindConfigFile(std::string const& dir, //---------------------------------------------------------------------------- bool cmFindPackageCommand::CheckVersion(std::string const& config_file) { + bool result = false; // by default, assume the version is not ok. + bool haveResult = false; + std::string version = "unknown"; + // Get the filename without the .cmake extension. std::string::size_type pos = config_file.rfind('.'); std::string version_file_base = config_file.substr(0, pos); @@ -1474,31 +1515,40 @@ bool cmFindPackageCommand::CheckVersion(std::string const& config_file) // Look for foo-config-version.cmake std::string version_file = version_file_base; version_file += "-version.cmake"; - if(cmSystemTools::FileExists(version_file.c_str(), true)) + if ((haveResult == false) + && (cmSystemTools::FileExists(version_file.c_str(), true))) { - return this->CheckVersionFile(version_file); + result = this->CheckVersionFile(version_file, version); + haveResult = true; } // Look for fooConfigVersion.cmake version_file = version_file_base; version_file += "Version.cmake"; - if(cmSystemTools::FileExists(version_file.c_str(), true)) + if ((haveResult == false) + && (cmSystemTools::FileExists(version_file.c_str(), true))) { - return this->CheckVersionFile(version_file); + result = this->CheckVersionFile(version_file, version); + haveResult = true; } + // If no version was requested a versionless package is acceptable. - if(this->Version.empty()) + if ((haveResult == false) && (this->Version.empty())) { - return true; + result = true; + haveResult = true; } - // No version file found. Assume the version is incompatible. - return false; + this->ConsideredConfigFiles.push_back(config_file); + this->ConsideredVersions.push_back(version); + + return result; } //---------------------------------------------------------------------------- -bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file) +bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file, + std::string& result_version) { // The version file will be loaded in an isolated scope. cmMakefile::ScopePushPop varScope(this->Makefile); @@ -1571,6 +1621,12 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file) } } + result_version = this->Makefile->GetSafeDefinition("PACKAGE_VERSION"); + if (result_version.empty()) + { + result_version = "unknown"; + } + // Succeed if the version is suitable. return suitable; } diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index 53ea4fc..2495d6c 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -98,7 +98,8 @@ private: bool CheckDirectory(std::string const& dir); bool FindConfigFile(std::string const& dir, std::string& file); bool CheckVersion(std::string const& config_file); - bool CheckVersionFile(std::string const& version_file); + bool CheckVersionFile(std::string const& version_file, + std::string& result_version); bool SearchPrefix(std::string const& prefix); bool SearchFrameworkPrefix(std::string const& prefix_in); bool SearchAppBundlePrefix(std::string const& prefix_in); @@ -137,6 +138,8 @@ private: std::vector Names; std::vector Configs; std::set IgnoredPaths; + std::vector ConsideredConfigFiles; + std::vector ConsideredVersions; }; #endif -- cgit v0.12 From 130b0e21958535a4f4f408cf7392fa9b3ee336fe Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 29 Aug 2010 17:43:45 +0200 Subject: Improve error message in Config-mode when no appropriate version was found If in config-mode config files have been found by find_package(), but their version didn't match the requested version, now all considered files and their versions are printed (instead of saying "didn't find config file) Alex --- Source/cmFindPackageCommand.cxx | 86 ++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index b8dcb3d..90fcf69 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -817,36 +817,56 @@ bool cmFindPackageCommand::HandlePackageMode() { // The variable is not set. cmOStringStream e; - e << "Could not find "; - if(!this->NoModule) - { - e << "module Find" << this->Name << ".cmake or "; - } - e << "a configuration file for package " << this->Name << ".\n"; - if(!this->NoModule) - { - e << "Adjust CMAKE_MODULE_PATH to find Find" - << this->Name << ".cmake or set "; - } - else - { - e << "Set "; - } - e << this->Variable << " to the directory containing a CMake " - << "configuration file for " << this->Name << ". "; - if(this->Configs.size() == 1) - { - e << "The file will be called " << this->Configs[0]; + // If there are files in ConsideredConfigs, it means that FooConfig.cmake + // have been found, but they didn't have appropriate versions. + if (this->ConsideredConfigFiles.size() > 0) + { + e << "Could not find configuration file for package " << this->Name + << " with " << (this->VersionExact ? "exact " : "at least ") + << "version " << this->Version << " .\n" + << "Found the following files:\n"; + for(std::vector::size_type i=0; + iConsideredConfigFiles.size(); i++) + { + e << " " << this->ConsideredConfigFiles[i] + << ", version: " << this->ConsideredVersions[i] << "\n"; + } } else { - e << "The file will have one of the following names:\n"; - for(std::vector::const_iterator ci = this->Configs.begin(); - ci != this->Configs.end(); ++ci) + e << "Could not find "; + if(!this->NoModule) + { + e << "module Find" << this->Name << ".cmake or "; + } + e << "a configuration file for package " << this->Name << ".\n"; + if(!this->NoModule) + { + e << "Adjust CMAKE_MODULE_PATH to find Find" + << this->Name << ".cmake or set "; + } + else + { + e << "Set "; + } + e << this->Variable << " to the directory containing a CMake " + << "configuration file for " << this->Name << ". "; + if(this->Configs.size() == 1) + { + e << "The file will be called " << this->Configs[0]; + } + else { - e << " " << *ci << "\n"; + e << "The file will have one of the following names:\n"; + for(std::vector::const_iterator ci=this->Configs.begin(); + ci != this->Configs.end(); ++ci) + { + e << " " << *ci << "\n"; + } } } + + this->Makefile->IssueMessage( this->Required? cmake::FATAL_ERROR : cmake::WARNING, e.str()); } @@ -911,20 +931,14 @@ bool cmFindPackageCommand::HandlePackageMode() consideredVersionsVar += "_CONSIDERED_VERSIONS"; std::string consideredConfigFiles; - for(std::vector::const_iterator - it = this->ConsideredConfigFiles.begin(); - it != this->ConsideredConfigFiles.end(); ++it) - { - consideredConfigFiles += *it; - consideredConfigFiles += ";"; - } - std::string consideredVersions; - for(std::vector::const_iterator - it = this->ConsideredVersions.begin(); - it != this->ConsideredVersions.end(); ++it) + + for(std::vector::size_type i=0; + iConsideredConfigFiles.size(); i++) { - consideredVersions += *it; + consideredConfigFiles += this->ConsideredConfigFiles[i]; + consideredConfigFiles += ";"; + consideredVersions += this->ConsideredVersions[i]; consideredVersions += ";"; } -- cgit v0.12 From 0367245f0c1a665d44b7169cc0f24eda5dbb4de3 Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 29 Aug 2010 17:51:44 +0200 Subject: Replace the two vector with one vector Before this patch there were two separate vectors, and the code made sure they always had the same size. With this patch the code doesn't have to ensure this anymore, there is only one vector now. Alex --- Source/cmFindPackageCommand.cxx | 27 ++++++++++++++------------- Source/cmFindPackageCommand.h | 5 +++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 90fcf69..48122a8 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -726,8 +726,7 @@ bool cmFindPackageCommand::FindModule(bool& found) //---------------------------------------------------------------------------- bool cmFindPackageCommand::HandlePackageMode() { - this->ConsideredConfigFiles.clear(); - this->ConsideredVersions.clear(); + this->ConsideredConfigs.clear(); // Support old capitalization behavior. std::string upperDir = cmSystemTools::UpperCase(this->Name); @@ -819,17 +818,17 @@ bool cmFindPackageCommand::HandlePackageMode() cmOStringStream e; // If there are files in ConsideredConfigs, it means that FooConfig.cmake // have been found, but they didn't have appropriate versions. - if (this->ConsideredConfigFiles.size() > 0) + if (this->ConsideredConfigs.size() > 0) { e << "Could not find configuration file for package " << this->Name << " with " << (this->VersionExact ? "exact " : "at least ") << "version " << this->Version << " .\n" << "Found the following files:\n"; - for(std::vector::size_type i=0; - iConsideredConfigFiles.size(); i++) + for(std::vector::size_type i=0; + iConsideredConfigs.size(); i++) { - e << " " << this->ConsideredConfigFiles[i] - << ", version: " << this->ConsideredVersions[i] << "\n"; + e << " " << this->ConsideredConfigs[i].filename + << ", version: " << this->ConsideredConfigs[i].version << "\n"; } } else @@ -933,12 +932,12 @@ bool cmFindPackageCommand::HandlePackageMode() std::string consideredConfigFiles; std::string consideredVersions; - for(std::vector::size_type i=0; - iConsideredConfigFiles.size(); i++) + for(std::vector::size_type i=0; + iConsideredConfigs.size(); i++) { - consideredConfigFiles += this->ConsideredConfigFiles[i]; + consideredConfigFiles += this->ConsideredConfigs[i].filename; consideredConfigFiles += ";"; - consideredVersions += this->ConsideredVersions[i]; + consideredVersions += this->ConsideredConfigs[i].version; consideredVersions += ";"; } @@ -1554,8 +1553,10 @@ bool cmFindPackageCommand::CheckVersion(std::string const& config_file) haveResult = true; } - this->ConsideredConfigFiles.push_back(config_file); - this->ConsideredVersions.push_back(version); + ConfigFileInfo configFileInfo; + configFileInfo.filename = config_file; + configFileInfo.version = version; + this->ConsideredConfigs.push_back(configFileInfo); return result; } diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index 2495d6c..57aeab9 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -138,8 +138,9 @@ private: std::vector Names; std::vector Configs; std::set IgnoredPaths; - std::vector ConsideredConfigFiles; - std::vector ConsideredVersions; + + struct ConfigFileInfo { std::string filename; std::string version; }; + std::vector ConsideredConfigs; }; #endif -- cgit v0.12 From cc955a042b582a12238cc94507bf50dd9bce1220 Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 29 Aug 2010 18:55:25 +0200 Subject: Small cleanup of FindPackageHandleStandardArgs.cmake -remove unnecessary arguments _VAR1 -move code for deciding the type of the message into helper macro _FPHSA_FAILURE_MESSAGE() Alex --- Modules/FindPackageHandleStandardArgs.cmake | 38 +++++++++++++---------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake index c698480..db3af11 100644 --- a/Modules/FindPackageHandleStandardArgs.cmake +++ b/Modules/FindPackageHandleStandardArgs.cmake @@ -71,7 +71,18 @@ INCLUDE(FindPackageMessage) INCLUDE(CMakeParseArguments) -FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG _VAR1) +MACRO(_FPHSA_FAILURE_MESSAGE _msg) + IF (${_NAME}_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "${_msg}") + ELSE (${_NAME}_FIND_REQUIRED) + IF (NOT ${_NAME}_FIND_QUIETLY) + MESSAGE(STATUS "${_msg}") + ENDIF (NOT ${_NAME}_FIND_QUIETLY) + ENDIF (${_NAME}_FIND_REQUIRED) +ENDMACRO(_FPHSA_FAILURE_MESSAGE _msg) + + +FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) # set up the arguments for CMAKE_PARSE_ARGUMENTS and check whether we are in # new extended or in the "old" mode: @@ -83,11 +94,11 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG _VAR1) IF(${INDEX} EQUAL -1) SET(FPHSA_FAIL_MESSAGE ${_FIRST_ARG}) - SET(FPHSA_REQUIRED_VARS ${_VAR1} ${ARGN}) + SET(FPHSA_REQUIRED_VARS ${ARGN}) SET(FPHSA_VERSION_VAR) ELSE(${INDEX} EQUAL -1) - CMAKE_PARSE_ARGUMENTS(FPHSA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${_VAR1} ${ARGN}) + CMAKE_PARSE_ARGUMENTS(FPHSA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN}) IF(FPHSA_UNPARSED_ARGUMENTS) MESSAGE(FATAL_ERROR "Unknown keywords given to FIND_PACKAGE_HANDLE_STANDARD_ARGS(): \"${FPHSA_UNPARSED_ARGUMENTS}\"") @@ -112,7 +123,7 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG _VAR1) STRING(TOUPPER ${_NAME} _NAME_UPPER) - # collect all variables which were not found, so they can be printed, so the + # collect all variables which were not found, so they can be printed, so the # user knows better what went wrong (#6375) SET(MISSING_VARS "") SET(DETAILS "") @@ -183,24 +194,9 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG _VAR1) FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG}" "${DETAILS}") ELSE (${_NAME_UPPER}_FOUND) IF(NOT VERSION_OK) - - IF (${_NAME}_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})") - ELSE (${_NAME}_FIND_REQUIRED) - IF (NOT ${_NAME}_FIND_QUIETLY) - MESSAGE(STATUS "${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})") - ENDIF (NOT ${_NAME}_FIND_QUIETLY) - ENDIF (${_NAME}_FIND_REQUIRED) - + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})") ELSE(NOT VERSION_OK) - - IF (${_NAME}_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "${FPHSA_FAIL_MESSAGE} (missing: ${MISSING_VARS}) ${VERSION_MSG}") - ELSE (${_NAME}_FIND_REQUIRED) - IF (NOT ${_NAME}_FIND_QUIETLY) - MESSAGE(STATUS "${FPHSA_FAIL_MESSAGE} (missing: ${MISSING_VARS}) ${VERSION_MSG}") - ENDIF (NOT ${_NAME}_FIND_QUIETLY) - ENDIF (${_NAME}_FIND_REQUIRED) + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} (missing: ${MISSING_VARS}) ${VERSION_MSG}") ENDIF(NOT VERSION_OK) ENDIF (${_NAME_UPPER}_FOUND) -- cgit v0.12 From b4b8f963917b9473be283d5b844faee4a018945d Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 29 Aug 2010 19:50:51 +0200 Subject: Don't create an empty element at the end of Foo_CONSIDERED_CONFIGS/VERSIONS Alex --- Source/cmFindPackageCommand.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 48122a8..8ee8fc7 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -935,10 +935,13 @@ bool cmFindPackageCommand::HandlePackageMode() for(std::vector::size_type i=0; iConsideredConfigs.size(); i++) { + if (i>0) + { + consideredConfigFiles += ";"; + consideredVersions += ";"; + } consideredConfigFiles += this->ConsideredConfigs[i].filename; - consideredConfigFiles += ";"; consideredVersions += this->ConsideredConfigs[i].version; - consideredVersions += ";"; } this->Makefile->AddDefinition(consideredConfigsVar.c_str(), -- cgit v0.12 From e8ae504c0e13a641660ae78a05d5a5184f352800 Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 29 Aug 2010 19:53:43 +0200 Subject: Add option CONFIG_MODE to FPHSA() When this option is used for FPHSA(), it automatically handles the information created by a preceding find_package(NO_MODULE) all and creates a proper success/error message. Alex --- Modules/FindPackageHandleStandardArgs.cmake | 64 +++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake index db3af11..a83f601 100644 --- a/Modules/FindPackageHandleStandardArgs.cmake +++ b/Modules/FindPackageHandleStandardArgs.cmake @@ -20,18 +20,24 @@ # The second mode is more powerful and also supports version checking: # FIND_PACKAGE_HANDLE_STANDARD_ARGS(NAME [REQUIRED_VARS ...] # [VERSION_VAR +# [CONFIG_MODE] # [FAIL_MESSAGE "Custom failure message"] ) # # As above, if through are all valid, _FOUND # will be set to TRUE. -# Via FAIL_MESSAGE a custom failure message can be specified, if this is not -# used, the default message will be displayed. +# After REQUIRED_VARS the variables which are required for this package are listed. # Following VERSION_VAR the name of the variable can be specified which holds # the version of the package which has been found. If this is done, this version # will be checked against the (potentially) specified required version used # in the find_package() call. The EXACT keyword is also handled. The default # messages include information about the required version and the version # which has been actually found, both if the version is ok or not. +# Use the option CONFIG_MODE if your FindXXX.cmake module is a wrapper for +# a find_package(... NO_MODULE) call, in this case all the information +# provided by the config-mode of find_package() will be evaluated +# automatically. +# Via FAIL_MESSAGE a custom failure message can be specified, if this is not +# used, the default message will be displayed. # # Example for mode 1: # @@ -53,6 +59,15 @@ # Also the version of BISON will be checked by using the version contained # in BISON_VERSION. # Since no FAIL_MESSAGE is given, the default messages will be printed. +# +# Another example for mode 2: +# +# FIND_PACKAGE(Automoc4 QUIET NO_MODULE HINTS /opt/automoc4) +# FIND_PACKAGE_HANDLE_STANDARD_ARGS(Automoc4 CONFIG_MODE) +# In this case, FindAutmoc4.cmake wraps a call to FIND_PACKAGE(Automoc4 NO_MODULE) +# and adds an additional search directory for automoc4. +# The following FIND_PACKAGE_HANDLE_STANDARD_ARGS() call produces a proper +# success/error message. #============================================================================= # Copyright 2007-2009 Kitware, Inc. @@ -70,7 +85,7 @@ INCLUDE(FindPackageMessage) INCLUDE(CMakeParseArguments) - +# internal helper macro MACRO(_FPHSA_FAILURE_MESSAGE _msg) IF (${_NAME}_FIND_REQUIRED) MESSAGE(FATAL_ERROR "${_msg}") @@ -86,7 +101,7 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) # set up the arguments for CMAKE_PARSE_ARGUMENTS and check whether we are in # new extended or in the "old" mode: - SET(options) # none + SET(options CONFIG_MODE) SET(oneValueArgs FAIL_MESSAGE VERSION_VAR) SET(multiValueArgs REQUIRED_VARS) SET(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} ) @@ -115,6 +130,12 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) SET(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}") ENDIF("${FPHSA_FAIL_MESSAGE}" STREQUAL "DEFAULT_MSG") + IF(FPHSA_CONFIG_MODE) + LIST(INSERT FPHSA_REQUIRED_VARS 0 ${_NAME}_CONFIG) + LIST(REMOVE_DUPLICATES FPHSA_REQUIRED_VARS) + SET(FPHSA_VERSION_VAR ${_NAME}_VERSION) + ENDIF(FPHSA_CONFIG_MODE) + IF(NOT FPHSA_REQUIRED_VARS) MESSAGE(FATAL_ERROR "No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()") ENDIF(NOT FPHSA_REQUIRED_VARS) @@ -122,6 +143,7 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) LIST(GET FPHSA_REQUIRED_VARS 0 _FIRST_REQUIRED_VAR) STRING(TOUPPER ${_NAME} _NAME_UPPER) + STRING(TOLOWER ${_NAME} _NAME_LOWER) # collect all variables which were not found, so they can be printed, so the # user knows better what went wrong (#6375) @@ -193,11 +215,35 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) IF (${_NAME_UPPER}_FOUND) FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG}" "${DETAILS}") ELSE (${_NAME_UPPER}_FOUND) - IF(NOT VERSION_OK) - _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})") - ELSE(NOT VERSION_OK) - _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} (missing: ${MISSING_VARS}) ${VERSION_MSG}") - ENDIF(NOT VERSION_OK) + + IF(FPHSA_CONFIG_MODE) + IF(${_NAME}_CONFIG) + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: found ${${_NAME}_CONFIG} ${VERSION_MSG}, but missing: ${MISSING_VARS}") + ELSE(${_NAME}_CONFIG) + # if _CONSIDERED_CONFIGS is set, the config-file has been found, but no suitable version + IF(${_NAME}_CONSIDERED_CONFIGS) + SET(configsText "") + LIST(LENGTH ${_NAME}_CONSIDERED_CONFIGS configsCount) + MATH(EXPR configsCount "${configsCount} - 1") + FOREACH(currentConfigIndex RANGE ${configsCount}) + LIST(GET ${_NAME}_CONSIDERED_CONFIGS ${currentConfigIndex} filename) + LIST(GET ${_NAME}_CONSIDERED_VERSIONS ${currentConfigIndex} version) + SET(configsText "${configsText} ${filename} (version ${version})\n") + ENDFOREACH(currentConfigIndex) + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} ${VERSION_MSG}, checked the following files:\n${configsText}") + + ELSE(${_NAME}_CONSIDERED_CONFIGS) + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG}(found neither ${_NAME}Config.cmake nor ${_NAME_LOWER}-config.cmake)") + ENDIF(${_NAME}_CONSIDERED_CONFIGS) + ENDIF(${_NAME}_CONFIG) + + ELSE(FPHSA_CONFIG_MODE) + IF(NOT VERSION_OK) + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})") + ELSE(NOT VERSION_OK) + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} (missing: ${MISSING_VARS}) ${VERSION_MSG}") + ENDIF(NOT VERSION_OK) + ENDIF(FPHSA_CONFIG_MODE) ENDIF (${_NAME_UPPER}_FOUND) -- cgit v0.12 From 4969c3b5bbf929d3f59e98c90849a85aadb7351a Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Mon, 30 Aug 2010 22:42:58 +0200 Subject: Improve version notice in the generated message Now the version number is also printed if no required version was specified, but a version number was detected (showing more information shouldn't hurt). The code for generating the failure message in config-mode is moved into a separate helper macro, it was becoming too much. Alex --- Modules/FindPackageHandleStandardArgs.cmake | 114 +++++++++++++++------------- 1 file changed, 61 insertions(+), 53 deletions(-) diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake index a83f601..cd33aa3 100644 --- a/Modules/FindPackageHandleStandardArgs.cmake +++ b/Modules/FindPackageHandleStandardArgs.cmake @@ -97,6 +97,33 @@ MACRO(_FPHSA_FAILURE_MESSAGE _msg) ENDMACRO(_FPHSA_FAILURE_MESSAGE _msg) +# internal helper macro to generate the failure message when used in CONFIG_MODE: +MACRO(_FPHSA_HANDLE_FAILURE_CONFIG_MODE) + # _CONFIG is set, but FOUND is false, this means that some other of the REQUIRED_VARS was not found: + IF(${_NAME}_CONFIG) + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: missing: ${MISSING_VARS} (found ${${_NAME}_CONFIG} ${VERSION_MSG})") + ELSE(${_NAME}_CONFIG) + # If _CONSIDERED_CONFIGS is set, the config-file has been found, but no suitable version. + # List them all in the error message: + IF(${_NAME}_CONSIDERED_CONFIGS) + SET(configsText "") + LIST(LENGTH ${_NAME}_CONSIDERED_CONFIGS configsCount) + MATH(EXPR configsCount "${configsCount} - 1") + FOREACH(currentConfigIndex RANGE ${configsCount}) + LIST(GET ${_NAME}_CONSIDERED_CONFIGS ${currentConfigIndex} filename) + LIST(GET ${_NAME}_CONSIDERED_VERSIONS ${currentConfigIndex} version) + SET(configsText "${configsText} ${filename} (version ${version})\n") + ENDFOREACH(currentConfigIndex) + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} ${VERSION_MSG}, checked the following files:\n${configsText}") + + ELSE(${_NAME}_CONSIDERED_CONFIGS) + # Simple case: No Config-file was found at all: + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: found neither ${_NAME}Config.cmake nor ${_NAME_LOWER}-config.cmake ${VERSION_MSG}") + ENDIF(${_NAME}_CONSIDERED_CONFIGS) + ENDIF(${_NAME}_CONFIG) +ENDMACRO(_FPHSA_HANDLE_FAILURE_CONFIG_MODE) + + FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) # set up the arguments for CMAKE_PARSE_ARGUMENTS and check whether we are in @@ -130,6 +157,8 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) SET(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}") ENDIF("${FPHSA_FAIL_MESSAGE}" STREQUAL "DEFAULT_MSG") + # In config-mode, we rely on the variable _CONFIG, which is set by find_package() + # when it successfully found the config-file, including version checking: IF(FPHSA_CONFIG_MODE) LIST(INSERT FPHSA_REQUIRED_VARS 0 ${_NAME}_CONFIG) LIST(REMOVE_DUPLICATES FPHSA_REQUIRED_VARS) @@ -164,44 +193,42 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) # version handling: SET(VERSION_MSG "") SET(VERSION_OK TRUE) + SET(VERSION ${${FPHSA_VERSION_VAR}} ) IF (${_NAME}_FIND_VERSION) - # if the package was found, check for the version using _FIND_VERSION - IF (${_NAME_UPPER}_FOUND) - SET(VERSION ${${FPHSA_VERSION_VAR}} ) - - IF(VERSION) - - IF(${_NAME}_FIND_VERSION_EXACT) # exact version required - IF (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}") - SET(VERSION_MSG " Found version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"") - SET(VERSION_OK FALSE) - ELSE (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}") - SET(VERSION_MSG " (found exact version \"${VERSION}\")") - ENDIF (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}") - - ELSE(${_NAME}_FIND_VERSION_EXACT) # minimum version specified: - IF ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}") - SET(VERSION_MSG " Found version \"${VERSION}\", but required is at least \"${${_NAME}_FIND_VERSION}\"") - SET(VERSION_OK FALSE) - ELSE ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}") - SET(VERSION_MSG " (found version \"${VERSION}\", required is \"${${_NAME}_FIND_VERSION}\")") - ENDIF ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}") - ENDIF(${_NAME}_FIND_VERSION_EXACT) - -# Uncomment the following two lines to see to which Find-modules the VERSION_VAR keywords still need to be added: -# ELSE(VERSION) -# SET(VERSION_MSG " (WARNING: Required version is \"${${_NAME}_FIND_VERSION}\", but version of ${_NAME} is unknown)") - ENDIF(VERSION) - - # if the package was not found, but a version was given, add that to the output: - ELSE (${_NAME_UPPER}_FOUND) + IF(VERSION) + + IF(${_NAME}_FIND_VERSION_EXACT) # exact version required + IF (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}") + SET(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"") + SET(VERSION_OK FALSE) + ELSE (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}") + SET(VERSION_MSG "(found suitable exact version \"${VERSION}\")") + ENDIF (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}") + + ELSE(${_NAME}_FIND_VERSION_EXACT) # minimum version specified: + IF ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}") + SET(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is at least \"${${_NAME}_FIND_VERSION}\"") + SET(VERSION_OK FALSE) + ELSE ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}") + SET(VERSION_MSG "(found suitable version \"${VERSION}\", required is \"${${_NAME}_FIND_VERSION}\")") + ENDIF ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}") + ENDIF(${_NAME}_FIND_VERSION_EXACT) + + ELSE(VERSION) + + # if the package was not found, but a version was given, add that to the output: IF(${_NAME}_FIND_VERSION_EXACT) - SET(VERSION_MSG " (Required is exact version \"${${_NAME}_FIND_VERSION}\")") + SET(VERSION_MSG "(Required is exact version \"${${_NAME}_FIND_VERSION}\")") ELSE(${_NAME}_FIND_VERSION_EXACT) - SET(VERSION_MSG " (Required is at least version \"${${_NAME}_FIND_VERSION}\")") + SET(VERSION_MSG "(Required is at least version \"${${_NAME}_FIND_VERSION}\")") ENDIF(${_NAME}_FIND_VERSION_EXACT) - ENDIF (${_NAME_UPPER}_FOUND) + + ENDIF(VERSION) + ELSE (${_NAME}_FIND_VERSION) + IF(VERSION) + SET(VERSION_MSG "(found version \"${VERSION}\")") + ENDIF(VERSION) ENDIF (${_NAME}_FIND_VERSION) IF(VERSION_OK) @@ -217,26 +244,7 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) ELSE (${_NAME_UPPER}_FOUND) IF(FPHSA_CONFIG_MODE) - IF(${_NAME}_CONFIG) - _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: found ${${_NAME}_CONFIG} ${VERSION_MSG}, but missing: ${MISSING_VARS}") - ELSE(${_NAME}_CONFIG) - # if _CONSIDERED_CONFIGS is set, the config-file has been found, but no suitable version - IF(${_NAME}_CONSIDERED_CONFIGS) - SET(configsText "") - LIST(LENGTH ${_NAME}_CONSIDERED_CONFIGS configsCount) - MATH(EXPR configsCount "${configsCount} - 1") - FOREACH(currentConfigIndex RANGE ${configsCount}) - LIST(GET ${_NAME}_CONSIDERED_CONFIGS ${currentConfigIndex} filename) - LIST(GET ${_NAME}_CONSIDERED_VERSIONS ${currentConfigIndex} version) - SET(configsText "${configsText} ${filename} (version ${version})\n") - ENDFOREACH(currentConfigIndex) - _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} ${VERSION_MSG}, checked the following files:\n${configsText}") - - ELSE(${_NAME}_CONSIDERED_CONFIGS) - _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG}(found neither ${_NAME}Config.cmake nor ${_NAME_LOWER}-config.cmake)") - ENDIF(${_NAME}_CONSIDERED_CONFIGS) - ENDIF(${_NAME}_CONFIG) - + _FPHSA_HANDLE_FAILURE_CONFIG_MODE() ELSE(FPHSA_CONFIG_MODE) IF(NOT VERSION_OK) _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})") -- cgit v0.12 From 5cdfc9c8ea675658c14d21848917f0e2d9ab93da Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Tue, 31 Aug 2010 21:10:00 +0200 Subject: Improve wording of the error message of find_package() in config-mode As suggested by Brad, this improves the wording of the error message in config-mode when config-files were found, but no suitable version. The patch also contains the small loop-optimization suggested by Brad. Alex --- Source/cmFindPackageCommand.cxx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 8ee8fc7..55c7cb9 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -820,10 +820,12 @@ bool cmFindPackageCommand::HandlePackageMode() // have been found, but they didn't have appropriate versions. if (this->ConsideredConfigs.size() > 0) { - e << "Could not find configuration file for package " << this->Name - << " with " << (this->VersionExact ? "exact " : "at least ") - << "version " << this->Version << " .\n" - << "Found the following files:\n"; + e << "Could not find a configuration file for package \"" + << this->Name << "\" that " + << (this->VersionExact? "exactly matches" : "is compatible with") + << " requested version \"" << this->Version << "\".\n" + << "The following configuration files were considered but not " + "accepted:\n"; for(std::vector::size_type i=0; iConsideredConfigs.size(); i++) { @@ -932,16 +934,15 @@ bool cmFindPackageCommand::HandlePackageMode() std::string consideredConfigFiles; std::string consideredVersions; + const char* sep = ""; for(std::vector::size_type i=0; iConsideredConfigs.size(); i++) { - if (i>0) - { - consideredConfigFiles += ";"; - consideredVersions += ";"; - } + consideredConfigFiles += sep; + consideredVersions += sep; consideredConfigFiles += this->ConsideredConfigs[i].filename; consideredVersions += this->ConsideredConfigs[i].version; + sep = ";"; } this->Makefile->AddDefinition(consideredConfigsVar.c_str(), -- cgit v0.12