From d0f950fdba88ac08d0e25e340fe558eba008810e Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 23 Dec 2012 11:20:37 +0100 Subject: [PATCH] Use mapped config properties to evaluate $ --- Source/cmGeneratorExpressionEvaluator.cxx | 20 +- Source/cmTarget.cxx | 236 ++++++++++++---------- Source/cmTarget.h | 5 + 3 files changed, 147 insertions(+), 114 deletions(-) diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index 4a7a034c0..8b8b86084 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -265,8 +265,24 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode return parameters.front().empty() ? "1" : "0"; } - return cmsysString_strcasecmp(parameters.begin()->c_str(), - context->Config) == 0 ? "1" : "0"; + if (cmsysString_strcasecmp(parameters.begin()->c_str(), + context->Config) == 0) + { + return "1"; + } + + if (context->CurrentTarget + && context->CurrentTarget->IsImported()) + { + const char* loc = 0; + const char* imp = 0; + std::string suffix; + return context->CurrentTarget->GetMappedConfig(context->Config, + &loc, + &imp, + suffix) ? "1" : "0"; + } + return "0"; } } configurationTestNode; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 58fab80cc..d60979c0a 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -4365,6 +4365,128 @@ cmTarget::GetImportInfo(const char* config) return &i->second; } +bool cmTarget::GetMappedConfig(std::string const& desired_config, + const char** loc, + const char** imp, + std::string& suffix) +{ + // Track the configuration-specific property suffix. + suffix = "_"; + suffix += desired_config; + + std::vector mappedConfigs; + { + std::string mapProp = "MAP_IMPORTED_CONFIG_"; + mapProp += desired_config; + if(const char* mapValue = this->GetProperty(mapProp.c_str())) + { + cmSystemTools::ExpandListArgument(mapValue, mappedConfigs); + } + } + + // If we needed to find one of the mapped configurations but did not + // On a DLL platform there may be only IMPORTED_IMPLIB for a shared + // library or an executable with exports. + bool allowImp = this->HasImportLibrary(); + + // If a mapping was found, check its configurations. + for(std::vector::const_iterator mci = mappedConfigs.begin(); + !*loc && !*imp && mci != mappedConfigs.end(); ++mci) + { + // Look for this configuration. + std::string mcUpper = cmSystemTools::UpperCase(mci->c_str()); + std::string locProp = "IMPORTED_LOCATION_"; + locProp += mcUpper; + *loc = this->GetProperty(locProp.c_str()); + if(allowImp) + { + std::string impProp = "IMPORTED_IMPLIB_"; + impProp += mcUpper; + *imp = this->GetProperty(impProp.c_str()); + } + + // If it was found, use it for all properties below. + if(*loc || *imp) + { + suffix = "_"; + suffix += mcUpper; + } + } + + // If we needed to find one of the mapped configurations but did not + // then the target is not found. The project does not want any + // other configuration. + if(!mappedConfigs.empty() && !*loc && !*imp) + { + return false; + } + + // If we have not yet found it then there are no mapped + // configurations. Look for an exact-match. + if(!*loc && !*imp) + { + std::string locProp = "IMPORTED_LOCATION"; + locProp += suffix; + *loc = this->GetProperty(locProp.c_str()); + if(allowImp) + { + std::string impProp = "IMPORTED_IMPLIB"; + impProp += suffix; + *imp = this->GetProperty(impProp.c_str()); + } + } + + // If we have not yet found it then there are no mapped + // configurations and no exact match. + if(!*loc && !*imp) + { + // The suffix computed above is not useful. + suffix = ""; + + // Look for a configuration-less location. This may be set by + // manually-written code. + *loc = this->GetProperty("IMPORTED_LOCATION"); + if(allowImp) + { + *imp = this->GetProperty("IMPORTED_IMPLIB"); + } + } + + // If we have not yet found it then the project is willing to try + // any available configuration. + if(!*loc && !*imp) + { + std::vector availableConfigs; + if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS")) + { + cmSystemTools::ExpandListArgument(iconfigs, availableConfigs); + } + for(std::vector::const_iterator + aci = availableConfigs.begin(); + !*loc && !*imp && aci != availableConfigs.end(); ++aci) + { + suffix = "_"; + suffix += cmSystemTools::UpperCase(*aci); + std::string locProp = "IMPORTED_LOCATION"; + locProp += suffix; + *loc = this->GetProperty(locProp.c_str()); + if(allowImp) + { + std::string impProp = "IMPORTED_IMPLIB"; + impProp += suffix; + *imp = this->GetProperty(impProp.c_str()); + } + } + } + // If we have not yet found it then the target is not available. + if(!*loc && !*imp) + { + return false; + } + + return true; +} + //---------------------------------------------------------------------------- void cmTarget::ComputeImportInfo(std::string const& desired_config, ImportInfo& info) @@ -4376,120 +4498,10 @@ void cmTarget::ComputeImportInfo(std::string const& desired_config, // Initialize members. info.NoSOName = false; - // Track the configuration-specific property suffix. - std::string suffix = "_"; - suffix += desired_config; - - // On a DLL platform there may be only IMPORTED_IMPLIB for a shared - // library or an executable with exports. - bool allowImp = this->HasImportLibrary(); - - // Look for a mapping from the current project's configuration to - // the imported project's configuration. - std::vector mappedConfigs; - { - std::string mapProp = "MAP_IMPORTED_CONFIG_"; - mapProp += desired_config; - if(const char* mapValue = this->GetProperty(mapProp.c_str())) - { - cmSystemTools::ExpandListArgument(mapValue, mappedConfigs); - } - } - - // If a mapping was found, check its configurations. const char* loc = 0; const char* imp = 0; - for(std::vector::const_iterator mci = mappedConfigs.begin(); - !loc && !imp && mci != mappedConfigs.end(); ++mci) - { - // Look for this configuration. - std::string mcUpper = cmSystemTools::UpperCase(mci->c_str()); - std::string locProp = "IMPORTED_LOCATION_"; - locProp += mcUpper; - loc = this->GetProperty(locProp.c_str()); - if(allowImp) - { - std::string impProp = "IMPORTED_IMPLIB_"; - impProp += mcUpper; - imp = this->GetProperty(impProp.c_str()); - } - - // If it was found, use it for all properties below. - if(loc || imp) - { - suffix = "_"; - suffix += mcUpper; - } - } - - // If we needed to find one of the mapped configurations but did not - // then the target is not found. The project does not want any - // other configuration. - if(!mappedConfigs.empty() && !loc && !imp) - { - return; - } - - // If we have not yet found it then there are no mapped - // configurations. Look for an exact-match. - if(!loc && !imp) - { - std::string locProp = "IMPORTED_LOCATION"; - locProp += suffix; - loc = this->GetProperty(locProp.c_str()); - if(allowImp) - { - std::string impProp = "IMPORTED_IMPLIB"; - impProp += suffix; - imp = this->GetProperty(impProp.c_str()); - } - } - - // If we have not yet found it then there are no mapped - // configurations and no exact match. - if(!loc && !imp) - { - // The suffix computed above is not useful. - suffix = ""; - - // Look for a configuration-less location. This may be set by - // manually-written code. - loc = this->GetProperty("IMPORTED_LOCATION"); - if(allowImp) - { - imp = this->GetProperty("IMPORTED_IMPLIB"); - } - } - - // If we have not yet found it then the project is willing to try - // any available configuration. - if(!loc && !imp) - { - std::vector availableConfigs; - if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS")) - { - cmSystemTools::ExpandListArgument(iconfigs, availableConfigs); - } - for(std::vector::const_iterator - aci = availableConfigs.begin(); - !loc && !imp && aci != availableConfigs.end(); ++aci) - { - suffix = "_"; - suffix += cmSystemTools::UpperCase(*aci); - std::string locProp = "IMPORTED_LOCATION"; - locProp += suffix; - loc = this->GetProperty(locProp.c_str()); - if(allowImp) - { - std::string impProp = "IMPORTED_IMPLIB"; - impProp += suffix; - imp = this->GetProperty(impProp.c_str()); - } - } - } - - // If we have not yet found it then the target is not available. - if(!loc && !imp) + std::string suffix; + if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix)) { return; } diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 3f3605043..52d5ca611 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -404,6 +404,11 @@ public: // Get the properties cmPropertyMap &GetProperties() { return this->Properties; }; + bool GetMappedConfig(std::string const& desired_config, + const char** loc, + const char** imp, + std::string& suffix); + // Define the properties static void DefineProperties(cmake *cm);