ENH: add global properties for collecting enabled/disabled features during

the cmake run and add macros print_enabled/disabled_features() and
set_feature_info(), so projects can get a nice overview at the end of the
cmake run what has been found and what hasn't
FIND_PACKAGE() automatically adds the packages to these global properties,
except when used with QUIET
Maybe this can also be useful for packagers to find out dependencies of
projects.

Alex
This commit is contained in:
Alexander Neundorf 2007-08-07 15:41:57 -04:00
parent f6d8942ac8
commit 8d7b502337
3 changed files with 158 additions and 0 deletions

View File

@ -0,0 +1,64 @@
# - Macros for generating a summary of enabled/disabled features
#
# PRINT_ENABLED_FEATURES()
# Print a summary of all enabled features. By default all successfull
# FIND_PACKAGE() calls will appear here, except the ones which used the QUIET keyword.
# Additional features can be added by appending an entry to the global ENABLED_FEATURES
# property. If SET_FEATURE_INFO() is used for that feature, the output will be much
# more informative.
#
# PRINT_DISABLED_FEATURES()
# Same as PRINT_ENABLED_FEATURES(), but for disabled features. It can be extended
# the same way by adding to the global property DISABLED_FEATURES.
#
# SET_FEATURE_INFO(NAME DESCRIPTION [URL [COMMENT] ] )
# Use this macro to set up information about the named feature, which will
# then be displayed by PRINT_ENABLED/DISABLED_FEATURES().
# Example: SET_FEATURE_INFO(LibXml2 "XML processing library." "http://xmlsoft.org/")
#
MACRO(SET_FEATURE_INFO _name _desc)
SET(_url "${ARGV2}")
SET(_comment "${ARGV3}")
SET_PROPERTIES(GLOBAL PROPERTIES ${_name}_DESCRIPTION "${_desc}" )
IF(_url MATCHES ".+")
SET_PROPERTIES(GLOBAL PROPERTIES ${_name}_URL "${_url}" )
ENDIF(_url MATCHES ".+")
IF(_comment MATCHES ".+")
SET_PROPERTIES(GLOBAL PROPERTIES ${_name}_COMMENT "${_comment}" )
ENDIF(_comment MATCHES ".+")
ENDMACRO(SET_FEATURE_INFO)
MACRO(_PRINT_FEATURES _property _text)
SET(_currentFeatureText "${_text}")
GET_PROPERTY(_EnabledFeatures GLOBAL ${_property})
FOREACH(_currentFeature ${_EnabledFeatures})
SET(_currentFeatureText "${_currentFeatureText}\n${_currentFeature}")
GET_PROPERTY(_info GLOBAL ${_currentFeature}_DESCRIPTION)
IF(_info)
SET(_currentFeatureText "${_currentFeatureText} , ${_info}")
ENDIF(_info)
GET_PROPERTY(_info GLOBAL ${_currentFeature}_URL)
IF(_info)
SET(_currentFeatureText "${_currentFeatureText} , <${_info}>")
ENDIF(_info)
GET_PROPERTY(_info GLOBAL ${_currentFeature}_COMMENT)
IF(_info)
SET(_currentFeatureText "${_currentFeatureText} , ${_info}")
ENDIF(_info)
ENDFOREACH(_currentFeature)
MESSAGE(STATUS "${_currentFeatureText}\n")
ENDMACRO(_PRINT_FEATURES)
MACRO(PRINT_ENABLED_FEATURES)
_PRINT_FEATURES( ENABLED_FEATURES "Enabled features:")
ENDMACRO(PRINT_ENABLED_FEATURES)
MACRO(PRINT_DISABLED_FEATURES)
_PRINT_FEATURES( DISABLED_FEATURES "Disabled features:")
ENDMACRO(PRINT_DISABLED_FEATURES)

View File

