summaryrefslogtreecommitdiff
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2021-10-08 09:13:33 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2021-10-08 09:13:33 +0900
commit48d9a397fa3cf76397824122450a1450af712716 (patch)
tree37bb17e0bcabc1da17c5606716c713de5d7d0366 /Source/cmMakefile.cxx
parent53666ee1cffac26c55edcbd9361dbd88a734cfa7 (diff)
downloadcmake-48d9a397fa3cf76397824122450a1450af712716.tar.gz
cmake-48d9a397fa3cf76397824122450a1450af712716.tar.bz2
cmake-48d9a397fa3cf76397824122450a1450af712716.zip
Imported Upstream version 3.13.0upstream/3.13.0
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx121
1 files changed, 86 insertions, 35 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index af97f8097..8d163b77d 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -11,6 +11,7 @@
#include <iterator>
#include <memory> // IWYU pragma: keep
#include <sstream>
+#include <stdio.h>
#include <stdlib.h>
#include <utility>
@@ -48,6 +49,11 @@
class cmMessenger;
+cmDirectoryId::cmDirectoryId(std::string s)
+ : String(std::move(s))
+{
+}
+
// default is not to be building executables
cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator,
cmStateSnapshot const& snapshot)
@@ -111,6 +117,17 @@ cmMakefile::~cmMakefile()
cmDeleteAll(this->EvaluationFiles);
}
+cmDirectoryId cmMakefile::GetDirectoryId() const
+{
+ // Use the instance pointer value to uniquely identify this directory.
+ // If we ever need to expose this to CMake language code we should
+ // add a read-only property in cmMakefile::GetProperty.
+ char buf[32];
+ sprintf(buf, "<%p>",
+ static_cast<void const*>(this)); // cast avoids format warning
+ return std::string(buf);
+}
+
void cmMakefile::IssueMessage(cmake::MessageType t,
std::string const& text) const
{
@@ -216,6 +233,27 @@ cmBacktraceRange cmMakefile::GetCompileDefinitionsBacktraces() const
.GetCompileDefinitionsEntryBacktraces();
}
+cmStringRange cmMakefile::GetLinkOptionsEntries() const
+{
+ return this->StateSnapshot.GetDirectory().GetLinkOptionsEntries();
+}
+
+cmBacktraceRange cmMakefile::GetLinkOptionsBacktraces() const
+{
+ return this->StateSnapshot.GetDirectory().GetLinkOptionsEntryBacktraces();
+}
+
+cmStringRange cmMakefile::GetLinkDirectoriesEntries() const
+{
+ return this->StateSnapshot.GetDirectory().GetLinkDirectoriesEntries();
+}
+
+cmBacktraceRange cmMakefile::GetLinkDirectoriesBacktraces() const
+{
+ return this->StateSnapshot.GetDirectory()
+ .GetLinkDirectoriesEntryBacktraces();
+}
+
cmListFileBacktrace cmMakefile::GetBacktrace() const
{
return this->Backtrace;
@@ -1205,6 +1243,23 @@ void cmMakefile::AddCompileOption(std::string const& option)
this->AppendProperty("COMPILE_OPTIONS", option.c_str());
}
+void cmMakefile::AddLinkOption(std::string const& option)
+{
+ this->AppendProperty("LINK_OPTIONS", option.c_str());
+}
+
+void cmMakefile::AddLinkDirectory(std::string const& directory, bool before)
+{
+ cmListFileBacktrace lfbt = this->GetBacktrace();
+ if (before) {
+ this->StateSnapshot.GetDirectory().PrependLinkDirectoriesEntry(directory,
+ lfbt);
+ } else {
+ this->StateSnapshot.GetDirectory().AppendLinkDirectoriesEntry(directory,
+ lfbt);
+ }
+}
+
bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove)
{
// Create a regular expression to match valid definitions.
@@ -1303,10 +1358,6 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent)
// link libraries
this->SetProperty("LINK_LIBRARIES", parent->GetProperty("LINK_LIBRARIES"));
- // link directories
- this->SetProperty("LINK_DIRECTORIES",
- parent->GetProperty("LINK_DIRECTORIES"));
-
// the initial project name
this->StateSnapshot.SetProjectName(parent->StateSnapshot.GetProjectName());
@@ -1620,12 +1671,12 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath,
}
}
-const char* cmMakefile::GetCurrentSourceDirectory() const
+const std::string& cmMakefile::GetCurrentSourceDirectory() const
{
return this->StateSnapshot.GetDirectory().GetCurrentSource();
}
-const char* cmMakefile::GetCurrentBinaryDirectory() const
+const std::string& cmMakefile::GetCurrentBinaryDirectory() const
{
return this->StateSnapshot.GetDirectory().GetCurrentBinary();
}
@@ -1703,7 +1754,8 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
cmStateEnums::CacheEntryType type,
bool force)
{
- const char* existingValue = this->GetState()->GetInitializedCacheValue(name);
+ const std::string* existingValue =
+ this->GetState()->GetInitializedCacheValue(name);
// must be outside the following if() to keep it alive long enough
std::string nvalue;
@@ -1713,7 +1765,7 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
// if this is not a force, then use the value from the cache
// if it is a force, then use the value being passed in
if (!force) {
- value = existingValue;
+ value = existingValue->c_str();
}
if (type == cmStateEnums::PATH || type == cmStateEnums::FILEPATH) {
std::vector<std::string>::size_type cc;
@@ -1723,7 +1775,7 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
cmSystemTools::ExpandListArgument(nvalue, files);
nvalue.clear();
for (cc = 0; cc < files.size(); cc++) {
- if (!cmSystemTools::IsOff(files[cc].c_str())) {
+ if (!cmSystemTools::IsOff(files[cc])) {
files[cc] = cmSystemTools::CollapseFullPath(files[cc]);
}
if (cc > 0) {
@@ -1733,7 +1785,7 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
}
this->GetCMakeInstance()->AddCacheEntry(name, nvalue.c_str(), doc, type);
- nvalue = this->GetState()->GetInitializedCacheValue(name);
+ nvalue = *this->GetState()->GetInitializedCacheValue(name);
value = nvalue.c_str();
}
}
@@ -1839,17 +1891,6 @@ void cmMakefile::AddGlobalLinkInformation(cmTarget& target)
return;
default:;
}
- if (const char* linkDirsProp = this->GetProperty("LINK_DIRECTORIES")) {
- std::vector<std::string> linkDirs;
- cmSystemTools::ExpandListArgument(linkDirsProp, linkDirs);
-
- for (std::string& linkDir : linkDirs) {
- // Sanitize the path the same way the link_directories command does
- // in case projects set the LINK_DIRECTORIES property directly.
- cmSystemTools::ConvertToUnixSlashes(linkDir);
- target.AddLinkDirectory(linkDir);
- }
- }
if (const char* linkLibsProp = this->GetProperty("LINK_LIBRARIES")) {
std::vector<std::string> linkLibs;
@@ -2339,21 +2380,21 @@ bool cmMakefile::CanIWriteThisFile(std::string const& fileName) const
cmSystemTools::SameFile(fileName, this->GetHomeOutputDirectory());
}
-const char* cmMakefile::GetRequiredDefinition(const std::string& name) const
+std::string cmMakefile::GetRequiredDefinition(const std::string& name) const
{
const char* ret = this->GetDefinition(name);
if (!ret) {
cmSystemTools::Error("Error required internal CMake variable not "
"set, cmake may not be built correctly.\n",
"Missing variable is:\n", name.c_str());
- return "";
+ return std::string();
}
- return ret;
+ return std::string(ret);
}
bool cmMakefile::IsDefinitionSet(const std::string& name) const
{
- const char* def = this->StateSnapshot.GetDefinition(name);
+ const std::string* def = this->StateSnapshot.GetDefinition(name);
if (!def) {
def = this->GetState()->GetInitializedCacheValue(name);
}
@@ -2361,16 +2402,16 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const
if (cmVariableWatch* vv = this->GetVariableWatch()) {
if (!def) {
vv->VariableAccessed(
- name, cmVariableWatch::UNKNOWN_VARIABLE_DEFINED_ACCESS, def, this);
+ name, cmVariableWatch::UNKNOWN_VARIABLE_DEFINED_ACCESS, nullptr, this);
}
}
#endif
return def != nullptr;
}
-const char* cmMakefile::GetDefinition(const std::string& name) const
+const std::string* cmMakefile::GetDef(const std::string& name) const
{
- const char* def = this->StateSnapshot.GetDefinition(name);
+ const std::string* def = this->StateSnapshot.GetDefinition(name);
if (!def) {
def = this->GetState()->GetInitializedCacheValue(name);
}
@@ -2381,7 +2422,7 @@ const char* cmMakefile::GetDefinition(const std::string& name) const
vv->VariableAccessed(name,
def ? cmVariableWatch::VARIABLE_READ_ACCESS
: cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS,
- def, this);
+ (def ? def->c_str() : nullptr), this);
if (watch_function_executed) {
// A callback was executed and may have caused re-allocation of the
@@ -2397,13 +2438,23 @@ const char* cmMakefile::GetDefinition(const std::string& name) const
return def;
}
-const char* cmMakefile::GetSafeDefinition(const std::string& def) const
+const char* cmMakefile::GetDefinition(const std::string& name) const
{
- const char* ret = this->GetDefinition(def);
- if (!ret) {
- return "";
+ const std::string* def = GetDef(name);
+ if (!def) {
+ return nullptr;
}
- return ret;
+ return def->c_str();
+}
+
+const std::string& cmMakefile::GetSafeDefinition(const std::string& name) const
+{
+ static std::string const empty;
+ const std::string* def = GetDef(name);
+ if (!def) {
+ return empty;
+ }
+ return *def;
}
std::vector<std::string> cmMakefile::GetDefinitions() const
@@ -4151,7 +4202,7 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id,
// Deprecate old policies, especially those that require a lot
// of code to maintain the old behavior.
- if (status == cmPolicies::OLD && id <= cmPolicies::CMP0054) {
+ if (status == cmPolicies::OLD && id <= cmPolicies::CMP0063) {
this->IssueMessage(cmake::DEPRECATION_WARNING,
cmPolicies::GetPolicyDeprecatedWarning(id));
}