summaryrefslogtreecommitdiffstats
path: root/Source/cmSourceFile.cxx
diff options
context:
space:
mode:
authorDeniz Bahadir <dbahadir@benocs.com>2020-11-09 00:06:51 (GMT)
committerDeniz Bahadir <dbahadir@benocs.com>2020-11-24 17:16:51 (GMT)
commit6624b65b3f478574512a23a7220abff4ed590011 (patch)
tree41a239c43b3a223ea8f27beac5b12d299d39c62c /Source/cmSourceFile.cxx
parentb14fe704f8fad5785f10f0d56c5b49a8e0e0e94c (diff)
downloadCMake-6624b65b3f478574512a23a7220abff4ed590011.zip
CMake-6624b65b3f478574512a23a7220abff4ed590011.tar.gz
CMake-6624b65b3f478574512a23a7220abff4ed590011.tar.bz2
GENERATED prop: Add implementation for policy CMP0118 being set to NEW
* Adding implementation for policy CMP0118 being set to `NEW`. * Adding new tests for policy CMP0118 being set to `NEW`. * Checking the `GENERATED` property with `get_source_file_property` or `get_property` now always returns exactly `1` or `0`. No other values will be returned. Note, that this is a backwards-incompatible change, even when policy CMP0118 is unset or set to `OLD`. * Additionally, as `get_source_file_property` and `get_property` now always check if a source-file was marked globally visible, even when CMP0118 is unset or set to `OLD`, they possibly return `1` where they might have returned `0` before the changes introduced by this commit. Note, that this is a backwards-incompatible change, even when policy CMP0118 is unset or set to `OLD`. * As a consequence, the tests for policy CMP0118 being unset or set to `OLD` got slightly adjusted, too, to reflect these changes in behavior.
Diffstat (limited to 'Source/cmSourceFile.cxx')
-rw-r--r--Source/cmSourceFile.cxx61
1 files changed, 46 insertions, 15 deletions
diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx
index 517b570..9d9a7c3 100644
--- a/Source/cmSourceFile.cxx
+++ b/Source/cmSourceFile.cxx
@@ -16,9 +16,12 @@
#include "cmake.h"
cmSourceFile::cmSourceFile(cmMakefile* mf, const std::string& name,
- cmSourceFileLocationKind kind)
- : Location(mf, name, kind)
+ bool generated, cmSourceFileLocationKind kind)
+ : Location(mf, name, (!generated) ? kind : cmSourceFileLocationKind::Known)
{
+ if (generated) {
+ this->MarkAsGenerated();
+ }
}
std::string const& cmSourceFile::GetExtension() const
@@ -26,6 +29,8 @@ std::string const& cmSourceFile::GetExtension() const
return this->Extension;
}
+const std::string propTRUE = "1";
+const std::string propFALSE = "0";
const std::string cmSourceFile::propLANGUAGE = "LANGUAGE";
const std::string cmSourceFile::propLOCATION = "LOCATION";
const std::string cmSourceFile::propGENERATED = "GENERATED";
@@ -112,11 +117,14 @@ bool cmSourceFile::FindFullPath(std::string* error,
std::string* cmp0115Warning)
{
// If the file is generated compute the location without checking on disk.
- if (this->GetIsGenerated()) {
+ // Note: We also check for a locally set GENERATED property, because
+ // it might have been set before policy CMP0118 was set to NEW.
+ if (this->GetIsGenerated(CheckScope::GlobalAndLocal)) {
// The file is either already a full path or is relative to the
// build directory for the target.
this->Location.DirectoryUseBinary();
this->FullPath = this->Location.GetFullPath();
+ this->FindFullPathFailed = false;
return true;
}
@@ -273,11 +281,6 @@ void cmSourceFile::SetProperty(const std::string& prop, const char* value)
} else {
this->Properties.SetProperty(prop, value);
}
-
- // Update IsGenerated flag
- if (prop == propGENERATED) {
- this->IsGenerated = cmIsOn(value);
- }
}
void cmSourceFile::AppendProperty(const std::string& prop,
@@ -301,11 +304,6 @@ void cmSourceFile::AppendProperty(const std::string& prop,
} else {
this->Properties.AppendProperty(prop, value, asString);
}
-
- // Update IsGenerated flag
- if (prop == propGENERATED) {
- this->IsGenerated = this->GetPropertyAsBool(propGENERATED);
- }
}
cmProp cmSourceFile::GetPropertyForUser(const std::string& prop)
@@ -336,6 +334,21 @@ cmProp cmSourceFile::GetPropertyForUser(const std::string& prop)
return &this->GetOrDetermineLanguage();
}
+ // Special handling for GENERATED property.
+ if (prop == propGENERATED) {
+ // We need to check policy CMP0118 in order to determine if we need to
+ // possibly consider the value of a locally set GENERATED property, too.
+ auto policyStatus =
+ this->Location.GetMakefile()->GetPolicyStatus(cmPolicies::CMP0118);
+ if (this->GetIsGenerated(
+ (policyStatus == cmPolicies::WARN || policyStatus == cmPolicies::OLD)
+ ? CheckScope::GlobalAndLocal
+ : CheckScope::Global)) {
+ return &propTRUE;
+ }
+ return &propFALSE;
+ }
+
// Perform the normal property lookup.
return this->GetProperty(prop);
}
@@ -411,11 +424,29 @@ bool cmSourceFile::GetPropertyAsBool(const std::string& prop) const
return cmIsOn(this->GetProperty(prop));
}
+void cmSourceFile::MarkAsGenerated()
+{
+ this->IsGenerated = true;
+ auto& mf = *this->Location.GetMakefile();
+ mf.GetGlobalGenerator()->MarkAsGeneratedFile(this->ResolveFullPath());
+}
+
+bool cmSourceFile::GetIsGenerated(CheckScope checkScope) const
+{
+ if (this->IsGenerated) {
+ // Globally marked as generated!
+ return true;
+ }
+ if (checkScope == CheckScope::GlobalAndLocal) {
+ // Check locally stored properties.
+ return this->GetPropertyAsBool(propGENERATED);
+ }
+ return false;
+}
+
void cmSourceFile::SetProperties(cmPropertyMap properties)
{
this->Properties = std::move(properties);
-
- this->IsGenerated = this->GetPropertyAsBool(propGENERATED);
}
cmCustomCommand* cmSourceFile::GetCustomCommand() const