@ -124,10 +124,12 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
bool foundModule = false; bool foundModule = false;
if(!this->FindModule(foundModule, quiet, required)) if(!this->FindModule(foundModule, quiet, required))
{ {
this->AppendSuccessInformation(quiet);
return false; return false;
} }
if(foundModule) if(foundModule)
{ {
this->AppendSuccessInformation(quiet);
return true; return true;
} }
} }
@ -172,6 +174,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
{ {
if(!this->FindConfig()) if(!this->FindConfig())
{ {
this->AppendSuccessInformation(quiet);
return false; return false;
} }
} }
@ -272,6 +275,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
} }
#endif #endif
this->AppendSuccessInformation(quiet);
return result; return result;
} }
@ -435,3 +439,67 @@ bool cmFindPackageCommand::ReadListFile(const char* f)
this->SetError(e.c_str()); this->SetError(e.c_str());
return false; return false;
} }
//----------------------------------------------------------------------------
void cmFindPackageCommand::AppendToProperty(const char* propertyName)
{
std::string propertyValue;
const char *prop =
this->Makefile->GetCMakeInstance()->GetProperty(propertyName);
if (prop && *prop)
{
propertyValue = prop;
std::vector<std::string> contents;
cmSystemTools::ExpandListArgument(propertyValue, contents, false);
bool alreadyInserted = false;
for(std::vector<std::string>::const_iterator it = contents.begin();
it != contents.end(); ++ it )
{
if (*it == this->Name)
{
alreadyInserted = true;
break;
}
}
if (!alreadyInserted)
{
propertyValue += ";";
propertyValue += this->Name;
}
}
else
{
propertyValue = this->Name;
}
this->Makefile->GetCMakeInstance()->SetProperty(propertyName,
propertyValue.c_str());
}
//----------------------------------------------------------------------------
void cmFindPackageCommand::AppendSuccessInformation(bool quiet)
{
std::string found = this->Name;
found += "_FOUND";
std::string upperFound = cmSystemTools::UpperCase(found);
const char* upperResult = this->Makefile->GetDefinition(upperFound.c_str());
const char* result = this->Makefile->GetDefinition(found.c_str());
if ((cmSystemTools::IsOn(result)) || (cmSystemTools::IsOn(upperResult)))
{
this->AppendToProperty("PACKAGES_FOUND");
if (!quiet)
{
this->AppendToProperty("ENABLED_FEATURES");
}
}
else
{
this->AppendToProperty("PACKAGES_NOT_FOUND");
if (!quiet)
{
this->AppendToProperty("DISABLED_FEATURES");
}
}
}

View File

@ -3044,6 +3044,32 @@ void cmake::DefineProperties(cmake *cm)
"FIND_LIBRARY command should automatically search the lib64 variant of " "FIND_LIBRARY command should automatically search the lib64 variant of "
"directories called lib in the search path when building 64-bit " "directories called lib in the search path when building 64-bit "
"binaries."); "binaries.");
cm->DefineProperty
("ENABLED_FEATURES", cmProperty::GLOBAL,
"List of features which are enabled during the CMake run.",
"List of features which are enabled during the CMake run. Be default "
"it contains the names of all packages which were found. This is "
"determined using the <NAME>_FOUND variables. Packages which are "
"searched QUIET are not listed. A project can add its own features to "
"this list.This property is used by the macros in FeatureSummary.cmake.");
cm->DefineProperty
("DISABLED_FEATURES", cmProperty::GLOBAL,
"List of features which are disabled during the CMake run.",
"List of features which are disabled during the CMake run. Be default "
"it contains the names of all packages which were not found. This is "
"determined using the <NAME>_FOUND variables. Packages which are "
"searched QUIET are not listed. A project can add its own features to "
"this list.This property is used by the macros in FeatureSummary.cmake.");
cm->DefineProperty
("PACKAGES_FOUND", cmProperty::GLOBAL,
"List of packages which were found during the CMake run.",
"List of packages which were found during the CMake run. Whether a "
"package has been found is determined using the <NAME>_FOUND variables.");
cm->DefineProperty
("PACKAGES_NOT_FOUND", cmProperty::GLOBAL,
"List of packages which were not found during the CMake run.",
"List of packages which were not found during the CMake run. Whether a "
"package has been found is determined using the <NAME>_FOUND variables.");
} }