mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-17 07:11:52 +08:00
cmTarget: Extract GetSources method
This commit is contained in:
@@ -1043,6 +1043,8 @@ private:
|
||||
static const char* ComputeLocationForBuild(cmTarget const* tgt);
|
||||
static const char* ComputeLocation(cmTarget const* tgt,
|
||||
std::string const& config);
|
||||
|
||||
static const char* GetSources(cmTarget const* tgt, cmMakefile* context);
|
||||
};
|
||||
|
||||
bool cmTargetPropertyComputer::HandleLocationPropertyPolicy(
|
||||
@@ -1112,6 +1114,95 @@ const char* cmTargetPropertyComputer::ComputeLocation(
|
||||
return loc.c_str();
|
||||
}
|
||||
|
||||
const char* cmTargetPropertyComputer::GetSources(cmTarget const* tgt,
|
||||
cmMakefile* context)
|
||||
{
|
||||
cmStringRange entries = tgt->GetSourceEntries();
|
||||
|
||||
if (entries.empty()) {
|
||||
return CM_NULLPTR;
|
||||
}
|
||||
|
||||
std::ostringstream ss;
|
||||
const char* sep = "";
|
||||
for (std::vector<std::string>::const_iterator i = entries.begin();
|
||||
i != entries.end(); ++i) {
|
||||
std::string const& entry = *i;
|
||||
|
||||
std::vector<std::string> files;
|
||||
cmSystemTools::ExpandListArgument(entry, files);
|
||||
for (std::vector<std::string>::const_iterator li = files.begin();
|
||||
li != files.end(); ++li) {
|
||||
if (cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
|
||||
(*li)[li->size() - 1] == '>') {
|
||||
std::string objLibName = li->substr(17, li->size() - 18);
|
||||
|
||||
if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
|
||||
ss << sep;
|
||||
sep = ";";
|
||||
ss << *li;
|
||||
continue;
|
||||
}
|
||||
|
||||
bool addContent = false;
|
||||
bool noMessage = true;
|
||||
std::ostringstream e;
|
||||
cmake::MessageType messageType = cmake::AUTHOR_WARNING;
|
||||
switch (context->GetPolicyStatus(cmPolicies::CMP0051)) {
|
||||
case cmPolicies::WARN:
|
||||
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
|
||||
noMessage = false;
|
||||
case cmPolicies::OLD:
|
||||
break;
|
||||
case cmPolicies::REQUIRED_ALWAYS:
|
||||
case cmPolicies::REQUIRED_IF_USED:
|
||||
case cmPolicies::NEW:
|
||||
addContent = true;
|
||||
}
|
||||
if (!noMessage) {
|
||||
e << "Target \"" << tgt->GetName()
|
||||
<< "\" contains "
|
||||
"$<TARGET_OBJECTS> generator expression in its sources "
|
||||
"list. "
|
||||
"This content was not previously part of the SOURCES "
|
||||
"property "
|
||||
"when that property was read at configure time. Code "
|
||||
"reading "
|
||||
"that property needs to be adapted to ignore the generator "
|
||||
"expression using the string(GENEX_STRIP) command.";
|
||||
context->IssueMessage(messageType, e.str());
|
||||
}
|
||||
if (addContent) {
|
||||
ss << sep;
|
||||
sep = ";";
|
||||
ss << *li;
|
||||
}
|
||||
} else if (cmGeneratorExpression::Find(*li) == std::string::npos) {
|
||||
ss << sep;
|
||||
sep = ";";
|
||||
ss << *li;
|
||||
} else {
|
||||
cmSourceFile* sf = tgt->GetMakefile()->GetOrCreateSource(*li);
|
||||
// Construct what is known about this source file location.
|
||||
cmSourceFileLocation const& location = sf->GetLocation();
|
||||
std::string sname = location.GetDirectory();
|
||||
if (!sname.empty()) {
|
||||
sname += "/";
|
||||
}
|
||||
sname += location.GetName();
|
||||
|
||||
ss << sep;
|
||||
sep = ";";
|
||||
// Append this list entry.
|
||||
ss << sname;
|
||||
}
|
||||
}
|
||||
}
|
||||
static std::string srcs;
|
||||
srcs = ss.str();
|
||||
return srcs.c_str();
|
||||
}
|
||||
|
||||
const char* cmTargetPropertyComputer::GetProperty(cmTarget const* tgt,
|
||||
const std::string& prop,
|
||||
cmMakefile* context)
|
||||
@@ -1156,89 +1247,7 @@ const char* cmTargetPropertyComputer::GetProperty(cmTarget const* tgt,
|
||||
}
|
||||
}
|
||||
if (prop == "SOURCES") {
|
||||
cmStringRange entries = tgt->GetSourceEntries();
|
||||
if (entries.empty()) {
|
||||
return CM_NULLPTR;
|
||||
}
|
||||
|
||||
std::ostringstream ss;
|
||||
const char* sep = "";
|
||||
for (std::vector<std::string>::const_iterator i = entries.begin();
|
||||
i != entries.end(); ++i) {
|
||||
std::string const& entry = *i;
|
||||
|
||||
std::vector<std::string> files;
|
||||
cmSystemTools::ExpandListArgument(entry, files);
|
||||
for (std::vector<std::string>::const_iterator li = files.begin();
|
||||
li != files.end(); ++li) {
|
||||
if (cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
|
||||
(*li)[li->size() - 1] == '>') {
|
||||
std::string objLibName = li->substr(17, li->size() - 18);
|
||||
|
||||
if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
|
||||
ss << sep;
|
||||
sep = ";";
|
||||
ss << *li;
|
||||
continue;
|
||||
}
|
||||
|
||||
bool addContent = false;
|
||||
bool noMessage = true;
|
||||
std::ostringstream e;
|
||||
cmake::MessageType messageType = cmake::AUTHOR_WARNING;
|
||||
switch (context->GetPolicyStatus(cmPolicies::CMP0051)) {
|
||||
case cmPolicies::WARN:
|
||||
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
|
||||
noMessage = false;
|
||||
case cmPolicies::OLD:
|
||||
break;
|
||||
case cmPolicies::REQUIRED_ALWAYS:
|
||||
case cmPolicies::REQUIRED_IF_USED:
|
||||
case cmPolicies::NEW:
|
||||
addContent = true;
|
||||
}
|
||||
if (!noMessage) {
|
||||
e << "Target \"" << tgt->GetName()
|
||||
<< "\" contains "
|
||||
"$<TARGET_OBJECTS> generator expression in its sources "
|
||||
"list. "
|
||||
"This content was not previously part of the SOURCES "
|
||||
"property "
|
||||
"when that property was read at configure time. Code "
|
||||
"reading "
|
||||
"that property needs to be adapted to ignore the generator "
|
||||
"expression using the string(GENEX_STRIP) command.";
|
||||
context->IssueMessage(messageType, e.str());
|
||||
}
|
||||
if (addContent) {
|
||||
ss << sep;
|
||||
sep = ";";
|
||||
ss << *li;
|
||||
}
|
||||
} else if (cmGeneratorExpression::Find(*li) == std::string::npos) {
|
||||
ss << sep;
|
||||
sep = ";";
|
||||
ss << *li;
|
||||
} else {
|
||||
cmSourceFile* sf = tgt->GetMakefile()->GetOrCreateSource(*li);
|
||||
// Construct what is known about this source file location.
|
||||
cmSourceFileLocation const& location = sf->GetLocation();
|
||||
std::string sname = location.GetDirectory();
|
||||
if (!sname.empty()) {
|
||||
sname += "/";
|
||||
}
|
||||
sname += location.GetName();
|
||||
|
||||
ss << sep;
|
||||
sep = ";";
|
||||
// Append this list entry.
|
||||
ss << sname;
|
||||
}
|
||||
}
|
||||
}
|
||||
static std::string srcs;
|
||||
srcs = ss.str();
|
||||
return srcs.c_str();
|
||||
return GetSources(tgt, context);
|
||||
}
|
||||
return CM_NULLPTR;
|
||||
}
|
||||
|
Reference in New Issue
Block a user