mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
Merge topic 'cps-fix-imported-configs'
eb51e55dcd
cmPackageInfoReader: Fix IMPORTED_CONFIGURATIONSc6a6d47233
find_package: CPS targets use CMP0200 Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !11120
This commit is contained in:
@@ -2107,7 +2107,10 @@ bool cmFindPackageCommand::ReadPackage()
|
|||||||
bool const hasComponentsRequested =
|
bool const hasComponentsRequested =
|
||||||
!this->RequiredComponents.empty() || !this->OptionalComponents.empty();
|
!this->RequiredComponents.empty() || !this->OptionalComponents.empty();
|
||||||
|
|
||||||
cmMakefile::CallRAII scope{ this->Makefile, this->FileFound, this->Status };
|
cmMakefile::CallRAII cs{ this->Makefile, this->FileFound, this->Status };
|
||||||
|
cmMakefile::PolicyPushPop ps{ this->Makefile };
|
||||||
|
|
||||||
|
this->Makefile->SetPolicy(cmPolicies::CMP0200, cmPolicies::NEW);
|
||||||
|
|
||||||
// Loop over appendices.
|
// Loop over appendices.
|
||||||
auto iter = this->CpsAppendices.begin();
|
auto iter = this->CpsAppendices.begin();
|
||||||
|
@@ -2,11 +2,13 @@
|
|||||||
file LICENSE.rst or https://cmake.org/licensing for details. */
|
file LICENSE.rst or https://cmake.org/licensing for details. */
|
||||||
#include "cmPackageInfoReader.h"
|
#include "cmPackageInfoReader.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include <cmext/algorithm>
|
||||||
#include <cmext/string_view>
|
#include <cmext/string_view>
|
||||||
|
|
||||||
#include <cm3p/json/reader.h>
|
#include <cm3p/json/reader.h>
|
||||||
@@ -17,12 +19,14 @@
|
|||||||
#include "cmsys/RegularExpression.hxx"
|
#include "cmsys/RegularExpression.hxx"
|
||||||
|
|
||||||
#include "cmExecutionStatus.h"
|
#include "cmExecutionStatus.h"
|
||||||
|
#include "cmList.h"
|
||||||
#include "cmListFileCache.h"
|
#include "cmListFileCache.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
#include "cmMessageType.h"
|
#include "cmMessageType.h"
|
||||||
#include "cmStringAlgorithms.h"
|
#include "cmStringAlgorithms.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
#include "cmTarget.h"
|
#include "cmTarget.h"
|
||||||
|
#include "cmValue.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@@ -572,6 +576,49 @@ std::string cmPackageInfoReader::ResolvePath(std::string path) const
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmPackageInfoReader::AddTargetConfiguration(
|
||||||
|
cmTarget* target, cm::string_view configuration) const
|
||||||
|
{
|
||||||
|
static std::string const icProp = "IMPORTED_CONFIGURATIONS";
|
||||||
|
|
||||||
|
std::string const& configUpper = cmSystemTools::UpperCase(configuration);
|
||||||
|
|
||||||
|
// Get existing list of imported configurations.
|
||||||
|
cmList configs;
|
||||||
|
if (cmValue v = target->GetProperty(icProp)) {
|
||||||
|
configs.assign(cmSystemTools::UpperCase(*v));
|
||||||
|
} else {
|
||||||
|
// If the existing list is empty, just add the new one and return.
|
||||||
|
target->SetProperty(icProp, configUpper);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cm::contains(configs, configUpper)) {
|
||||||
|
// If the configuration is already listed, we don't need to do anything.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the new configuration.
|
||||||
|
configs.append(configUpper);
|
||||||
|
|
||||||
|
// Rebuild the configuration list by extracting any configuration in the
|
||||||
|
// default configurations and reinserting it at the beginning of the list
|
||||||
|
// according to the order of the default configurations.
|
||||||
|
std::vector<std::string> newConfigs;
|
||||||
|
for (std::string const& c : this->DefaultConfigurations) {
|
||||||
|
auto ci = std::find(configs.begin(), configs.end(), c);
|
||||||
|
if (ci != configs.end()) {
|
||||||
|
newConfigs.emplace_back(std::move(*ci));
|
||||||
|
configs.erase(ci);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (std::string& c : configs) {
|
||||||
|
newConfigs.emplace_back(std::move(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
target->SetProperty("IMPORTED_CONFIGURATIONS", cmJoin(newConfigs, ";"_s));
|
||||||
|
}
|
||||||
|
|
||||||
void cmPackageInfoReader::SetImportProperty(cmTarget* target,
|
void cmPackageInfoReader::SetImportProperty(cmTarget* target,
|
||||||
cm::string_view property,
|
cm::string_view property,
|
||||||
cm::string_view configuration,
|
cm::string_view configuration,
|
||||||
@@ -607,9 +654,7 @@ void cmPackageInfoReader::SetTargetProperties(
|
|||||||
{
|
{
|
||||||
// Add configuration (if applicable).
|
// Add configuration (if applicable).
|
||||||
if (!configuration.empty()) {
|
if (!configuration.empty()) {
|
||||||
target->AppendProperty("IMPORTED_CONFIGURATIONS",
|
this->AddTargetConfiguration(target, configuration);
|
||||||
cmSystemTools::UpperCase(configuration),
|
|
||||||
makefile->GetBacktrace());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add compile and link features.
|
// Add compile and link features.
|
||||||
@@ -694,12 +739,6 @@ cmTarget* cmPackageInfoReader::AddLibraryComponent(
|
|||||||
cmTarget* const target = makefile->AddImportedTarget(name, type, false);
|
cmTarget* const target = makefile->AddImportedTarget(name, type, false);
|
||||||
target->SetOrigin(cmTarget::Origin::Cps);
|
target->SetOrigin(cmTarget::Origin::Cps);
|
||||||
|
|
||||||
// Set default configurations.
|
|
||||||
if (!this->DefaultConfigurations.empty()) {
|
|
||||||
target->SetProperty("IMPORTED_CONFIGURATIONS",
|
|
||||||
cmJoin(this->DefaultConfigurations, ";"_s));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set target properties.
|
// Set target properties.
|
||||||
this->SetTargetProperties(makefile, target, data, package, {});
|
this->SetTargetProperties(makefile, target, data, package, {});
|
||||||
auto const& cfgData = data["configurations"];
|
auto const& cfgData = data["configurations"];
|
||||||
|
@@ -91,6 +91,9 @@ private:
|
|||||||
Json::Value const& data,
|
Json::Value const& data,
|
||||||
std::string const& package) const;
|
std::string const& package) const;
|
||||||
|
|
||||||
|
void AddTargetConfiguration(cmTarget* target,
|
||||||
|
cm::string_view configuration) const;
|
||||||
|
|
||||||
void SetTargetProperties(cmMakefile* makefile, cmTarget* target,
|
void SetTargetProperties(cmMakefile* makefile, cmTarget* target,
|
||||||
Json::Value const& data, std::string const& package,
|
Json::Value const& data, std::string const& package,
|
||||||
cm::string_view configuration) const;
|
cm::string_view configuration) const;
|
||||||
|
@@ -314,13 +314,21 @@ endif()
|
|||||||
find_package(DefaultConfigurationsTest)
|
find_package(DefaultConfigurationsTest)
|
||||||
if(NOT DefaultConfigurationsTest_FOUND)
|
if(NOT DefaultConfigurationsTest_FOUND)
|
||||||
message(SEND_ERROR "DefaultConfigurationsTest not found !")
|
message(SEND_ERROR "DefaultConfigurationsTest not found !")
|
||||||
elseif(NOT TARGET DefaultConfigurationsTest::Target)
|
elseif(NOT TARGET DefaultConfigurationsTest::Target1)
|
||||||
message(SEND_ERROR "DefaultConfigurationsTest::Target missing !")
|
message(SEND_ERROR "DefaultConfigurationsTest::Target1 missing !")
|
||||||
|
elseif(NOT TARGET DefaultConfigurationsTest::Target2)
|
||||||
|
message(SEND_ERROR "DefaultConfigurationsTest::Target2 missing !")
|
||||||
else()
|
else()
|
||||||
get_property(dct_configs
|
get_property(dct1_configs
|
||||||
TARGET DefaultConfigurationsTest::Target PROPERTY IMPORTED_CONFIGURATIONS)
|
TARGET DefaultConfigurationsTest::Target1 PROPERTY IMPORTED_CONFIGURATIONS)
|
||||||
if(NOT "${dct_configs}" STREQUAL "DEFAULT;TEST")
|
if(NOT "${dct1_configs}" STREQUAL "DEFAULT;TEST")
|
||||||
message(SEND_ERROR "DefaultConfigurationsTest::Target has wrong configurations '${dct_configs}' !")
|
message(SEND_ERROR "DefaultConfigurationsTest::Target1 has wrong configurations '${dct1_configs}' !")
|
||||||
endif()
|
endif()
|
||||||
set(dct_configs)
|
get_property(dct2_configs
|
||||||
|
TARGET DefaultConfigurationsTest::Target2 PROPERTY IMPORTED_CONFIGURATIONS)
|
||||||
|
if(NOT "${dct2_configs}" STREQUAL "TEST")
|
||||||
|
message(SEND_ERROR "DefaultConfigurationsTest::Target2 has wrong configurations '${dct2_configs}' !")
|
||||||
|
endif()
|
||||||
|
set(dct1_configs)
|
||||||
|
set(dct2_configs)
|
||||||
endif()
|
endif()
|
||||||
|
@@ -4,7 +4,15 @@
|
|||||||
"cps_path": "@prefix@/cps",
|
"cps_path": "@prefix@/cps",
|
||||||
"configurations": [ "Default" ],
|
"configurations": [ "Default" ],
|
||||||
"components": {
|
"components": {
|
||||||
"Target": {
|
"Target1": {
|
||||||
|
"type": "interface",
|
||||||
|
"configurations": {
|
||||||
|
"Test": {
|
||||||
|
"includes": [ "@prefix@/include" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Target2": {
|
||||||
"type": "interface",
|
"type": "interface",
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"Test": {
|
"Test": {
|
||||||
|
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"cps_version": "0.13",
|
||||||
|
"name": "DefaultConfigurationsTest",
|
||||||
|
"configuration": "Default",
|
||||||
|
"components": {
|
||||||
|
"Target1": {
|
||||||
|
"includes": [ "@prefix@/include" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user