2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2001-01-11 22:55:47 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2001-01-11 22:55:47 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2000-08-29 23:26:29 +04:00
|
|
|
#include "cmMakefile.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2001-01-18 19:20:24 +03:00
|
|
|
#include "cmCommand.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmCommandArgumentParserHelper.h"
|
2001-02-13 03:49:52 +03:00
|
|
|
#include "cmCommands.h"
|
2001-04-20 01:39:03 +04:00
|
|
|
#include "cmFunctionBlocker.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmGeneratorExpression.h"
|
2015-08-01 13:05:13 +03:00
|
|
|
#include "cmGeneratorExpressionEvaluationFile.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmGlobalGenerator.h"
|
2001-08-29 02:28:31 +04:00
|
|
|
#include "cmListFileCache.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmOutputConverter.h"
|
|
|
|
#include "cmSourceFile.h"
|
|
|
|
#include "cmSourceFileLocation.h"
|
|
|
|
#include "cmState.h"
|
|
|
|
#include "cmSystemTools.h"
|
2005-04-24 23:59:51 +04:00
|
|
|
#include "cmTest.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmVersion.h"
|
2004-10-27 18:47:14 +04:00
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
|
|
|
# include "cmVariableWatch.h"
|
|
|
|
#endif
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmAlgorithms.h"
|
2006-02-19 23:25:27 +03:00
|
|
|
#include "cmInstallGenerator.h"
|
2009-03-16 17:40:46 +03:00
|
|
|
#include "cmTestGenerator.h"
|
2002-08-28 22:51:10 +04:00
|
|
|
#include "cmake.h"
|
2003-05-24 00:40:55 +04:00
|
|
|
#include <stdlib.h> // required for atoi
|
2003-06-23 22:10:12 +04:00
|
|
|
|
2014-01-04 09:47:13 +04:00
|
|
|
#include <cmsys/FStream.hxx>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmsys/RegularExpression.hxx>
|
2008-01-28 16:38:36 +03:00
|
|
|
#include <cmsys/auto_ptr.hxx>
|
|
|
|
|
2013-07-12 11:14:31 +04:00
|
|
|
#include <assert.h>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <ctype.h> // for isspace
|
|
|
|
#include <list>
|
2006-05-23 20:51:26 +04:00
|
|
|
|
2000-08-29 23:26:29 +04:00
|
|
|
// default is not to be building executables
|
2015-08-02 12:20:28 +03:00
|
|
|
cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator,
|
|
|
|
cmState::Snapshot const& snapshot)
|
|
|
|
: GlobalGenerator(globalGenerator),
|
2016-04-14 18:24:08 +03:00
|
|
|
StateSnapshot(snapshot),
|
|
|
|
Backtrace(snapshot)
|
2000-08-29 23:26:29 +04:00
|
|
|
{
|
2015-08-25 23:19:57 +03:00
|
|
|
this->IsSourceFileTryCompile = false;
|
2007-12-03 21:35:41 +03:00
|
|
|
|
2015-05-16 17:39:36 +03:00
|
|
|
this->WarnUnused = this->GetCMakeInstance()->GetWarnUnused();
|
|
|
|
this->CheckSystemVars = this->GetCMakeInstance()->GetCheckSystemVars();
|
2007-12-03 21:35:41 +03:00
|
|
|
|
2015-05-04 17:16:34 +03:00
|
|
|
this->SuppressWatches = false;
|
|
|
|
|
2001-06-21 23:02:52 +04:00
|
|
|
// Setup the default include complaint regular expression (match nothing).
|
2006-03-15 19:02:08 +03:00
|
|
|
this->ComplainFileRegularExpression = "^$";
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2006-03-15 19:02:08 +03:00
|
|
|
this->DefineFlags = " ";
|
2006-03-22 17:58:11 +03:00
|
|
|
|
2007-06-11 18:25:40 +04:00
|
|
|
this->cmDefineRegex.compile("#cmakedefine[ \t]+([A-Za-z_0-9]*)");
|
|
|
|
this->cmDefine01Regex.compile("#cmakedefine01[ \t]+([A-Za-z_0-9]*)");
|
|
|
|
this->cmAtVarRegex.compile("(@[A-Za-z_0-9/.+-]+@)");
|
2014-02-08 07:37:54 +04:00
|
|
|
this->cmNamedCurly.compile("^[A-Za-z0-9/_.+-]+{");
|
2008-03-06 18:57:59 +03:00
|
|
|
|
2015-07-26 13:56:10 +03:00
|
|
|
this->StateSnapshot = this->StateSnapshot.GetState()
|
|
|
|
->CreatePolicyScopeSnapshot(this->StateSnapshot);
|
|
|
|
|
2008-03-06 18:57:59 +03:00
|
|
|
// Enter a policy level for this directory.
|
|
|
|
this->PushPolicy();
|
2008-03-31 21:33:09 +04:00
|
|
|
|
2014-11-18 18:34:30 +03:00
|
|
|
// push empty loop block
|
|
|
|
this->PushLoopBlockBarrier();
|
|
|
|
|
2008-03-31 21:33:09 +04:00
|
|
|
// By default the check is not done. It is enabled by
|
|
|
|
// cmListFileCache in the top level if necessary.
|
|
|
|
this->CheckCMP0000 = false;
|
2015-04-27 23:38:45 +03:00
|
|
|
|
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
|
|
|
this->AddSourceGroup("", "^.*$");
|
|
|
|
this->AddSourceGroup
|
|
|
|
("Source Files",
|
|
|
|
"\\.(C|M|c|c\\+\\+|cc|cpp|cxx|f|f90|for|fpp"
|
|
|
|
"|ftn|m|mm|rc|def|r|odl|idl|hpj|bat)$");
|
|
|
|
this->AddSourceGroup("Header Files", CM_HEADER_REGEX);
|
|
|
|
this->AddSourceGroup("CMake Rules", "\\.rule$");
|
|
|
|
this->AddSourceGroup("Resources", "\\.plist$");
|
|
|
|
this->AddSourceGroup("Object Files", "\\.(lo|o|obj)$");
|
|
|
|
#endif
|
2007-06-11 18:25:40 +04:00
|
|
|
}
|
2003-02-14 05:57:05 +03:00
|
|
|
|
2001-01-05 19:41:20 +03:00
|
|
|
cmMakefile::~cmMakefile()
|
|
|
|
{
|
2015-01-04 15:33:16 +03:00
|
|
|
cmDeleteAll(this->InstallGenerators);
|
|
|
|
cmDeleteAll(this->TestGenerators);
|
|
|
|
cmDeleteAll(this->SourceFiles);
|
|
|
|
cmDeleteAll(this->Tests);
|
|
|
|
cmDeleteAll(this->ImportedTargetsOwned);
|
|
|
|
cmDeleteAll(this->FinalPassCommands);
|
|
|
|
cmDeleteAll(this->FunctionBlockers);
|
2015-08-01 13:05:13 +03:00
|
|
|
cmDeleteAll(this->EvaluationFiles);
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|
|
|
|
|
2008-03-12 16:25:14 +03:00
|
|
|
void cmMakefile::IssueMessage(cmake::MessageType t,
|
2015-11-08 15:20:47 +03:00
|
|
|
std::string const& text,
|
|
|
|
bool force) const
|
2008-03-07 16:40:36 +03:00
|
|
|
{
|
2008-03-13 20:48:57 +03:00
|
|
|
// Collect context information.
|
2015-05-31 20:37:08 +03:00
|
|
|
if(!this->ExecutionStatusStack.empty())
|
2008-03-07 16:40:36 +03:00
|
|
|
{
|
2008-03-13 20:48:57 +03:00
|
|
|
if((t == cmake::FATAL_ERROR) || (t == cmake::INTERNAL_ERROR))
|
2008-03-07 16:40:36 +03:00
|
|
|
{
|
2015-05-31 20:37:08 +03:00
|
|
|
this->ExecutionStatusStack.back()->SetNestedError(true);
|
2008-03-07 16:40:36 +03:00
|
|
|
}
|
2008-03-10 22:40:57 +03:00
|
|
|
}
|
2016-04-14 18:24:08 +03:00
|
|
|
this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace(), force);
|
2008-03-13 20:48:57 +03:00
|
|
|
}
|
2008-03-07 16:40:36 +03:00
|
|
|
|
2015-07-18 11:52:09 +03:00
|
|
|
cmStringRange cmMakefile::GetIncludeDirectoriesEntries() const
|
2015-07-08 23:58:30 +03:00
|
|
|
{
|
2015-07-18 13:28:49 +03:00
|
|
|
return this->StateSnapshot.GetDirectory().GetIncludeDirectoriesEntries();
|
2015-07-08 23:58:30 +03:00
|
|
|
}
|
|
|
|
|
2015-07-18 11:52:09 +03:00
|
|
|
cmBacktraceRange cmMakefile::GetIncludeDirectoriesBacktraces() const
|
2015-07-09 00:35:01 +03:00
|
|
|
{
|
2015-07-18 13:28:49 +03:00
|
|
|
return this->StateSnapshot.GetDirectory()
|
|
|
|
.GetIncludeDirectoriesEntryBacktraces();
|
2015-07-09 00:35:01 +03:00
|
|
|
}
|
|
|
|
|
2015-07-18 11:52:09 +03:00
|
|
|
cmStringRange cmMakefile::GetCompileOptionsEntries() const
|
2015-07-08 23:58:30 +03:00
|
|
|
{
|
2015-07-18 13:28:49 +03:00
|
|
|
return this->StateSnapshot.GetDirectory().GetCompileOptionsEntries();
|
2015-07-09 00:17:16 +03:00
|
|
|
}
|
|
|
|
|
2015-07-18 11:52:09 +03:00
|
|
|
cmBacktraceRange cmMakefile::GetCompileOptionsBacktraces() const
|
2015-07-09 00:17:16 +03:00
|
|
|
{
|
2015-07-18 13:28:49 +03:00
|
|
|
return this->StateSnapshot.GetDirectory().GetCompileOptionsEntryBacktraces();
|
2015-07-08 23:58:30 +03:00
|
|
|
}
|
|
|
|
|
2015-07-18 11:52:09 +03:00
|
|
|
cmStringRange cmMakefile::GetCompileDefinitionsEntries() const
|
2015-07-08 23:58:30 +03:00
|
|
|
{
|
2015-07-18 13:28:49 +03:00
|
|
|
return this->StateSnapshot.GetDirectory().GetCompileDefinitionsEntries();
|
2015-07-09 00:11:22 +03:00
|
|
|
}
|
|
|
|
|
2015-07-18 11:52:09 +03:00
|
|
|
cmBacktraceRange cmMakefile::GetCompileDefinitionsBacktraces() const
|
2015-07-09 00:11:22 +03:00
|
|
|
{
|
2015-07-18 13:28:49 +03:00
|
|
|
return this->StateSnapshot.GetDirectory()
|
|
|
|
.GetCompileDefinitionsEntryBacktraces();
|
2015-07-08 23:58:30 +03:00
|
|
|
}
|
|
|
|
|
2014-05-23 22:41:46 +04:00
|
|
|
cmListFileBacktrace cmMakefile::GetBacktrace() const
|
2008-03-13 20:48:57 +03:00
|
|
|
{
|
2016-04-14 18:24:08 +03:00
|
|
|
return this->Backtrace;
|
2008-03-07 16:40:36 +03:00
|
|
|
}
|
|
|
|
|
2016-04-14 18:24:08 +03:00
|
|
|
cmListFileBacktrace cmMakefile::GetBacktrace(cmCommandContext const& cc) const
|
2015-05-29 02:14:19 +03:00
|
|
|
{
|
2016-04-14 18:24:08 +03:00
|
|
|
cmListFileContext lfc;
|
|
|
|
lfc.Name = cc.Name;
|
|
|
|
lfc.Line = cc.Line;
|
|
|
|
lfc.FilePath = this->StateSnapshot.GetExecutionListFile();
|
|
|
|
return this->Backtrace.Push(lfc);
|
2008-03-07 16:40:36 +03:00
|
|
|
}
|
|
|
|
|
2015-05-18 22:35:29 +03:00
|
|
|
cmListFileContext cmMakefile::GetExecutionContext() const
|
|
|
|
{
|
2016-04-14 18:24:08 +03:00
|
|
|
cmListFileContext const& cur = this->Backtrace.Top();
|
|
|
|
cmListFileContext lfc;
|
|
|
|
lfc.Name = cur.Name;
|
|
|
|
lfc.Line = cur.Line;
|
|
|
|
lfc.FilePath = this->StateSnapshot.GetExecutionListFile();
|
|
|
|
return lfc;
|
2015-05-18 22:35:29 +03:00
|
|
|
}
|
|
|
|
|
2014-01-22 18:00:29 +04:00
|
|
|
void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const
|
2012-05-15 02:50:30 +04:00
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream msg;
|
2015-06-13 20:18:28 +03:00
|
|
|
msg << this->GetExecutionFilePath() << "(" << lff.Line << "): ";
|
2012-05-15 02:50:30 +04:00
|
|
|
msg << lff.Name << "(";
|
2015-07-22 00:18:53 +03:00
|
|
|
bool expand = this->GetCMakeInstance()->GetTraceExpand();
|
|
|
|
std::string temp;
|
2012-05-15 02:50:30 +04:00
|
|
|
for(std::vector<cmListFileArgument>::const_iterator i =
|
|
|
|
lff.Arguments.begin(); i != lff.Arguments.end(); ++i)
|
|
|
|
{
|
2015-07-22 00:18:53 +03:00
|
|
|
if (expand)
|
|
|
|
{
|
|
|
|
temp = i->Value;
|
|
|
|
this->ExpandVariablesInString(temp);
|
|
|
|
msg << temp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg << i->Value;
|
|
|
|
}
|
2012-05-15 02:50:30 +04:00
|
|
|
msg << " ";
|
|
|
|
}
|
|
|
|
msg << ")";
|
|
|
|
cmSystemTools::Message(msg.str().c_str());
|
|
|
|
}
|
|
|
|
|
2016-04-14 18:02:40 +03:00
|
|
|
// Helper class to make sure the call stack is valid.
|
|
|
|
class cmMakefileCall
|
|
|
|
{
|
|
|
|
public:
|
2016-04-14 18:24:08 +03:00
|
|
|
cmMakefileCall(cmMakefile* mf, cmCommandContext const& cc,
|
2016-04-14 18:02:40 +03:00
|
|
|
cmExecutionStatus& status): Makefile(mf)
|
|
|
|
{
|
2016-04-14 18:24:08 +03:00
|
|
|
cmListFileContext const& lfc =
|
|
|
|
cmListFileContext::FromCommandContext(
|
|
|
|
cc, this->Makefile->StateSnapshot.GetExecutionListFile());
|
|
|
|
this->Makefile->Backtrace = this->Makefile->Backtrace.Push(lfc);
|
2016-04-14 18:02:40 +03:00
|
|
|
this->Makefile->ExecutionStatusStack.push_back(&status);
|
|
|
|
}
|
|
|
|
|
|
|
|
~cmMakefileCall()
|
|
|
|
{
|
|
|
|
this->Makefile->ExecutionStatusStack.pop_back();
|
2016-04-14 18:24:08 +03:00
|
|
|
this->Makefile->Backtrace = this->Makefile->Backtrace.Pop();
|
2016-04-14 18:02:40 +03:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
cmMakefile* Makefile;
|
|
|
|
};
|
|
|
|
|
2008-01-23 18:28:26 +03:00
|
|
|
bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
|
|
|
|
cmExecutionStatus &status)
|
2001-07-26 00:53:13 +04:00
|
|
|
{
|
2002-12-12 19:36:28 +03:00
|
|
|
bool result = true;
|
2008-01-23 18:28:26 +03:00
|
|
|
|
2002-07-17 18:48:39 +04:00
|
|
|
// quick return if blocked
|
2008-01-23 18:28:26 +03:00
|
|
|
if(this->IsFunctionBlocked(lff,status))
|
2002-07-17 18:48:39 +04:00
|
|
|
{
|
2002-12-12 19:36:28 +03:00
|
|
|
// No error.
|
|
|
|
return result;
|
2002-07-17 18:48:39 +04:00
|
|
|
}
|
2010-09-28 23:44:22 +04:00
|
|
|
|
2006-03-15 19:02:08 +03:00
|
|
|
std::string name = lff.Name;
|
2008-01-23 18:28:26 +03:00
|
|
|
|
2008-03-07 16:40:36 +03:00
|
|
|
// Place this call on the call stack.
|
|
|
|
cmMakefileCall stack_manager(this, lff, status);
|
|
|
|
static_cast<void>(stack_manager);
|
|
|
|
|
|
|
|
// Lookup the command prototype.
|
2015-04-11 13:52:14 +03:00
|
|
|
if(cmCommand* proto = this->GetState()->GetCommand(name))
|
2008-03-07 16:40:36 +03:00
|
|
|
{
|
|
|
|
// Clone the prototype.
|
|
|
|
cmsys::auto_ptr<cmCommand> pcmd(proto->Clone());
|
|
|
|
pcmd->SetMakefile(this);
|
|
|
|
|
|
|
|
// Decide whether to invoke the command.
|
|
|
|
if(pcmd->GetEnabled() && !cmSystemTools::GetFatalErrorOccured() &&
|
2011-07-13 20:59:51 +04:00
|
|
|
(this->GetCMakeInstance()->GetWorkingMode() != cmake::SCRIPT_MODE
|
|
|
|
|| pcmd->IsScriptable()))
|
2011-07-02 19:50:05 +04:00
|
|
|
|
2008-03-07 16:40:36 +03:00
|
|
|
{
|
2012-05-15 02:50:30 +04:00
|
|
|
// if trace is enabled, print out invoke information
|
2008-07-31 18:33:25 +04:00
|
|
|
if(this->GetCMakeInstance()->GetTrace())
|
|
|
|
{
|
2012-05-15 02:50:30 +04:00
|
|
|
this->PrintCommandTrace(lff);
|
2008-07-31 18:33:25 +04:00
|
|
|
}
|
2008-03-07 16:40:36 +03:00
|
|
|
// Try invoking the command.
|
|
|
|
if(!pcmd->InvokeInitialPass(lff.Arguments,status) ||
|
|
|
|
status.GetNestedError())
|
2001-07-26 00:53:13 +04:00
|
|
|
{
|
2008-03-07 16:40:36 +03:00
|
|
|
if(!status.GetNestedError())
|
|
|
|
{
|
|
|
|
// The command invocation requested that we report an error.
|
2008-03-11 17:29:56 +03:00
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, pcmd->GetError());
|
2008-03-07 16:40:36 +03:00
|
|
|
}
|
2005-03-18 18:41:41 +03:00
|
|
|
result = false;
|
2011-07-13 20:59:51 +04:00
|
|
|
if ( this->GetCMakeInstance()->GetWorkingMode() != cmake::NORMAL_MODE)
|
2001-07-26 00:53:13 +04:00
|
|
|
{
|
2005-03-18 18:41:41 +03:00
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
2001-07-26 00:53:13 +04:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 21:31:34 +04:00
|
|
|
else if(pcmd->HasFinalPass())
|
2005-03-18 18:41:41 +03:00
|
|
|
{
|
|
|
|
// use the command
|
2012-02-29 11:49:42 +04:00
|
|
|
this->FinalPassCommands.push_back(pcmd.release());
|
2005-03-18 18:41:41 +03:00
|
|
|
}
|
2001-07-26 00:53:13 +04:00
|
|
|
}
|
2011-07-13 20:59:51 +04:00
|
|
|
else if ( this->GetCMakeInstance()->GetWorkingMode() == cmake::SCRIPT_MODE
|
2008-03-07 16:40:36 +03:00
|
|
|
&& !pcmd->IsScriptable() )
|
2003-10-29 17:45:26 +03:00
|
|
|
{
|
2008-03-07 16:40:36 +03:00
|
|
|
std::string error = "Command ";
|
|
|
|
error += pcmd->GetName();
|
|
|
|
error += "() is not scriptable";
|
2008-03-11 17:29:56 +03:00
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, error);
|
2003-10-29 17:45:26 +03:00
|
|
|
result = false;
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
}
|
2001-07-26 00:53:13 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-01-21 20:50:48 +03:00
|
|
|
if(!cmSystemTools::GetFatalErrorOccured())
|
|
|
|
{
|
2008-03-07 16:40:36 +03:00
|
|
|
std::string error = "Unknown CMake command \"";
|
|
|
|
error += lff.Name;
|
|
|
|
error += "\".";
|
2008-03-11 17:29:56 +03:00
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, error);
|
2003-01-21 20:50:48 +03:00
|
|
|
result = false;
|
2006-06-15 18:24:46 +04:00
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
2003-01-21 20:50:48 +03:00
|
|
|
}
|
2001-07-26 00:53:13 +04:00
|
|
|
}
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2002-12-12 19:36:28 +03:00
|
|
|
return result;
|
2001-07-26 00:53:13 +04:00
|
|
|
}
|
|
|
|
|
2009-01-22 18:57:16 +03:00
|
|
|
class cmMakefile::IncludeScope
|
|
|
|
{
|
|
|
|
public:
|
2015-06-21 21:09:13 +03:00
|
|
|
IncludeScope(cmMakefile* mf, std::string const& filenametoread,
|
|
|
|
bool noPolicyScope);
|
2009-01-22 18:57:16 +03:00
|
|
|
~IncludeScope();
|
|
|
|
void Quiet() { this->ReportError = false; }
|
|
|
|
private:
|
|
|
|
cmMakefile* Makefile;
|
2009-01-22 21:18:40 +03:00
|
|
|
bool NoPolicyScope;
|
|
|
|
bool CheckCMP0011;
|
2009-01-22 18:57:16 +03:00
|
|
|
bool ReportError;
|
2009-01-22 21:18:40 +03:00
|
|
|
void EnforceCMP0011();
|
2009-01-22 18:57:16 +03:00
|
|
|
};
|
|
|
|
|
2015-06-21 20:50:18 +03:00
|
|
|
cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf,
|
2015-06-21 21:09:13 +03:00
|
|
|
std::string const& filenametoread,
|
2009-01-22 21:18:40 +03:00
|
|
|
bool noPolicyScope):
|
2015-06-21 20:50:18 +03:00
|
|
|
Makefile(mf), NoPolicyScope(noPolicyScope),
|
2009-01-22 21:18:40 +03:00
|
|
|
CheckCMP0011(false), ReportError(true)
|
2009-01-22 18:57:16 +03:00
|
|
|
{
|
2016-04-14 18:24:08 +03:00
|
|
|
this->Makefile->Backtrace =
|
|
|
|
this->Makefile->Backtrace.Push(filenametoread);
|
|
|
|
|
2015-07-28 09:09:49 +03:00
|
|
|
this->Makefile->PushFunctionBlockerBarrier();
|
|
|
|
|
|
|
|
this->Makefile->StateSnapshot =
|
2016-04-12 23:08:24 +03:00
|
|
|
this->Makefile->GetState()->CreateIncludeFileSnapshot(
|
2015-07-28 09:09:49 +03:00
|
|
|
this->Makefile->StateSnapshot,
|
|
|
|
filenametoread);
|
2009-01-22 21:18:40 +03:00
|
|
|
if(!this->NoPolicyScope)
|
|
|
|
{
|
|
|
|
// Check CMP0011 to determine the policy scope type.
|
|
|
|
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0011))
|
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
|
|
|
// We need to push a scope to detect whether the script sets
|
|
|
|
// any policies that would affect the includer and therefore
|
|
|
|
// requires a warning. We use a weak scope to simulate OLD
|
|
|
|
// behavior by allowing policy changes to affect the includer.
|
|
|
|
this->Makefile->PushPolicy(true);
|
|
|
|
this->CheckCMP0011 = true;
|
|
|
|
break;
|
|
|
|
case cmPolicies::OLD:
|
|
|
|
// OLD behavior is to not push a scope at all.
|
|
|
|
this->NoPolicyScope = true;
|
|
|
|
break;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
|
|
// We should never make this policy required, but we handle it
|
|
|
|
// here just in case.
|
|
|
|
this->CheckCMP0011 = true;
|
|
|
|
case cmPolicies::NEW:
|
|
|
|
// NEW behavior is to push a (strong) scope.
|
|
|
|
this->Makefile->PushPolicy();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-01-22 18:57:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmMakefile::IncludeScope::~IncludeScope()
|
|
|
|
{
|
2009-01-22 21:18:40 +03:00
|
|
|
if(!this->NoPolicyScope)
|
|
|
|
{
|
|
|
|
// If we need to enforce policy CMP0011 then the top entry is the
|
|
|
|
// one we pushed above. If the entry is empty, then the included
|
|
|
|
// script did not set any policies that might affect the includer so
|
|
|
|
// we do not need to enforce the policy.
|
2015-07-26 14:04:09 +03:00
|
|
|
if(this->CheckCMP0011
|
|
|
|
&& !this->Makefile->StateSnapshot.HasDefinedPolicyCMP0011())
|
2009-01-22 21:18:40 +03:00
|
|
|
{
|
|
|
|
this->CheckCMP0011 = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pop the scope we pushed for the script.
|
|
|
|
this->Makefile->PopPolicy();
|
|
|
|
|
|
|
|
// We enforce the policy after the script's policy stack entry has
|
|
|
|
// been removed.
|
|
|
|
if(this->CheckCMP0011)
|
|
|
|
{
|
|
|
|
this->EnforceCMP0011();
|
|
|
|
}
|
|
|
|
}
|
2015-11-24 19:44:57 +03:00
|
|
|
this->Makefile->PopSnapshot(this->ReportError);
|
2015-07-28 09:09:49 +03:00
|
|
|
|
|
|
|
this->Makefile->PopFunctionBlockerBarrier(this->ReportError);
|
2016-04-14 18:24:08 +03:00
|
|
|
|
|
|
|
this->Makefile->Backtrace = this->Makefile->Backtrace.Pop();
|
2009-01-22 21:18:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefile::IncludeScope::EnforceCMP0011()
|
|
|
|
{
|
|
|
|
// We check the setting of this policy again because the included
|
|
|
|
// script might actually set this policy for its includer.
|
|
|
|
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0011))
|
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
|
|
|
// Warn because the user did not set this policy.
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream w;
|
2015-05-03 11:12:10 +03:00
|
|
|
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0011) << "\n"
|
2015-06-21 20:50:18 +03:00
|
|
|
<< "The included script\n "
|
2015-07-18 14:18:34 +03:00
|
|
|
<< this->Makefile->GetExecutionFilePath() << "\n"
|
2009-01-22 21:18:40 +03:00
|
|
|
<< "affects policy settings. "
|
|
|
|
<< "CMake is implying the NO_POLICY_SCOPE option for compatibility, "
|
|
|
|
<< "so the effects are applied to the including context.";
|
|
|
|
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2015-05-03 11:12:10 +03:00
|
|
|
e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0011) << "\n"
|
2015-06-21 20:50:18 +03:00
|
|
|
<< "The included script\n "
|
2015-07-18 14:18:34 +03:00
|
|
|
<< this->Makefile->GetExecutionFilePath() << "\n"
|
2009-01-22 21:18:40 +03:00
|
|
|
<< "affects policy settings, so it requires this policy to be set.";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2009-01-22 21:18:40 +03:00
|
|
|
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case cmPolicies::OLD:
|
|
|
|
case cmPolicies::NEW:
|
|
|
|
// The script set this policy. We assume the purpose of the
|
|
|
|
// script is to initialize policies for its includer, and since
|
|
|
|
// the policy is now set for later scripts, we do not warn.
|
|
|
|
break;
|
|
|
|
}
|
2009-01-22 18:57:16 +03:00
|
|
|
}
|
|
|
|
|
2015-06-21 21:02:16 +03:00
|
|
|
bool cmMakefile::ReadDependentFile(const char* filename, bool noPolicyScope)
|
2015-04-18 15:50:32 +03:00
|
|
|
{
|
2015-05-15 00:47:40 +03:00
|
|
|
this->AddDefinition("CMAKE_PARENT_LIST_FILE",
|
|
|
|
this->GetDefinition("CMAKE_CURRENT_LIST_FILE"));
|
2015-06-21 21:07:40 +03:00
|
|
|
std::string filenametoread =
|
|
|
|
cmSystemTools::CollapseFullPath(filename,
|
|
|
|
this->GetCurrentSourceDirectory());
|
|
|
|
|
2015-06-21 21:09:13 +03:00
|
|
|
IncludeScope incScope(this, filenametoread, noPolicyScope);
|
2015-06-21 21:07:40 +03:00
|
|
|
|
|
|
|
cmListFile listFile;
|
|
|
|
if (!listFile.ParseFile(filenametoread.c_str(), false, this))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-07-05 20:28:45 +03:00
|
|
|
|
2015-06-21 21:07:40 +03:00
|
|
|
this->ReadListFile(listFile, filenametoread);
|
2015-06-21 20:51:46 +03:00
|
|
|
if(cmSystemTools::GetFatalErrorOccured())
|
|
|
|
{
|
|
|
|
incScope.Quiet();
|
|
|
|
}
|
2015-06-21 21:07:40 +03:00
|
|
|
return true;
|
2015-05-15 01:09:53 +03:00
|
|
|
}
|
|
|
|
|
2015-06-21 23:50:13 +03:00
|
|
|
class cmMakefile::ListFileScope
|
|
|
|
{
|
|
|
|
public:
|
2015-06-21 23:56:15 +03:00
|
|
|
ListFileScope(cmMakefile* mf, std::string const& filenametoread)
|
2015-06-21 23:50:13 +03:00
|
|
|
: Makefile(mf), ReportError(true)
|
|
|
|
{
|
2016-04-14 18:24:08 +03:00
|
|
|
this->Makefile->Backtrace =
|
|
|
|
this->Makefile->Backtrace.Push(filenametoread);
|
|
|
|
|
2015-06-21 22:26:36 +03:00
|
|
|
this->Makefile->StateSnapshot =
|
|
|
|
this->Makefile->GetState()->CreateInlineListFileSnapshot(
|
2016-04-14 18:24:08 +03:00
|
|
|
this->Makefile->StateSnapshot, filenametoread);
|
2015-06-21 22:26:36 +03:00
|
|
|
assert(this->Makefile->StateSnapshot.IsValid());
|
2015-07-28 09:09:49 +03:00
|
|
|
|
2015-06-21 23:53:16 +03:00
|
|
|
this->Makefile->PushFunctionBlockerBarrier();
|
2015-06-21 23:50:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
~ListFileScope()
|
|
|
|
{
|
2015-11-24 19:44:57 +03:00
|
|
|
this->Makefile->PopSnapshot(this->ReportError);
|
2015-06-21 23:53:16 +03:00
|
|
|
this->Makefile->PopFunctionBlockerBarrier(this->ReportError);
|
2016-04-14 18:24:08 +03:00
|
|
|
this->Makefile->Backtrace = this->Makefile->Backtrace.Pop();
|
2015-06-21 23:50:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Quiet() { this->ReportError = false; }
|
|
|
|
private:
|
|
|
|
cmMakefile* Makefile;
|
|
|
|
bool ReportError;
|
|
|
|
};
|
|
|
|
|
2015-06-21 21:02:16 +03:00
|
|
|
bool cmMakefile::ReadListFile(const char* filename)
|
2015-05-15 01:09:53 +03:00
|
|
|
{
|
2015-04-18 15:50:37 +03:00
|
|
|
std::string filenametoread =
|
2015-06-21 21:02:16 +03:00
|
|
|
cmSystemTools::CollapseFullPath(filename,
|
2015-04-16 23:37:08 +03:00
|
|
|
this->GetCurrentSourceDirectory());
|
2007-04-04 20:05:10 +04:00
|
|
|
|
2015-06-21 23:56:15 +03:00
|
|
|
ListFileScope scope(this, filenametoread);
|
2015-06-21 20:43:55 +03:00
|
|
|
|
|
|
|
cmListFile listFile;
|
2015-06-21 21:07:40 +03:00
|
|
|
if (!listFile.ParseFile(filenametoread.c_str(), false, this))
|
2015-06-21 20:43:55 +03:00
|
|
|
{
|
2015-06-21 20:44:37 +03:00
|
|
|
return false;
|
2015-06-21 20:43:55 +03:00
|
|
|
}
|
|
|
|
|
2015-06-21 21:07:40 +03:00
|
|
|
this->ReadListFile(listFile, filenametoread);
|
2015-06-21 23:50:13 +03:00
|
|
|
if(cmSystemTools::GetFatalErrorOccured())
|
|
|
|
{
|
|
|
|
scope.Quiet();
|
|
|
|
}
|
2015-06-21 21:07:40 +03:00
|
|
|
return true;
|
2015-04-18 15:50:32 +03:00
|
|
|
}
|
|
|
|
|
2015-06-21 21:07:40 +03:00
|
|
|
void cmMakefile::ReadListFile(cmListFile const& listFile,
|
|
|
|
std::string const& filenametoread)
|
2000-08-29 23:26:29 +04:00
|
|
|
{
|
2015-06-21 20:44:37 +03:00
|
|
|
// add this list file to the list of dependencies
|
|
|
|
this->ListFiles.push_back(filenametoread);
|
2007-04-04 20:05:10 +04:00
|
|
|
|
2015-04-18 15:50:33 +03:00
|
|
|
std::string currentParentFile
|
|
|
|
= this->GetSafeDefinition("CMAKE_PARENT_LIST_FILE");
|
|
|
|
std::string currentFile
|
|
|
|
= this->GetSafeDefinition("CMAKE_CURRENT_LIST_FILE");
|
|
|
|
|
2015-04-18 15:50:38 +03:00
|
|
|
this->AddDefinition("CMAKE_CURRENT_LIST_FILE", filenametoread.c_str());
|
|
|
|
this->AddDefinition("CMAKE_CURRENT_LIST_DIR",
|
|
|
|
cmSystemTools::GetFilenamePath(filenametoread).c_str());
|
|
|
|
|
2015-04-18 15:50:33 +03:00
|
|
|
this->MarkVariableAsUsed("CMAKE_PARENT_LIST_FILE");
|
2015-04-18 15:50:38 +03:00
|
|
|
this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_FILE");
|
|
|
|
this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_DIR");
|
|
|
|
|
2009-01-15 22:37:14 +03:00
|
|
|
// Run the parsed commands.
|
2015-06-21 20:38:02 +03:00
|
|
|
const size_t numberFunctions = listFile.Functions.size();
|
2002-03-13 18:25:11 +03:00
|
|
|
for(size_t i =0; i < numberFunctions; ++i)
|
2000-08-29 23:26:29 +04:00
|
|
|
{
|
2008-01-23 18:28:26 +03:00
|
|
|
cmExecutionStatus status;
|
2015-06-21 20:38:02 +03:00
|
|
|
this->ExecuteCommand(listFile.Functions[i],status);
|
2009-01-21 17:48:00 +03:00
|
|
|
if(cmSystemTools::GetFatalErrorOccured())
|
2005-05-05 18:40:37 +04:00
|
|
|
{
|
2009-01-21 17:48:00 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(status.GetReturnInvoked())
|
|
|
|
{
|
|
|
|
// Exit early due to return command.
|
2008-03-10 22:41:07 +03:00
|
|
|
break;
|
2005-05-05 18:40:37 +04:00
|
|
|
}
|
2000-08-29 23:26:29 +04:00
|
|
|
}
|
2015-06-21 20:57:15 +03:00
|
|
|
this->CheckForUnusedVariables();
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2015-06-21 20:57:15 +03:00
|
|
|
this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile.c_str());
|
|
|
|
this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.c_str());
|
|
|
|
this->AddDefinition("CMAKE_CURRENT_LIST_DIR",
|
|
|
|
cmSystemTools::GetFilenamePath(currentFile).c_str());
|
|
|
|
this->MarkVariableAsUsed("CMAKE_PARENT_LIST_FILE");
|
|
|
|
this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_FILE");
|
|
|
|
this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_DIR");
|
2000-08-29 23:26:29 +04:00
|
|
|
}
|
2001-02-13 03:49:52 +03:00
|
|
|
|
2014-01-22 18:00:29 +04:00
|
|
|
void cmMakefile::EnforceDirectoryLevelRules() const
|
2008-03-31 21:33:09 +04:00
|
|
|
{
|
|
|
|
// Diagnose a violation of CMP0000 if necessary.
|
|
|
|
if(this->CheckCMP0000)
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream msg;
|
2008-03-31 21:33:09 +04:00
|
|
|
msg << "No cmake_minimum_required command is present. "
|
|
|
|
<< "A line of code such as\n"
|
|
|
|
<< " cmake_minimum_required(VERSION "
|
|
|
|
<< cmVersion::GetMajorVersion() << "."
|
|
|
|
<< cmVersion::GetMinorVersion()
|
|
|
|
<< ")\n"
|
|
|
|
<< "should be added at the top of the file. "
|
|
|
|
<< "The version specified may be lower if you wish to "
|
|
|
|
<< "support older CMake versions for this project. "
|
|
|
|
<< "For more information run "
|
|
|
|
<< "\"cmake --help-policy CMP0000\".";
|
|
|
|
switch (this->GetPolicyStatus(cmPolicies::CMP0000))
|
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
|
|
|
// Warn because the user did not provide a mimimum required
|
|
|
|
// version.
|
2014-03-11 03:04:11 +04:00
|
|
|
this->IssueMessage(cmake::AUTHOR_WARNING, msg.str());
|
2008-03-31 21:33:09 +04:00
|
|
|
case cmPolicies::OLD:
|
|
|
|
// OLD behavior is to use policy version 2.4 set in
|
|
|
|
// cmListFileCache.
|
|
|
|
break;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
|
|
case cmPolicies::NEW:
|
|
|
|
// NEW behavior is to issue an error.
|
2014-03-11 03:04:11 +04:00
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, msg.str());
|
2008-03-31 21:33:09 +04:00
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-04-11 22:59:02 +04:00
|
|
|
|
2015-08-01 13:05:13 +03:00
|
|
|
void cmMakefile::AddEvaluationFile(const std::string& inputFile,
|
|
|
|
cmsys::auto_ptr<cmCompiledGeneratorExpression> outputName,
|
|
|
|
cmsys::auto_ptr<cmCompiledGeneratorExpression> condition,
|
|
|
|
bool inputIsContent)
|
|
|
|
{
|
|
|
|
this->EvaluationFiles.push_back(
|
|
|
|
new cmGeneratorExpressionEvaluationFile(inputFile, outputName,
|
2015-08-01 13:19:32 +03:00
|
|
|
condition,
|
2015-08-01 13:05:13 +03:00
|
|
|
inputIsContent));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<cmGeneratorExpressionEvaluationFile*>
|
|
|
|
cmMakefile::GetEvaluationFiles() const
|
|
|
|
{
|
|
|
|
return this->EvaluationFiles;
|
|
|
|
}
|
|
|
|
|
2015-09-16 23:08:22 +03:00
|
|
|
std::vector<cmExportBuildFileGenerator*>
|
|
|
|
cmMakefile::GetExportBuildFileGenerators() const
|
|
|
|
{
|
|
|
|
return this->ExportBuildFileGenerators;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefile::RemoveExportBuildFileGeneratorCMP0024(
|
|
|
|
cmExportBuildFileGenerator* gen)
|
|
|
|
{
|
|
|
|
std::vector<cmExportBuildFileGenerator*>::iterator it =
|
|
|
|
std::find(this->ExportBuildFileGenerators.begin(),
|
|
|
|
this->ExportBuildFileGenerators.end(), gen);
|
|
|
|
if(it != this->ExportBuildFileGenerators.end())
|
|
|
|
{
|
|
|
|
this->ExportBuildFileGenerators.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefile::AddExportBuildFileGenerator(cmExportBuildFileGenerator* gen)
|
|
|
|
{
|
|
|
|
this->ExportBuildFileGenerators.push_back(gen);
|
|
|
|
}
|
|
|
|
|
2013-08-28 20:49:53 +04:00
|
|
|
namespace
|
|
|
|
{
|
2013-09-03 23:31:12 +04:00
|
|
|
struct file_not_persistent
|
2013-08-28 20:49:53 +04:00
|
|
|
{
|
|
|
|
bool operator()(const std::string& path) const
|
2013-09-03 23:31:12 +04:00
|
|
|
{
|
|
|
|
return !(path.find("CMakeTmp") == path.npos &&
|
|
|
|
cmSystemTools::FileExists(path.c_str()));
|
|
|
|
}
|
2013-08-28 20:49:53 +04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2001-07-26 02:30:27 +04:00
|
|
|
void cmMakefile::FinalPass()
|
2001-01-05 19:41:20 +03:00
|
|
|
{
|
|
|
|
// do all the variable expansions here
|
2012-12-06 18:59:18 +04:00
|
|
|
this->ExpandVariablesCMP0019();
|
2001-07-27 21:06:05 +04:00
|
|
|
|
2001-01-18 19:20:24 +03:00
|
|
|
// give all the commands a chance to do something
|
2001-01-05 19:41:20 +03:00
|
|
|
// after the file has been parsed before generation
|
2012-02-29 11:49:42 +04:00
|
|
|
for(std::vector<cmCommand*>::iterator i = this->FinalPassCommands.begin();
|
|
|
|
i != this->FinalPassCommands.end(); ++i)
|
2001-01-05 19:41:20 +03:00
|
|
|
{
|
|
|
|
(*i)->FinalPass();
|
2000-08-29 23:26:29 +04:00
|
|
|
}
|
2001-07-26 02:30:27 +04:00
|
|
|
|
2013-08-28 20:49:53 +04:00
|
|
|
//go through all configured files and see which ones still exist.
|
|
|
|
//we don't want cmake to re-run if a configured file is created and deleted
|
|
|
|
//during processing as that would make it a transient file that can't
|
|
|
|
//influence the build process
|
|
|
|
|
|
|
|
//remove_if will move all items that don't have a valid file name to the
|
|
|
|
//back of the vector
|
2013-09-03 23:31:12 +04:00
|
|
|
std::vector<std::string>::iterator new_output_files_end = std::remove_if(
|
|
|
|
this->OutputFiles.begin(),
|
|
|
|
this->OutputFiles.end(),
|
|
|
|
file_not_persistent() );
|
2013-08-28 20:49:53 +04:00
|
|
|
//we just have to erase all items at the back
|
2013-09-03 23:31:12 +04:00
|
|
|
this->OutputFiles.erase(new_output_files_end, this->OutputFiles.end() );
|
|
|
|
|
|
|
|
//if a configured file is used as input for another configured file,
|
|
|
|
//and then deleted it will show up in the input list files so we
|
|
|
|
//need to scan those too
|
|
|
|
std::vector<std::string>::iterator new_list_files_end = std::remove_if(
|
|
|
|
this->ListFiles.begin(),
|
|
|
|
this->ListFiles.end(),
|
|
|
|
file_not_persistent() );
|
2013-08-28 20:49:53 +04:00
|
|
|
|
2013-09-03 23:31:12 +04:00
|
|
|
this->ListFiles.erase(new_list_files_end, this->ListFiles.end() );
|
2001-07-26 02:30:27 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 19:21:30 +04:00
|
|
|
// Generate the output file
|
2002-09-15 16:52:24 +04:00
|
|
|
void cmMakefile::ConfigureFinalPass()
|
2001-07-26 02:30:27 +04:00
|
|
|
{
|
|
|
|
this->FinalPass();
|
2005-06-10 18:45:43 +04:00
|
|
|
const char* oldValue
|
|
|
|
= this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
|
2013-10-18 19:25:49 +04:00
|
|
|
if (oldValue && cmSystemTools::VersionCompare(
|
|
|
|
cmSystemTools::OP_LESS, oldValue, "2.4"))
|
2005-06-10 18:45:43 +04:00
|
|
|
{
|
2013-10-18 19:25:49 +04:00
|
|
|
this->IssueMessage(
|
|
|
|
cmake::FATAL_ERROR,
|
|
|
|
"You have set CMAKE_BACKWARDS_COMPATIBILITY to a CMake version less "
|
|
|
|
"than 2.4. This version of CMake only supports backwards compatibility "
|
|
|
|
"with CMake 2.4 or later. For compatibility with older versions please "
|
|
|
|
"use any CMake 2.8.x release or lower.");
|
2005-06-10 18:45:43 +04:00
|
|
|
}
|
2001-06-06 04:34:01 +04:00
|
|
|
}
|
|
|
|
|
2005-02-22 18:32:44 +03:00
|
|
|
void
|
2014-02-07 02:31:47 +04:00
|
|
|
cmMakefile::AddCustomCommandToTarget(const std::string& target,
|
2014-11-14 02:54:52 +03:00
|
|
|
const std::vector<std::string>& byproducts,
|
2005-02-22 18:32:44 +03:00
|
|
|
const std::vector<std::string>& depends,
|
|
|
|
const cmCustomCommandLines& commandLines,
|
|
|
|
cmTarget::CustomCommandType type,
|
2006-02-08 18:58:36 +03:00
|
|
|
const char* comment,
|
2006-09-28 19:30:49 +04:00
|
|
|
const char* workingDir,
|
2014-11-05 23:37:52 +03:00
|
|
|
bool escapeOldStyle,
|
2014-11-14 02:54:52 +03:00
|
|
|
bool uses_terminal)
|
2003-06-03 18:30:23 +04:00
|
|
|
{
|
2005-02-22 18:32:44 +03:00
|
|
|
// Find the target to which to add the custom command.
|
2006-03-15 19:02:08 +03:00
|
|
|
cmTargets::iterator ti = this->Targets.find(target);
|
2013-11-20 12:53:06 +04:00
|
|
|
|
|
|
|
if(ti == this->Targets.end())
|
2005-02-22 18:32:44 +03:00
|
|
|
{
|
2013-11-20 12:53:06 +04:00
|
|
|
cmake::MessageType messageType = cmake::AUTHOR_WARNING;
|
|
|
|
bool issueMessage = false;
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2013-11-20 12:53:06 +04:00
|
|
|
switch(this->GetPolicyStatus(cmPolicies::CMP0040))
|
2012-03-12 18:47:40 +04:00
|
|
|
{
|
2013-11-20 12:53:06 +04:00
|
|
|
case cmPolicies::WARN:
|
2015-05-03 11:12:10 +03:00
|
|
|
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0040) << "\n";
|
2013-11-20 12:53:06 +04:00
|
|
|
issueMessage = true;
|
|
|
|
case cmPolicies::OLD:
|
|
|
|
break;
|
|
|
|
case cmPolicies::NEW:
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
|
|
issueMessage = true;
|
|
|
|
messageType = cmake::FATAL_ERROR;
|
2012-03-12 18:47:40 +04:00
|
|
|
}
|
2013-11-20 12:53:06 +04:00
|
|
|
|
|
|
|
if(issueMessage)
|
2003-06-03 18:30:23 +04:00
|
|
|
{
|
2016-01-28 18:12:26 +03:00
|
|
|
if (cmTarget const* t = this->FindTargetToUse(target))
|
|
|
|
{
|
|
|
|
if (t->IsImported())
|
|
|
|
{
|
|
|
|
e << "TARGET '" << target
|
|
|
|
<< "' is IMPORTED and does not build here.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e << "TARGET '" << target
|
|
|
|
<< "' was not created in this directory.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e << "No TARGET '" << target
|
|
|
|
<< "' has been created in this directory.";
|
|
|
|
}
|
2014-03-11 03:04:11 +04:00
|
|
|
IssueMessage(messageType, e.str());
|
2005-02-22 18:32:44 +03:00
|
|
|
}
|
2013-11-20 12:53:06 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-08 01:21:51 +03:00
|
|
|
if(ti->second.GetType() == cmState::OBJECT_LIBRARY)
|
2013-11-20 12:53:06 +04:00
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2013-11-20 12:53:06 +04:00
|
|
|
e << "Target \"" << target << "\" is an OBJECT library "
|
|
|
|
"that may not have PRE_BUILD, PRE_LINK, or POST_BUILD commands.";
|
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
return;
|
|
|
|
}
|
2015-10-08 01:21:51 +03:00
|
|
|
if(ti->second.GetType() == cmState::INTERFACE_LIBRARY)
|
2014-03-19 18:50:01 +04:00
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2014-03-19 18:50:01 +04:00
|
|
|
e << "Target \"" << target << "\" is an INTERFACE library "
|
|
|
|
"that may not have PRE_BUILD, PRE_LINK, or POST_BUILD commands.";
|
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
return;
|
|
|
|
}
|
2014-11-14 02:54:52 +03:00
|
|
|
|
|
|
|
// Always create the byproduct sources and mark them generated.
|
|
|
|
for(std::vector<std::string>::const_iterator o = byproducts.begin();
|
|
|
|
o != byproducts.end(); ++o)
|
|
|
|
{
|
|
|
|
if(cmSourceFile* out = this->GetOrCreateSource(*o, true))
|
|
|
|
{
|
|
|
|
out->SetProperty("GENERATED", "1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-20 12:53:06 +04:00
|
|
|
// Add the command to the appropriate build step for the target.
|
|
|
|
std::vector<std::string> no_output;
|
2014-11-14 02:54:52 +03:00
|
|
|
cmCustomCommand cc(this, no_output, byproducts, depends,
|
2013-11-20 12:53:06 +04:00
|
|
|
commandLines, comment, workingDir);
|
|
|
|
cc.SetEscapeOldStyle(escapeOldStyle);
|
|
|
|
cc.SetEscapeAllowMakeVars(true);
|
2014-11-05 23:37:52 +03:00
|
|
|
cc.SetUsesTerminal(uses_terminal);
|
2013-11-20 12:53:06 +04:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case cmTarget::PRE_BUILD:
|
|
|
|
ti->second.AddPreBuildCommand(cc);
|
|
|
|
break;
|
|
|
|
case cmTarget::PRE_LINK:
|
|
|
|
ti->second.AddPreLinkCommand(cc);
|
|
|
|
break;
|
|
|
|
case cmTarget::POST_BUILD:
|
|
|
|
ti->second.AddPostBuildCommand(cc);
|
|
|
|
break;
|
2003-06-03 18:30:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-18 22:42:43 +04:00
|
|
|
cmSourceFile*
|
2006-04-11 19:06:19 +04:00
|
|
|
cmMakefile::AddCustomCommandToOutput(const std::vector<std::string>& outputs,
|
2014-11-14 02:54:52 +03:00
|
|
|
const std::vector<std::string>& byproducts,
|
2005-02-22 18:32:44 +03:00
|
|
|
const std::vector<std::string>& depends,
|
2014-02-25 05:32:55 +04:00
|
|
|
const std::string& main_dependency,
|
2005-02-22 18:32:44 +03:00
|
|
|
const cmCustomCommandLines& commandLines,
|
|
|
|
const char* comment,
|
2006-02-08 18:58:36 +03:00
|
|
|
const char* workingDir,
|
2006-09-28 19:30:49 +04:00
|
|
|
bool replace,
|
2014-11-05 23:37:52 +03:00
|
|
|
bool escapeOldStyle,
|
|
|
|
bool uses_terminal)
|
2003-06-03 18:30:23 +04:00
|
|
|
{
|
2006-04-11 19:06:19 +04:00
|
|
|
// Make sure there is at least one output.
|
|
|
|
if(outputs.empty())
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("Attempt to add a custom rule with no output!");
|
2012-04-18 22:42:43 +04:00
|
|
|
return 0;
|
2006-04-11 19:06:19 +04:00
|
|
|
}
|
|
|
|
|
2011-03-15 00:47:31 +03:00
|
|
|
// Validate custom commands. TODO: More strict?
|
|
|
|
for(cmCustomCommandLines::const_iterator i=commandLines.begin();
|
|
|
|
i != commandLines.end(); ++i)
|
|
|
|
{
|
|
|
|
cmCustomCommandLine const& cl = *i;
|
|
|
|
if(!cl.empty() && !cl[0].empty() && cl[0][0] == '"')
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2011-03-15 00:47:31 +03:00
|
|
|
e << "COMMAND may not contain literal quotes:\n " << cl[0] << "\n";
|
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
2012-04-18 22:42:43 +04:00
|
|
|
return 0;
|
2011-03-15 00:47:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-22 18:32:44 +03:00
|
|
|
// Choose a source file on which to store the custom command.
|
|
|
|
cmSourceFile* file = 0;
|
2014-03-13 01:29:04 +04:00
|
|
|
if(!commandLines.empty() && !main_dependency.empty())
|
2005-02-22 18:32:44 +03:00
|
|
|
{
|
|
|
|
// The main dependency was specified. Use it unless a different
|
|
|
|
// custom command already used it.
|
|
|
|
file = this->GetSource(main_dependency);
|
|
|
|
if(file && file->GetCustomCommand() && !replace)
|
2003-11-03 23:57:56 +03:00
|
|
|
{
|
2005-02-22 18:32:44 +03:00
|
|
|
// The main dependency already has a custom command.
|
|
|
|
if(commandLines == file->GetCustomCommand()->GetCommandLines())
|
2003-11-03 23:57:56 +03:00
|
|
|
{
|
2005-02-22 18:32:44 +03:00
|
|
|
// The existing custom command is identical. Silently ignore
|
|
|
|
// the duplicate.
|
2012-04-18 22:42:43 +04:00
|
|
|
return file;
|
2003-11-03 23:57:56 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-22 18:32:44 +03:00
|
|
|
// The existing custom command is different. We need to
|
|
|
|
// generate a rule file for this new command.
|
|
|
|
file = 0;
|
2003-06-04 22:00:30 +04:00
|
|
|
}
|
2003-06-03 18:30:23 +04:00
|
|
|
}
|
2014-03-12 02:04:11 +04:00
|
|
|
else if (!file)
|
2003-06-03 18:30:23 +04:00
|
|
|
{
|
2014-03-12 02:04:11 +04:00
|
|
|
file = this->CreateSource(main_dependency);
|
2003-06-03 18:30:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-22 18:32:44 +03:00
|
|
|
// Generate a rule file if the main dependency is not available.
|
|
|
|
if(!file)
|
2003-06-03 18:30:23 +04:00
|
|
|
{
|
2015-05-03 12:10:30 +03:00
|
|
|
cmGlobalGenerator* gg = this->GetGlobalGenerator();
|
2012-04-18 23:28:12 +04:00
|
|
|
|
2006-04-11 19:06:19 +04:00
|
|
|
// Construct a rule file associated with the first output produced.
|
2012-04-18 23:28:12 +04:00
|
|
|
std::string outName = gg->GenerateRuleFile(outputs[0]);
|
|
|
|
|
2005-02-22 18:32:44 +03:00
|
|
|
// Check if the rule file already exists.
|
2014-03-11 03:04:11 +04:00
|
|
|
file = this->GetSource(outName);
|
2005-02-22 18:32:44 +03:00
|
|
|
if(file && file->GetCustomCommand() && !replace)
|
2003-06-03 18:30:23 +04:00
|
|
|
{
|
2005-02-22 18:32:44 +03:00
|
|
|
// The rule file already exists.
|
|
|
|
if(commandLines != file->GetCustomCommand()->GetCommandLines())
|
2003-06-04 21:42:42 +04:00
|
|
|
{
|
2005-02-22 18:32:44 +03:00
|
|
|
cmSystemTools::Error("Attempt to add a custom rule to output \"",
|
2006-04-11 19:06:19 +04:00
|
|
|
outName.c_str(),
|
|
|
|
"\" which already has a custom rule.");
|
2003-06-04 21:42:42 +04:00
|
|
|
}
|
2012-04-18 22:42:43 +04:00
|
|
|
return file;
|
2003-06-03 18:30:23 +04:00
|
|
|
}
|
2005-02-22 18:32:44 +03:00
|
|
|
|
|
|
|
// Create a cmSourceFile for the rule file.
|
2014-03-12 02:04:11 +04:00
|
|
|
if (!file)
|
|
|
|
{
|
|
|
|
file = this->CreateSource(outName, true);
|
|
|
|
}
|
2014-07-14 20:55:04 +04:00
|
|
|
file->SetProperty("__CMAKE_RULE", "1");
|
2003-06-03 18:30:23 +04:00
|
|
|
}
|
2005-02-22 18:32:44 +03:00
|
|
|
|
2006-04-11 19:06:19 +04:00
|
|
|
// Always create the output sources and mark them generated.
|
|
|
|
for(std::vector<std::string>::const_iterator o = outputs.begin();
|
|
|
|
o != outputs.end(); ++o)
|
2004-08-05 01:24:21 +04:00
|
|
|
{
|
2014-03-11 03:04:11 +04:00
|
|
|
if(cmSourceFile* out = this->GetOrCreateSource(*o, true))
|
2006-04-11 19:06:19 +04:00
|
|
|
{
|
|
|
|
out->SetProperty("GENERATED", "1");
|
|
|
|
}
|
2004-08-05 01:24:21 +04:00
|
|
|
}
|
2014-11-14 02:54:52 +03:00
|
|
|
for(std::vector<std::string>::const_iterator o = byproducts.begin();
|
|
|
|
o != byproducts.end(); ++o)
|
|
|
|
{
|
|
|
|
if(cmSourceFile* out = this->GetOrCreateSource(*o, true))
|
|
|
|
{
|
|
|
|
out->SetProperty("GENERATED", "1");
|
|
|
|
}
|
|
|
|
}
|
2005-02-22 18:32:44 +03:00
|
|
|
|
|
|
|
// Attach the custom command to the file.
|
2004-08-05 01:24:21 +04:00
|
|
|
if(file)
|
2003-06-03 18:30:23 +04:00
|
|
|
{
|
2014-03-22 06:27:59 +04:00
|
|
|
// Construct a complete list of dependencies.
|
|
|
|
std::vector<std::string> depends2(depends);
|
|
|
|
if(!main_dependency.empty())
|
|
|
|
{
|
|
|
|
depends2.push_back(main_dependency);
|
|
|
|
}
|
|
|
|
|
2005-02-22 18:32:44 +03:00
|
|
|
cmCustomCommand* cc =
|
2014-11-14 02:54:52 +03:00
|
|
|
new cmCustomCommand(this, outputs, byproducts, depends2,
|
|
|
|
commandLines, comment, workingDir);
|
2006-09-28 19:30:49 +04:00
|
|
|
cc->SetEscapeOldStyle(escapeOldStyle);
|
2008-06-04 20:10:52 +04:00
|
|
|
cc->SetEscapeAllowMakeVars(true);
|
2014-11-05 23:37:52 +03:00
|
|
|
cc->SetUsesTerminal(uses_terminal);
|
2004-08-05 01:24:21 +04:00
|
|
|
file->SetCustomCommand(cc);
|
2013-08-06 20:12:50 +04:00
|
|
|
this->UpdateOutputToSourceMap(outputs, file);
|
2003-06-03 18:30:23 +04:00
|
|
|
}
|
2012-04-18 22:42:43 +04:00
|
|
|
return file;
|
2003-06-03 18:30:23 +04:00
|
|
|
}
|
|
|
|
|
2013-08-06 20:12:50 +04:00
|
|
|
void
|
|
|
|
cmMakefile::UpdateOutputToSourceMap(std::vector<std::string> const& outputs,
|
|
|
|
cmSourceFile* source)
|
|
|
|
{
|
|
|
|
for(std::vector<std::string>::const_iterator o = outputs.begin();
|
|
|
|
o != outputs.end(); ++o)
|
|
|
|
{
|
|
|
|
this->UpdateOutputToSourceMap(*o, source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmMakefile::UpdateOutputToSourceMap(std::string const& output,
|
|
|
|
cmSourceFile* source)
|
|
|
|
{
|
2013-09-30 17:27:49 +04:00
|
|
|
OutputToSourceMap::iterator i = this->OutputToSource.find(output);
|
|
|
|
if(i != this->OutputToSource.end())
|
|
|
|
{
|
|
|
|
// Multiple custom commands produce the same output but may
|
|
|
|
// be attached to a different source file (MAIN_DEPENDENCY).
|
|
|
|
// LinearGetSourceFileWithOutput would return the first one,
|
|
|
|
// so keep the mapping for the first one.
|
|
|
|
//
|
|
|
|
// TODO: Warn the user about this case. However, the VS 8 generator
|
|
|
|
// triggers it for separate generate.stamp rules in ZERO_CHECK and
|
|
|
|
// individual targets.
|
|
|
|
return;
|
|
|
|
}
|
2013-08-06 20:12:50 +04:00
|
|
|
this->OutputToSource[output] = source;
|
|
|
|
}
|
|
|
|
|
2012-04-18 22:42:43 +04:00
|
|
|
cmSourceFile*
|
2014-02-08 00:32:48 +04:00
|
|
|
cmMakefile::AddCustomCommandToOutput(const std::string& output,
|
2006-04-11 19:06:19 +04:00
|
|
|
const std::vector<std::string>& depends,
|
2014-02-25 05:32:55 +04:00
|
|
|
const std::string& main_dependency,
|
2006-04-11 19:06:19 +04:00
|
|
|
const cmCustomCommandLines& commandLines,
|
|
|
|
const char* comment,
|
|
|
|
const char* workingDir,
|
2006-09-28 19:30:49 +04:00
|
|
|
bool replace,
|
2014-11-05 23:37:52 +03:00
|
|
|
bool escapeOldStyle,
|
|
|
|
bool uses_terminal)
|
2006-04-11 19:06:19 +04:00
|
|
|
{
|
|
|
|
std::vector<std::string> outputs;
|
|
|
|
outputs.push_back(output);
|
2014-11-14 02:54:52 +03:00
|
|
|
std::vector<std::string> no_byproducts;
|
|
|
|
return this->AddCustomCommandToOutput(outputs, no_byproducts,
|
|
|
|
depends, main_dependency,
|
2012-04-18 22:42:43 +04:00
|
|
|
commandLines, comment, workingDir,
|
2014-11-05 23:37:52 +03:00
|
|
|
replace, escapeOldStyle,
|
|
|
|
uses_terminal);
|
2006-04-11 19:06:19 +04:00
|
|
|
}
|
|
|
|
|
2005-02-22 18:32:44 +03:00
|
|
|
void
|
2014-02-07 02:31:47 +04:00
|
|
|
cmMakefile::AddCustomCommandOldStyle(const std::string& target,
|
2005-02-22 18:32:44 +03:00
|
|
|
const std::vector<std::string>& outputs,
|
|
|
|
const std::vector<std::string>& depends,
|
2014-02-25 05:32:55 +04:00
|
|
|
const std::string& source,
|
2005-02-22 18:32:44 +03:00
|
|
|
const cmCustomCommandLines& commandLines,
|
|
|
|
const char* comment)
|
2003-06-06 00:45:06 +04:00
|
|
|
{
|
2005-02-22 18:32:44 +03:00
|
|
|
// Translate the old-style signature to one of the new-style
|
|
|
|
// signatures.
|
2014-02-07 02:31:47 +04:00
|
|
|
if(source == target)
|
2005-02-22 18:32:44 +03:00
|
|
|
{
|
|
|
|
// In the old-style signature if the source and target were the
|
|
|
|
// same then it added a post-build rule to the target. Preserve
|
|
|
|
// this behavior.
|
2014-11-14 02:54:52 +03:00
|
|
|
std::vector<std::string> no_byproducts;
|
|
|
|
this->AddCustomCommandToTarget(target, no_byproducts,
|
|
|
|
depends, commandLines,
|
2006-02-08 18:58:36 +03:00
|
|
|
cmTarget::POST_BUILD, comment, 0);
|
2005-02-22 18:32:44 +03:00
|
|
|
return;
|
|
|
|
}
|
2003-06-06 00:45:06 +04:00
|
|
|
|
2005-02-22 18:32:44 +03:00
|
|
|
// Each output must get its own copy of this rule.
|
|
|
|
cmsys::RegularExpression sourceFiles("\\.(C|M|c|c\\+\\+|cc|cpp|cxx|m|mm|"
|
|
|
|
"rc|def|r|odl|idl|hpj|bat|h|h\\+\\+|"
|
|
|
|
"hm|hpp|hxx|in|txx|inl)$");
|
|
|
|
for(std::vector<std::string>::const_iterator oi = outputs.begin();
|
|
|
|
oi != outputs.end(); ++oi)
|
2001-04-11 22:59:02 +04:00
|
|
|
{
|
2005-02-22 18:32:44 +03:00
|
|
|
// Get the name of this output.
|
|
|
|
const char* output = oi->c_str();
|
2012-04-18 22:42:43 +04:00
|
|
|
cmSourceFile* sf;
|
2005-02-22 18:32:44 +03:00
|
|
|
|
|
|
|
// Choose whether to use a main dependency.
|
|
|
|
if(sourceFiles.find(source))
|
2002-12-11 00:47:37 +03:00
|
|
|
{
|
2005-02-22 18:32:44 +03:00
|
|
|
// The source looks like a real file. Use it as the main dependency.
|
2012-04-18 22:42:43 +04:00
|
|
|
sf = this->AddCustomCommandToOutput(output, depends, source,
|
|
|
|
commandLines, comment, 0);
|
2002-12-11 00:47:37 +03:00
|
|
|
}
|
2005-02-22 18:32:44 +03:00
|
|
|
else
|
2003-06-03 18:30:23 +04:00
|
|
|
{
|
2005-02-22 18:32:44 +03:00
|
|
|
// The source may not be a real file. Do not use a main dependency.
|
2014-02-25 05:32:55 +04:00
|
|
|
std::string no_main_dependency = "";
|
2005-02-22 18:32:44 +03:00
|
|
|
std::vector<std::string> depends2 = depends;
|
|
|
|
depends2.push_back(source);
|
2012-04-18 22:42:43 +04:00
|
|
|
sf = this->AddCustomCommandToOutput(output, depends2, no_main_dependency,
|
|
|
|
commandLines, comment, 0);
|
2003-06-03 18:30:23 +04:00
|
|
|
}
|
2005-02-22 18:32:44 +03:00
|
|
|
|
|
|
|
// If the rule was added to the source (and not a .rule file),
|
|
|
|
// then add the source to the target to make sure the rule is
|
|
|
|
// included.
|
2012-04-18 22:42:43 +04:00
|
|
|
if(sf && !sf->GetPropertyAsBool("__CMAKE_RULE"))
|
2001-06-07 22:52:29 +04:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
if (this->Targets.find(target) != this->Targets.end())
|
2005-02-22 18:32:44 +03:00
|
|
|
{
|
2014-03-12 15:45:14 +04:00
|
|
|
this->Targets[target].AddSource(sf->GetFullPath());
|
2005-02-22 18:32:44 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("Attempt to add a custom rule to a target "
|
2014-02-07 02:31:47 +04:00
|
|
|
"that does not exist yet for target ",
|
|
|
|
target.c_str());
|
2005-02-22 18:32:44 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-06-07 22:52:29 +04:00
|
|
|
}
|
2001-04-11 22:59:02 +04:00
|
|
|
}
|
2001-03-20 21:20:59 +03:00
|
|
|
}
|
2001-01-05 19:41:20 +03:00
|
|
|
|
2015-07-29 17:41:30 +03:00
|
|
|
cmTarget*
|
|
|
|
cmMakefile::AddUtilityCommand(const std::string& utilityName,
|
|
|
|
bool excludeFromAll,
|
|
|
|
const std::vector<std::string>& depends,
|
|
|
|
const char* workingDirectory,
|
|
|
|
const char* command,
|
|
|
|
const char* arg1,
|
|
|
|
const char* arg2,
|
|
|
|
const char* arg3,
|
|
|
|
const char* arg4)
|
2005-02-22 18:32:44 +03:00
|
|
|
{
|
|
|
|
// Construct the command line for the custom command.
|
|
|
|
cmCustomCommandLine commandLine;
|
|
|
|
commandLine.push_back(command);
|
|
|
|
if(arg1)
|
|
|
|
{
|
|
|
|
commandLine.push_back(arg1);
|
|
|
|
}
|
|
|
|
if(arg2)
|
|
|
|
{
|
|
|
|
commandLine.push_back(arg2);
|
|
|
|
}
|
|
|
|
if(arg3)
|
|
|
|
{
|
|
|
|
commandLine.push_back(arg3);
|
|
|
|
}
|
2005-06-17 00:33:24 +04:00
|
|
|
if(arg4)
|
|
|
|
{
|
|
|
|
commandLine.push_back(arg4);
|
|
|
|
}
|
2005-02-22 18:32:44 +03:00
|
|
|
cmCustomCommandLines commandLines;
|
|
|
|
commandLines.push_back(commandLine);
|
|
|
|
|
|
|
|
// Call the real signature of this method.
|
2015-07-29 17:41:30 +03:00
|
|
|
return this->AddUtilityCommand(utilityName, excludeFromAll, workingDirectory,
|
|
|
|
depends, commandLines);
|
2005-02-22 18:32:44 +03:00
|
|
|
}
|
|
|
|
|
2008-10-09 19:00:54 +04:00
|
|
|
cmTarget*
|
2014-02-08 08:55:28 +04:00
|
|
|
cmMakefile::AddUtilityCommand(const std::string& utilityName,
|
2008-10-09 19:00:54 +04:00
|
|
|
bool excludeFromAll,
|
|
|
|
const char* workingDirectory,
|
|
|
|
const std::vector<std::string>& depends,
|
|
|
|
const cmCustomCommandLines& commandLines,
|
2014-11-05 23:37:52 +03:00
|
|
|
bool escapeOldStyle, const char* comment,
|
|
|
|
bool uses_terminal)
|
2014-11-14 02:54:52 +03:00
|
|
|
{
|
|
|
|
std::vector<std::string> no_byproducts;
|
|
|
|
return this->AddUtilityCommand(utilityName, excludeFromAll, workingDirectory,
|
|
|
|
no_byproducts, depends, commandLines,
|
|
|
|
escapeOldStyle, comment, uses_terminal);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmTarget*
|
|
|
|
cmMakefile::AddUtilityCommand(const std::string& utilityName,
|
|
|
|
bool excludeFromAll,
|
|
|
|
const char* workingDirectory,
|
|
|
|
const std::vector<std::string>& byproducts,
|
|
|
|
const std::vector<std::string>& depends,
|
|
|
|
const cmCustomCommandLines& commandLines,
|
|
|
|
bool escapeOldStyle, const char* comment,
|
|
|
|
bool uses_terminal)
|
2005-02-22 18:32:44 +03:00
|
|
|
{
|
|
|
|
// Create a target instance for this utility.
|
2015-10-08 01:21:51 +03:00
|
|
|
cmTarget* target = this->AddNewTarget(cmState::UTILITY, utilityName);
|
2007-03-13 22:18:27 +03:00
|
|
|
if (excludeFromAll)
|
|
|
|
{
|
2007-05-22 18:24:59 +04:00
|
|
|
target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
|
2007-03-13 22:18:27 +03:00
|
|
|
}
|
2006-10-05 02:10:30 +04:00
|
|
|
if(!comment)
|
|
|
|
{
|
|
|
|
// Use an empty comment to avoid generation of default comment.
|
|
|
|
comment = "";
|
|
|
|
}
|
|
|
|
|
2005-02-22 18:32:44 +03:00
|
|
|
// Store the custom command in the target.
|
2014-03-13 01:29:04 +04:00
|
|
|
if (!commandLines.empty() || !depends.empty())
|
2006-10-02 18:20:53 +04:00
|
|
|
{
|
2015-04-16 21:06:54 +03:00
|
|
|
std::string force = this->GetCurrentBinaryDirectory();
|
2014-03-13 01:29:04 +04:00
|
|
|
force += cmake::GetCMakeFilesDirectory();
|
|
|
|
force += "/";
|
|
|
|
force += utilityName;
|
2014-11-14 02:54:52 +03:00
|
|
|
std::vector<std::string> forced;
|
|
|
|
forced.push_back(force);
|
2014-03-13 01:29:04 +04:00
|
|
|
std::string no_main_dependency = "";
|
|
|
|
bool no_replace = false;
|
2014-11-14 02:54:52 +03:00
|
|
|
this->AddCustomCommandToOutput(forced, byproducts,
|
|
|
|
depends, no_main_dependency,
|
2014-03-13 01:29:04 +04:00
|
|
|
commandLines, comment,
|
|
|
|
workingDirectory, no_replace,
|
2014-11-05 23:37:52 +03:00
|
|
|
escapeOldStyle, uses_terminal);
|
2014-03-13 01:29:04 +04:00
|
|
|
cmSourceFile* sf = target->AddSourceCMP0049(force);
|
|
|
|
|
|
|
|
// The output is not actually created so mark it symbolic.
|
|
|
|
if(sf)
|
|
|
|
{
|
|
|
|
sf->SetProperty("SYMBOLIC", "1");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("Could not get source file entry for ",
|
|
|
|
force.c_str());
|
|
|
|
}
|
2014-11-14 02:54:52 +03:00
|
|
|
|
|
|
|
// Always create the byproduct sources and mark them generated.
|
|
|
|
for(std::vector<std::string>::const_iterator o = byproducts.begin();
|
|
|
|
o != byproducts.end(); ++o)
|
|
|
|
{
|
|
|
|
if(cmSourceFile* out = this->GetOrCreateSource(*o, true))
|
|
|
|
{
|
|
|
|
out->SetProperty("GENERATED", "1");
|
|
|
|
}
|
|
|
|
}
|
2006-10-02 18:20:53 +04:00
|
|
|
}
|
2008-10-09 19:00:54 +04:00
|
|
|
return target;
|
2005-02-22 18:32:44 +03:00
|
|
|
}
|
|
|
|
|
2001-01-05 19:41:20 +03:00
|
|
|
void cmMakefile::AddDefineFlag(const char* flag)
|
|
|
|
{
|
2007-03-07 19:03:57 +03:00
|
|
|
if (!flag)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-26 21:30:10 +04:00
|
|
|
// Update the string used for the old DEFINITIONS property.
|
|
|
|
this->AddDefineFlag(flag, this->DefineFlagsOrig);
|
|
|
|
|
2008-01-18 03:29:43 +03:00
|
|
|
// If this is really a definition, update COMPILE_DEFINITIONS.
|
|
|
|
if(this->ParseDefineFlag(flag, false))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-26 21:30:10 +04:00
|
|
|
// Add this flag that does not look like a definition.
|
|
|
|
this->AddDefineFlag(flag, this->DefineFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefile::AddDefineFlag(const char* flag, std::string& dflags)
|
|
|
|
{
|
2007-03-07 19:03:57 +03:00
|
|
|
// remove any \n\r
|
2015-02-18 02:44:45 +03:00
|
|
|
std::string::size_type initSize = dflags.size();
|
|
|
|
dflags += std::string(" ") + flag;
|
|
|
|
std::string::iterator flagStart = dflags.begin() + initSize + 1;
|
|
|
|
std::replace(flagStart, dflags.end(), '\n', ' ');
|
|
|
|
std::replace(flagStart, dflags.end(), '\r', ' ');
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|
|
|
|
|
2001-03-09 18:53:32 +03:00
|
|
|
|
2004-04-15 21:58:10 +04:00
|
|
|
void cmMakefile::RemoveDefineFlag(const char* flag)
|
|
|
|
{
|
2006-05-23 20:51:26 +04:00
|
|
|
// Check the length of the flag to remove.
|
|
|
|
std::string::size_type len = strlen(flag);
|
|
|
|
if(len < 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-26 21:30:10 +04:00
|
|
|
// Update the string used for the old DEFINITIONS property.
|
|
|
|
this->RemoveDefineFlag(flag, len, this->DefineFlagsOrig);
|
|
|
|
|
2008-01-18 03:29:43 +03:00
|
|
|
// If this is really a definition, update COMPILE_DEFINITIONS.
|
|
|
|
if(this->ParseDefineFlag(flag, true))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-26 21:30:10 +04:00
|
|
|
// Remove this flag that does not look like a definition.
|
|
|
|
this->RemoveDefineFlag(flag, len, this->DefineFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefile::RemoveDefineFlag(const char* flag,
|
|
|
|
std::string::size_type len,
|
|
|
|
std::string& dflags)
|
|
|
|
{
|
2006-05-23 20:51:26 +04:00
|
|
|
// Remove all instances of the flag that are surrounded by
|
|
|
|
// whitespace or the beginning/end of the string.
|
2008-06-26 21:30:10 +04:00
|
|
|
for(std::string::size_type lpos = dflags.find(flag, 0);
|
|
|
|
lpos != std::string::npos; lpos = dflags.find(flag, lpos))
|
2006-05-23 20:51:26 +04:00
|
|
|
{
|
|
|
|
std::string::size_type rpos = lpos + len;
|
2008-06-26 21:30:10 +04:00
|
|
|
if((lpos <= 0 || isspace(dflags[lpos-1])) &&
|
|
|
|
(rpos >= dflags.size() || isspace(dflags[rpos])))
|
2006-05-23 20:51:26 +04:00
|
|
|
{
|
2008-06-26 21:30:10 +04:00
|
|
|
dflags.erase(lpos, len);
|
2006-05-23 20:51:26 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++lpos;
|
|
|
|
}
|
|
|
|
}
|
2004-04-15 21:58:10 +04:00
|
|
|
}
|
|
|
|
|
2013-06-04 12:30:24 +04:00
|
|
|
void cmMakefile::AddCompileOption(const char* option)
|
|
|
|
{
|
|
|
|
this->AppendProperty("COMPILE_OPTIONS", option);
|
|
|
|
}
|
|
|
|
|
2008-01-18 03:29:43 +03:00
|
|
|
bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove)
|
|
|
|
{
|
|
|
|
// Create a regular expression to match valid definitions.
|
|
|
|
static cmsys::RegularExpression
|
2008-03-14 00:38:51 +03:00
|
|
|
valid("^[-/]D[A-Za-z_][A-Za-z0-9_]*(=.*)?$");
|
2008-01-18 03:29:43 +03:00
|
|
|
|
|
|
|
// Make sure the definition matches.
|
2008-03-14 00:11:57 +03:00
|
|
|
if(!valid.find(def.c_str()))
|
2008-01-18 03:29:43 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-03-14 00:11:57 +03:00
|
|
|
// Definitions with non-trivial values require a policy check.
|
|
|
|
static cmsys::RegularExpression
|
|
|
|
trivial("^[-/]D[A-Za-z_][A-Za-z0-9_]*(=[A-Za-z0-9_.]+)?$");
|
|
|
|
if(!trivial.find(def.c_str()))
|
|
|
|
{
|
|
|
|
// This definition has a non-trivial value.
|
|
|
|
switch(this->GetPolicyStatus(cmPolicies::CMP0005))
|
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
|
|
|
this->IssueMessage(
|
|
|
|
cmake::AUTHOR_WARNING,
|
2015-05-03 11:12:10 +03:00
|
|
|
cmPolicies::GetPolicyWarning(cmPolicies::CMP0005)
|
2008-03-14 00:11:57 +03:00
|
|
|
);
|
|
|
|
case cmPolicies::OLD:
|
|
|
|
// OLD behavior is to not escape the value. We should not
|
|
|
|
// convert the definition to use the property.
|
|
|
|
return false;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
|
|
this->IssueMessage(
|
|
|
|
cmake::FATAL_ERROR,
|
2015-05-03 11:12:10 +03:00
|
|
|
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0005)
|
2008-03-14 00:11:57 +03:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
case cmPolicies::NEW:
|
|
|
|
// NEW behavior is to escape the value. Proceed to convert it
|
|
|
|
// to an entry in the property.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-18 03:29:43 +03:00
|
|
|
// Get the definition part after the flag.
|
|
|
|
const char* define = def.c_str() + 2;
|
|
|
|
|
|
|
|
if(remove)
|
|
|
|
{
|
|
|
|
if(const char* cdefs = this->GetProperty("COMPILE_DEFINITIONS"))
|
|
|
|
{
|
|
|
|
// Expand the list.
|
|
|
|
std::vector<std::string> defs;
|
|
|
|
cmSystemTools::ExpandListArgument(cdefs, defs);
|
|
|
|
|
|
|
|
// Recompose the list without the definition.
|
2015-01-28 00:39:46 +03:00
|
|
|
std::vector<std::string>::const_iterator defEnd =
|
|
|
|
std::remove(defs.begin(), defs.end(), define);
|
|
|
|
std::vector<std::string>::const_iterator defBegin =
|
|
|
|
defs.begin();
|
2015-07-18 11:45:18 +03:00
|
|
|
std::string ndefs = cmJoin(cmMakeRange(defBegin, defEnd), ";");
|
2008-01-18 03:29:43 +03:00
|
|
|
|
|
|
|
// Store the new list.
|
|
|
|
this->SetProperty("COMPILE_DEFINITIONS", ndefs.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Append the definition to the directory property.
|
|
|
|
this->AppendProperty("COMPILE_DEFINITIONS", define);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-07 02:31:47 +04:00
|
|
|
void cmMakefile::AddLinkLibrary(const std::string& lib,
|
2015-10-10 14:56:36 +03:00
|
|
|
cmTargetLinkLibraryType llt)
|
2001-04-27 00:22:53 +04:00
|
|
|
{
|
2006-11-30 01:10:29 +03:00
|
|
|
cmTarget::LibraryID tmp;
|
2006-11-29 23:45:49 +03:00
|
|
|
tmp.first = lib;
|
|
|
|
tmp.second = llt;
|
|
|
|
this->LinkLibraries.push_back(tmp);
|
2001-04-30 18:44:00 +04:00
|
|
|
}
|
|
|
|
|
2014-02-07 02:31:47 +04:00
|
|
|
void cmMakefile::AddLinkLibraryForTarget(const std::string& target,
|
|
|
|
const std::string& lib,
|
2015-10-10 14:56:36 +03:00
|
|
|
cmTargetLinkLibraryType llt)
|
2007-06-08 19:57:16 +04:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
cmTargets::iterator i = this->Targets.find(target);
|
|
|
|
if ( i != this->Targets.end())
|
2001-04-30 18:44:00 +04:00
|
|
|
{
|
2015-05-03 12:10:30 +03:00
|
|
|
cmTarget* tgt = this->GetGlobalGenerator()->FindTarget(lib);
|
2006-05-05 01:54:31 +04:00
|
|
|
if(tgt)
|
|
|
|
{
|
|
|
|
// if it is not a static or shared library then you can not link to it
|
2015-10-08 01:21:51 +03:00
|
|
|
if(!((tgt->GetType() == cmState::STATIC_LIBRARY) ||
|
|
|
|
(tgt->GetType() == cmState::SHARED_LIBRARY) ||
|
|
|
|
(tgt->GetType() == cmState::INTERFACE_LIBRARY) ||
|
2008-01-28 16:38:36 +03:00
|
|
|
tgt->IsExecutableWithExports()))
|
2006-05-19 21:02:12 +04:00
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2008-08-19 18:28:22 +04:00
|
|
|
e << "Target \"" << lib << "\" of type "
|
2015-10-08 01:26:50 +03:00
|
|
|
<< cmState::GetTargetTypeName(tgt->GetType())
|
2008-08-19 18:28:22 +04:00
|
|
|
<< " may not be linked into another target. "
|
|
|
|
<< "One may link only to STATIC or SHARED libraries, or "
|
2007-03-22 16:45:25 +03:00
|
|
|
<< "to executables with the ENABLE_EXPORTS property set.";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
2006-05-05 01:54:31 +04:00
|
|
|
}
|
|
|
|
}
|
2002-05-02 21:17:10 +04:00
|
|
|
i->second.AddLinkLibrary( *this, target, lib, llt );
|
2001-04-30 18:44:00 +04:00
|
|
|
}
|
2001-07-11 00:20:24 +04:00
|
|
|
else
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2006-03-14 17:37:50 +03:00
|
|
|
e << "Attempt to add link library \""
|
|
|
|
<< lib << "\" to target \""
|
2010-12-15 20:18:59 +03:00
|
|
|
<< target << "\" which is not built in this directory.";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
2001-07-11 00:20:24 +04:00
|
|
|
}
|
2001-04-27 00:22:53 +04:00
|
|
|
}
|
|
|
|
|
2014-02-07 02:31:47 +04:00
|
|
|
void cmMakefile::AddLinkDirectoryForTarget(const std::string& target,
|
|
|
|
const std::string& d)
|
2002-05-02 21:17:10 +04:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
cmTargets::iterator i = this->Targets.find(target);
|
|
|
|
if ( i != this->Targets.end())
|
2002-05-02 21:17:10 +04:00
|
|
|
{
|
2013-07-12 11:14:31 +04:00
|
|
|
if(this->IsAlias(target))
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2013-07-12 11:14:31 +04:00
|
|
|
e << "ALIAS target \"" << target << "\" "
|
|
|
|
<< "may not be linked into another target.";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
2013-07-12 11:14:31 +04:00
|
|
|
return;
|
|
|
|
}
|
2002-05-02 21:17:10 +04:00
|
|
|
i->second.AddLinkDirectory( d );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-12 20:29:09 +04:00
|
|
|
cmSystemTools::Error
|
2013-05-01 13:36:14 +04:00
|
|
|
("Attempt to add link directories to non-existent target: ",
|
2014-02-07 02:31:47 +04:00
|
|
|
target.c_str(), " for directory ", d.c_str());
|
2002-05-02 21:17:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-07 02:31:47 +04:00
|
|
|
void cmMakefile::AddLinkLibrary(const std::string& lib)
|
2001-01-05 19:41:20 +03:00
|
|
|
{
|
2015-10-10 14:56:36 +03:00
|
|
|
this->AddLinkLibrary(lib,GENERAL_LibraryType);
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|
|
|
|
|
2015-06-06 10:17:45 +03:00
|
|
|
void cmMakefile::InitializeFromParent(cmMakefile* parent)
|
2005-03-18 18:41:41 +03:00
|
|
|
{
|
2006-10-05 16:55:59 +04:00
|
|
|
this->SystemIncludeDirectories = parent->SystemIncludeDirectories;
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2005-03-18 18:41:41 +03:00
|
|
|
// define flags
|
2006-03-15 19:02:08 +03:00
|
|
|
this->DefineFlags = parent->DefineFlags;
|
2008-10-09 21:52:25 +04:00
|
|
|
this->DefineFlagsOrig = parent->DefineFlagsOrig;
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2008-05-14 19:54:52 +04:00
|
|
|
// Include transform property. There is no per-config version.
|
|
|
|
{
|
|
|
|
const char* prop = "IMPLICIT_DEPENDS_INCLUDE_TRANSFORM";
|
|
|
|
this->SetProperty(prop, parent->GetProperty(prop));
|
|
|
|
}
|
|
|
|
|
2008-01-18 04:34:10 +03:00
|
|
|
// compile definitions property and per-config versions
|
2013-12-30 16:33:02 +04:00
|
|
|
cmPolicies::PolicyStatus polSt = this->GetPolicyStatus(cmPolicies::CMP0043);
|
|
|
|
if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD)
|
|
|
|
{
|
|
|
|
this->SetProperty("COMPILE_DEFINITIONS",
|
|
|
|
parent->GetProperty("COMPILE_DEFINITIONS"));
|
|
|
|
std::vector<std::string> configs;
|
|
|
|
this->GetConfigurations(configs);
|
|
|
|
for(std::vector<std::string>::const_iterator ci = configs.begin();
|
|
|
|
ci != configs.end(); ++ci)
|
|
|
|
{
|
|
|
|
std::string defPropName = "COMPILE_DEFINITIONS_";
|
|
|
|
defPropName += cmSystemTools::UpperCase(*ci);
|
2014-03-11 03:04:11 +04:00
|
|
|
const char* prop = parent->GetProperty(defPropName);
|
|
|
|
this->SetProperty(defPropName, prop);
|
2013-12-30 16:33:02 +04:00
|
|
|
}
|
2008-01-18 04:34:10 +03:00
|
|
|
}
|
2008-01-18 03:50:39 +03:00
|
|
|
|
2005-03-18 18:41:41 +03:00
|
|
|
// link libraries
|
2006-03-15 19:02:08 +03:00
|
|
|
this->LinkLibraries = parent->LinkLibraries;
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2005-03-22 18:23:04 +03:00
|
|
|
// link directories
|
2015-07-18 14:52:46 +03:00
|
|
|
this->SetProperty("LINK_DIRECTORIES",
|
|
|
|
parent->GetProperty("LINK_DIRECTORIES"));
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2005-03-18 18:41:41 +03:00
|
|
|
// the initial project name
|
2015-10-07 01:17:20 +03:00
|
|
|
this->StateSnapshot.SetProjectName(parent->StateSnapshot.GetProjectName());
|
2005-07-28 01:23:39 +04:00
|
|
|
|
|
|
|
// Copy include regular expressions.
|
2006-03-15 19:02:08 +03:00
|
|
|
this->ComplainFileRegularExpression = parent->ComplainFileRegularExpression;
|
2008-01-28 16:38:36 +03:00
|
|
|
|
|
|
|
// Imported targets.
|
|
|
|
this->ImportedTargets = parent->ImportedTargets;
|
2005-03-18 18:41:41 +03:00
|
|
|
}
|
|
|
|
|
2015-05-31 20:37:08 +03:00
|
|
|
void cmMakefile::PushFunctionScope(std::string const& fileName,
|
|
|
|
const cmPolicies::PolicyMap& pm)
|
2015-05-31 19:19:58 +03:00
|
|
|
{
|
2015-06-21 22:26:36 +03:00
|
|
|
this->StateSnapshot =
|
|
|
|
this->GetState()->CreateFunctionCallSnapshot(
|
2016-04-14 18:24:08 +03:00
|
|
|
this->StateSnapshot, fileName);
|
2015-06-21 22:26:36 +03:00
|
|
|
assert(this->StateSnapshot.IsValid());
|
|
|
|
|
2015-06-01 00:45:52 +03:00
|
|
|
this->PushLoopBlockBarrier();
|
|
|
|
|
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
|
|
|
this->GetGlobalGenerator()->GetFileLockPool().PushFunctionScope();
|
|
|
|
#endif
|
2015-05-31 19:19:58 +03:00
|
|
|
|
|
|
|
this->PushFunctionBlockerBarrier();
|
|
|
|
|
|
|
|
this->PushPolicy(true, pm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefile::PopFunctionScope(bool reportError)
|
|
|
|
{
|
|
|
|
this->PopPolicy();
|
|
|
|
|
2015-11-24 19:44:57 +03:00
|
|
|
this->PopSnapshot(reportError);
|
2015-06-21 22:26:36 +03:00
|
|
|
|
2015-05-31 19:19:58 +03:00
|
|
|
this->PopFunctionBlockerBarrier(reportError);
|
|
|
|
|
2015-06-01 00:45:52 +03:00
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
|
|
|
this->GetGlobalGenerator()->GetFileLockPool().PopFunctionScope();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
this->PopLoopBlockBarrier();
|
|
|
|
|
|
|
|
this->CheckForUnusedVariables();
|
2015-05-31 19:19:58 +03:00
|
|
|
}
|
|
|
|
|
2015-05-31 20:37:08 +03:00
|
|
|
void cmMakefile::PushMacroScope(std::string const& fileName,
|
|
|
|
const cmPolicies::PolicyMap& pm)
|
2015-05-31 19:32:01 +03:00
|
|
|
{
|
2015-06-21 22:26:36 +03:00
|
|
|
this->StateSnapshot =
|
|
|
|
this->GetState()->CreateMacroCallSnapshot(
|
2016-04-14 18:24:08 +03:00
|
|
|
this->StateSnapshot, fileName);
|
2015-06-21 22:26:36 +03:00
|
|
|
assert(this->StateSnapshot.IsValid());
|
|
|
|
|
2015-05-31 19:32:01 +03:00
|
|
|
this->PushFunctionBlockerBarrier();
|
|
|
|
|
|
|
|
this->PushPolicy(true, pm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefile::PopMacroScope(bool reportError)
|
|
|
|
{
|
|
|
|
this->PopPolicy();
|
2015-11-24 19:44:57 +03:00
|
|
|
this->PopSnapshot(reportError);
|
2015-06-21 22:26:36 +03:00
|
|
|
|
2015-05-31 19:32:01 +03:00
|
|
|
this->PopFunctionBlockerBarrier(reportError);
|
|
|
|
}
|
|
|
|
|
2015-06-06 15:07:15 +03:00
|
|
|
bool cmMakefile::IsRootMakefile() const
|
|
|
|
{
|
|
|
|
return !this->StateSnapshot.GetBuildsystemDirectoryParent().IsValid();
|
|
|
|
}
|
|
|
|
|
2015-06-22 00:13:24 +03:00
|
|
|
class cmMakefile::BuildsystemFileScope
|
|
|
|
{
|
|
|
|
public:
|
2015-06-22 00:19:50 +03:00
|
|
|
BuildsystemFileScope(cmMakefile* mf)
|
2015-06-22 00:13:24 +03:00
|
|
|
: Makefile(mf), ReportError(true)
|
|
|
|
{
|
2015-06-22 00:19:50 +03:00
|
|
|
std::string currentStart =
|
2015-07-18 20:11:05 +03:00
|
|
|
this->Makefile->StateSnapshot.GetDirectory().GetCurrentSource();
|
2015-06-22 00:19:50 +03:00
|
|
|
currentStart += "/CMakeLists.txt";
|
2015-05-31 20:37:08 +03:00
|
|
|
this->Makefile->StateSnapshot.SetListFile(currentStart);
|
2015-07-26 13:56:10 +03:00
|
|
|
this->Makefile->StateSnapshot = this->Makefile->StateSnapshot.GetState()
|
|
|
|
->CreatePolicyScopeSnapshot(this->Makefile->StateSnapshot);
|
2015-06-22 00:13:24 +03:00
|
|
|
this->Makefile->PushFunctionBlockerBarrier();
|
2015-06-26 01:13:22 +03:00
|
|
|
|
|
|
|
this->GG = mf->GetGlobalGenerator();
|
|
|
|
this->CurrentMakefile = this->GG->GetCurrentMakefile();
|
|
|
|
this->Snapshot = this->GG->GetCMakeInstance()->GetCurrentSnapshot();
|
2015-07-08 00:50:54 +03:00
|
|
|
this->GG->GetCMakeInstance()->SetCurrentSnapshot(this->Snapshot);
|
2015-06-26 01:13:22 +03:00
|
|
|
this->GG->SetCurrentMakefile(mf);
|
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
|
|
|
this->GG->GetFileLockPool().PushFileScope();
|
|
|
|
#endif
|
2015-06-22 00:13:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
~BuildsystemFileScope()
|
|
|
|
{
|
|
|
|
this->Makefile->PopFunctionBlockerBarrier(this->ReportError);
|
2015-11-24 19:44:57 +03:00
|
|
|
this->Makefile->PopSnapshot(this->ReportError);
|
2015-06-26 01:13:22 +03:00
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
|
|
|
this->GG->GetFileLockPool().PopFileScope();
|
|
|
|
#endif
|
|
|
|
this->GG->SetCurrentMakefile(this->CurrentMakefile);
|
|
|
|
this->GG->GetCMakeInstance()->SetCurrentSnapshot(this->Snapshot);
|
2015-06-22 00:13:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Quiet() { this->ReportError = false; }
|
|
|
|
private:
|
|
|
|
cmMakefile* Makefile;
|
2015-06-26 01:13:22 +03:00
|
|
|
cmGlobalGenerator* GG;
|
|
|
|
cmMakefile* CurrentMakefile;
|
|
|
|
cmState::Snapshot Snapshot;
|
2015-06-22 00:13:24 +03:00
|
|
|
bool ReportError;
|
|
|
|
};
|
|
|
|
|
2015-05-30 20:50:58 +03:00
|
|
|
void cmMakefile::Configure()
|
|
|
|
{
|
2016-04-14 18:24:08 +03:00
|
|
|
std::string currentStart =
|
|
|
|
this->StateSnapshot.GetDirectory().GetCurrentSource();
|
|
|
|
currentStart += "/CMakeLists.txt";
|
|
|
|
|
|
|
|
// Add the bottom of all backtraces within this directory.
|
|
|
|
// We will never pop this scope because it should be available
|
|
|
|
// for messages during the generate step too.
|
|
|
|
this->Backtrace = this->Backtrace.Push(currentStart);
|
|
|
|
|
2015-06-26 01:11:10 +03:00
|
|
|
BuildsystemFileScope scope(this);
|
2015-05-30 20:50:58 +03:00
|
|
|
|
|
|
|
// make sure the CMakeFiles dir is there
|
2015-07-18 20:11:05 +03:00
|
|
|
std::string filesDir = this->StateSnapshot.GetDirectory().GetCurrentBinary();
|
2015-05-30 20:50:58 +03:00
|
|
|
filesDir += cmake::GetCMakeFilesDirectory();
|
|
|
|
cmSystemTools::MakeDirectory(filesDir.c_str());
|
|
|
|
|
|
|
|
assert(cmSystemTools::FileExists(currentStart.c_str(), true));
|
2015-06-22 00:13:24 +03:00
|
|
|
this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentStart.c_str());
|
|
|
|
|
|
|
|
cmListFile listFile;
|
|
|
|
if (!listFile.ParseFile(currentStart.c_str(), this->IsRootMakefile(), this))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->ReadListFile(listFile, currentStart);
|
|
|
|
if(cmSystemTools::GetFatalErrorOccured())
|
|
|
|
{
|
|
|
|
scope.Quiet();
|
|
|
|
}
|
2015-05-30 20:50:58 +03:00
|
|
|
|
|
|
|
// at the end handle any old style subdirs
|
2015-06-03 01:55:00 +03:00
|
|
|
std::vector<cmMakefile*> subdirs = this->UnConfiguredDirectories;
|
2015-05-30 20:50:58 +03:00
|
|
|
|
|
|
|
// for each subdir recurse
|
2015-06-03 01:55:00 +03:00
|
|
|
std::vector<cmMakefile*>::iterator sdi = subdirs.begin();
|
2015-05-30 20:50:58 +03:00
|
|
|
for (; sdi != subdirs.end(); ++sdi)
|
|
|
|
{
|
2015-10-12 20:34:06 +03:00
|
|
|
(*sdi)->StateSnapshot.InitializeFromParent_ForSubdirsCommand();
|
2015-06-03 01:55:00 +03:00
|
|
|
this->ConfigureSubDirectory(*sdi);
|
2015-05-30 20:50:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
this->AddCMakeDependFilesFromUser();
|
|
|
|
}
|
|
|
|
|
2015-05-30 20:53:02 +03:00
|
|
|
void cmMakefile::ConfigureSubDirectory(cmMakefile *mf)
|
2005-03-18 18:41:41 +03:00
|
|
|
{
|
2015-06-06 10:17:45 +03:00
|
|
|
mf->InitializeFromParent(this);
|
2015-05-30 20:53:02 +03:00
|
|
|
std::string currentStart = mf->GetCurrentSourceDirectory();
|
2007-07-20 16:48:32 +04:00
|
|
|
if (this->GetCMakeInstance()->GetDebugOutput())
|
|
|
|
{
|
|
|
|
std::string msg=" Entering ";
|
2015-05-14 22:18:06 +03:00
|
|
|
msg += currentStart;
|
2007-07-20 16:48:32 +04:00
|
|
|
cmSystemTools::Message(msg.c_str());
|
|
|
|
}
|
2015-05-14 22:18:06 +03:00
|
|
|
|
2015-08-04 23:39:31 +03:00
|
|
|
std::string const currentStartFile = currentStart + "/CMakeLists.txt";
|
|
|
|
if (!cmSystemTools::FileExists(currentStartFile, true))
|
2015-05-14 22:18:06 +03:00
|
|
|
{
|
|
|
|
// The file is missing. Check policy CMP0014.
|
|
|
|
std::ostringstream e;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2015-05-14 22:18:06 +03:00
|
|
|
e << "The source directory\n"
|
|
|
|
<< " " << currentStart << "\n"
|
|
|
|
<< "does not contain a CMakeLists.txt file.";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2015-05-14 22:18:06 +03:00
|
|
|
switch (this->GetPolicyStatus(cmPolicies::CMP0014))
|
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
|
|
|
// Print the warning.
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2015-05-14 22:18:06 +03:00
|
|
|
e << "\n"
|
|
|
|
<< "CMake does not support this case but it used "
|
|
|
|
<< "to work accidentally and is being allowed for "
|
|
|
|
<< "compatibility."
|
|
|
|
<< "\n"
|
|
|
|
<< cmPolicies::GetPolicyWarning(cmPolicies::CMP0014);
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2015-05-14 22:18:06 +03:00
|
|
|
this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
|
|
|
|
case cmPolicies::OLD:
|
|
|
|
// OLD behavior does not warn.
|
|
|
|
break;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
|
|
e << "\n"
|
|
|
|
<< cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0014);
|
|
|
|
case cmPolicies::NEW:
|
|
|
|
// NEW behavior prints the error.
|
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2005-03-18 18:41:41 +03:00
|
|
|
// finally configure the subdir
|
2015-05-30 20:53:02 +03:00
|
|
|
mf->Configure();
|
2015-05-30 20:39:08 +03:00
|
|
|
|
2007-07-20 16:48:32 +04:00
|
|
|
if (this->GetCMakeInstance()->GetDebugOutput())
|
|
|
|
{
|
|
|
|
std::string msg=" Returning to ";
|
2015-04-16 22:17:41 +03:00
|
|
|
msg += this->GetCurrentSourceDirectory();
|
2007-07-20 16:48:32 +04:00
|
|
|
cmSystemTools::Message(msg.c_str());
|
|
|
|
}
|
2005-03-18 18:41:41 +03:00
|
|
|
}
|
|
|
|
|
2014-02-08 00:33:35 +04:00
|
|
|
void cmMakefile::AddSubDirectory(const std::string& srcPath,
|
|
|
|
const std::string& binPath,
|
2015-04-01 21:01:52 +03:00
|
|
|
bool excludeFromAll,
|
2005-03-18 18:41:41 +03:00
|
|
|
bool immediate)
|
2005-03-14 19:29:15 +03:00
|
|
|
{
|
2009-02-27 19:23:14 +03:00
|
|
|
// Make sure the binary directory is unique.
|
2009-06-17 21:40:09 +04:00
|
|
|
if(!this->EnforceUniqueDir(srcPath, binPath))
|
2009-02-27 19:23:14 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-24 12:50:55 +03:00
|
|
|
cmState::Snapshot newSnapshot = this->GetState()
|
2016-04-14 18:24:08 +03:00
|
|
|
->CreateBuildsystemDirectorySnapshot(this->StateSnapshot);
|
2015-05-24 12:50:55 +03:00
|
|
|
|
2015-05-31 02:57:04 +03:00
|
|
|
newSnapshot.GetDirectory().SetCurrentSource(srcPath);
|
|
|
|
newSnapshot.GetDirectory().SetCurrentBinary(binPath);
|
2015-10-06 01:04:30 +03:00
|
|
|
|
2015-10-13 22:57:54 +03:00
|
|
|
cmSystemTools::MakeDirectory(binPath.c_str());
|
|
|
|
|
2015-05-31 02:57:04 +03:00
|
|
|
cmMakefile* subMf = new cmMakefile(this->GlobalGenerator, newSnapshot);
|
|
|
|
this->GetGlobalGenerator()->AddMakefile(subMf);
|
2015-10-06 01:04:30 +03:00
|
|
|
|
2007-03-13 21:23:08 +03:00
|
|
|
if(excludeFromAll)
|
|
|
|
{
|
2015-06-03 01:57:31 +03:00
|
|
|
subMf->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
|
2007-03-13 21:23:08 +03:00
|
|
|
}
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2005-03-18 18:41:41 +03:00
|
|
|
if (immediate)
|
|
|
|
{
|
2015-06-03 01:57:31 +03:00
|
|
|
this->ConfigureSubDirectory(subMf);
|
2005-03-18 18:41:41 +03:00
|
|
|
}
|
2015-05-30 20:39:08 +03:00
|
|
|
else
|
|
|
|
{
|
2015-06-03 01:57:31 +03:00
|
|
|
this->UnConfiguredDirectories.push_back(subMf);
|
2005-03-18 18:41:41 +03:00
|
|
|
}
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|
|
|
|
|
2015-04-16 10:24:16 +03:00
|
|
|
const char* cmMakefile::GetCurrentSourceDirectory() const
|
|
|
|
{
|
2015-07-18 20:11:05 +03:00
|
|
|
return this->StateSnapshot.GetDirectory().GetCurrentSource();
|
2015-04-16 10:24:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* cmMakefile::GetCurrentBinaryDirectory() const
|
|
|
|
{
|
2015-07-18 20:11:05 +03:00
|
|
|
return this->StateSnapshot.GetDirectory().GetCurrentBinary();
|
2015-04-16 10:24:16 +03:00
|
|
|
}
|
|
|
|
|
2015-10-27 00:18:20 +03:00
|
|
|
std::vector<cmTarget*> cmMakefile::GetImportedTargets() const
|
|
|
|
{
|
|
|
|
std::vector<cmTarget*> tgts;
|
|
|
|
tgts.reserve(this->ImportedTargets.size());
|
|
|
|
for (TargetMap::const_iterator it = this->ImportedTargets.begin();
|
|
|
|
it != this->ImportedTargets.end(); ++it)
|
|
|
|
{
|
|
|
|
tgts.push_back(it->second);
|
|
|
|
}
|
|
|
|
return tgts;
|
|
|
|
}
|
|
|
|
|
2013-01-20 15:28:59 +04:00
|
|
|
void cmMakefile::AddIncludeDirectories(const std::vector<std::string> &incs,
|
|
|
|
bool before)
|
2012-01-24 20:54:46 +04:00
|
|
|
{
|
2013-01-20 15:28:59 +04:00
|
|
|
if (incs.empty())
|
2012-01-24 20:54:46 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-23 22:41:46 +04:00
|
|
|
cmListFileBacktrace lfbt = this->GetBacktrace();
|
2015-07-08 01:29:41 +03:00
|
|
|
std::string entryString = cmJoin(incs, ";");
|
2015-07-18 13:28:49 +03:00
|
|
|
if (before)
|
|
|
|
{
|
|
|
|
this->StateSnapshot.GetDirectory()
|
|
|
|
.PrependIncludeDirectoriesEntry(entryString, lfbt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->StateSnapshot.GetDirectory()
|
|
|
|
.AppendIncludeDirectoriesEntry(entryString, lfbt);
|
|
|
|
}
|
2011-12-04 19:40:39 +04:00
|
|
|
|
|
|
|
// Property on each target:
|
|
|
|
for (cmTargets::iterator l = this->Targets.begin();
|
|
|
|
l != this->Targets.end(); ++l)
|
|
|
|
{
|
|
|
|
cmTarget &t = l->second;
|
2015-07-09 00:35:01 +03:00
|
|
|
t.InsertInclude(entryString, lfbt, before);
|
2004-12-02 21:14:14 +03:00
|
|
|
}
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|
|
|
|
|
2013-01-20 15:28:59 +04:00
|
|
|
void
|
2014-02-10 09:21:34 +04:00
|
|
|
cmMakefile::AddSystemIncludeDirectories(const std::set<std::string> &incs)
|
2006-10-05 16:55:59 +04:00
|
|
|
{
|
2014-11-25 18:33:00 +03:00
|
|
|
this->SystemIncludeDirectories.insert(incs.begin(), incs.end());
|
2006-10-05 16:55:59 +04:00
|
|
|
|
2013-07-02 00:55:25 +04:00
|
|
|
for (cmTargets::iterator l = this->Targets.begin();
|
|
|
|
l != this->Targets.end(); ++l)
|
2013-01-25 12:26:35 +04:00
|
|
|
{
|
2013-07-02 00:55:25 +04:00
|
|
|
cmTarget &t = l->second;
|
|
|
|
t.AddSystemIncludeDirectories(incs);
|
2013-01-25 12:26:35 +04:00
|
|
|
}
|
2006-10-05 16:55:59 +04:00
|
|
|
}
|
|
|
|
|
2014-02-05 01:06:56 +04:00
|
|
|
void cmMakefile::AddDefinition(const std::string& name, const char* value)
|
2001-01-05 19:41:20 +03:00
|
|
|
{
|
2002-09-11 22:05:45 +04:00
|
|
|
if (!value )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2007-10-22 20:49:09 +04:00
|
|
|
|
2015-05-17 13:07:10 +03:00
|
|
|
if (this->VariableInitialized(name))
|
2010-09-14 23:22:31 +04:00
|
|
|
{
|
2015-05-17 17:28:39 +03:00
|
|
|
this->LogUnused("changing definition", name);
|
2010-09-14 23:22:31 +04:00
|
|
|
}
|
2015-06-21 22:26:43 +03:00
|
|
|
this->StateSnapshot.SetDefinition(name, value);
|
2004-10-27 18:47:14 +04:00
|
|
|
|
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
2003-01-08 20:59:52 +03:00
|
|
|
cmVariableWatch* vv = this->GetVariableWatch();
|
|
|
|
if ( vv )
|
|
|
|
{
|
2009-07-22 22:22:45 +04:00
|
|
|
vv->VariableAccessed(name,
|
2007-04-11 23:13:05 +04:00
|
|
|
cmVariableWatch::VARIABLE_MODIFIED_ACCESS,
|
|
|
|
value,
|
|
|
|
this);
|
2003-01-08 20:59:52 +03:00
|
|
|
}
|
2004-10-27 18:47:14 +04:00
|
|
|
#endif
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|
2001-05-11 00:21:45 +04:00
|
|
|
|
2001-08-08 19:54:46 +04:00
|
|
|
|
2014-02-05 01:06:56 +04:00
|
|
|
void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
|
2001-08-08 19:54:46 +04:00
|
|
|
const char* doc,
|
2015-04-07 23:45:54 +03:00
|
|
|
cmState::CacheEntryType type,
|
2008-11-22 00:32:39 +03:00
|
|
|
bool force)
|
2001-08-08 19:54:46 +04:00
|
|
|
{
|
2015-04-06 11:46:25 +03:00
|
|
|
const char* existingValue =
|
2015-04-06 11:52:45 +03:00
|
|
|
this->GetState()->GetInitializedCacheValue(name);
|
2016-04-20 23:40:58 +03:00
|
|
|
// must be outside the following if() to keep it alive long enough
|
|
|
|
std::string nvalue;
|
|
|
|
|
2015-04-06 11:46:25 +03:00
|
|
|
if(existingValue
|
2015-04-06 11:52:45 +03:00
|
|
|
&& (this->GetState()->GetCacheEntryType(name)
|
2015-04-07 23:45:54 +03:00
|
|
|
== cmState::UNINITIALIZED))
|
2003-08-01 22:10:26 +04:00
|
|
|
{
|
2008-11-22 00:32:39 +03:00
|
|
|
// 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)
|
|
|
|
{
|
2016-04-20 23:40:58 +03:00
|
|
|
value = existingValue;
|
2008-11-22 00:32:39 +03:00
|
|
|
}
|
2015-04-07 23:45:54 +03:00
|
|
|
if ( type == cmState::PATH || type == cmState::FILEPATH )
|
2003-08-08 18:07:09 +04:00
|
|
|
{
|
|
|
|
std::vector<std::string>::size_type cc;
|
|
|
|
std::vector<std::string> files;
|
2016-04-20 23:40:58 +03:00
|
|
|
nvalue = value ? value : "";
|
|
|
|
|
|
|
|
cmSystemTools::ExpandListArgument(nvalue, files);
|
|
|
|
nvalue = "";
|
2003-08-08 18:07:09 +04:00
|
|
|
for ( cc = 0; cc < files.size(); cc ++ )
|
|
|
|
{
|
2009-10-07 22:37:19 +04:00
|
|
|
if(!cmSystemTools::IsOff(files[cc].c_str()))
|
|
|
|
{
|
2014-10-15 16:54:05 +04:00
|
|
|
files[cc] = cmSystemTools::CollapseFullPath(files[cc]);
|
2009-10-07 22:37:19 +04:00
|
|
|
}
|
2003-08-08 18:07:09 +04:00
|
|
|
if ( cc > 0 )
|
|
|
|
{
|
|
|
|
nvalue += ";";
|
|
|
|
}
|
|
|
|
nvalue += files[cc];
|
|
|
|
}
|
|
|
|
|
2015-10-10 16:03:41 +03:00
|
|
|
this->GetCMakeInstance()->AddCacheEntry(name, nvalue.c_str(), doc, type);
|
2016-04-20 23:40:58 +03:00
|
|
|
nvalue = this->GetState()->GetInitializedCacheValue(name);
|
|
|
|
value = nvalue.c_str();
|
2003-08-08 18:07:09 +04:00
|
|
|
}
|
|
|
|
|
2003-08-01 22:10:26 +04:00
|
|
|
}
|
2016-04-20 23:40:58 +03:00
|
|
|
this->GetCMakeInstance()->AddCacheEntry(name, value, doc, type);
|
2007-03-15 20:48:15 +03:00
|
|
|
// if there was a definition then remove it
|
2015-06-21 22:26:43 +03:00
|
|
|
this->StateSnapshot.RemoveDefinition(name);
|
2001-08-08 19:54:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-05 01:06:56 +04:00
|
|
|
void cmMakefile::AddDefinition(const std::string& name, bool value)
|
2001-04-24 20:40:37 +04:00
|
|
|
{
|
2015-05-17 13:07:10 +03:00
|
|
|
if (this->VariableInitialized(name))
|
2010-09-14 23:22:31 +04:00
|
|
|
{
|
2015-05-17 17:28:39 +03:00
|
|
|
this->LogUnused("changing definition", name);
|
2010-09-14 23:22:31 +04:00
|
|
|
}
|
2015-06-21 22:26:43 +03:00
|
|
|
|
|
|
|
this->StateSnapshot.SetDefinition(name, value ? "ON" : "OFF");
|
|
|
|
|
2004-10-27 18:47:14 +04:00
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
2003-01-08 20:59:52 +03:00
|
|
|
cmVariableWatch* vv = this->GetVariableWatch();
|
|
|
|
if ( vv )
|
|
|
|
{
|
2007-04-11 23:13:05 +04:00
|
|
|
vv->VariableAccessed(name, cmVariableWatch::VARIABLE_MODIFIED_ACCESS,
|
|
|
|
value?"ON":"OFF", this);
|
2003-01-08 20:59:52 +03:00
|
|
|
}
|
2004-10-27 18:47:14 +04:00
|
|
|
#endif
|
2001-04-24 20:40:37 +04:00
|
|
|
}
|
2001-01-05 19:41:20 +03:00
|
|
|
|
2010-09-22 20:40:43 +04:00
|
|
|
void cmMakefile::CheckForUnusedVariables() const
|
|
|
|
{
|
2011-06-21 23:59:10 +04:00
|
|
|
if (!this->WarnUnused)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-06-21 22:26:43 +03:00
|
|
|
const std::vector<std::string>& unused = this->StateSnapshot.UnusedKeys();
|
2015-05-17 17:19:55 +03:00
|
|
|
std::vector<std::string>::const_iterator it = unused.begin();
|
|
|
|
for (; it != unused.end(); ++it)
|
2010-09-22 20:40:43 +04:00
|
|
|
{
|
2015-05-17 17:28:39 +03:00
|
|
|
this->LogUnused("out of scope", *it);
|
2010-09-22 20:40:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-05 01:06:56 +04:00
|
|
|
void cmMakefile::MarkVariableAsUsed(const std::string& var)
|
2010-09-15 19:34:35 +04:00
|
|
|
{
|
2015-06-21 22:26:43 +03:00
|
|
|
this->StateSnapshot.GetDefinition(var);
|
2010-09-15 19:34:35 +04:00
|
|
|
}
|
|
|
|
|
2014-02-05 01:06:56 +04:00
|
|
|
bool cmMakefile::VariableInitialized(const std::string& var) const
|
2010-08-24 22:38:06 +04:00
|
|
|
{
|
2015-06-21 22:26:43 +03:00
|
|
|
return this->StateSnapshot.IsInitialized(var);
|
2010-08-24 22:38:06 +04:00
|
|
|
}
|
|
|
|
|
2015-05-17 17:28:39 +03:00
|
|
|
void cmMakefile::LogUnused(const char* reason,
|
2014-02-05 01:06:56 +04:00
|
|
|
const std::string& name) const
|
2010-09-14 23:22:31 +04:00
|
|
|
{
|
2015-05-17 17:19:55 +03:00
|
|
|
if (this->WarnUnused)
|
2010-09-14 23:22:31 +04:00
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
std::string path;
|
2015-05-31 20:37:08 +03:00
|
|
|
if (!this->ExecutionStatusStack.empty())
|
2010-09-22 20:41:58 +04:00
|
|
|
{
|
2016-04-15 17:13:12 +03:00
|
|
|
path = this->GetExecutionContext().FilePath;
|
2010-09-22 20:41:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-16 21:06:54 +03:00
|
|
|
path = this->GetCurrentSourceDirectory();
|
2010-09-22 20:41:58 +04:00
|
|
|
path += "/CMakeLists.txt";
|
|
|
|
}
|
2015-05-22 01:38:03 +03:00
|
|
|
|
2010-09-14 23:22:31 +04:00
|
|
|
if (this->CheckSystemVars ||
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::IsSubDirectory(path,
|
2010-09-16 19:49:58 +04:00
|
|
|
this->GetHomeDirectory()) ||
|
2014-10-15 16:54:05 +04:00
|
|
|
(cmSystemTools::IsSubDirectory(path,
|
2010-12-03 20:49:37 +03:00
|
|
|
this->GetHomeOutputDirectory()) &&
|
2014-10-15 16:54:05 +04:00
|
|
|
!cmSystemTools::IsSubDirectory(path,
|
2010-12-03 20:49:37 +03:00
|
|
|
cmake::GetCMakeFilesDirectory())))
|
2010-09-14 23:22:31 +04:00
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream msg;
|
2010-12-08 00:38:25 +03:00
|
|
|
msg << "unused variable (" << reason << ") \'" << name << "\'";
|
2016-04-15 17:13:12 +03:00
|
|
|
this->IssueMessage(cmake::AUTHOR_WARNING, msg.str());
|
2010-09-14 23:22:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-05 01:06:56 +04:00
|
|
|
void cmMakefile::RemoveDefinition(const std::string& name)
|
2002-09-18 18:39:41 +04:00
|
|
|
{
|
2015-05-17 13:07:10 +03:00
|
|
|
if (this->VariableInitialized(name))
|
2010-09-16 21:52:17 +04:00
|
|
|
{
|
2015-05-17 17:28:39 +03:00
|
|
|
this->LogUnused("unsetting", name);
|
2010-09-16 21:52:17 +04:00
|
|
|
}
|
2015-06-21 22:26:43 +03:00
|
|
|
this->StateSnapshot.RemoveDefinition(name);
|
2004-10-27 18:47:14 +04:00
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
2003-01-08 20:59:52 +03:00
|
|
|
cmVariableWatch* vv = this->GetVariableWatch();
|
|
|
|
if ( vv )
|
|
|
|
{
|
2007-04-11 23:13:05 +04:00
|
|
|
vv->VariableAccessed(name, cmVariableWatch::VARIABLE_REMOVED_ACCESS,
|
|
|
|
0, this);
|
2003-01-08 20:59:52 +03:00
|
|
|
}
|
2004-10-27 18:47:14 +04:00
|
|
|
#endif
|
2002-09-18 18:39:41 +04:00
|
|
|
}
|
|
|
|
|
2014-02-05 01:06:56 +04:00
|
|
|
void cmMakefile::RemoveCacheDefinition(const std::string& name)
|
2008-08-25 18:31:29 +04:00
|
|
|
{
|
2015-04-06 11:52:45 +03:00
|
|
|
this->GetState()->RemoveCacheEntry(name);
|
2008-08-25 18:31:29 +04:00
|
|
|
}
|
|
|
|
|
2015-08-02 11:57:31 +03:00
|
|
|
void cmMakefile::SetProjectName(std::string const& p)
|
2001-01-05 19:41:20 +03:00
|
|
|
{
|
2015-08-02 10:41:06 +03:00
|
|
|
this->StateSnapshot.SetProjectName(p);
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|
|
|
|
|
2014-02-07 02:31:47 +04:00
|
|
|
void cmMakefile::AddGlobalLinkInformation(const std::string& name,
|
|
|
|
cmTarget& target)
|
2002-05-02 23:56:13 +04:00
|
|
|
{
|
2002-06-03 18:25:55 +04:00
|
|
|
// for these targets do not add anything
|
|
|
|
switch(target.GetType())
|
|
|
|
{
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::UTILITY:
|
|
|
|
case cmState::GLOBAL_TARGET:
|
|
|
|
case cmState::INTERFACE_LIBRARY:
|
2002-10-24 18:23:11 +04:00
|
|
|
return;
|
2002-06-19 01:20:27 +04:00
|
|
|
default:;
|
2002-06-03 18:25:55 +04:00
|
|
|
}
|
2015-07-18 14:52:46 +03:00
|
|
|
if (const char* linkDirsProp = this->GetProperty("LINK_DIRECTORIES"))
|
2002-05-02 23:56:13 +04:00
|
|
|
{
|
2015-07-18 14:52:46 +03:00
|
|
|
std::vector<std::string> linkDirs;
|
|
|
|
cmSystemTools::ExpandListArgument(linkDirsProp, linkDirs);
|
|
|
|
|
|
|
|
for(std::vector<std::string>::iterator j = linkDirs.begin();
|
|
|
|
j != linkDirs.end(); ++j)
|
|
|
|
{
|
|
|
|
std::string newdir = *j;
|
|
|
|
// remove trailing slashes
|
|
|
|
if(*j->rbegin() == '/')
|
|
|
|
{
|
|
|
|
newdir = j->substr(0, j->size()-1);
|
|
|
|
}
|
|
|
|
if(std::find(this->LinkDirectories.begin(),
|
|
|
|
this->LinkDirectories.end(), newdir)
|
|
|
|
== this->LinkDirectories.end())
|
2015-08-24 08:45:26 +03:00
|
|
|
{
|
|
|
|
target.AddLinkDirectory(*j);
|
2015-07-18 14:52:46 +03:00
|
|
|
}
|
|
|
|
}
|
2002-05-02 23:56:13 +04:00
|
|
|
}
|
2006-03-15 19:02:08 +03:00
|
|
|
target.MergeLinkLibraries( *this, name, this->LinkLibraries );
|
2002-05-02 23:56:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-25 14:43:00 +03:00
|
|
|
void cmMakefile::AddAlias(const std::string& lname,
|
|
|
|
std::string const& tgtName)
|
2013-07-12 11:14:31 +04:00
|
|
|
{
|
2015-10-25 14:43:00 +03:00
|
|
|
this->AliasTargets[lname] = tgtName;
|
|
|
|
this->GetGlobalGenerator()->AddAlias(lname, tgtName);
|
2013-07-12 11:14:31 +04:00
|
|
|
}
|
|
|
|
|
2014-02-07 02:31:47 +04:00
|
|
|
cmTarget* cmMakefile::AddLibrary(const std::string& lname,
|
2015-10-08 01:21:51 +03:00
|
|
|
cmState::TargetType type,
|
2006-10-02 19:14:00 +04:00
|
|
|
const std::vector<std::string> &srcs,
|
2007-03-12 17:26:59 +03:00
|
|
|
bool excludeFromAll)
|
2001-04-11 22:59:02 +04:00
|
|
|
{
|
2007-06-22 17:58:10 +04:00
|
|
|
// wrong type ? default to STATIC
|
2015-10-08 01:21:51 +03:00
|
|
|
if ( (type != cmState::STATIC_LIBRARY)
|
|
|
|
&& (type != cmState::SHARED_LIBRARY)
|
|
|
|
&& (type != cmState::MODULE_LIBRARY)
|
|
|
|
&& (type != cmState::OBJECT_LIBRARY)
|
|
|
|
&& (type != cmState::INTERFACE_LIBRARY))
|
2007-06-22 17:58:10 +04:00
|
|
|
{
|
2012-03-12 18:47:40 +04:00
|
|
|
this->IssueMessage(cmake::INTERNAL_ERROR,
|
|
|
|
"cmMakefile::AddLibrary given invalid target type.");
|
2015-10-08 01:21:51 +03:00
|
|
|
type = cmState::STATIC_LIBRARY;
|
2001-08-29 02:02:59 +04:00
|
|
|
}
|
2002-11-20 02:01:05 +03:00
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
cmTarget* target = this->AddNewTarget(type, lname);
|
2002-05-02 23:10:19 +04:00
|
|
|
// Clear its dependencies. Otherwise, dependencies might persist
|
|
|
|
// over changes in CMakeLists.txt, making the information stale and
|
|
|
|
// hence useless.
|
2007-05-22 18:24:59 +04:00
|
|
|
target->ClearDependencyInformation( *this, lname );
|
2007-03-13 21:23:08 +03:00
|
|
|
if(excludeFromAll)
|
|
|
|
{
|
2007-05-22 18:24:59 +04:00
|
|
|
target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
|
2007-03-13 21:23:08 +03:00
|
|
|
}
|
2007-06-18 19:59:23 +04:00
|
|
|
target->AddSources(srcs);
|
2007-05-22 18:24:59 +04:00
|
|
|
this->AddGlobalLinkInformation(lname, *target);
|
2011-08-10 21:51:07 +04:00
|
|
|
return target;
|
2001-04-11 22:59:02 +04:00
|
|
|
}
|
|
|
|
|
2007-06-08 19:57:16 +04:00
|
|
|
cmTarget* cmMakefile::AddExecutable(const char *exeName,
|
2006-10-02 19:14:00 +04:00
|
|
|
const std::vector<std::string> &srcs,
|
2007-03-12 17:26:59 +03:00
|
|
|
bool excludeFromAll)
|
2001-01-05 19:41:20 +03:00
|
|
|
{
|
2015-10-08 01:21:51 +03:00
|
|
|
cmTarget* target = this->AddNewTarget(cmState::EXECUTABLE, exeName);
|
2007-03-13 21:23:08 +03:00
|
|
|
if(excludeFromAll)
|
|
|
|
{
|
2007-05-22 18:24:59 +04:00
|
|
|
target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
|
2007-03-13 21:23:08 +03:00
|
|
|
}
|
2007-06-18 19:59:23 +04:00
|
|
|
target->AddSources(srcs);
|
2007-05-22 18:24:59 +04:00
|
|
|
this->AddGlobalLinkInformation(exeName, *target);
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
cmTarget*
|
2015-10-08 01:21:51 +03:00
|
|
|
cmMakefile::AddNewTarget(cmState::TargetType type, const std::string& name)
|
2007-05-22 18:24:59 +04:00
|
|
|
{
|
2008-03-13 20:48:57 +03:00
|
|
|
cmTargets::iterator it =
|
|
|
|
this->Targets.insert(cmTargets::value_type(name, cmTarget())).first;
|
|
|
|
cmTarget& target = it->second;
|
2007-05-22 18:24:59 +04:00
|
|
|
target.SetType(type, name);
|
|
|
|
target.SetMakefile(this);
|
2016-02-08 20:37:47 +03:00
|
|
|
this->GetGlobalGenerator()->IndexTarget(&it->second);
|
2004-02-29 02:59:19 +03:00
|
|
|
return &it->second;
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|
|
|
|
|
2014-01-22 18:00:29 +04:00
|
|
|
cmSourceFile*
|
2014-02-06 23:05:57 +04:00
|
|
|
cmMakefile::LinearGetSourceFileWithOutput(const std::string& name) const
|
2003-06-03 18:30:23 +04:00
|
|
|
{
|
2005-02-24 21:45:37 +03:00
|
|
|
std::string out;
|
2003-06-20 19:23:47 +04:00
|
|
|
|
2003-06-03 18:30:23 +04:00
|
|
|
// look through all the source files that have custom commands
|
|
|
|
// and see if the custom command has the passed source file as an output
|
2007-06-08 19:57:16 +04:00
|
|
|
for(std::vector<cmSourceFile*>::const_iterator i =
|
2006-05-12 20:29:09 +04:00
|
|
|
this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
|
2003-06-03 18:30:23 +04:00
|
|
|
{
|
|
|
|
// does this source file have a custom command?
|
|
|
|
if ((*i)->GetCustomCommand())
|
|
|
|
{
|
2014-03-17 18:33:54 +04:00
|
|
|
// Does the output of the custom command match the source file name?
|
2006-04-11 19:06:19 +04:00
|
|
|
const std::vector<std::string>& outputs =
|
|
|
|
(*i)->GetCustomCommand()->GetOutputs();
|
|
|
|
for(std::vector<std::string>::const_iterator o = outputs.begin();
|
|
|
|
o != outputs.end(); ++o)
|
2003-06-03 18:30:23 +04:00
|
|
|
{
|
2006-04-11 19:06:19 +04:00
|
|
|
out = *o;
|
|
|
|
std::string::size_type pos = out.rfind(name);
|
|
|
|
// If the output matches exactly
|
|
|
|
if (pos != out.npos &&
|
|
|
|
pos == out.size() - name.size() &&
|
|
|
|
(pos ==0 || out[pos-1] == '/'))
|
|
|
|
{
|
|
|
|
return *i;
|
|
|
|
}
|
2003-06-03 18:30:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2003-06-03 18:30:23 +04:00
|
|
|
// otherwise return NULL
|
2003-06-04 16:40:09 +04:00
|
|
|
return 0;
|
2003-06-03 18:30:23 +04:00
|
|
|
}
|
|
|
|
|
2014-02-06 23:05:57 +04:00
|
|
|
cmSourceFile *cmMakefile::GetSourceFileWithOutput(
|
|
|
|
const std::string& name) const
|
2013-08-06 20:12:50 +04:00
|
|
|
{
|
|
|
|
// If the queried path is not absolute we use the backward compatible
|
|
|
|
// linear-time search for an output with a matching suffix.
|
2014-02-06 23:05:57 +04:00
|
|
|
if(!cmSystemTools::FileIsFullPath(name.c_str()))
|
2013-08-06 20:12:50 +04:00
|
|
|
{
|
2014-03-17 18:34:53 +04:00
|
|
|
return this->LinearGetSourceFileWithOutput(name);
|
2013-08-06 20:12:50 +04:00
|
|
|
}
|
|
|
|
// Otherwise we use an efficient lookup map.
|
2014-01-22 18:00:29 +04:00
|
|
|
OutputToSourceMap::const_iterator o = this->OutputToSource.find(name);
|
2013-08-06 20:12:50 +04:00
|
|
|
if (o != this->OutputToSource.end())
|
|
|
|
{
|
|
|
|
return (*o).second;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-22 17:58:11 +03:00
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
2014-01-21 18:16:43 +04:00
|
|
|
cmSourceGroup*
|
|
|
|
cmMakefile::GetSourceGroup(const std::vector<std::string>&name) const
|
2002-10-05 02:16:13 +04:00
|
|
|
{
|
2007-08-24 22:21:49 +04:00
|
|
|
cmSourceGroup* sg = 0;
|
|
|
|
|
2015-10-25 17:03:55 +03:00
|
|
|
// first look for source group starting with the same as the one we want
|
2014-01-21 18:16:43 +04:00
|
|
|
for (std::vector<cmSourceGroup>::const_iterator
|
|
|
|
sgIt = this->SourceGroups.begin();
|
|
|
|
sgIt != this->SourceGroups.end(); ++sgIt)
|
2002-10-05 02:16:13 +04:00
|
|
|
{
|
2007-08-24 22:21:49 +04:00
|
|
|
std::string sgName = sgIt->GetName();
|
|
|
|
if(sgName == name[0])
|
2002-10-05 02:16:13 +04:00
|
|
|
{
|
2014-01-21 18:16:43 +04:00
|
|
|
sg = const_cast<cmSourceGroup*>(&(*sgIt));
|
2007-08-24 22:21:49 +04:00
|
|
|
break;
|
2007-06-08 19:57:16 +04:00
|
|
|
}
|
2007-08-24 22:21:49 +04:00
|
|
|
}
|
2005-07-13 19:21:30 +04:00
|
|
|
|
2007-08-24 22:21:49 +04:00
|
|
|
if(sg != 0)
|
|
|
|
{
|
|
|
|
// iterate through its children to find match source group
|
|
|
|
for(unsigned int i=1; i<name.size(); ++i)
|
|
|
|
{
|
2014-01-22 17:45:13 +04:00
|
|
|
sg = sg->LookupChild(name[i].c_str());
|
2007-08-24 22:21:49 +04:00
|
|
|
if(sg == 0)
|
2005-07-13 19:21:30 +04:00
|
|
|
{
|
2007-08-24 22:21:49 +04:00
|
|
|
break;
|
2005-07-13 19:21:30 +04:00
|
|
|
}
|
2002-10-05 02:16:13 +04:00
|
|
|
}
|
|
|
|
}
|
2007-08-24 22:21:49 +04:00
|
|
|
return sg;
|
2002-10-05 02:16:13 +04:00
|
|
|
}
|
2001-05-02 00:55:32 +04:00
|
|
|
|
2014-02-06 23:05:57 +04:00
|
|
|
void cmMakefile::AddSourceGroup(const std::string& name,
|
2007-08-26 11:17:11 +04:00
|
|
|
const char* regex)
|
2001-03-20 21:20:59 +03:00
|
|
|
{
|
2014-02-06 23:05:57 +04:00
|
|
|
std::vector<std::string> nameVector;
|
|
|
|
nameVector.push_back(name);
|
2015-10-25 17:04:07 +03:00
|
|
|
this->AddSourceGroup(nameVector, regex);
|
2007-08-24 22:21:49 +04:00
|
|
|
}
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2007-08-24 22:21:49 +04:00
|
|
|
void cmMakefile::AddSourceGroup(const std::vector<std::string>& name,
|
2007-08-26 11:17:11 +04:00
|
|
|
const char* regex)
|
2007-08-24 22:21:49 +04:00
|
|
|
{
|
|
|
|
cmSourceGroup* sg = 0;
|
|
|
|
std::vector<std::string> currentName;
|
|
|
|
int i = 0;
|
2007-08-29 00:27:10 +04:00
|
|
|
const int lastElement = static_cast<int>(name.size()-1);
|
2007-08-24 22:21:49 +04:00
|
|
|
for(i=lastElement; i>=0; --i)
|
|
|
|
{
|
|
|
|
currentName.assign(name.begin(), name.begin()+i+1);
|
|
|
|
sg = this->GetSourceGroup(currentName);
|
|
|
|
if(sg != 0)
|
2001-03-20 21:20:59 +03:00
|
|
|
{
|
2007-08-24 22:21:49 +04:00
|
|
|
break;
|
2005-07-13 19:21:30 +04:00
|
|
|
}
|
2007-08-24 22:21:49 +04:00
|
|
|
}
|
2005-07-13 19:21:30 +04:00
|
|
|
|
2007-08-24 22:21:49 +04:00
|
|
|
// i now contains the index of the last found component
|
|
|
|
if(i==lastElement)
|
|
|
|
{
|
|
|
|
// group already exists, replace its regular expression
|
2015-03-25 19:38:37 +03:00
|
|
|
if ( regex && sg)
|
2007-08-24 22:21:49 +04:00
|
|
|
{
|
|
|
|
// We only want to set the regular expression. If there are already
|
|
|
|
// source files in the group, we don't want to remove them.
|
|
|
|
sg->SetGroupRegex(regex);
|
2001-03-20 21:20:59 +03:00
|
|
|
}
|
2007-08-24 22:21:49 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(i==-1)
|
|
|
|
{
|
2012-11-07 20:13:09 +04:00
|
|
|
// group does not exist nor belong to any existing group
|
2007-08-24 22:21:49 +04:00
|
|
|
// add its first component
|
|
|
|
this->SourceGroups.push_back(cmSourceGroup(name[0].c_str(), regex));
|
|
|
|
sg = this->GetSourceGroup(currentName);
|
|
|
|
i = 0; // last component found
|
2001-03-20 21:20:59 +03:00
|
|
|
}
|
2015-03-25 19:38:37 +03:00
|
|
|
if(!sg)
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("Could not create source group ");
|
|
|
|
return;
|
|
|
|
}
|
2007-08-24 22:21:49 +04:00
|
|
|
// build the whole source group path
|
|
|
|
for(++i; i<=lastElement; ++i)
|
|
|
|
{
|
2009-07-11 08:05:20 +04:00
|
|
|
sg->AddChild(cmSourceGroup(name[i].c_str(), 0, sg->GetFullName()));
|
2014-01-22 17:45:13 +04:00
|
|
|
sg = sg->LookupChild(name[i].c_str());
|
2007-08-24 22:21:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sg->SetGroupRegex(regex);
|
2001-03-20 21:20:59 +03:00
|
|
|
}
|
2007-08-24 22:21:49 +04:00
|
|
|
|
2006-03-22 17:58:11 +03:00
|
|
|
#endif
|
2001-01-05 19:41:20 +03:00
|
|
|
|
2012-12-06 18:59:18 +04:00
|
|
|
static bool mightExpandVariablesCMP0019(const char* s)
|
|
|
|
{
|
|
|
|
return s && *s && strstr(s,"${") && strchr(s,'}');
|
|
|
|
}
|
2000-08-30 21:35:41 +04:00
|
|
|
|
2012-12-06 18:59:18 +04:00
|
|
|
void cmMakefile::ExpandVariablesCMP0019()
|
2001-01-05 19:41:20 +03:00
|
|
|
{
|
2012-12-06 18:59:18 +04:00
|
|
|
// Drop this ancient compatibility behavior with a policy.
|
|
|
|
cmPolicies::PolicyStatus pol = this->GetPolicyStatus(cmPolicies::CMP0019);
|
|
|
|
if(pol != cmPolicies::OLD && pol != cmPolicies::WARN)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream w;
|
2012-01-24 20:54:46 +04:00
|
|
|
|
|
|
|
const char *includeDirs = this->GetProperty("INCLUDE_DIRECTORIES");
|
2012-12-06 18:59:18 +04:00
|
|
|
if(mightExpandVariablesCMP0019(includeDirs))
|
2001-01-05 19:41:20 +03:00
|
|
|
{
|
2012-01-24 20:54:46 +04:00
|
|
|
std::string dirs = includeDirs;
|
|
|
|
this->ExpandVariablesInString(dirs, true, true);
|
2012-12-06 18:59:18 +04:00
|
|
|
if(pol == cmPolicies::WARN && dirs != includeDirs)
|
|
|
|
{
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2012-12-06 18:59:18 +04:00
|
|
|
w << "Evaluated directory INCLUDE_DIRECTORIES\n"
|
|
|
|
<< " " << includeDirs << "\n"
|
|
|
|
<< "as\n"
|
|
|
|
<< " " << dirs << "\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2012-12-06 18:59:18 +04:00
|
|
|
}
|
2012-01-24 20:54:46 +04:00
|
|
|
this->SetProperty("INCLUDE_DIRECTORIES", dirs.c_str());
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|
2012-01-24 20:54:46 +04:00
|
|
|
|
2012-02-22 16:14:11 +04:00
|
|
|
// Also for each target's INCLUDE_DIRECTORIES property:
|
|
|
|
for (cmTargets::iterator l = this->Targets.begin();
|
|
|
|
l != this->Targets.end(); ++l)
|
|
|
|
{
|
|
|
|
cmTarget &t = l->second;
|
2015-10-08 01:21:51 +03:00
|
|
|
if (t.GetType() == cmState::INTERFACE_LIBRARY
|
|
|
|
|| t.GetType() == cmState::GLOBAL_TARGET)
|
2013-11-20 15:44:04 +04:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2012-02-23 17:11:09 +04:00
|
|
|
includeDirs = t.GetProperty("INCLUDE_DIRECTORIES");
|
2012-12-06 18:59:18 +04:00
|
|
|
if(mightExpandVariablesCMP0019(includeDirs))
|
2012-02-22 16:14:11 +04:00
|
|
|
{
|
|
|
|
std::string dirs = includeDirs;
|
|
|
|
this->ExpandVariablesInString(dirs, true, true);
|
2012-12-06 18:59:18 +04:00
|
|
|
if(pol == cmPolicies::WARN && dirs != includeDirs)
|
|
|
|
{
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2012-12-06 18:59:18 +04:00
|
|
|
w << "Evaluated target " << t.GetName() << " INCLUDE_DIRECTORIES\n"
|
|
|
|
<< " " << includeDirs << "\n"
|
|
|
|
<< "as\n"
|
|
|
|
<< " " << dirs << "\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2012-12-06 18:59:18 +04:00
|
|
|
}
|
2012-02-22 16:14:11 +04:00
|
|
|
t.SetProperty("INCLUDE_DIRECTORIES", dirs.c_str());
|
|
|
|
}
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|
2012-02-22 16:14:11 +04:00
|
|
|
|
2015-07-18 14:52:46 +03:00
|
|
|
if (const char* linkDirsProp = this->GetProperty("LINK_DIRECTORIES"))
|
2001-01-05 19:41:20 +03:00
|
|
|
{
|
2015-07-18 14:52:46 +03:00
|
|
|
if(mightExpandVariablesCMP0019(linkDirsProp))
|
2012-12-06 18:59:18 +04:00
|
|
|
{
|
2015-07-18 14:52:46 +03:00
|
|
|
std::string d = linkDirsProp;
|
|
|
|
std::string orig = linkDirsProp;
|
|
|
|
this->ExpandVariablesInString(d, true, true);
|
|
|
|
if(pol == cmPolicies::WARN && d != orig)
|
2012-12-06 18:59:18 +04:00
|
|
|
{
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2015-07-18 14:52:46 +03:00
|
|
|
w << "Evaluated link directories\n"
|
2012-12-06 18:59:18 +04:00
|
|
|
<< " " << orig << "\n"
|
|
|
|
<< "as\n"
|
2015-07-18 14:52:46 +03:00
|
|
|
<< " " << d << "\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2012-12-06 18:59:18 +04:00
|
|
|
}
|
|
|
|
}
|
2001-02-16 19:34:23 +03:00
|
|
|
}
|
2007-06-08 19:57:16 +04:00
|
|
|
for(cmTarget::LinkLibraryVectorType::iterator l =
|
2006-03-15 19:02:08 +03:00
|
|
|
this->LinkLibraries.begin();
|
|
|
|
l != this->LinkLibraries.end(); ++l)
|
2001-02-16 19:34:23 +03:00
|
|
|
{
|
2012-12-06 18:59:18 +04:00
|
|
|
if(mightExpandVariablesCMP0019(l->first.c_str()))
|
|
|
|
{
|
|
|
|
std::string orig = l->first;
|
|
|
|
this->ExpandVariablesInString(l->first, true, true);
|
|
|
|
if(pol == cmPolicies::WARN && l->first != orig)
|
|
|
|
{
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2012-12-06 18:59:18 +04:00
|
|
|
w << "Evaluated link library\n"
|
|
|
|
<< " " << orig << "\n"
|
|
|
|
<< "as\n"
|
|
|
|
<< " " << l->first << "\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2012-12-06 18:59:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!w.str().empty())
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream m;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2015-05-03 11:12:10 +03:00
|
|
|
m << cmPolicies::GetPolicyWarning(cmPolicies::CMP0019)
|
2012-12-06 18:59:18 +04:00
|
|
|
<< "\n"
|
|
|
|
<< "The following variable evaluations were encountered:\n"
|
|
|
|
<< w.str();
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2012-12-06 18:59:18 +04:00
|
|
|
this->IssueMessage(cmake::AUTHOR_WARNING, m.str());
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-05 01:06:56 +04:00
|
|
|
bool cmMakefile::IsOn(const std::string& name) const
|
2001-08-08 19:54:46 +04:00
|
|
|
{
|
|
|
|
const char* value = this->GetDefinition(name);
|
|
|
|
return cmSystemTools::IsOn(value);
|
|
|
|
}
|
|
|
|
|
2014-02-05 01:06:56 +04:00
|
|
|
bool cmMakefile::IsSet(const std::string& name) const
|
2005-04-02 00:48:46 +04:00
|
|
|
{
|
|
|
|
const char* value = this->GetDefinition(name);
|
|
|
|
if ( !value )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! *value )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( cmSystemTools::IsNOTFOUND(value) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-30 21:45:14 +04:00
|
|
|
bool cmMakefile::PlatformIs64Bit() const
|
|
|
|
{
|
|
|
|
if(const char* sizeof_dptr = this->GetDefinition("CMAKE_SIZEOF_VOID_P"))
|
|
|
|
{
|
|
|
|
return atoi(sizeof_dptr) == 8;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-18 22:30:54 +03:00
|
|
|
bool cmMakefile::PlatformIsAppleIos() const
|
|
|
|
{
|
|
|
|
std::string sdkRoot;
|
|
|
|
sdkRoot = this->GetSafeDefinition("CMAKE_OSX_SYSROOT");
|
|
|
|
sdkRoot = cmSystemTools::LowerCase(sdkRoot);
|
|
|
|
|
2015-10-23 23:19:43 +03:00
|
|
|
const std::string embedded[] =
|
|
|
|
{
|
|
|
|
"appletvos", "appletvsimulator",
|
|
|
|
"iphoneos", "iphonesimulator",
|
|
|
|
"watchos", "watchsimulator",
|
|
|
|
};
|
|
|
|
|
|
|
|
for(size_t i = 0; i < sizeof(embedded) / sizeof(embedded[0]); ++i)
|
|
|
|
{
|
|
|
|
if(sdkRoot.find(embedded[i]) == 0 ||
|
|
|
|
sdkRoot.find(std::string("/") + embedded[i]) != std::string::npos)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-08-18 22:30:54 +03:00
|
|
|
}
|
|
|
|
|
2014-02-04 06:20:56 +04:00
|
|
|
const char* cmMakefile::GetSONameFlag(const std::string& language) const
|
2012-04-22 17:42:55 +04:00
|
|
|
{
|
2012-06-20 19:04:35 +04:00
|
|
|
std::string name = "CMAKE_SHARED_LIBRARY_SONAME";
|
2014-02-04 06:20:56 +04:00
|
|
|
if(!language.empty())
|
2012-06-20 19:04:35 +04:00
|
|
|
{
|
|
|
|
name += "_";
|
|
|
|
name += language;
|
|
|
|
}
|
2012-04-22 17:42:55 +04:00
|
|
|
name += "_FLAG";
|
2014-03-11 03:04:11 +04:00
|
|
|
return GetDefinition(name);
|
2012-04-22 17:42:55 +04:00
|
|
|
}
|
|
|
|
|
2014-01-22 18:00:29 +04:00
|
|
|
bool cmMakefile::CanIWriteThisFile(const char* fileName) const
|
2006-03-22 22:40:36 +03:00
|
|
|
{
|
|
|
|
if ( !this->IsOn("CMAKE_DISABLE_SOURCE_CHANGES") )
|
|
|
|
{
|
2006-03-22 22:45:12 +03:00
|
|
|
return true;
|
2006-03-22 22:40:36 +03:00
|
|
|
}
|
2013-01-22 06:44:08 +04:00
|
|
|
// If we are doing an in-source build, then the test will always fail
|
2007-06-08 19:57:16 +04:00
|
|
|
if ( cmSystemTools::SameFile(this->GetHomeDirectory(),
|
2006-05-12 20:29:09 +04:00
|
|
|
this->GetHomeOutputDirectory()) )
|
2006-03-22 22:40:36 +03:00
|
|
|
{
|
|
|
|
if ( this->IsOn("CMAKE_DISABLE_IN_SOURCE_BUILD") )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-22 06:44:08 +04:00
|
|
|
// Check if this is a subdirectory of the source tree but not a
|
|
|
|
// subdirectory of the build tree
|
2006-03-22 22:40:36 +03:00
|
|
|
if ( cmSystemTools::IsSubDirectory(fileName,
|
|
|
|
this->GetHomeDirectory()) &&
|
|
|
|
!cmSystemTools::IsSubDirectory(fileName,
|
|
|
|
this->GetHomeOutputDirectory()) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-05 01:06:56 +04:00
|
|
|
const char* cmMakefile::GetRequiredDefinition(const std::string& name) const
|
2004-08-06 22:51:41 +04:00
|
|
|
{
|
|
|
|
const char* ret = this->GetDefinition(name);
|
|
|
|
if(!ret)
|
|
|
|
{
|
2006-05-12 20:29:09 +04:00
|
|
|
cmSystemTools::Error("Error required internal CMake variable not "
|
|
|
|
"set, cmake may be not be built correctly.\n",
|
2004-08-06 22:51:41 +04:00
|
|
|
"Missing variable is:\n",
|
2014-02-05 01:06:56 +04:00
|
|
|
name.c_str());
|
2004-08-06 22:51:41 +04:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-05 01:06:56 +04:00
|
|
|
bool cmMakefile::IsDefinitionSet(const std::string& name) const
|
2001-01-05 19:41:20 +03:00
|
|
|
{
|
2015-06-21 22:26:43 +03:00
|
|
|
const char* def = this->StateSnapshot.GetDefinition(name);
|
2009-07-22 22:22:45 +04:00
|
|
|
if(!def)
|
2003-01-08 20:59:52 +03:00
|
|
|
{
|
2015-04-06 11:52:45 +03:00
|
|
|
def = this->GetState()->GetInitializedCacheValue(name);
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|
2007-05-18 01:40:59 +04:00
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
|
|
|
if(cmVariableWatch* vv = this->GetVariableWatch())
|
|
|
|
{
|
|
|
|
if(!def)
|
|
|
|
{
|
|
|
|
vv->VariableAccessed
|
|
|
|
(name, cmVariableWatch::UNKNOWN_VARIABLE_DEFINED_ACCESS,
|
|
|
|
def, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return def?true:false;
|
2007-05-17 23:12:13 +04:00
|
|
|
}
|
|
|
|
|
2014-02-05 01:06:56 +04:00
|
|
|
const char* cmMakefile::GetDefinition(const std::string& name) const
|
2007-05-17 23:12:13 +04:00
|
|
|
{
|
2015-06-21 22:26:43 +03:00
|
|
|
const char* def = this->StateSnapshot.GetDefinition(name);
|
2009-07-22 22:22:45 +04:00
|
|
|
if(!def)
|
2007-05-18 01:40:59 +04:00
|
|
|
{
|
2015-04-06 11:52:45 +03:00
|
|
|
def = this->GetState()->GetInitializedCacheValue(name);
|
2007-05-18 01:40:59 +04:00
|
|
|
}
|
2004-10-27 18:47:14 +04:00
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
2003-01-08 20:59:52 +03:00
|
|
|
cmVariableWatch* vv = this->GetVariableWatch();
|
2014-05-21 01:00:28 +04:00
|
|
|
if ( vv && !this->SuppressWatches )
|
2003-01-08 20:59:52 +03:00
|
|
|
{
|
2016-03-23 12:37:51 +03:00
|
|
|
bool const watch_function_executed =
|
2014-05-06 01:25:24 +04:00
|
|
|
vv->VariableAccessed(name,
|
2016-03-23 12:37:51 +03:00
|
|
|
def ? cmVariableWatch::VARIABLE_READ_ACCESS
|
|
|
|
: cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS,
|
|
|
|
def, this);
|
|
|
|
|
|
|
|
if (watch_function_executed)
|
|
|
|
{
|
|
|
|
// A callback was executed and may have caused re-allocation of the
|
|
|
|
// variable storage. Look it up again for now.
|
|
|
|
// FIXME: Refactor variable storage to avoid this problem.
|
|
|
|
def = this->StateSnapshot.GetDefinition(name);
|
|
|
|
if(!def)
|
|
|
|
{
|
|
|
|
def = this->GetState()->GetInitializedCacheValue(name);
|
|
|
|
}
|
2003-01-08 20:59:52 +03:00
|
|
|
}
|
|
|
|
}
|
2004-10-27 18:47:14 +04:00
|
|
|
#endif
|
2003-01-08 20:59:52 +03:00
|
|
|
return def;
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|
2001-01-12 20:43:00 +03:00
|
|
|
|
2014-02-05 01:06:56 +04:00
|
|
|
const char* cmMakefile::GetSafeDefinition(const std::string& def) const
|
2004-04-27 19:30:31 +04:00
|
|
|
{
|
|
|
|
const char* ret = this->GetDefinition(def);
|
|
|
|
if(!ret)
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-06-07 16:12:51 +03:00
|
|
|
std::vector<std::string> cmMakefile::GetDefinitions() const
|
2003-03-06 19:19:28 +03:00
|
|
|
{
|
2015-06-21 22:26:43 +03:00
|
|
|
std::vector<std::string> res = this->StateSnapshot.ClosureKeys();
|
2015-06-07 16:12:51 +03:00
|
|
|
std::vector<std::string> cacheKeys = this->GetState()->GetCacheEntryKeys();
|
2015-04-05 11:48:04 +03:00
|
|
|
res.insert(res.end(), cacheKeys.begin(), cacheKeys.end());
|
2015-04-06 13:30:21 +03:00
|
|
|
std::sort(res.begin(), res.end());
|
2003-03-06 19:19:28 +03:00
|
|
|
return res;
|
|
|
|
}
|
2001-01-12 20:43:00 +03:00
|
|
|
|
2001-02-13 03:49:52 +03:00
|
|
|
|
2014-01-22 18:00:29 +04:00
|
|
|
const char *cmMakefile::ExpandVariablesInString(std::string& source) const
|
2001-06-22 19:14:32 +04:00
|
|
|
{
|
2005-06-17 23:50:08 +04:00
|
|
|
return this->ExpandVariablesInString(source, false, false);
|
2001-06-22 19:14:32 +04:00
|
|
|
}
|
|
|
|
|
2001-09-02 00:12:52 +04:00
|
|
|
const char *cmMakefile::ExpandVariablesInString(std::string& source,
|
2001-10-30 22:05:07 +03:00
|
|
|
bool escapeQuotes,
|
2005-06-17 23:50:08 +04:00
|
|
|
bool noEscapes,
|
2004-08-04 18:45:11 +04:00
|
|
|
bool atOnly,
|
2004-08-04 22:34:03 +04:00
|
|
|
const char* filename,
|
2005-04-12 21:27:07 +04:00
|
|
|
long line,
|
2006-10-04 22:37:42 +04:00
|
|
|
bool removeEmpty,
|
2014-01-22 18:00:29 +04:00
|
|
|
bool replaceAt) const
|
2001-02-13 03:49:52 +03:00
|
|
|
{
|
2014-02-08 07:37:54 +04:00
|
|
|
bool compareResults = false;
|
|
|
|
cmake::MessageType mtype = cmake::LOG;
|
|
|
|
std::string errorstr;
|
|
|
|
std::string original;
|
|
|
|
|
|
|
|
// Sanity check the @ONLY mode.
|
|
|
|
if(atOnly && (!noEscapes || !removeEmpty))
|
2005-06-13 19:00:29 +04:00
|
|
|
{
|
2014-02-08 07:37:54 +04:00
|
|
|
// This case should never be called. At-only is for
|
|
|
|
// configure-file/string which always does no escapes.
|
|
|
|
this->IssueMessage(cmake::INTERNAL_ERROR,
|
|
|
|
"ExpandVariablesInString @ONLY called "
|
|
|
|
"on something with escapes.");
|
2005-06-13 19:00:29 +04:00
|
|
|
return source.c_str();
|
|
|
|
}
|
2007-06-07 00:20:02 +04:00
|
|
|
|
2014-02-08 07:37:54 +04:00
|
|
|
// Variables used in the WARN case.
|
|
|
|
std::string newResult;
|
|
|
|
std::string newErrorstr;
|
|
|
|
cmake::MessageType newError = cmake::LOG;
|
|
|
|
|
|
|
|
switch(this->GetPolicyStatus(cmPolicies::CMP0053))
|
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
|
|
|
{
|
|
|
|
// Save the original string for the warning.
|
|
|
|
original = source;
|
|
|
|
newResult = source;
|
|
|
|
compareResults = true;
|
2014-05-21 01:00:28 +04:00
|
|
|
// Suppress variable watches to avoid calling hooks twice. Suppress new
|
|
|
|
// dereferences since the OLD behavior is still what is actually used.
|
|
|
|
this->SuppressWatches = true;
|
2014-02-08 07:37:54 +04:00
|
|
|
newError =
|
|
|
|
ExpandVariablesInStringNew(newErrorstr, newResult, escapeQuotes,
|
|
|
|
noEscapes, atOnly, filename, line,
|
|
|
|
removeEmpty, replaceAt);
|
2014-05-21 01:00:28 +04:00
|
|
|
this->SuppressWatches = false;
|
2014-02-08 07:37:54 +04:00
|
|
|
}
|
|
|
|
case cmPolicies::OLD:
|
|
|
|
mtype = ExpandVariablesInStringOld(errorstr, source, escapeQuotes,
|
|
|
|
noEscapes, atOnly, filename,
|
|
|
|
line, removeEmpty, true);
|
|
|
|
break;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
|
|
// Messaging here would be *very* verbose.
|
|
|
|
case cmPolicies::NEW:
|
|
|
|
mtype = ExpandVariablesInStringNew(errorstr, source, escapeQuotes,
|
|
|
|
noEscapes, atOnly, filename,
|
|
|
|
line, removeEmpty, replaceAt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If it's an error in either case, just report the error...
|
|
|
|
if(mtype != cmake::LOG)
|
2007-06-07 00:20:02 +04:00
|
|
|
{
|
2014-02-08 07:37:54 +04:00
|
|
|
if(mtype == cmake::FATAL_ERROR)
|
|
|
|
{
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
}
|
|
|
|
this->IssueMessage(mtype, errorstr);
|
|
|
|
}
|
|
|
|
// ...otherwise, see if there's a difference that needs to be warned about.
|
|
|
|
else if(compareResults && (newResult != source || newError != mtype))
|
|
|
|
{
|
|
|
|
std::string msg =
|
2015-05-03 11:12:10 +03:00
|
|
|
cmPolicies::GetPolicyWarning(cmPolicies::CMP0053);
|
2014-02-08 07:37:54 +04:00
|
|
|
msg += "\n";
|
|
|
|
|
|
|
|
std::string msg_input = original;
|
|
|
|
cmSystemTools::ReplaceString(msg_input, "\n", "\n ");
|
|
|
|
msg += "For input:\n '";
|
|
|
|
msg += msg_input;
|
|
|
|
msg += "'\n";
|
|
|
|
|
|
|
|
std::string msg_old = source;
|
|
|
|
cmSystemTools::ReplaceString(msg_old, "\n", "\n ");
|
|
|
|
msg += "the old evaluation rules produce:\n '";
|
|
|
|
msg += msg_old;
|
|
|
|
msg += "'\n";
|
|
|
|
|
|
|
|
if(newError == mtype)
|
|
|
|
{
|
|
|
|
std::string msg_new = newResult;
|
|
|
|
cmSystemTools::ReplaceString(msg_new, "\n", "\n ");
|
|
|
|
msg += "but the new evaluation rules produce:\n '";
|
|
|
|
msg += msg_new;
|
|
|
|
msg += "'\n";
|
|
|
|
}
|
|
|
|
else
|
2007-06-07 00:20:02 +04:00
|
|
|
{
|
2014-02-08 07:37:54 +04:00
|
|
|
std::string msg_err = newErrorstr;
|
|
|
|
cmSystemTools::ReplaceString(msg_err, "\n", "\n ");
|
|
|
|
msg += "but the new evaluation rules produce an error:\n ";
|
|
|
|
msg += msg_err;
|
|
|
|
msg += "\n";
|
2007-06-07 00:20:02 +04:00
|
|
|
}
|
|
|
|
|
2014-02-08 07:37:54 +04:00
|
|
|
msg +=
|
|
|
|
"Using the old result for compatibility since the policy is not set.";
|
|
|
|
|
|
|
|
this->IssueMessage(cmake::AUTHOR_WARNING, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return source.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
cmake::MessageType cmMakefile::ExpandVariablesInStringOld(
|
|
|
|
std::string& errorstr,
|
|
|
|
std::string& source,
|
|
|
|
bool escapeQuotes,
|
|
|
|
bool noEscapes,
|
|
|
|
bool atOnly,
|
|
|
|
const char* filename,
|
|
|
|
long line,
|
|
|
|
bool removeEmpty,
|
|
|
|
bool replaceAt) const
|
|
|
|
{
|
|
|
|
// Fast path strings without any special characters.
|
|
|
|
if ( source.find_first_of("$@\\") == source.npos)
|
|
|
|
{
|
|
|
|
return cmake::LOG;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special-case the @ONLY mode.
|
|
|
|
if(atOnly)
|
|
|
|
{
|
2007-06-07 00:20:02 +04:00
|
|
|
// Store an original copy of the input.
|
|
|
|
std::string input = source;
|
|
|
|
|
|
|
|
// Start with empty output.
|
|
|
|
source = "";
|
|
|
|
|
|
|
|
// Look for one @VAR@ at a time.
|
|
|
|
const char* in = input.c_str();
|
|
|
|
while(this->cmAtVarRegex.find(in))
|
|
|
|
{
|
|
|
|
// Get the range of the string to replace.
|
|
|
|
const char* first = in + this->cmAtVarRegex.start();
|
|
|
|
const char* last = in + this->cmAtVarRegex.end();
|
|
|
|
|
|
|
|
// Store the unchanged part of the string now.
|
|
|
|
source.append(in, first-in);
|
|
|
|
|
|
|
|
// Lookup the definition of VAR.
|
|
|
|
std::string var(first+1, last-first-2);
|
2014-03-11 03:04:11 +04:00
|
|
|
if(const char* val = this->GetDefinition(var))
|
2007-06-07 00:20:02 +04:00
|
|
|
{
|
|
|
|
// Store the value in the output escaping as requested.
|
|
|
|
if(escapeQuotes)
|
|
|
|
{
|
|
|
|
source.append(cmSystemTools::EscapeQuotes(val));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
source.append(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue looking for @VAR@ further along the string.
|
|
|
|
in = last;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append the rest of the unchanged part of the string.
|
|
|
|
source.append(in);
|
|
|
|
|
2014-02-08 07:37:54 +04:00
|
|
|
return cmake::LOG;
|
2007-06-07 00:20:02 +04:00
|
|
|
}
|
|
|
|
|
2001-07-28 00:29:50 +04:00
|
|
|
// This method replaces ${VAR} and @VAR@ where VAR is looked up
|
2002-01-22 18:17:37 +03:00
|
|
|
// with GetDefinition(), if not found in the map, nothing is expanded.
|
2001-08-18 20:52:19 +04:00
|
|
|
// It also supports the $ENV{VAR} syntax where VAR is looked up in
|
|
|
|
// the current environment variables.
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2007-02-09 21:44:37 +03:00
|
|
|
cmCommandArgumentParserHelper parser;
|
|
|
|
parser.SetMakefile(this);
|
|
|
|
parser.SetLineFile(line, filename);
|
|
|
|
parser.SetEscapeQuotes(escapeQuotes);
|
|
|
|
parser.SetNoEscapeMode(noEscapes);
|
|
|
|
parser.SetReplaceAtSyntax(replaceAt);
|
|
|
|
parser.SetRemoveEmpty(removeEmpty);
|
|
|
|
int res = parser.ParseString(source.c_str(), 0);
|
2008-09-24 16:51:19 +04:00
|
|
|
const char* emsg = parser.GetError();
|
2014-02-08 07:37:54 +04:00
|
|
|
cmake::MessageType mtype = cmake::LOG;
|
2008-09-24 16:51:19 +04:00
|
|
|
if ( res && !emsg[0] )
|
2007-02-09 21:44:37 +03:00
|
|
|
{
|
|
|
|
source = parser.GetResult();
|
2005-06-13 19:00:29 +04:00
|
|
|
}
|
2007-02-09 21:44:37 +03:00
|
|
|
else
|
2005-06-13 19:00:29 +04:00
|
|
|
{
|
2008-09-24 16:51:19 +04:00
|
|
|
// Construct the main error message.
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream error;
|
2008-09-24 16:51:19 +04:00
|
|
|
error << "Syntax error in cmake code ";
|
|
|
|
if(filename && line > 0)
|
2005-07-13 19:21:30 +04:00
|
|
|
{
|
2008-09-24 16:51:19 +04:00
|
|
|
// This filename and line number may be more specific than the
|
|
|
|
// command context because one command invocation can have
|
|
|
|
// arguments on multiple lines.
|
|
|
|
error << "at\n"
|
|
|
|
<< " " << filename << ":" << line << "\n";
|
2001-07-28 00:29:50 +04:00
|
|
|
}
|
2008-09-24 16:51:19 +04:00
|
|
|
error << "when parsing string\n"
|
2014-03-11 16:35:32 +04:00
|
|
|
<< " " << source << "\n";
|
2008-09-24 16:51:19 +04:00
|
|
|
error << emsg;
|
|
|
|
|
|
|
|
// If the parser failed ("res" is false) then this is a real
|
|
|
|
// argument parsing error, so the policy applies. Otherwise the
|
|
|
|
// parser reported an error message without failing because the
|
|
|
|
// helper implementation is unhappy, which has always reported an
|
|
|
|
// error.
|
2014-02-08 07:37:54 +04:00
|
|
|
mtype = cmake::FATAL_ERROR;
|
2008-09-24 16:51:19 +04:00
|
|
|
if(!res)
|
2001-07-28 00:29:50 +04:00
|
|
|
{
|
2008-09-24 16:51:19 +04:00
|
|
|
// This is a real argument parsing error. Use policy CMP0010 to
|
|
|
|
// decide whether it is an error.
|
|
|
|
switch(this->GetPolicyStatus(cmPolicies::CMP0010))
|
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
2015-05-03 11:12:10 +03:00
|
|
|
error << "\n" << cmPolicies::GetPolicyWarning(cmPolicies::CMP0010);
|
2008-09-24 16:51:19 +04:00
|
|
|
case cmPolicies::OLD:
|
|
|
|
// OLD behavior is to just warn and continue.
|
|
|
|
mtype = cmake::AUTHOR_WARNING;
|
|
|
|
break;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
|
|
error << "\n"
|
2015-05-03 11:12:10 +03:00
|
|
|
<< cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0010);
|
2008-09-24 16:51:19 +04:00
|
|
|
case cmPolicies::NEW:
|
|
|
|
// NEW behavior is to report the error.
|
|
|
|
break;
|
|
|
|
}
|
2001-07-28 00:29:50 +04:00
|
|
|
}
|
2014-02-08 07:37:54 +04:00
|
|
|
errorstr = error.str();
|
2001-09-02 00:12:52 +04:00
|
|
|
}
|
2014-02-08 07:37:54 +04:00
|
|
|
return mtype;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
NORMAL,
|
|
|
|
ENVIRONMENT,
|
|
|
|
CACHE
|
|
|
|
} t_domain;
|
|
|
|
struct t_lookup
|
|
|
|
{
|
|
|
|
t_lookup(): domain(NORMAL), loc(0) {}
|
|
|
|
t_domain domain;
|
|
|
|
size_t loc;
|
|
|
|
};
|
|
|
|
|
|
|
|
cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
|
|
|
|
std::string& errorstr,
|
|
|
|
std::string& source,
|
|
|
|
bool escapeQuotes,
|
|
|
|
bool noEscapes,
|
|
|
|
bool atOnly,
|
|
|
|
const char* filename,
|
|
|
|
long line,
|
|
|
|
bool removeEmpty,
|
|
|
|
bool replaceAt) const
|
|
|
|
{
|
|
|
|
// This method replaces ${VAR} and @VAR@ where VAR is looked up
|
|
|
|
// with GetDefinition(), if not found in the map, nothing is expanded.
|
|
|
|
// It also supports the $ENV{VAR} syntax where VAR is looked up in
|
|
|
|
// the current environment variables.
|
|
|
|
|
|
|
|
const char* in = source.c_str();
|
|
|
|
const char* last = in;
|
|
|
|
std::string result;
|
|
|
|
result.reserve(source.size());
|
2016-01-15 16:37:25 +03:00
|
|
|
std::vector<t_lookup> openstack;
|
2014-02-08 07:37:54 +04:00
|
|
|
bool error = false;
|
|
|
|
bool done = false;
|
|
|
|
cmake::MessageType mtype = cmake::LOG;
|
|
|
|
|
2015-04-06 11:52:45 +03:00
|
|
|
cmState* state = this->GetCMakeInstance()->GetState();
|
|
|
|
|
2014-02-08 07:37:54 +04:00
|
|
|
do
|
|
|
|
{
|
|
|
|
char inc = *in;
|
|
|
|
switch(inc)
|
|
|
|
{
|
|
|
|
case '}':
|
2016-01-15 16:37:25 +03:00
|
|
|
if(!openstack.empty())
|
2014-02-08 07:37:54 +04:00
|
|
|
{
|
2016-01-15 16:37:25 +03:00
|
|
|
t_lookup var = openstack.back();
|
|
|
|
openstack.pop_back();
|
2014-02-08 07:37:54 +04:00
|
|
|
result.append(last, in - last);
|
|
|
|
std::string const& lookup = result.substr(var.loc);
|
|
|
|
const char* value = NULL;
|
|
|
|
std::string varresult;
|
|
|
|
static const std::string lineVar = "CMAKE_CURRENT_LIST_LINE";
|
|
|
|
switch(var.domain)
|
|
|
|
{
|
|
|
|
case NORMAL:
|
|
|
|
if(filename && lookup == lineVar)
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream ostr;
|
2014-02-08 07:37:54 +04:00
|
|
|
ostr << line;
|
|
|
|
varresult = ostr.str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = this->GetDefinition(lookup);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ENVIRONMENT:
|
|
|
|
value = cmSystemTools::GetEnv(lookup.c_str());
|
|
|
|
break;
|
|
|
|
case CACHE:
|
2015-04-06 11:52:45 +03:00
|
|
|
value = state->GetCacheEntryValue(lookup);
|
2014-02-08 07:37:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Get the string we're meant to append to.
|
|
|
|
if(value)
|
|
|
|
{
|
|
|
|
if(escapeQuotes)
|
|
|
|
{
|
|
|
|
varresult = cmSystemTools::EscapeQuotes(value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
varresult = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(!removeEmpty)
|
|
|
|
{
|
|
|
|
// check to see if we need to print a warning
|
|
|
|
// if strict mode is on and the variable has
|
|
|
|
// not been "cleared"/initialized with a set(foo ) call
|
|
|
|
if(this->GetCMakeInstance()->GetWarnUninitialized() &&
|
|
|
|
!this->VariableInitialized(lookup))
|
|
|
|
{
|
|
|
|
if (this->CheckSystemVars ||
|
|
|
|
cmSystemTools::IsSubDirectory(filename,
|
|
|
|
this->GetHomeDirectory()) ||
|
|
|
|
cmSystemTools::IsSubDirectory(filename,
|
|
|
|
this->GetHomeOutputDirectory()))
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream msg;
|
2014-02-08 07:37:54 +04:00
|
|
|
msg << "uninitialized variable \'" << lookup << "\'";
|
2016-04-15 17:13:12 +03:00
|
|
|
this->IssueMessage(cmake::AUTHOR_WARNING, msg.str());
|
2014-02-08 07:37:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.replace(var.loc, result.size() - var.loc, varresult);
|
|
|
|
// Start looking from here on out.
|
|
|
|
last = in + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '$':
|
|
|
|
if(!atOnly)
|
|
|
|
{
|
|
|
|
t_lookup lookup;
|
|
|
|
const char* next = in + 1;
|
|
|
|
const char* start = NULL;
|
|
|
|
char nextc = *next;
|
|
|
|
if(nextc == '{')
|
|
|
|
{
|
|
|
|
// Looking for a variable.
|
|
|
|
start = in + 2;
|
|
|
|
lookup.domain = NORMAL;
|
|
|
|
}
|
|
|
|
else if(nextc == '<')
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else if(!nextc)
|
|
|
|
{
|
|
|
|
result.append(last, next - last);
|
|
|
|
last = next;
|
|
|
|
}
|
|
|
|
else if(cmHasLiteralPrefix(next, "ENV{"))
|
|
|
|
{
|
|
|
|
// Looking for an environment variable.
|
|
|
|
start = in + 5;
|
|
|
|
lookup.domain = ENVIRONMENT;
|
|
|
|
}
|
|
|
|
else if(cmHasLiteralPrefix(next, "CACHE{"))
|
|
|
|
{
|
|
|
|
// Looking for a cache variable.
|
|
|
|
start = in + 7;
|
|
|
|
lookup.domain = CACHE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(this->cmNamedCurly.find(next))
|
|
|
|
{
|
|
|
|
errorstr = "Syntax $"
|
|
|
|
+ std::string(next, this->cmNamedCurly.end())
|
|
|
|
+ "{} is not supported. Only ${}, $ENV{}, "
|
|
|
|
"and $CACHE{} are allowed.";
|
|
|
|
mtype = cmake::FATAL_ERROR;
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(start)
|
|
|
|
{
|
|
|
|
result.append(last, in - last);
|
|
|
|
last = start;
|
|
|
|
in = start - 1;
|
|
|
|
lookup.loc = result.size();
|
2016-01-15 16:37:25 +03:00
|
|
|
openstack.push_back(lookup);
|
2014-02-08 07:37:54 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '\\':
|
|
|
|
if(!noEscapes)
|
|
|
|
{
|
|
|
|
const char* next = in + 1;
|
|
|
|
char nextc = *next;
|
|
|
|
if(nextc == 't')
|
|
|
|
{
|
|
|
|
result.append(last, in - last);
|
|
|
|
result.append("\t");
|
|
|
|
last = next + 1;
|
|
|
|
}
|
|
|
|
else if(nextc == 'n')
|
|
|
|
{
|
|
|
|
result.append(last, in - last);
|
|
|
|
result.append("\n");
|
|
|
|
last = next + 1;
|
|
|
|
}
|
|
|
|
else if(nextc == 'r')
|
|
|
|
{
|
|
|
|
result.append(last, in - last);
|
|
|
|
result.append("\r");
|
|
|
|
last = next + 1;
|
|
|
|
}
|
2016-01-15 16:37:25 +03:00
|
|
|
else if(nextc == ';' && openstack.empty())
|
2014-02-08 07:37:54 +04:00
|
|
|
{
|
|
|
|
// Handled in ExpandListArgument; pass the backslash literally.
|
|
|
|
}
|
|
|
|
else if (isalnum(nextc) || nextc == '\0')
|
|
|
|
{
|
|
|
|
errorstr += "Invalid character escape '\\";
|
|
|
|
if (nextc)
|
|
|
|
{
|
|
|
|
errorstr += nextc;
|
|
|
|
errorstr += "'.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
errorstr += "' (at end of input).";
|
|
|
|
}
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Take what we've found so far, skipping the escape character.
|
|
|
|
result.append(last, in - last);
|
|
|
|
// Start tracking from the next character.
|
|
|
|
last = in + 1;
|
|
|
|
}
|
|
|
|
// Skip the next character since it was escaped, but don't read past
|
|
|
|
// the end of the string.
|
|
|
|
if(*last)
|
|
|
|
{
|
|
|
|
++in;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
// Onto the next line.
|
|
|
|
++line;
|
|
|
|
break;
|
|
|
|
case '\0':
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
case '@':
|
|
|
|
if(replaceAt)
|
|
|
|
{
|
|
|
|
const char* nextAt = strchr(in + 1, '@');
|
|
|
|
if(nextAt && nextAt != in + 1 &&
|
|
|
|
nextAt == in + 1 + strspn(in + 1,
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
"abcdefghijklmnopqrstuvwxyz"
|
|
|
|
"0123456789/_.+-"))
|
|
|
|
{
|
|
|
|
std::string variable(in + 1, nextAt - in - 1);
|
|
|
|
std::string varresult = this->GetSafeDefinition(variable);
|
|
|
|
if(escapeQuotes)
|
|
|
|
{
|
|
|
|
varresult = cmSystemTools::EscapeQuotes(varresult);
|
|
|
|
}
|
|
|
|
// Skip over the variable.
|
|
|
|
result.append(last, in - last);
|
|
|
|
result.append(varresult);
|
|
|
|
in = nextAt;
|
|
|
|
last = in + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Failed to find a valid @ expansion; treat it as literal.
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
default:
|
|
|
|
{
|
2016-01-15 16:37:25 +03:00
|
|
|
if(!openstack.empty() &&
|
2014-02-08 07:37:54 +04:00
|
|
|
!(isalnum(inc) || inc == '_' ||
|
|
|
|
inc == '/' || inc == '.' ||
|
|
|
|
inc == '+' || inc == '-'))
|
|
|
|
{
|
|
|
|
errorstr += "Invalid character (\'";
|
|
|
|
errorstr += inc;
|
|
|
|
result.append(last, in - last);
|
|
|
|
errorstr += "\') in a variable name: "
|
2016-01-15 16:37:25 +03:00
|
|
|
"'" + result.substr(openstack.back().loc) + "'";
|
2014-02-08 07:37:54 +04:00
|
|
|
mtype = cmake::FATAL_ERROR;
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Look at the next character.
|
|
|
|
} while(!error && !done && *++in);
|
|
|
|
|
|
|
|
// Check for open variable references yet.
|
2016-01-15 16:37:25 +03:00
|
|
|
if(!error && !openstack.empty())
|
2014-02-08 07:37:54 +04:00
|
|
|
{
|
|
|
|
// There's an open variable reference waiting. Policy CMP0010 flags
|
|
|
|
// whether this is an error or not. The new parser now enforces
|
|
|
|
// CMP0010 as well.
|
|
|
|
errorstr += "There is an unterminated variable reference.";
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(error)
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream emsg;
|
2014-02-08 07:37:54 +04:00
|
|
|
emsg << "Syntax error in cmake code ";
|
|
|
|
if(filename)
|
|
|
|
{
|
|
|
|
// This filename and line number may be more specific than the
|
|
|
|
// command context because one command invocation can have
|
|
|
|
// arguments on multiple lines.
|
|
|
|
emsg << "at\n"
|
|
|
|
<< " " << filename << ":" << line << "\n";
|
|
|
|
}
|
|
|
|
emsg << "when parsing string\n"
|
|
|
|
<< " " << source << "\n";
|
|
|
|
emsg << errorstr;
|
|
|
|
mtype = cmake::FATAL_ERROR;
|
|
|
|
errorstr = emsg.str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Append the rest of the unchanged part of the string.
|
|
|
|
result.append(last);
|
|
|
|
|
|
|
|
source = result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mtype;
|
2001-02-13 03:49:52 +03:00
|
|
|
}
|
|
|
|
|
2001-10-30 22:05:07 +03:00
|
|
|
void cmMakefile::RemoveVariablesInString(std::string& source,
|
|
|
|
bool atOnly) const
|
2001-04-30 18:44:00 +04:00
|
|
|
{
|
2001-10-30 22:05:07 +03:00
|
|
|
if(!atOnly)
|
2001-04-30 18:44:00 +04:00
|
|
|
{
|
2003-06-23 22:10:12 +04:00
|
|
|
cmsys::RegularExpression var("(\\${[A-Za-z_0-9]*})");
|
2001-10-30 22:05:07 +03:00
|
|
|
while (var.find(source))
|
|
|
|
{
|
|
|
|
source.erase(var.start(),var.end() - var.start());
|
|
|
|
}
|
2001-04-30 18:44:00 +04:00
|
|
|
}
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2001-10-30 22:05:07 +03:00
|
|
|
if(!atOnly)
|
2001-08-18 20:52:19 +04:00
|
|
|
{
|
2003-06-23 22:10:12 +04:00
|
|
|
cmsys::RegularExpression varb("(\\$ENV{[A-Za-z_0-9]*})");
|
2001-10-30 22:05:07 +03:00
|
|
|
while (varb.find(source))
|
|
|
|
{
|
|
|
|
source.erase(varb.start(),varb.end() - varb.start());
|
|
|
|
}
|
2001-08-18 20:52:19 +04:00
|
|
|
}
|
2003-06-23 22:10:12 +04:00
|
|
|
cmsys::RegularExpression var2("(@[A-Za-z_0-9]*@)");
|
2001-04-30 18:44:00 +04:00
|
|
|
while (var2.find(source))
|
|
|
|
{
|
2001-05-04 19:30:46 +04:00
|
|
|
source.erase(var2.start(),var2.end() - var2.start());
|
2001-04-30 18:44:00 +04:00
|
|
|
}
|
|
|
|
}
|
2001-02-23 03:24:43 +03:00
|
|
|
|
2014-02-10 07:48:34 +04:00
|
|
|
std::string
|
2010-09-08 22:54:49 +04:00
|
|
|
cmMakefile::GetConfigurations(std::vector<std::string>& configs,
|
2015-09-30 15:47:02 +03:00
|
|
|
bool singleConfig) const
|
2010-09-08 22:54:49 +04:00
|
|
|
{
|
2015-05-03 12:10:30 +03:00
|
|
|
if(this->GetGlobalGenerator()->IsMultiConfig())
|
2010-09-08 22:54:49 +04:00
|
|
|
{
|
|
|
|
if(const char* configTypes =
|
|
|
|
this->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
|
|
|
|
{
|
|
|
|
cmSystemTools::ExpandListArgument(configTypes, configs);
|
|
|
|
}
|
2014-02-10 07:48:34 +04:00
|
|
|
return "";
|
2010-09-08 22:54:49 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-10 07:48:34 +04:00
|
|
|
const std::string& buildType = this->GetSafeDefinition("CMAKE_BUILD_TYPE");
|
2015-09-30 15:47:02 +03:00
|
|
|
if(singleConfig && !buildType.empty())
|
2010-09-08 22:54:49 +04:00
|
|
|
{
|
|
|
|
configs.push_back(buildType);
|
|
|
|
}
|
|
|
|
return buildType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-22 17:58:11 +03:00
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
2001-03-20 21:20:59 +03:00
|
|
|
/**
|
|
|
|
* Find a source group whose regular expression matches the filename
|
|
|
|
* part of the given source name. Search backward through the list of
|
|
|
|
* source groups, and take the first matching group found. This way
|
|
|
|
* non-inherited SOURCE_GROUP commands will have precedence over
|
|
|
|
* inherited ones.
|
|
|
|
*/
|
2014-01-21 19:43:47 +04:00
|
|
|
cmSourceGroup*
|
2001-04-11 22:59:02 +04:00
|
|
|
cmMakefile::FindSourceGroup(const char* source,
|
2014-01-21 19:43:47 +04:00
|
|
|
std::vector<cmSourceGroup> &groups) const
|
2001-03-20 21:20:59 +03:00
|
|
|
{
|
2003-07-23 23:32:54 +04:00
|
|
|
// First search for a group that lists the file explicitly.
|
|
|
|
for(std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin();
|
|
|
|
sg != groups.rend(); ++sg)
|
2001-03-20 21:20:59 +03:00
|
|
|
{
|
2005-07-13 19:21:30 +04:00
|
|
|
cmSourceGroup *result = sg->MatchChildrenFiles(source);
|
|
|
|
if(result)
|
2003-07-23 23:32:54 +04:00
|
|
|
{
|
2014-01-21 19:43:47 +04:00
|
|
|
return result;
|
2003-07-23 23:32:54 +04:00
|
|
|
}
|
2001-03-20 21:20:59 +03:00
|
|
|
}
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2003-07-23 23:32:54 +04:00
|
|
|
// Now search for a group whose regex matches the file.
|
2001-04-11 22:59:02 +04:00
|
|
|
for(std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin();
|
|
|
|
sg != groups.rend(); ++sg)
|
2001-03-20 21:20:59 +03:00
|
|
|
{
|
2005-07-13 19:21:30 +04:00
|
|
|
cmSourceGroup *result = sg->MatchChildrenRegex(source);
|
|
|
|
if(result)
|
2001-03-20 21:20:59 +03:00
|
|
|
{
|
2014-01-21 19:43:47 +04:00
|
|
|
return result;
|
2001-03-20 21:20:59 +03:00
|
|
|
}
|
|
|
|
}
|
2005-07-13 19:21:30 +04:00
|
|
|
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2001-03-20 21:20:59 +03:00
|
|
|
// Shouldn't get here, but just in case, return the default group.
|
2014-01-21 19:43:47 +04:00
|
|
|
return &groups.front();
|
2001-03-20 21:20:59 +03:00
|
|
|
}
|
2006-03-22 17:58:11 +03:00
|
|
|
#endif
|
2001-04-11 22:59:02 +04:00
|
|
|
|
2008-01-23 18:28:26 +03:00
|
|
|
bool cmMakefile::IsFunctionBlocked(const cmListFileFunction& lff,
|
|
|
|
cmExecutionStatus &status)
|
2001-04-20 01:39:03 +04:00
|
|
|
{
|
2002-06-28 05:17:25 +04:00
|
|
|
// if there are no blockers get out of here
|
2006-03-15 19:02:08 +03:00
|
|
|
if (this->FunctionBlockers.begin() == this->FunctionBlockers.end())
|
2002-06-28 05:17:25 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-04-20 01:39:03 +04:00
|
|
|
// loop over all function blockers to see if any block this command
|
2002-08-09 20:00:49 +04:00
|
|
|
// evaluate in reverse, this is critical for balanced IF statements etc
|
2009-01-21 17:48:00 +03:00
|
|
|
std::vector<cmFunctionBlocker*>::reverse_iterator pos;
|
2007-06-08 19:57:16 +04:00
|
|
|
for (pos = this->FunctionBlockers.rbegin();
|
2006-03-15 19:02:08 +03:00
|
|
|
pos != this->FunctionBlockers.rend(); ++pos)
|
2001-04-20 01:39:03 +04:00
|
|
|
{
|
2008-01-23 18:28:26 +03:00
|
|
|
if((*pos)->IsFunctionBlocked(lff, *this, status))
|
2001-04-20 01:39:03 +04:00
|
|
|
{
|
2002-12-12 02:13:33 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2002-12-12 02:13:33 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-01-21 17:48:00 +03:00
|
|
|
void cmMakefile::PushFunctionBlockerBarrier()
|
|
|
|
{
|
|
|
|
this->FunctionBlockerBarriers.push_back(this->FunctionBlockers.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefile::PopFunctionBlockerBarrier(bool reportError)
|
|
|
|
{
|
|
|
|
// Remove any extra entries pushed on the barrier.
|
|
|
|
FunctionBlockersType::size_type barrier =
|
|
|
|
this->FunctionBlockerBarriers.back();
|
|
|
|
while(this->FunctionBlockers.size() > barrier)
|
|
|
|
{
|
|
|
|
cmsys::auto_ptr<cmFunctionBlocker> fb(this->FunctionBlockers.back());
|
|
|
|
this->FunctionBlockers.pop_back();
|
|
|
|
if(reportError)
|
|
|
|
{
|
2009-01-21 17:48:20 +03:00
|
|
|
// Report the context in which the unclosed block was opened.
|
|
|
|
cmListFileContext const& lfc = fb->GetStartingContext();
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2009-01-21 17:48:20 +03:00
|
|
|
e << "A logical block opening on the line\n"
|
|
|
|
<< " " << lfc << "\n"
|
|
|
|
<< "is not closed.";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2009-01-21 17:48:20 +03:00
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
reportError = false;
|
2009-01-21 17:48:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the barrier.
|
|
|
|
this->FunctionBlockerBarriers.pop_back();
|
|
|
|
}
|
|
|
|
|
2014-11-18 18:34:30 +03:00
|
|
|
void cmMakefile::PushLoopBlock()
|
|
|
|
{
|
|
|
|
assert(!this->LoopBlockCounter.empty());
|
|
|
|
this->LoopBlockCounter.top()++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefile::PopLoopBlock()
|
|
|
|
{
|
|
|
|
assert(!this->LoopBlockCounter.empty());
|
|
|
|
assert(this->LoopBlockCounter.top() > 0);
|
|
|
|
this->LoopBlockCounter.top()--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefile::PushLoopBlockBarrier()
|
|
|
|
{
|
|
|
|
this->LoopBlockCounter.push(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefile::PopLoopBlockBarrier()
|
|
|
|
{
|
|
|
|
assert(!this->LoopBlockCounter.empty());
|
|
|
|
assert(this->LoopBlockCounter.top() == 0);
|
|
|
|
this->LoopBlockCounter.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmMakefile::IsLoopBlock() const
|
|
|
|
{
|
|
|
|
assert(!this->LoopBlockCounter.empty());
|
|
|
|
return !this->LoopBlockCounter.empty() && this->LoopBlockCounter.top() > 0;
|
|
|
|
}
|
|
|
|
|
2015-05-23 21:32:05 +03:00
|
|
|
std::string cmMakefile::GetExecutionFilePath() const
|
|
|
|
{
|
2015-07-04 13:20:47 +03:00
|
|
|
assert(this->StateSnapshot.IsValid());
|
|
|
|
return this->StateSnapshot.GetExecutionListFile();
|
2015-05-23 21:32:05 +03:00
|
|
|
}
|
|
|
|
|
2008-09-24 16:51:33 +04:00
|
|
|
bool cmMakefile::ExpandArguments(
|
2002-12-12 02:13:33 +03:00
|
|
|
std::vector<cmListFileArgument> const& inArgs,
|
2015-05-23 21:32:05 +03:00
|
|
|
std::vector<std::string>& outArgs, const char* filename) const
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
2015-05-23 21:32:05 +03:00
|
|
|
std::string efp = this->GetExecutionFilePath();
|
|
|
|
if (!filename)
|
|
|
|
{
|
|
|
|
filename = efp.c_str();
|
|
|
|
}
|
2002-12-12 02:13:33 +03:00
|
|
|
std::vector<cmListFileArgument>::const_iterator i;
|
2003-06-24 23:23:34 +04:00
|
|
|
std::string value;
|
|
|
|
outArgs.reserve(inArgs.size());
|
2002-12-12 02:13:33 +03:00
|
|
|
for(i = inArgs.begin(); i != inArgs.end(); ++i)
|
|
|
|
{
|
2013-08-06 23:58:22 +04:00
|
|
|
// No expansion in a bracket argument.
|
|
|
|
if(i->Delim == cmListFileArgument::Bracket)
|
|
|
|
{
|
|
|
|
outArgs.push_back(i->Value);
|
|
|
|
continue;
|
|
|
|
}
|
2002-12-12 02:13:33 +03:00
|
|
|
// Expand the variables in the argument.
|
2003-06-24 23:23:34 +04:00
|
|
|
value = i->Value;
|
2007-06-08 19:57:16 +04:00
|
|
|
this->ExpandVariablesInString(value, false, false, false,
|
2015-05-23 21:32:05 +03:00
|
|
|
filename, i->Line, false, false);
|
2004-08-04 18:45:11 +04:00
|
|
|
|
2002-12-12 02:13:33 +03:00
|
|
|
// If the argument is quoted, it should be one argument.
|
|
|
|
// Otherwise, it may be a list of arguments.
|
2012-08-06 18:07:58 +04:00
|
|
|
if(i->Delim == cmListFileArgument::Quoted)
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
|
|
|
outArgs.push_back(value);
|
2002-03-27 00:45:52 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-12-12 02:13:33 +03:00
|
|
|
cmSystemTools::ExpandListArgument(value, outArgs);
|
2001-04-20 01:39:03 +04:00
|
|
|
}
|
|
|
|
}
|
2008-09-24 16:51:33 +04:00
|
|
|
return !cmSystemTools::GetFatalErrorOccured();
|
2001-04-20 01:39:03 +04:00
|
|
|
}
|
|
|
|
|
2014-09-04 22:21:28 +04:00
|
|
|
bool cmMakefile::ExpandArguments(
|
|
|
|
std::vector<cmListFileArgument> const& inArgs,
|
2015-05-23 21:32:05 +03:00
|
|
|
std::vector<cmExpandedCommandArgument>& outArgs, const char* filename) const
|
2014-09-04 22:21:28 +04:00
|
|
|
{
|
2015-05-23 21:32:05 +03:00
|
|
|
std::string efp = this->GetExecutionFilePath();
|
|
|
|
if (!filename)
|
|
|
|
{
|
|
|
|
filename = efp.c_str();
|
|
|
|
}
|
2014-09-04 22:21:28 +04:00
|
|
|
std::vector<cmListFileArgument>::const_iterator i;
|
|
|
|
std::string value;
|
|
|
|
outArgs.reserve(inArgs.size());
|
|
|
|
for(i = inArgs.begin(); i != inArgs.end(); ++i)
|
|
|
|
{
|
|
|
|
// No expansion in a bracket argument.
|
|
|
|
if(i->Delim == cmListFileArgument::Bracket)
|
|
|
|
{
|
|
|
|
outArgs.push_back(cmExpandedCommandArgument(i->Value, true));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Expand the variables in the argument.
|
|
|
|
value = i->Value;
|
|
|
|
this->ExpandVariablesInString(value, false, false, false,
|
2015-05-23 21:32:05 +03:00
|
|
|
filename, i->Line, false, false);
|
2014-09-04 22:21:28 +04:00
|
|
|
|
|
|
|
// If the argument is quoted, it should be one argument.
|
|
|
|
// Otherwise, it may be a list of arguments.
|
|
|
|
if(i->Delim == cmListFileArgument::Quoted)
|
|
|
|
{
|
|
|
|
outArgs.push_back(cmExpandedCommandArgument(value, true));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector<std::string> stringArgs;
|
|
|
|
cmSystemTools::ExpandListArgument(value, stringArgs);
|
|
|
|
for(size_t j = 0; j < stringArgs.size(); ++j)
|
|
|
|
{
|
|
|
|
outArgs.push_back(cmExpandedCommandArgument(stringArgs[j], false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return !cmSystemTools::GetFatalErrorOccured();
|
|
|
|
}
|
|
|
|
|
2009-01-21 17:48:20 +03:00
|
|
|
void cmMakefile::AddFunctionBlocker(cmFunctionBlocker* fb)
|
|
|
|
{
|
2015-05-31 20:37:08 +03:00
|
|
|
if(!this->ExecutionStatusStack.empty())
|
2009-01-21 17:48:20 +03:00
|
|
|
{
|
|
|
|
// Record the context in which the blocker is created.
|
2015-05-18 22:35:29 +03:00
|
|
|
fb->SetStartingContext(this->GetExecutionContext());
|
2009-01-21 17:48:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
this->FunctionBlockers.push_back(fb);
|
|
|
|
}
|
|
|
|
|
2009-01-20 22:36:18 +03:00
|
|
|
cmsys::auto_ptr<cmFunctionBlocker>
|
2009-01-21 17:49:00 +03:00
|
|
|
cmMakefile::RemoveFunctionBlocker(cmFunctionBlocker* fb,
|
|
|
|
const cmListFileFunction& lff)
|
2001-04-20 01:39:03 +04:00
|
|
|
{
|
2009-01-21 17:48:00 +03:00
|
|
|
// Find the function blocker stack barrier for the current scope.
|
|
|
|
// We only remove a blocker whose index is not less than the barrier.
|
|
|
|
FunctionBlockersType::size_type barrier = 0;
|
|
|
|
if(!this->FunctionBlockerBarriers.empty())
|
2001-04-20 01:39:03 +04:00
|
|
|
{
|
2009-01-21 17:48:00 +03:00
|
|
|
barrier = this->FunctionBlockerBarriers.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search for the function blocker whose scope this command ends.
|
|
|
|
for(FunctionBlockersType::size_type
|
|
|
|
i = this->FunctionBlockers.size(); i > barrier; --i)
|
|
|
|
{
|
|
|
|
std::vector<cmFunctionBlocker*>::iterator pos =
|
|
|
|
this->FunctionBlockers.begin() + (i - 1);
|
2009-01-21 17:49:00 +03:00
|
|
|
if (*pos == fb)
|
2001-04-20 01:39:03 +04:00
|
|
|
{
|
2009-01-21 17:49:00 +03:00
|
|
|
// Warn if the arguments do not match, but always remove.
|
|
|
|
if(!(*pos)->ShouldRemove(lff, *this))
|
|
|
|
{
|
|
|
|
cmListFileContext const& lfc = fb->GetStartingContext();
|
2015-07-04 14:12:50 +03:00
|
|
|
cmListFileContext closingContext =
|
|
|
|
cmListFileContext::FromCommandContext(lff, lfc.FilePath);
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2009-01-21 17:49:00 +03:00
|
|
|
e << "A logical block opening on the line\n"
|
|
|
|
<< " " << lfc << "\n"
|
|
|
|
<< "closes on the line\n"
|
2015-07-04 14:12:50 +03:00
|
|
|
<< " " << closingContext << "\n"
|
2009-01-21 17:49:00 +03:00
|
|
|
<< "with mis-matching arguments.";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2009-01-21 17:49:00 +03:00
|
|
|
this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
|
|
|
|
}
|
2001-06-04 18:18:03 +04:00
|
|
|
cmFunctionBlocker* b = *pos;
|
2009-01-21 17:48:00 +03:00
|
|
|
this->FunctionBlockers.erase(pos);
|
2009-01-20 22:36:18 +03:00
|
|
|
return cmsys::auto_ptr<cmFunctionBlocker>(b);
|
2001-04-20 01:39:03 +04:00
|
|
|
}
|
|
|
|
}
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2009-01-20 22:36:18 +03:00
|
|
|
return cmsys::auto_ptr<cmFunctionBlocker>();
|
2001-04-20 01:39:03 +04:00
|
|
|
}
|
2001-04-30 18:44:00 +04:00
|
|
|
|
2015-04-12 21:10:45 +03:00
|
|
|
const char* cmMakefile::GetHomeDirectory() const
|
|
|
|
{
|
2015-04-26 18:18:27 +03:00
|
|
|
return this->GetCMakeInstance()->GetHomeDirectory();
|
2015-04-12 21:10:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* cmMakefile::GetHomeOutputDirectory() const
|
|
|
|
{
|
2015-04-26 18:18:27 +03:00
|
|
|
return this->GetCMakeInstance()->GetHomeOutputDirectory();
|
2015-04-12 21:10:45 +03:00
|
|
|
}
|
|
|
|
|
2011-02-03 02:18:14 +03:00
|
|
|
void cmMakefile::SetScriptModeFile(const char* scriptfile)
|
|
|
|
{
|
|
|
|
this->AddDefinition("CMAKE_SCRIPT_MODE_FILE", scriptfile);
|
|
|
|
}
|
|
|
|
|
2011-02-03 05:17:23 +03:00
|
|
|
void cmMakefile::SetArgcArgv(const std::vector<std::string>& args)
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream strStream;
|
2011-02-03 05:17:23 +03:00
|
|
|
strStream << args.size();
|
|
|
|
this->AddDefinition("CMAKE_ARGC", strStream.str().c_str());
|
|
|
|
//this->MarkVariableAsUsed("CMAKE_ARGC");
|
|
|
|
|
|
|
|
for (unsigned int t = 0; t < args.size(); ++t)
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream tmpStream;
|
2011-02-03 05:17:23 +03:00
|
|
|
tmpStream << "CMAKE_ARGV" << t;
|
2014-03-11 03:04:11 +04:00
|
|
|
this->AddDefinition(tmpStream.str(), args[t].c_str());
|
2011-02-03 05:17:23 +03:00
|
|
|
//this->MarkVariableAsUsed(tmpStream.str().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-06 23:05:57 +04:00
|
|
|
cmSourceFile* cmMakefile::GetSource(const std::string& sourceName) const
|
2002-03-29 18:06:30 +03:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
cmSourceFileLocation sfl(this, sourceName);
|
|
|
|
for(std::vector<cmSourceFile*>::const_iterator
|
|
|
|
sfi = this->SourceFiles.begin();
|
|
|
|
sfi != this->SourceFiles.end(); ++sfi)
|
2003-06-06 00:12:25 +04:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
cmSourceFile* sf = *sfi;
|
|
|
|
if(sf->Matches(sfl))
|
2003-06-06 00:12:25 +04:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
return sf;
|
2003-06-06 00:12:25 +04:00
|
|
|
}
|
2007-06-08 19:57:16 +04:00
|
|
|
}
|
2002-03-29 18:06:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-12 02:04:11 +04:00
|
|
|
cmSourceFile* cmMakefile::CreateSource(const std::string& sourceName,
|
|
|
|
bool generated)
|
|
|
|
{
|
|
|
|
cmSourceFile* sf = new cmSourceFile(this, sourceName);
|
|
|
|
if(generated)
|
|
|
|
{
|
|
|
|
sf->SetProperty("GENERATED", "1");
|
|
|
|
}
|
|
|
|
this->SourceFiles.push_back(sf);
|
|
|
|
return sf;
|
|
|
|
}
|
|
|
|
|
2014-02-06 23:05:57 +04:00
|
|
|
cmSourceFile* cmMakefile::GetOrCreateSource(const std::string& sourceName,
|
2003-06-03 18:30:23 +04:00
|
|
|
bool generated)
|
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
if(cmSourceFile* esf = this->GetSource(sourceName))
|
2003-06-05 22:40:25 +04:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
return esf;
|
2003-06-03 18:30:23 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-12 02:04:11 +04:00
|
|
|
return this->CreateSource(sourceName, generated);
|
2003-06-03 18:30:23 +04:00
|
|
|
}
|
|
|
|
}
|
2002-03-29 18:06:30 +03:00
|
|
|
|
2010-09-28 23:44:22 +04:00
|
|
|
void cmMakefile::EnableLanguage(std::vector<std::string> const & lang,
|
2007-06-28 17:09:26 +04:00
|
|
|
bool optional)
|
2002-04-03 00:43:23 +04:00
|
|
|
{
|
2006-02-25 01:35:35 +03:00
|
|
|
this->AddDefinition("CMAKE_CFG_INTDIR",
|
2015-05-03 12:10:30 +03:00
|
|
|
this->GetGlobalGenerator()->GetCMakeCFGIntDir());
|
|
|
|
this->GetGlobalGenerator()->EnableLanguage(lang, this, optional);
|
2002-04-03 00:43:23 +04:00
|
|
|
}
|
2002-05-02 00:33:27 +04:00
|
|
|
|
2014-02-25 02:38:30 +04:00
|
|
|
int cmMakefile::TryCompile(const std::string& srcdir,
|
|
|
|
const std::string& bindir,
|
2014-02-08 00:40:05 +04:00
|
|
|
const std::string& projectName,
|
2014-02-07 02:31:47 +04:00
|
|
|
const std::string& targetName,
|
2009-08-04 22:37:46 +04:00
|
|
|
bool fast,
|
2002-09-20 21:15:56 +04:00
|
|
|
const std::vector<std::string> *cmakeArgs,
|
2014-07-31 20:48:46 +04:00
|
|
|
std::string& output)
|
2002-08-28 22:51:10 +04:00
|
|
|
{
|
2015-08-25 23:19:57 +03:00
|
|
|
this->IsSourceFileTryCompile = fast;
|
2002-08-28 22:51:10 +04:00
|
|
|
// does the binary directory exist ? If not create it...
|
2014-10-15 16:54:05 +04:00
|
|
|
if (!cmSystemTools::FileIsDirectory(bindir))
|
2002-08-28 22:51:10 +04:00
|
|
|
{
|
2014-02-25 02:38:30 +04:00
|
|
|
cmSystemTools::MakeDirectory(bindir.c_str());
|
2002-08-28 22:51:10 +04:00
|
|
|
}
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2002-08-28 22:51:10 +04:00
|
|
|
// change to the tests directory and run cmake
|
|
|
|
// use the cmake object instead of calling cmake
|
|
|
|
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::ChangeDirectory(bindir);
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2002-08-28 22:51:10 +04:00
|
|
|
// make sure the same generator is used
|
|
|
|
// use this program as the cmake to be run, it should not
|
|
|
|
// be run that way but the cmake object requires a vailid path
|
2002-09-06 21:06:23 +04:00
|
|
|
cmake cm;
|
2002-09-12 19:08:06 +04:00
|
|
|
cm.SetIsInTryCompile(true);
|
2006-05-12 20:29:09 +04:00
|
|
|
cmGlobalGenerator *gg = cm.CreateGlobalGenerator
|
2015-05-03 12:10:30 +03:00
|
|
|
(this->GetGlobalGenerator()->GetName());
|
2002-09-06 21:06:23 +04:00
|
|
|
if (!gg)
|
|
|
|
{
|
|
|
|
cmSystemTools::Error(
|
|
|
|
"Internal CMake error, TryCompile bad GlobalGenerator");
|
|
|
|
// return to the original directory
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::ChangeDirectory(cwd);
|
2015-08-25 23:19:57 +03:00
|
|
|
this->IsSourceFileTryCompile = false;
|
2002-09-06 21:06:23 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2002-09-11 20:52:11 +04:00
|
|
|
cm.SetGlobalGenerator(gg);
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2002-09-06 21:06:23 +04:00
|
|
|
// do a configure
|
|
|
|
cm.SetHomeDirectory(srcdir);
|
|
|
|
cm.SetHomeOutputDirectory(bindir);
|
2014-09-05 22:25:27 +04:00
|
|
|
cm.SetGeneratorPlatform(this->GetCMakeInstance()->GetGeneratorPlatform());
|
2012-12-10 19:42:33 +04:00
|
|
|
cm.SetGeneratorToolset(this->GetCMakeInstance()->GetGeneratorToolset());
|
2002-09-17 21:59:58 +04:00
|
|
|
cm.LoadCache();
|
2011-01-18 01:21:30 +03:00
|
|
|
if(!gg->IsMultiConfig())
|
|
|
|
{
|
|
|
|
if(const char* config =
|
|
|
|
this->GetDefinition("CMAKE_TRY_COMPILE_CONFIGURATION"))
|
|
|
|
{
|
|
|
|
// Tell the single-configuration generator which one to use.
|
|
|
|
// Add this before the user-provided CMake arguments in case
|
|
|
|
// one of the arguments is -DCMAKE_BUILD_TYPE=...
|
|
|
|
cm.AddCacheEntry("CMAKE_BUILD_TYPE", config,
|
2015-04-07 23:45:54 +03:00
|
|
|
"Build configuration", cmState::STRING);
|
2011-01-18 01:21:30 +03:00
|
|
|
}
|
|
|
|
}
|
2002-09-18 19:37:40 +04:00
|
|
|
// if cmake args were provided then pass them in
|
|
|
|
if (cmakeArgs)
|
|
|
|
{
|
2011-01-12 01:10:28 +03:00
|
|
|
// FIXME: Workaround to ignore unused CLI variables in try-compile.
|
|
|
|
//
|
|
|
|
// Ideally we should use SetArgs to honor options like --warn-unused-vars.
|
|
|
|
// However, there is a subtle problem when certain arguments are passed to
|
|
|
|
// a macro wrapping around try_compile or try_run that does not escape
|
|
|
|
// semicolons in its parameters but just passes ${ARGV} or ${ARGN}. In
|
|
|
|
// this case a list argument like "-DVAR=a;b" gets split into multiple
|
|
|
|
// cmake arguments "-DVAR=a" and "b". Currently SetCacheArgs ignores
|
|
|
|
// argument "b" and uses just "-DVAR=a", leading to a subtle bug in that
|
|
|
|
// the try_compile or try_run does not get the proper value of VAR. If we
|
|
|
|
// call SetArgs here then it would treat "b" as the source directory and
|
|
|
|
// cause an error such as "The source directory .../CMakeFiles/CMakeTmp/b
|
|
|
|
// does not exist", thus breaking the try_compile or try_run completely.
|
|
|
|
//
|
|
|
|
// Strictly speaking the bug is in the wrapper macro because the CMake
|
|
|
|
// language has always flattened nested lists and the macro should escape
|
|
|
|
// the semicolons in its arguments before forwarding them. However, this
|
|
|
|
// bug is so subtle that projects typically work anyway, usually because
|
|
|
|
// the value VAR=a is sufficient for the try_compile or try_run to get the
|
|
|
|
// correct result. Calling SetArgs here would break such projects that
|
|
|
|
// previously built. Instead we work around the issue by never reporting
|
|
|
|
// unused arguments and ignoring options such as --warn-unused-vars.
|
2010-10-07 20:28:25 +04:00
|
|
|
cm.SetWarnUnusedCli(false);
|
2010-10-07 20:22:00 +04:00
|
|
|
//cm.SetArgs(*cmakeArgs, true);
|
|
|
|
|
2002-09-18 19:37:40 +04:00
|
|
|
cm.SetCacheArgs(*cmakeArgs);
|
|
|
|
}
|
2002-09-13 18:42:50 +04:00
|
|
|
// to save time we pass the EnableLanguage info directly
|
2015-05-03 12:10:30 +03:00
|
|
|
gg->EnableLanguagesFromGenerator(this->GetGlobalGenerator(), this);
|
2008-03-11 22:17:58 +03:00
|
|
|
if(this->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS"))
|
|
|
|
{
|
|
|
|
cm.AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS",
|
2015-04-07 23:45:54 +03:00
|
|
|
"TRUE", "", cmState::INTERNAL);
|
2008-03-11 22:17:58 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cm.AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS",
|
2015-04-07 23:45:54 +03:00
|
|
|
"FALSE", "", cmState::INTERNAL);
|
2010-09-28 23:44:22 +04:00
|
|
|
}
|
2002-09-17 21:59:58 +04:00
|
|
|
if (cm.Configure() != 0)
|
2002-08-28 22:51:10 +04:00
|
|
|
{
|
|
|
|
cmSystemTools::Error(
|
2002-09-06 21:06:23 +04:00
|
|
|
"Internal CMake error, TryCompile configure of cmake failed");
|
2002-08-28 22:51:10 +04:00
|
|
|
// return to the original directory
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::ChangeDirectory(cwd);
|
2015-08-25 23:19:57 +03:00
|
|
|
this->IsSourceFileTryCompile = false;
|
2002-08-28 22:51:10 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-09-06 21:06:23 +04:00
|
|
|
if (cm.Generate() != 0)
|
2002-08-28 22:51:10 +04:00
|
|
|
{
|
|
|
|
cmSystemTools::Error(
|
2002-09-06 21:06:23 +04:00
|
|
|
"Internal CMake error, TryCompile generation of cmake failed");
|
2002-08-28 22:51:10 +04:00
|
|
|
// return to the original directory
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::ChangeDirectory(cwd);
|
2015-08-25 23:19:57 +03:00
|
|
|
this->IsSourceFileTryCompile = false;
|
2002-08-28 22:51:10 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// finally call the generator to actually build the resulting project
|
2015-05-03 12:10:30 +03:00
|
|
|
int ret = this->GetGlobalGenerator()->TryCompile(srcdir,bindir,
|
|
|
|
projectName,
|
|
|
|
targetName,
|
|
|
|
fast,
|
|
|
|
output,
|
|
|
|
this);
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::ChangeDirectory(cwd);
|
2015-08-25 23:19:57 +03:00
|
|
|
this->IsSourceFileTryCompile = false;
|
2002-09-11 00:52:39 +04:00
|
|
|
return ret;
|
2002-08-28 22:51:10 +04:00
|
|
|
}
|
|
|
|
|
2012-09-05 03:44:11 +04:00
|
|
|
bool cmMakefile::GetIsSourceFileTryCompile() const
|
|
|
|
{
|
2015-08-25 23:19:57 +03:00
|
|
|
return this->IsSourceFileTryCompile;
|
2012-09-05 03:44:11 +04:00
|
|
|
}
|
|
|
|
|
2003-01-08 20:59:52 +03:00
|
|
|
cmake *cmMakefile::GetCMakeInstance() const
|
|
|
|
{
|
2015-08-02 12:20:28 +03:00
|
|
|
return this->GlobalGenerator->GetCMakeInstance();
|
2015-05-03 12:08:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmGlobalGenerator* cmMakefile::GetGlobalGenerator() const
|
|
|
|
{
|
2015-08-02 12:20:28 +03:00
|
|
|
return this->GlobalGenerator;
|
2003-01-08 20:59:52 +03:00
|
|
|
}
|
|
|
|
|
2004-10-27 18:47:14 +04:00
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
2003-01-08 20:59:52 +03:00
|
|
|
cmVariableWatch *cmMakefile::GetVariableWatch() const
|
|
|
|
{
|
|
|
|
if ( this->GetCMakeInstance() &&
|
|
|
|
this->GetCMakeInstance()->GetVariableWatch() )
|
|
|
|
{
|
|
|
|
return this->GetCMakeInstance()->GetVariableWatch();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2004-10-27 18:47:14 +04:00
|
|
|
#endif
|
2003-01-08 20:59:52 +03:00
|
|
|
|
2015-04-04 22:20:12 +03:00
|
|
|
cmState *cmMakefile::GetState() const
|
2002-09-06 21:06:23 +04:00
|
|
|
{
|
2015-04-04 22:20:12 +03:00
|
|
|
return this->GetCMakeInstance()->GetState();
|
2002-09-06 21:06:23 +04:00
|
|
|
}
|
2002-09-20 23:01:00 +04:00
|
|
|
|
2014-01-22 18:00:29 +04:00
|
|
|
void cmMakefile::DisplayStatus(const char* message, float s) const
|
2002-11-13 23:59:40 +03:00
|
|
|
{
|
2015-05-03 12:41:29 +03:00
|
|
|
cmake* cm = this->GetCMakeInstance();
|
2011-08-16 02:40:59 +04:00
|
|
|
if (cm->GetWorkingMode() == cmake::FIND_PACKAGE_MODE)
|
|
|
|
{
|
|
|
|
// don't output any STATUS message in FIND_PACKAGE_MODE, since they will
|
|
|
|
// directly be fed to the compiler, which will be confused.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cm->UpdateProgress(message, s);
|
2002-11-13 23:59:40 +03:00
|
|
|
}
|
2002-12-02 23:59:59 +03:00
|
|
|
|
2014-01-22 18:00:29 +04:00
|
|
|
std::string cmMakefile::GetModulesFile(const char* filename) const
|
2004-02-29 02:59:19 +03:00
|
|
|
{
|
2010-11-18 00:32:53 +03:00
|
|
|
std::string result;
|
|
|
|
|
|
|
|
// We search the module always in CMAKE_ROOT and in CMAKE_MODULE_PATH,
|
|
|
|
// and then decide based on the policy setting which one to return.
|
|
|
|
// See CMP0017 for more details.
|
|
|
|
// The specific problem was that KDE 4.5.0 installs a
|
|
|
|
// FindPackageHandleStandardArgs.cmake which doesn't have the new features
|
|
|
|
// of FPHSA.cmake introduced in CMake 2.8.3 yet, and by setting
|
|
|
|
// CMAKE_MODULE_PATH also e.g. FindZLIB.cmake from cmake included
|
|
|
|
// FPHSA.cmake from kdelibs and not from CMake, and tried to use the
|
|
|
|
// new features, which were not there in the version from kdelibs, and so
|
|
|
|
// failed ("
|
|
|
|
std::string moduleInCMakeRoot;
|
|
|
|
std::string moduleInCMakeModulePath;
|
|
|
|
|
|
|
|
// Always search in CMAKE_MODULE_PATH:
|
|
|
|
const char* cmakeModulePath = this->GetDefinition("CMAKE_MODULE_PATH");
|
|
|
|
if(cmakeModulePath)
|
|
|
|
{
|
|
|
|
std::vector<std::string> modulePath;
|
|
|
|
cmSystemTools::ExpandListArgument(cmakeModulePath, modulePath);
|
|
|
|
|
|
|
|
//Look through the possible module directories.
|
|
|
|
for(std::vector<std::string>::iterator i = modulePath.begin();
|
|
|
|
i != modulePath.end(); ++i)
|
|
|
|
{
|
|
|
|
std::string itempl = *i;
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(itempl);
|
|
|
|
itempl += "/";
|
|
|
|
itempl += filename;
|
|
|
|
if(cmSystemTools::FileExists(itempl.c_str()))
|
|
|
|
{
|
|
|
|
moduleInCMakeModulePath = itempl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always search in the standard modules location.
|
2016-03-14 17:38:19 +03:00
|
|
|
moduleInCMakeRoot = cmSystemTools::GetCMakeRoot();
|
|
|
|
moduleInCMakeRoot += "/Modules/";
|
|
|
|
moduleInCMakeRoot += filename;
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(moduleInCMakeRoot);
|
|
|
|
if(!cmSystemTools::FileExists(moduleInCMakeRoot.c_str()))
|
2004-02-29 02:59:19 +03:00
|
|
|
{
|
2016-03-14 17:38:19 +03:00
|
|
|
moduleInCMakeRoot = "";
|
2004-02-29 02:59:19 +03:00
|
|
|
}
|
|
|
|
|
2010-11-18 00:32:53 +03:00
|
|
|
// Normally, prefer the files found in CMAKE_MODULE_PATH. Only when the file
|
|
|
|
// from which we are being called is located itself in CMAKE_ROOT, then
|
|
|
|
// prefer results from CMAKE_ROOT depending on the policy setting.
|
|
|
|
result = moduleInCMakeModulePath;
|
2015-01-15 02:31:49 +03:00
|
|
|
if (result.empty())
|
2004-02-29 02:59:19 +03:00
|
|
|
{
|
2010-11-18 00:32:53 +03:00
|
|
|
result = moduleInCMakeRoot;
|
2004-02-29 02:59:19 +03:00
|
|
|
}
|
2010-11-18 00:32:53 +03:00
|
|
|
|
2015-01-15 02:06:11 +03:00
|
|
|
if (!moduleInCMakeModulePath.empty() && !moduleInCMakeRoot.empty())
|
2004-02-29 02:59:19 +03:00
|
|
|
{
|
2010-11-18 00:32:53 +03:00
|
|
|
const char* currentFile = this->GetDefinition("CMAKE_CURRENT_LIST_FILE");
|
2016-03-14 17:38:19 +03:00
|
|
|
std::string mods = cmSystemTools::GetCMakeRoot() + "/Modules/";
|
2014-03-04 18:28:48 +04:00
|
|
|
if (currentFile && strncmp(currentFile, mods.c_str(), mods.size()) == 0)
|
2004-02-29 02:59:19 +03:00
|
|
|
{
|
2010-11-18 00:32:53 +03:00
|
|
|
switch (this->GetPolicyStatus(cmPolicies::CMP0017))
|
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2010-11-18 00:32:53 +03:00
|
|
|
e << "File " << currentFile << " includes "
|
|
|
|
<< moduleInCMakeModulePath
|
|
|
|
<< " (found via CMAKE_MODULE_PATH) which shadows "
|
|
|
|
<< moduleInCMakeRoot << ". This may cause errors later on .\n"
|
2015-05-03 11:12:10 +03:00
|
|
|
<< cmPolicies::GetPolicyWarning(cmPolicies::CMP0017);
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2010-11-18 00:32:53 +03:00
|
|
|
|
|
|
|
this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
|
|
|
|
// break; // fall through to OLD behaviour
|
|
|
|
}
|
|
|
|
case cmPolicies::OLD:
|
|
|
|
result = moduleInCMakeModulePath;
|
|
|
|
break;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
|
|
case cmPolicies::NEW:
|
|
|
|
result = moduleInCMakeRoot;
|
|
|
|
break;
|
|
|
|
}
|
2004-02-29 02:59:19 +03:00
|
|
|
}
|
|
|
|
}
|
2010-11-18 00:32:53 +03:00
|
|
|
|
|
|
|
return result;
|
2004-02-29 02:59:19 +03:00
|
|
|
}
|
2004-03-04 02:18:47 +03:00
|
|
|
|
|
|
|
void cmMakefile::ConfigureString(const std::string& input,
|
|
|
|
std::string& output, bool atOnly,
|
2014-01-22 19:33:56 +04:00
|
|
|
bool escapeQuotes) const
|
2004-03-04 02:18:47 +03:00
|
|
|
{
|
|
|
|
// Split input to handle one line at a time.
|
2007-06-08 19:57:16 +04:00
|
|
|
std::string::const_iterator lineStart = input.begin();
|
2004-03-04 02:18:47 +03:00
|
|
|
while(lineStart != input.end())
|
|
|
|
{
|
|
|
|
// Find the end of this line.
|
|
|
|
std::string::const_iterator lineEnd = lineStart;
|
|
|
|
while(lineEnd != input.end() && *lineEnd != '\n')
|
|
|
|
{
|
|
|
|
++lineEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the line.
|
|
|
|
std::string line(lineStart, lineEnd);
|
|
|
|
|
|
|
|
// Skip the newline character.
|
|
|
|
bool haveNewline = (lineEnd != input.end());
|
|
|
|
if(haveNewline)
|
|
|
|
{
|
|
|
|
++lineEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace #cmakedefine instances.
|
2006-03-15 19:02:08 +03:00
|
|
|
if(this->cmDefineRegex.find(line))
|
2004-03-04 02:18:47 +03:00
|
|
|
{
|
2007-06-08 19:57:16 +04:00
|
|
|
const char* def =
|
2014-03-11 03:04:11 +04:00
|
|
|
this->GetDefinition(this->cmDefineRegex.match(1));
|
2004-03-04 02:18:47 +03:00
|
|
|
if(!cmSystemTools::IsOff(def))
|
|
|
|
{
|
|
|
|
cmSystemTools::ReplaceString(line, "#cmakedefine", "#define");
|
|
|
|
output += line;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-07-11 23:50:32 +04:00
|
|
|
output += "/* #undef ";
|
|
|
|
output += this->cmDefineRegex.match(1);
|
2004-03-04 02:18:47 +03:00
|
|
|
output += " */";
|
|
|
|
}
|
|
|
|
}
|
2006-03-15 19:02:08 +03:00
|
|
|
else if(this->cmDefine01Regex.find(line))
|
2006-01-04 00:40:51 +03:00
|
|
|
{
|
2007-06-08 19:57:16 +04:00
|
|
|
const char* def =
|
2014-03-11 03:04:11 +04:00
|
|
|
this->GetDefinition(this->cmDefine01Regex.match(1));
|
2006-01-04 00:40:51 +03:00
|
|
|
cmSystemTools::ReplaceString(line, "#cmakedefine01", "#define");
|
|
|
|
output += line;
|
|
|
|
if(!cmSystemTools::IsOff(def))
|
|
|
|
{
|
|
|
|
output += " 1";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
output += " 0";
|
|
|
|
}
|
|
|
|
}
|
2004-03-04 02:18:47 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
output += line;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(haveNewline)
|
|
|
|
{
|
|
|
|
output += "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move to the next line.
|
|
|
|
lineStart = lineEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform variable replacements.
|
2007-06-08 19:57:16 +04:00
|
|
|
this->ExpandVariablesInString(output, escapeQuotes, true,
|
2014-02-08 07:37:54 +04:00
|
|
|
atOnly, 0, -1, true, true);
|
2004-03-04 02:18:47 +03:00
|
|
|
}
|
2004-03-09 03:05:04 +03:00
|
|
|
|
2007-06-08 19:57:16 +04:00
|
|
|
int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
|
2011-11-20 17:04:11 +04:00
|
|
|
bool copyonly, bool atOnly, bool escapeQuotes,
|
|
|
|
const cmNewLineStyle& newLine)
|
2004-03-09 03:05:04 +03:00
|
|
|
{
|
2004-05-27 20:53:15 +04:00
|
|
|
int res = 1;
|
2006-03-22 22:40:36 +03:00
|
|
|
if ( !this->CanIWriteThisFile(outfile) )
|
|
|
|
{
|
2007-06-08 19:57:16 +04:00
|
|
|
cmSystemTools::Error("Attempt to write file: ",
|
2006-05-12 20:29:09 +04:00
|
|
|
outfile, " into a source directory.");
|
2006-03-22 22:40:36 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2004-03-29 01:00:57 +04:00
|
|
|
if ( !cmSystemTools::FileExists(infile) )
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("File ", infile, " does not exist.");
|
|
|
|
return 0;
|
|
|
|
}
|
2004-03-09 03:05:04 +03:00
|
|
|
std::string soutfile = outfile;
|
|
|
|
std::string sinfile = infile;
|
2013-06-18 21:41:50 +04:00
|
|
|
this->AddCMakeDependFile(sinfile);
|
2004-03-09 03:05:04 +03:00
|
|
|
cmSystemTools::ConvertToUnixSlashes(soutfile);
|
2013-08-28 20:49:53 +04:00
|
|
|
|
2013-07-30 22:39:31 +04:00
|
|
|
// Re-generate if non-temporary outputs are missing.
|
2013-08-28 20:49:53 +04:00
|
|
|
//when we finalize the configuration we will remove all
|
|
|
|
//output files that now don't exist.
|
|
|
|
this->AddCMakeOutputFile(soutfile);
|
|
|
|
|
2004-03-09 03:05:04 +03:00
|
|
|
mode_t perm = 0;
|
|
|
|
cmSystemTools::GetPermissions(sinfile.c_str(), perm);
|
|
|
|
std::string::size_type pos = soutfile.rfind('/');
|
|
|
|
if(pos != std::string::npos)
|
|
|
|
{
|
|
|
|
std::string path = soutfile.substr(0, pos);
|
|
|
|
cmSystemTools::MakeDirectory(path.c_str());
|
|
|
|
}
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2004-03-09 03:05:04 +03:00
|
|
|
if(copyonly)
|
|
|
|
{
|
|
|
|
if ( !cmSystemTools::CopyFileIfDifferent(sinfile.c_str(),
|
2005-07-13 19:21:30 +04:00
|
|
|
soutfile.c_str()))
|
2004-03-09 03:05:04 +03:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-20 17:04:11 +04:00
|
|
|
std::string newLineCharacters;
|
|
|
|
std::ios_base::openmode omode = std::ios_base::out | std::ios_base::trunc;
|
|
|
|
if (newLine.IsValid())
|
|
|
|
{
|
|
|
|
newLineCharacters = newLine.GetCharacters();
|
|
|
|
omode |= std::ios::binary;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newLineCharacters = "\n";
|
|
|
|
}
|
2004-03-09 03:05:04 +03:00
|
|
|
std::string tempOutputFile = soutfile;
|
|
|
|
tempOutputFile += ".tmp";
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ofstream fout(tempOutputFile.c_str(), omode);
|
2004-03-09 03:05:04 +03:00
|
|
|
if(!fout)
|
|
|
|
{
|
|
|
|
cmSystemTools::Error(
|
2007-06-08 19:57:16 +04:00
|
|
|
"Could not open file for write in copy operation ",
|
2005-07-13 19:21:30 +04:00
|
|
|
tempOutputFile.c_str());
|
2004-09-08 00:55:25 +04:00
|
|
|
cmSystemTools::ReportLastSystemError("");
|
2004-03-09 03:05:04 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream fin(sinfile.c_str());
|
2004-03-09 03:05:04 +03:00
|
|
|
if(!fin)
|
|
|
|
{
|
2004-07-09 22:18:44 +04:00
|
|
|
cmSystemTools::Error("Could not open file for read in copy operation ",
|
2004-03-09 03:05:04 +03:00
|
|
|
sinfile.c_str());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-07 09:55:07 +04:00
|
|
|
cmsys::FStream::BOM bom = cmsys::FStream::ReadBOM(fin);
|
|
|
|
if(bom != cmsys::FStream::BOM_None &&
|
|
|
|
bom != cmsys::FStream::BOM_UTF8)
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2014-03-07 09:55:07 +04:00
|
|
|
e << "File starts with a Byte-Order-Mark that is not UTF-8:\n "
|
|
|
|
<< sinfile;
|
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// rewind to copy BOM to output file
|
|
|
|
fin.seekg(0);
|
|
|
|
|
|
|
|
|
2004-03-09 03:05:04 +03:00
|
|
|
// now copy input to output and expand variables in the
|
|
|
|
// input file at the same time
|
|
|
|
std::string inLine;
|
|
|
|
std::string outLine;
|
|
|
|
while( cmSystemTools::GetLineFromStream(fin, inLine) )
|
|
|
|
{
|
|
|
|
outLine = "";
|
|
|
|
this->ConfigureString(inLine, outLine, atOnly, escapeQuotes);
|
2011-11-20 17:04:11 +04:00
|
|
|
fout << outLine.c_str() << newLineCharacters;
|
2004-03-09 03:05:04 +03:00
|
|
|
}
|
|
|
|
// close the files before attempting to copy
|
|
|
|
fin.close();
|
|
|
|
fout.close();
|
2004-05-27 20:53:15 +04:00
|
|
|
if ( !cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(),
|
2005-07-13 19:21:30 +04:00
|
|
|
soutfile.c_str()) )
|
2004-05-27 20:53:15 +04:00
|
|
|
{
|
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmSystemTools::SetPermissions(soutfile.c_str(), perm);
|
|
|
|
}
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::RemoveFile(tempOutputFile);
|
2004-03-09 03:05:04 +03:00
|
|
|
}
|
2004-05-27 20:53:15 +04:00
|
|
|
return res;
|
2004-03-09 03:05:04 +03:00
|
|
|
}
|
|
|
|
|
2013-09-03 00:27:32 +04:00
|
|
|
void cmMakefile::SetProperty(const std::string& prop, const char* value)
|
2004-05-21 00:56:34 +04:00
|
|
|
{
|
2015-07-18 16:18:59 +03:00
|
|
|
cmListFileBacktrace lfbt = this->GetBacktrace();
|
|
|
|
this->StateSnapshot.GetDirectory().SetProperty(prop, value, lfbt);
|
2006-12-07 17:45:32 +03:00
|
|
|
}
|
|
|
|
|
2013-09-03 00:27:32 +04:00
|
|
|
void cmMakefile::AppendProperty(const std::string& prop,
|
|
|
|
const char* value,
|
2011-07-14 01:14:41 +04:00
|
|
|
bool asString)
|
2008-01-18 02:13:55 +03:00
|
|
|
{
|
2015-07-18 16:18:59 +03:00
|
|
|
cmListFileBacktrace lfbt = this->GetBacktrace();
|
|
|
|
this->StateSnapshot.GetDirectory().AppendProperty(prop, value,
|
|
|
|
asString, lfbt);
|
2008-01-18 02:13:55 +03:00
|
|
|
}
|
|
|
|
|
2013-09-03 00:27:32 +04:00
|
|
|
const char *cmMakefile::GetProperty(const std::string& prop) const
|
2006-12-07 17:45:32 +03:00
|
|
|
{
|
2015-07-18 16:18:59 +03:00
|
|
|
return this->StateSnapshot.GetDirectory().GetProperty(prop);
|
2006-12-07 17:45:32 +03:00
|
|
|
}
|
|
|
|
|
2013-09-03 00:27:32 +04:00
|
|
|
const char *cmMakefile::GetProperty(const std::string& prop,
|
2015-06-06 10:41:30 +03:00
|
|
|
bool chain) const
|
2004-05-21 00:56:34 +04:00
|
|
|
{
|
2015-07-18 16:18:59 +03:00
|
|
|
return this->StateSnapshot.GetDirectory().GetProperty(prop, chain);
|
2004-05-21 00:56:34 +04:00
|
|
|
}
|
|
|
|
|
2013-09-03 00:27:32 +04:00
|
|
|
bool cmMakefile::GetPropertyAsBool(const std::string& prop) const
|
2004-05-21 00:56:34 +04:00
|
|
|
{
|
2006-12-07 17:45:32 +03:00
|
|
|
return cmSystemTools::IsOn(this->GetProperty(prop));
|
2004-05-21 00:56:34 +04:00
|
|
|
}
|
2005-02-17 00:35:32 +03:00
|
|
|
|
2015-07-18 19:59:18 +03:00
|
|
|
std::vector<std::string> cmMakefile::GetPropertyKeys() const
|
|
|
|
{
|
2015-07-18 16:18:59 +03:00
|
|
|
return this->StateSnapshot.GetDirectory().GetPropertyKeys();
|
2015-07-18 19:59:18 +03:00
|
|
|
}
|
|
|
|
|
2016-04-01 17:26:08 +03:00
|
|
|
cmTarget* cmMakefile::FindLocalNonAliasTarget(const std::string& name) const
|
2005-02-17 00:35:32 +03:00
|
|
|
{
|
2013-11-19 14:47:36 +04:00
|
|
|
cmTargets::iterator i = this->Targets.find( name );
|
|
|
|
if ( i != this->Targets.end() )
|
2005-02-17 00:35:32 +03:00
|
|
|
{
|
2007-05-22 18:24:59 +04:00
|
|
|
return &i->second;
|
2005-02-17 00:35:32 +03:00
|
|
|
}
|
2007-05-22 18:24:59 +04:00
|
|
|
return 0;
|
2005-02-17 00:35:32 +03:00
|
|
|
}
|
2005-04-24 23:59:51 +04:00
|
|
|
|
2014-02-04 06:20:33 +04:00
|
|
|
cmTest* cmMakefile::CreateTest(const std::string& testName)
|
2005-04-24 23:59:51 +04:00
|
|
|
{
|
|
|
|
cmTest* test = this->GetTest(testName);
|
|
|
|
if ( test )
|
|
|
|
{
|
|
|
|
return test;
|
|
|
|
}
|
2009-08-11 17:07:28 +04:00
|
|
|
test = new cmTest(this);
|
2005-04-24 23:59:51 +04:00
|
|
|
test->SetName(testName);
|
2009-01-05 23:00:57 +03:00
|
|
|
this->Tests[testName] = test;
|
2005-04-24 23:59:51 +04:00
|
|
|
return test;
|
|
|
|
}
|
|
|
|
|
2014-02-04 06:20:33 +04:00
|
|
|
cmTest* cmMakefile::GetTest(const std::string& testName) const
|
2005-04-24 23:59:51 +04:00
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, cmTest*>::const_iterator
|
2014-02-04 06:20:33 +04:00
|
|
|
mi = this->Tests.find(testName);
|
|
|
|
if(mi != this->Tests.end())
|
2005-04-24 23:59:51 +04:00
|
|
|
{
|
2014-02-04 06:20:33 +04:00
|
|
|
return mi->second;
|
2005-04-24 23:59:51 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-21 23:14:49 +04:00
|
|
|
void cmMakefile::AddCMakeDependFilesFromUser()
|
|
|
|
{
|
|
|
|
std::vector<std::string> deps;
|
|
|
|
if(const char* deps_str = this->GetProperty("CMAKE_CONFIGURE_DEPENDS"))
|
|
|
|
{
|
|
|
|
cmSystemTools::ExpandListArgument(deps_str, deps);
|
|
|
|
}
|
|
|
|
for(std::vector<std::string>::iterator i = deps.begin();
|
|
|
|
i != deps.end(); ++i)
|
|
|
|
{
|
|
|
|
if(cmSystemTools::FileIsFullPath(i->c_str()))
|
|
|
|
{
|
|
|
|
this->AddCMakeDependFile(*i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-16 22:17:41 +03:00
|
|
|
std::string f = this->GetCurrentSourceDirectory();
|
2014-01-21 23:14:49 +04:00
|
|
|
f += "/";
|
|
|
|
f += *i;
|
|
|
|
this->AddCMakeDependFile(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-16 08:30:33 +03:00
|
|
|
std::string cmMakefile::FormatListFileStack() const
|
2006-06-22 23:31:19 +04:00
|
|
|
{
|
2015-07-08 00:37:20 +03:00
|
|
|
std::vector<std::string> listFiles;
|
|
|
|
cmState::Snapshot snp = this->StateSnapshot;
|
|
|
|
while (snp.IsValid())
|
|
|
|
{
|
|
|
|
listFiles.push_back(snp.GetExecutionListFile());
|
|
|
|
snp = snp.GetCallStackParent();
|
|
|
|
}
|
|
|
|
std::reverse(listFiles.begin(), listFiles.end());
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream tmp;
|
2015-07-08 00:37:20 +03:00
|
|
|
size_t depth = listFiles.size();
|
2007-07-17 17:25:08 +04:00
|
|
|
if (depth > 0)
|
2006-06-22 23:31:19 +04:00
|
|
|
{
|
2015-07-08 00:37:20 +03:00
|
|
|
std::vector<std::string>::const_iterator it = listFiles.end();
|
2007-07-17 17:25:08 +04:00
|
|
|
do
|
|
|
|
{
|
2015-07-08 00:37:20 +03:00
|
|
|
if (depth != listFiles.size())
|
2007-07-17 17:25:08 +04:00
|
|
|
{
|
2007-07-19 19:13:01 +04:00
|
|
|
tmp << "\n ";
|
2007-07-17 17:25:08 +04:00
|
|
|
}
|
|
|
|
--it;
|
|
|
|
tmp << "[";
|
|
|
|
tmp << depth;
|
|
|
|
tmp << "]\t";
|
|
|
|
tmp << *it;
|
|
|
|
depth--;
|
|
|
|
}
|
2015-07-08 00:37:20 +03:00
|
|
|
while (it != listFiles.begin());
|
2006-06-22 23:31:19 +04:00
|
|
|
}
|
2007-05-01 19:46:47 +04:00
|
|
|
return tmp.str();
|
2006-06-22 23:31:19 +04:00
|
|
|
}
|
2006-12-07 17:45:32 +03:00
|
|
|
|
2007-12-03 21:35:41 +03:00
|
|
|
|
|
|
|
void cmMakefile::PushScope()
|
|
|
|
{
|
2015-08-01 20:41:26 +03:00
|
|
|
this->StateSnapshot = this->GetState()->CreateVariableScopeSnapshot(
|
2016-04-14 18:24:08 +03:00
|
|
|
this->StateSnapshot);
|
2014-11-18 18:34:30 +03:00
|
|
|
this->PushLoopBlockBarrier();
|
2014-11-26 01:49:25 +03:00
|
|
|
|
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
2015-05-03 12:10:30 +03:00
|
|
|
this->GetGlobalGenerator()->GetFileLockPool().PushFunctionScope();
|
2014-11-26 01:49:25 +03:00
|
|
|
#endif
|
2007-12-03 21:35:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefile::PopScope()
|
|
|
|
{
|
2014-11-26 01:49:25 +03:00
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
2015-05-03 12:10:30 +03:00
|
|
|
this->GetGlobalGenerator()->GetFileLockPool().PopFunctionScope();
|
2014-11-26 01:49:25 +03:00
|
|
|
#endif
|
|
|
|
|
2014-11-18 18:34:30 +03:00
|
|
|
this->PopLoopBlockBarrier();
|
|
|
|
|
2015-05-17 17:19:55 +03:00
|
|
|
this->CheckForUnusedVariables();
|
2015-04-25 17:03:04 +03:00
|
|
|
|
2015-11-24 21:37:34 +03:00
|
|
|
this->PopSnapshot();
|
2007-12-03 21:35:41 +03:00
|
|
|
}
|
|
|
|
|
2014-02-05 01:06:56 +04:00
|
|
|
void cmMakefile::RaiseScope(const std::string& var, const char *varDef)
|
2007-12-03 21:35:41 +03:00
|
|
|
{
|
2013-09-03 00:27:32 +04:00
|
|
|
if (var.empty())
|
2008-01-03 19:22:33 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2007-12-03 21:35:41 +03:00
|
|
|
|
2015-06-21 22:26:43 +03:00
|
|
|
if (!this->StateSnapshot.RaiseScope(var, varDef))
|
2009-11-02 19:56:17 +03:00
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream m;
|
2009-11-02 19:56:17 +03:00
|
|
|
m << "Cannot set \"" << var << "\": current scope has no parent.";
|
|
|
|
this->IssueMessage(cmake::AUTHOR_WARNING, m.str());
|
|
|
|
}
|
2007-12-03 21:35:41 +03:00
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
cmTarget*
|
2014-02-07 02:31:47 +04:00
|
|
|
cmMakefile::AddImportedTarget(const std::string& name,
|
2015-10-08 01:21:51 +03:00
|
|
|
cmState::TargetType type,
|
2012-01-25 22:39:26 +04:00
|
|
|
bool global)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
|
|
|
// Create the target.
|
|
|
|
cmsys::auto_ptr<cmTarget> target(new cmTarget);
|
|
|
|
target->SetType(type, name);
|
2015-10-25 14:22:51 +03:00
|
|
|
target->MarkAsImported(global);
|
2013-12-26 17:11:23 +04:00
|
|
|
target->SetMakefile(this);
|
2008-01-28 16:38:36 +03:00
|
|
|
|
|
|
|
// Add to the set of available imported targets.
|
|
|
|
this->ImportedTargets[name] = target.get();
|
2016-02-08 20:37:47 +03:00
|
|
|
this->GetGlobalGenerator()->IndexTarget(target.get());
|
2008-01-28 16:38:36 +03:00
|
|
|
|
|
|
|
// Transfer ownership to this cmMakefile object.
|
|
|
|
this->ImportedTargetsOwned.push_back(target.get());
|
|
|
|
return target.release();
|
|
|
|
}
|
|
|
|
|
2014-01-16 02:56:38 +04:00
|
|
|
cmTarget* cmMakefile::FindTargetToUse(const std::string& name,
|
2014-01-22 18:00:29 +04:00
|
|
|
bool excludeAliases) const
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
|
|
|
// Look for an imported target. These take priority because they
|
|
|
|
// are more local in scope and do not have to be globally unique.
|
2014-04-30 21:27:33 +04:00
|
|
|
TargetMap::const_iterator
|
2008-01-28 16:38:36 +03:00
|
|
|
imported = this->ImportedTargets.find(name);
|
|
|
|
if(imported != this->ImportedTargets.end())
|
|
|
|
{
|
|
|
|
return imported->second;
|
|
|
|
}
|
|
|
|
|
2010-12-13 19:26:53 +03:00
|
|
|
// Look for a target built in this directory.
|
2016-04-01 17:26:08 +03:00
|
|
|
if(cmTarget* t = this->FindLocalNonAliasTarget(name))
|
2010-12-13 19:26:53 +03:00
|
|
|
{
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
// Look for a target built in this project.
|
2015-05-03 12:10:30 +03:00
|
|
|
return this->GetGlobalGenerator()->FindTarget(name, excludeAliases);
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
2008-02-11 21:35:39 +03:00
|
|
|
|
2014-01-22 18:00:29 +04:00
|
|
|
bool cmMakefile::IsAlias(const std::string& name) const
|
2013-07-12 11:14:31 +04:00
|
|
|
{
|
|
|
|
if (this->AliasTargets.find(name) != this->AliasTargets.end())
|
|
|
|
return true;
|
2015-05-03 12:10:30 +03:00
|
|
|
return this->GetGlobalGenerator()->IsAlias(name);
|
2013-07-12 11:14:31 +04:00
|
|
|
}
|
|
|
|
|
2008-02-15 00:42:29 +03:00
|
|
|
bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg,
|
2014-01-22 18:00:29 +04:00
|
|
|
bool isCustom) const
|
2008-02-11 21:35:39 +03:00
|
|
|
{
|
2014-01-16 02:56:38 +04:00
|
|
|
if(this->IsAlias(name))
|
2013-07-12 11:14:31 +04:00
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2013-07-12 11:14:31 +04:00
|
|
|
e << "cannot create target \"" << name
|
|
|
|
<< "\" because an alias with the same name already exists.";
|
|
|
|
msg = e.str();
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-16 02:56:38 +04:00
|
|
|
if(cmTarget* existing = this->FindTargetToUse(name))
|
2008-02-11 21:35:39 +03:00
|
|
|
{
|
|
|
|
// The name given conflicts with an existing target. Produce an
|
|
|
|
// error in a compatible way.
|
|
|
|
if(existing->IsImported())
|
|
|
|
{
|
|
|
|
// Imported targets were not supported in previous versions.
|
|
|
|
// This is new code, so we can make it an error.
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2008-02-11 21:35:39 +03:00
|
|
|
e << "cannot create target \"" << name
|
|
|
|
<< "\" because an imported target with the same name already exists.";
|
|
|
|
msg = e.str();
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-28 23:44:22 +04:00
|
|
|
else
|
2008-02-11 21:35:39 +03:00
|
|
|
{
|
2008-03-01 23:20:35 +03:00
|
|
|
// target names must be globally unique
|
2008-03-13 18:38:46 +03:00
|
|
|
switch (this->GetPolicyStatus(cmPolicies::CMP0002))
|
2008-03-01 23:20:35 +03:00
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
2015-05-03 11:12:10 +03:00
|
|
|
this->IssueMessage(cmake::AUTHOR_WARNING, cmPolicies::
|
2008-03-13 18:38:46 +03:00
|
|
|
GetPolicyWarning(cmPolicies::CMP0002));
|
2008-03-01 23:20:35 +03:00
|
|
|
case cmPolicies::OLD:
|
|
|
|
return true;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
2008-03-01 23:44:17 +03:00
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
2008-03-11 17:29:56 +03:00
|
|
|
this->IssueMessage(cmake::FATAL_ERROR,
|
2015-05-03 11:12:10 +03:00
|
|
|
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0002)
|
2008-03-08 17:13:13 +03:00
|
|
|
);
|
|
|
|
return true;
|
2008-03-01 23:20:35 +03:00
|
|
|
case cmPolicies::NEW:
|
|
|
|
break;
|
|
|
|
}
|
2010-09-28 23:44:22 +04:00
|
|
|
|
2008-02-15 00:42:29 +03:00
|
|
|
// The conflict is with a non-imported target.
|
|
|
|
// Allow this if the user has requested support.
|
2015-05-03 12:41:29 +03:00
|
|
|
cmake* cm = this->GetCMakeInstance();
|
2015-10-08 01:21:51 +03:00
|
|
|
if(isCustom && existing->GetType() == cmState::UTILITY &&
|
2008-02-15 00:42:29 +03:00
|
|
|
this != existing->GetMakefile() &&
|
2015-04-11 15:15:55 +03:00
|
|
|
cm->GetState()
|
|
|
|
->GetGlobalPropertyAsBool("ALLOW_DUPLICATE_CUSTOM_TARGETS"))
|
2008-02-15 00:42:29 +03:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Produce an error that tells the user how to work around the
|
|
|
|
// problem.
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2008-02-11 21:35:39 +03:00
|
|
|
e << "cannot create target \"" << name
|
|
|
|
<< "\" because another target with the same name already exists. "
|
2008-02-15 00:42:29 +03:00
|
|
|
<< "The existing target is ";
|
|
|
|
switch(existing->GetType())
|
|
|
|
{
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::EXECUTABLE:
|
2008-02-15 00:42:29 +03:00
|
|
|
e << "an executable ";
|
|
|
|
break;
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::STATIC_LIBRARY:
|
2008-02-15 00:42:29 +03:00
|
|
|
e << "a static library ";
|
|
|
|
break;
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::SHARED_LIBRARY:
|
2008-02-15 00:42:29 +03:00
|
|
|
e << "a shared library ";
|
|
|
|
break;
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::MODULE_LIBRARY:
|
2008-02-15 00:42:29 +03:00
|
|
|
e << "a module library ";
|
|
|
|
break;
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::UTILITY:
|
2008-02-15 00:42:29 +03:00
|
|
|
e << "a custom target ";
|
|
|
|
break;
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::INTERFACE_LIBRARY:
|
2014-03-18 03:09:40 +04:00
|
|
|
e << "an interface library ";
|
|
|
|
break;
|
2008-02-15 00:42:29 +03:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
e << "created in source directory \""
|
2015-04-16 22:17:41 +03:00
|
|
|
<< existing->GetMakefile()->GetCurrentSourceDirectory() << "\". "
|
2008-03-13 18:38:46 +03:00
|
|
|
<< "See documentation for policy CMP0002 for more details.";
|
2008-03-08 00:36:57 +03:00
|
|
|
msg = e.str();
|
2008-02-11 21:35:39 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2008-03-01 23:20:35 +03:00
|
|
|
|
2014-02-08 00:33:35 +04:00
|
|
|
bool cmMakefile::EnforceUniqueDir(const std::string& srcPath,
|
|
|
|
const std::string& binPath) const
|
2009-06-17 21:40:09 +04:00
|
|
|
{
|
|
|
|
// Make sure the binary directory is unique.
|
2015-05-03 12:10:30 +03:00
|
|
|
cmGlobalGenerator* gg = this->GetGlobalGenerator();
|
2009-06-17 21:40:09 +04:00
|
|
|
if(gg->BinaryDirectoryIsNew(binPath))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2009-06-17 21:40:09 +04:00
|
|
|
switch (this->GetPolicyStatus(cmPolicies::CMP0013))
|
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
|
|
|
// Print the warning.
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2015-05-03 11:12:10 +03:00
|
|
|
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0013)
|
2009-06-17 21:40:09 +04:00
|
|
|
<< "\n"
|
|
|
|
<< "The binary directory\n"
|
|
|
|
<< " " << binPath << "\n"
|
|
|
|
<< "is already used to build a source directory. "
|
|
|
|
<< "This command uses it to build source directory\n"
|
|
|
|
<< " " << srcPath << "\n"
|
|
|
|
<< "which can generate conflicting build files. "
|
|
|
|
<< "CMake does not support this use case but it used "
|
|
|
|
<< "to work accidentally and is being allowed for "
|
|
|
|
<< "compatibility.";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2009-06-17 21:40:09 +04:00
|
|
|
this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
|
|
|
|
case cmPolicies::OLD:
|
|
|
|
// OLD behavior does not warn.
|
|
|
|
return true;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
2015-05-03 11:12:10 +03:00
|
|
|
e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0013)
|
2009-06-17 21:40:09 +04:00
|
|
|
<< "\n";
|
|
|
|
case cmPolicies::NEW:
|
|
|
|
// NEW behavior prints the error.
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2009-06-17 21:40:09 +04:00
|
|
|
e << "The binary directory\n"
|
|
|
|
<< " " << binPath << "\n"
|
|
|
|
<< "is already used to build a source directory. "
|
|
|
|
<< "It cannot be used to build source directory\n"
|
|
|
|
<< " " << srcPath << "\n"
|
|
|
|
<< "Specify a unique binary directory name.";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2009-06-17 21:40:09 +04:00
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-25 11:24:53 +04:00
|
|
|
void cmMakefile::AddQtUiFileWithOptions(cmSourceFile *sf)
|
|
|
|
{
|
|
|
|
this->QtUiFilesWithOptions.push_back(sf);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<cmSourceFile*> cmMakefile::GetQtUiFilesWithOptions() const
|
|
|
|
{
|
|
|
|
return this->QtUiFilesWithOptions;
|
|
|
|
}
|
|
|
|
|
2014-12-01 18:51:49 +03:00
|
|
|
static std::string const matchVariables[] = {
|
|
|
|
"CMAKE_MATCH_0",
|
|
|
|
"CMAKE_MATCH_1",
|
|
|
|
"CMAKE_MATCH_2",
|
|
|
|
"CMAKE_MATCH_3",
|
|
|
|
"CMAKE_MATCH_4",
|
|
|
|
"CMAKE_MATCH_5",
|
|
|
|
"CMAKE_MATCH_6",
|
|
|
|
"CMAKE_MATCH_7",
|
|
|
|
"CMAKE_MATCH_8",
|
|
|
|
"CMAKE_MATCH_9"
|
|
|
|
};
|
|
|
|
|
|
|
|
static std::string const nMatchesVariable = "CMAKE_MATCH_COUNT";
|
|
|
|
|
|
|
|
void cmMakefile::ClearMatches()
|
|
|
|
{
|
|
|
|
const char* nMatchesStr = this->GetDefinition(nMatchesVariable);
|
|
|
|
if (!nMatchesStr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int nMatches = atoi(nMatchesStr);
|
|
|
|
for (int i=0; i<=nMatches; i++)
|
|
|
|
{
|
|
|
|
std::string const& var = matchVariables[i];
|
|
|
|
std::string const& s = this->GetSafeDefinition(var);
|
|
|
|
if(!s.empty())
|
|
|
|
{
|
|
|
|
this->AddDefinition(var, "");
|
|
|
|
this->MarkVariableAsUsed(var);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->AddDefinition(nMatchesVariable, "0");
|
|
|
|
this->MarkVariableAsUsed(nMatchesVariable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefile::StoreMatches(cmsys::RegularExpression& re)
|
|
|
|
{
|
|
|
|
char highest = 0;
|
|
|
|
for (int i=0; i<10; i++)
|
|
|
|
{
|
|
|
|
std::string const& m = re.match(i);
|
|
|
|
if(!m.empty())
|
|
|
|
{
|
|
|
|
std::string const& var = matchVariables[i];
|
|
|
|
this->AddDefinition(var, m.c_str());
|
|
|
|
this->MarkVariableAsUsed(var);
|
|
|
|
highest = static_cast<char>('0' + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
char nMatches[] = {highest, '\0'};
|
|
|
|
this->AddDefinition(nMatchesVariable, nMatches);
|
|
|
|
this->MarkVariableAsUsed(nMatchesVariable);
|
|
|
|
}
|
|
|
|
|
2015-06-04 20:42:32 +03:00
|
|
|
cmState::Snapshot cmMakefile::GetStateSnapshot() const
|
|
|
|
{
|
|
|
|
return this->StateSnapshot;
|
|
|
|
}
|
|
|
|
|
2015-06-07 15:50:54 +03:00
|
|
|
const char* cmMakefile::GetDefineFlagsCMP0059() const
|
|
|
|
{
|
|
|
|
return this->DefineFlagsOrig.c_str();
|
|
|
|
}
|
|
|
|
|
2008-08-19 00:29:00 +04:00
|
|
|
cmPolicies::PolicyStatus
|
2014-01-22 17:58:58 +04:00
|
|
|
cmMakefile::GetPolicyStatus(cmPolicies::PolicyID id) const
|
2008-03-01 23:20:35 +03:00
|
|
|
{
|
2015-07-26 14:04:09 +03:00
|
|
|
return this->StateSnapshot.GetPolicy(id);
|
2008-03-01 23:20:35 +03:00
|
|
|
}
|
|
|
|
|
2014-04-02 22:02:03 +04:00
|
|
|
bool cmMakefile::PolicyOptionalWarningEnabled(std::string const& var)
|
|
|
|
{
|
|
|
|
// Check for an explicit CMAKE_POLICY_WARNING_CMP<NNNN> setting.
|
|
|
|
if(!var.empty())
|
|
|
|
{
|
2014-04-02 22:31:04 +04:00
|
|
|
if(const char* val = this->GetDefinition(var))
|
2014-04-02 22:02:03 +04:00
|
|
|
{
|
|
|
|
return cmSystemTools::IsOn(val);
|
|
|
|
}
|
|
|
|
}
|
2015-07-22 00:18:53 +03:00
|
|
|
// Enable optional policy warnings with --debug-output, --trace,
|
|
|
|
// or --trace-expand.
|
2014-04-02 22:02:03 +04:00
|
|
|
cmake* cm = this->GetCMakeInstance();
|
|
|
|
return cm->GetDebugOutput() || cm->GetTrace();
|
|
|
|
}
|
|
|
|
|
2010-09-28 23:44:22 +04:00
|
|
|
bool cmMakefile::SetPolicy(const char *id,
|
2008-03-01 23:20:35 +03:00
|
|
|
cmPolicies::PolicyStatus status)
|
|
|
|
{
|
|
|
|
cmPolicies::PolicyID pid;
|
2015-05-03 11:12:10 +03:00
|
|
|
if (!cmPolicies::GetPolicyID(id, /* out */ pid))
|
2008-03-13 21:13:44 +03:00
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2008-03-13 21:13:44 +03:00
|
|
|
e << "Policy \"" << id << "\" is not known to this version of CMake.";
|
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
2008-03-01 23:20:35 +03:00
|
|
|
return false;
|
2008-03-13 21:13:44 +03:00
|
|
|
}
|
2008-03-01 23:20:35 +03:00
|
|
|
return this->SetPolicy(pid,status);
|
|
|
|
}
|
|
|
|
|
2008-08-19 00:29:00 +04:00
|
|
|
bool cmMakefile::SetPolicy(cmPolicies::PolicyID id,
|
2008-03-01 23:20:35 +03:00
|
|
|
cmPolicies::PolicyStatus status)
|
|
|
|
{
|
2008-08-19 00:29:00 +04:00
|
|
|
// A REQUIRED_ALWAYS policy may be set only to NEW.
|
|
|
|
if(status != cmPolicies::NEW &&
|
2015-05-03 11:12:10 +03:00
|
|
|
cmPolicies::GetPolicyStatus(id) ==
|
2008-08-19 00:29:00 +04:00
|
|
|
cmPolicies::REQUIRED_ALWAYS)
|
|
|
|
{
|
|
|
|
std::string msg =
|
2015-05-03 11:12:10 +03:00
|
|
|
cmPolicies::GetRequiredAlwaysPolicyError(id);
|
2014-03-11 03:04:11 +04:00
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, msg);
|
2008-08-19 00:29:00 +04:00
|
|
|
return false;
|
|
|
|
}
|
2008-03-07 23:30:35 +03:00
|
|
|
|
2015-07-26 14:04:09 +03:00
|
|
|
this->StateSnapshot.SetPolicy(id, status);
|
2008-08-19 00:29:00 +04:00
|
|
|
return true;
|
2008-03-01 23:20:35 +03:00
|
|
|
}
|
|
|
|
|
2015-11-24 21:06:42 +03:00
|
|
|
cmMakefile::PolicyPushPop::PolicyPushPop(cmMakefile* m): Makefile(m)
|
2009-01-22 18:56:50 +03:00
|
|
|
{
|
2015-11-24 21:06:42 +03:00
|
|
|
this->Makefile->PushPolicy();
|
2009-01-22 18:56:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmMakefile::PolicyPushPop::~PolicyPushPop()
|
|
|
|
{
|
2009-01-22 18:57:16 +03:00
|
|
|
this->Makefile->PopPolicy();
|
|
|
|
}
|
|
|
|
|
2009-01-22 21:16:27 +03:00
|
|
|
void cmMakefile::PushPolicy(bool weak, cmPolicies::PolicyMap const& pm)
|
2009-01-22 18:57:16 +03:00
|
|
|
{
|
2015-07-26 14:04:09 +03:00
|
|
|
this->StateSnapshot.PushPolicy(pm, weak);
|
2009-01-22 18:57:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefile::PopPolicy()
|
|
|
|
{
|
2015-07-26 14:04:09 +03:00
|
|
|
if (!this->StateSnapshot.PopPolicy())
|
2009-01-22 18:56:50 +03:00
|
|
|
{
|
2009-01-22 18:57:16 +03:00
|
|
|
this->IssueMessage(cmake::FATAL_ERROR,
|
|
|
|
"cmake_policy POP without matching PUSH");
|
2009-01-22 18:56:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-24 19:44:57 +03:00
|
|
|
void cmMakefile::PopSnapshot(bool reportError)
|
2008-03-01 23:20:35 +03:00
|
|
|
{
|
2015-11-24 19:44:57 +03:00
|
|
|
// cmState::Snapshot manages nested policy scopes within it.
|
|
|
|
// Since the scope corresponding to the snapshot is closing,
|
|
|
|
// reject any still-open nested policy scopes with an error.
|
2015-07-26 14:04:09 +03:00
|
|
|
while (!this->StateSnapshot.CanPopPolicyScope())
|
2008-03-06 02:21:10 +03:00
|
|
|
{
|
|
|
|
if(reportError)
|
|
|
|
{
|
2009-01-22 18:57:16 +03:00
|
|
|
this->IssueMessage(cmake::FATAL_ERROR,
|
|
|
|
"cmake_policy PUSH without matching POP");
|
|
|
|
reportError = false;
|
2008-03-06 02:21:10 +03:00
|
|
|
}
|
2009-01-22 18:57:16 +03:00
|
|
|
this->PopPolicy();
|
2008-03-06 02:21:10 +03:00
|
|
|
}
|
2009-01-22 18:57:16 +03:00
|
|
|
|
2015-07-26 14:04:09 +03:00
|
|
|
this->StateSnapshot = this->GetState()->Pop(this->StateSnapshot);
|
|
|
|
assert(this->StateSnapshot.IsValid());
|
2008-03-01 23:20:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmMakefile::SetPolicyVersion(const char *version)
|
|
|
|
{
|
2015-05-03 11:12:10 +03:00
|
|
|
return cmPolicies::ApplyPolicyVersion(this,version);
|
2008-03-01 23:20:35 +03:00
|
|
|
}
|
2009-01-22 21:16:47 +03:00
|
|
|
|
2015-10-20 20:13:52 +03:00
|
|
|
bool cmMakefile::HasCMP0054AlreadyBeenReported(
|
|
|
|
cmListFileContext const& context) const
|
2014-09-04 22:21:28 +04:00
|
|
|
{
|
2015-10-20 20:13:52 +03:00
|
|
|
return !this->CMP0054ReportedIds.insert(context).second;
|
2014-09-04 22:21:28 +04:00
|
|
|
}
|
|
|
|
|
2009-01-22 21:16:47 +03:00
|
|
|
void cmMakefile::RecordPolicies(cmPolicies::PolicyMap& pm)
|
|
|
|
{
|
|
|
|
/* Record the setting of every policy. */
|
|
|
|
typedef cmPolicies::PolicyID PolicyID;
|
|
|
|
for(PolicyID pid = cmPolicies::CMP0000;
|
|
|
|
pid != cmPolicies::CMPCOUNT; pid = PolicyID(pid+1))
|
|
|
|
{
|
2015-05-03 11:12:28 +03:00
|
|
|
pm.Set(pid, this->GetPolicyStatus(pid));
|
2009-01-22 21:16:47 +03:00
|
|
|
}
|
|
|
|
}
|
2014-04-02 17:57:15 +04:00
|
|
|
|
2015-05-08 22:41:08 +03:00
|
|
|
bool cmMakefile::IgnoreErrorsCMP0061() const
|
|
|
|
{
|
|
|
|
bool ignoreErrors = true;
|
|
|
|
switch (this->GetPolicyStatus(cmPolicies::CMP0061))
|
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
|
|
|
// No warning for this policy!
|
|
|
|
case cmPolicies::OLD:
|
|
|
|
break;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
|
|
case cmPolicies::NEW:
|
|
|
|
ignoreErrors = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ignoreErrors;
|
|
|
|
}
|
|
|
|
|
2014-04-02 17:57:15 +04:00
|
|
|
#define FEATURE_STRING(F) , #F
|
2013-11-04 04:15:43 +04:00
|
|
|
static const char * const C_FEATURES[] = {
|
|
|
|
0
|
|
|
|
FOR_EACH_C_FEATURE(FEATURE_STRING)
|
|
|
|
};
|
2014-04-02 17:57:15 +04:00
|
|
|
|
|
|
|
static const char * const CXX_FEATURES[] = {
|
|
|
|
0
|
|
|
|
FOR_EACH_CXX_FEATURE(FEATURE_STRING)
|
|
|
|
};
|
2014-05-10 15:11:50 +04:00
|
|
|
#undef FEATURE_STRING
|
2014-04-02 17:57:15 +04:00
|
|
|
|
2013-11-04 04:15:43 +04:00
|
|
|
static const char * const C_STANDARDS[] = {
|
|
|
|
"90"
|
|
|
|
, "99"
|
|
|
|
, "11"
|
|
|
|
};
|
2014-04-02 17:57:15 +04:00
|
|
|
static const char * const CXX_STANDARDS[] = {
|
|
|
|
"98"
|
|
|
|
, "11"
|
2014-05-06 02:21:14 +04:00
|
|
|
, "14"
|
2014-04-02 17:57:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
bool cmMakefile::
|
|
|
|
AddRequiredTargetFeature(cmTarget *target, const std::string& feature,
|
|
|
|
std::string *error) const
|
|
|
|
{
|
2013-10-22 17:05:49 +04:00
|
|
|
if (cmGeneratorExpression::Find(feature) != std::string::npos)
|
|
|
|
{
|
|
|
|
target->AppendProperty("COMPILE_FEATURES", feature.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
2014-05-15 13:33:20 +04:00
|
|
|
|
|
|
|
std::string lang;
|
|
|
|
if (!this->CompileFeatureKnown(target, feature, lang, error))
|
2014-04-02 17:57:15 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-15 13:33:20 +04:00
|
|
|
const char* features = this->CompileFeaturesAvailable(lang, error);
|
|
|
|
if (!features)
|
2014-04-02 17:57:15 +04:00
|
|
|
{
|
2014-04-15 20:09:21 +04:00
|
|
|
return false;
|
2014-04-02 17:57:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> availableFeatures;
|
2014-05-15 13:33:20 +04:00
|
|
|
cmSystemTools::ExpandListArgument(features, availableFeatures);
|
2014-04-02 17:57:15 +04:00
|
|
|
if (std::find(availableFeatures.begin(),
|
|
|
|
availableFeatures.end(),
|
|
|
|
feature) == availableFeatures.end())
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2014-04-02 17:57:15 +04:00
|
|
|
e << "The compiler feature \"" << feature
|
2014-05-07 14:36:22 +04:00
|
|
|
<< "\" is not known to " << lang << " compiler\n\""
|
2014-04-02 17:57:15 +04:00
|
|
|
<< this->GetDefinition("CMAKE_" + lang + "_COMPILER_ID")
|
|
|
|
<< "\"\nversion "
|
|
|
|
<< this->GetDefinition("CMAKE_" + lang + "_COMPILER_VERSION") << ".";
|
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
target->AppendProperty("COMPILE_FEATURES", feature.c_str());
|
|
|
|
|
2014-05-15 13:33:20 +04:00
|
|
|
return lang == "C"
|
2013-11-04 04:15:43 +04:00
|
|
|
? this->AddRequiredTargetCFeature(target, feature)
|
|
|
|
: this->AddRequiredTargetCxxFeature(target, feature);
|
|
|
|
}
|
|
|
|
|
2014-05-15 13:33:20 +04:00
|
|
|
bool cmMakefile::
|
|
|
|
CompileFeatureKnown(cmTarget const* target, const std::string& feature,
|
|
|
|
std::string& lang, std::string *error) const
|
|
|
|
{
|
|
|
|
assert(cmGeneratorExpression::Find(feature) == std::string::npos);
|
|
|
|
|
|
|
|
bool isCFeature = std::find_if(cmArrayBegin(C_FEATURES) + 1,
|
|
|
|
cmArrayEnd(C_FEATURES), cmStrCmp(feature))
|
|
|
|
!= cmArrayEnd(C_FEATURES);
|
|
|
|
if (isCFeature)
|
|
|
|
{
|
|
|
|
lang = "C";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool isCxxFeature = std::find_if(cmArrayBegin(CXX_FEATURES) + 1,
|
|
|
|
cmArrayEnd(CXX_FEATURES), cmStrCmp(feature))
|
|
|
|
!= cmArrayEnd(CXX_FEATURES);
|
|
|
|
if (isCxxFeature)
|
|
|
|
{
|
|
|
|
lang = "CXX";
|
|
|
|
return true;
|
|
|
|
}
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2014-05-15 13:33:20 +04:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
e << "specified";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e << "Specified";
|
|
|
|
}
|
|
|
|
e << " unknown feature \"" << feature << "\" for "
|
|
|
|
"target \"" << target->GetName() << "\".";
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
*error = e.str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-15 13:33:20 +04:00
|
|
|
const char* cmMakefile::
|
|
|
|
CompileFeaturesAvailable(const std::string& lang, std::string *error) const
|
|
|
|
{
|
|
|
|
const char* featuresKnown =
|
|
|
|
this->GetDefinition("CMAKE_" + lang + "_COMPILE_FEATURES");
|
|
|
|
|
|
|
|
if (!featuresKnown || !*featuresKnown)
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2014-05-15 13:33:20 +04:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
e << "no";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e << "No";
|
|
|
|
}
|
|
|
|
e << " known features for " << lang << " compiler\n\""
|
|
|
|
<< this->GetDefinition("CMAKE_" + lang + "_COMPILER_ID")
|
|
|
|
<< "\"\nversion "
|
|
|
|
<< this->GetDefinition("CMAKE_" + lang + "_COMPILER_VERSION") << ".";
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
*error = e.str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return featuresKnown;
|
|
|
|
}
|
|
|
|
|
2015-01-11 19:43:44 +03:00
|
|
|
bool cmMakefile::HaveStandardAvailable(cmTarget const* target,
|
2014-05-15 13:54:24 +04:00
|
|
|
std::string const& lang,
|
|
|
|
const std::string& feature) const
|
|
|
|
{
|
|
|
|
return lang == "C"
|
2015-01-11 19:43:44 +03:00
|
|
|
? this->HaveCStandardAvailable(target, feature)
|
|
|
|
: this->HaveCxxStandardAvailable(target, feature);
|
2014-05-15 13:54:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmMakefile::
|
2015-01-11 19:43:44 +03:00
|
|
|
HaveCStandardAvailable(cmTarget const* target,
|
|
|
|
const std::string& feature) const
|
2014-05-15 13:54:24 +04:00
|
|
|
{
|
2015-01-27 00:42:36 +03:00
|
|
|
const char* defaultCStandard =
|
|
|
|
this->GetDefinition("CMAKE_C_STANDARD_DEFAULT");
|
|
|
|
if (!defaultCStandard)
|
|
|
|
{
|
|
|
|
std::ostringstream e;
|
|
|
|
e << "CMAKE_C_STANDARD_DEFAULT is not set. COMPILE_FEATURES support "
|
|
|
|
"not fully configured for this compiler.";
|
|
|
|
this->IssueMessage(cmake::INTERNAL_ERROR, e.str());
|
|
|
|
// Return true so the caller does not try to lookup the default standard.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS),
|
|
|
|
cmStrCmp(defaultCStandard)) == cmArrayEnd(C_STANDARDS))
|
|
|
|
{
|
|
|
|
std::ostringstream e;
|
|
|
|
e << "The CMAKE_C_STANDARD_DEFAULT variable contains an "
|
|
|
|
"invalid value: \"" << defaultCStandard << "\".";
|
|
|
|
this->IssueMessage(cmake::INTERNAL_ERROR, e.str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-15 13:54:24 +04:00
|
|
|
bool needC90 = false;
|
|
|
|
bool needC99 = false;
|
|
|
|
bool needC11 = false;
|
|
|
|
|
|
|
|
this->CheckNeededCLanguage(feature, needC90, needC99, needC11);
|
|
|
|
|
|
|
|
const char *existingCStandard = target->GetProperty("C_STANDARD");
|
|
|
|
if (!existingCStandard)
|
|
|
|
{
|
2015-01-27 00:42:36 +03:00
|
|
|
existingCStandard = defaultCStandard;
|
2014-05-15 13:54:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS),
|
|
|
|
cmStrCmp(existingCStandard)) == cmArrayEnd(C_STANDARDS))
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2014-05-15 13:54:24 +04:00
|
|
|
e << "The C_STANDARD property on target \"" << target->GetName()
|
|
|
|
<< "\" contained an invalid value: \"" << existingCStandard << "\".";
|
2014-10-15 16:54:05 +04:00
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
2014-05-15 13:54:24 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * const *existingCIt = existingCStandard
|
|
|
|
? std::find_if(cmArrayBegin(C_STANDARDS),
|
|
|
|
cmArrayEnd(C_STANDARDS),
|
|
|
|
cmStrCmp(existingCStandard))
|
|
|
|
: cmArrayEnd(C_STANDARDS);
|
|
|
|
|
|
|
|
if (needC11 && existingCStandard && existingCIt <
|
|
|
|
std::find_if(cmArrayBegin(C_STANDARDS),
|
|
|
|
cmArrayEnd(C_STANDARDS),
|
|
|
|
cmStrCmp("11")))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(needC99 && existingCStandard && existingCIt <
|
|
|
|
std::find_if(cmArrayBegin(C_STANDARDS),
|
|
|
|
cmArrayEnd(C_STANDARDS),
|
|
|
|
cmStrCmp("99")))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(needC90 && existingCStandard && existingCIt <
|
|
|
|
std::find_if(cmArrayBegin(C_STANDARDS),
|
|
|
|
cmArrayEnd(C_STANDARDS),
|
|
|
|
cmStrCmp("90")))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-15 13:32:30 +04:00
|
|
|
bool cmMakefile::IsLaterStandard(std::string const& lang,
|
|
|
|
std::string const& lhs,
|
|
|
|
std::string const& rhs)
|
|
|
|
{
|
|
|
|
if (lang == "C")
|
|
|
|
{
|
|
|
|
const char * const *rhsIt = std::find_if(cmArrayBegin(C_STANDARDS),
|
|
|
|
cmArrayEnd(C_STANDARDS),
|
|
|
|
cmStrCmp(rhs));
|
|
|
|
|
|
|
|
return std::find_if(rhsIt, cmArrayEnd(C_STANDARDS),
|
|
|
|
cmStrCmp(lhs)) != cmArrayEnd(C_STANDARDS);
|
|
|
|
}
|
|
|
|
const char * const *rhsIt = std::find_if(cmArrayBegin(CXX_STANDARDS),
|
|
|
|
cmArrayEnd(CXX_STANDARDS),
|
|
|
|
cmStrCmp(rhs));
|
|
|
|
|
|
|
|
return std::find_if(rhsIt, cmArrayEnd(CXX_STANDARDS),
|
|
|
|
cmStrCmp(lhs)) != cmArrayEnd(CXX_STANDARDS);
|
|
|
|
}
|
|
|
|
|
2015-01-11 19:43:44 +03:00
|
|
|
bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target,
|
2014-05-15 13:54:24 +04:00
|
|
|
const std::string& feature) const
|
|
|
|
{
|
2015-01-27 00:42:36 +03:00
|
|
|
const char* defaultCxxStandard =
|
|
|
|
this->GetDefinition("CMAKE_CXX_STANDARD_DEFAULT");
|
|
|
|
if (!defaultCxxStandard)
|
|
|
|
{
|
|
|
|
std::ostringstream e;
|
|
|
|
e << "CMAKE_CXX_STANDARD_DEFAULT is not set. COMPILE_FEATURES support "
|
|
|
|
"not fully configured for this compiler.";
|
|
|
|
this->IssueMessage(cmake::INTERNAL_ERROR, e.str());
|
|
|
|
// Return true so the caller does not try to lookup the default standard.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS),
|
|
|
|
cmStrCmp(defaultCxxStandard)) == cmArrayEnd(CXX_STANDARDS))
|
|
|
|
{
|
|
|
|
std::ostringstream e;
|
|
|
|
e << "The CMAKE_CXX_STANDARD_DEFAULT variable contains an "
|
|
|
|
"invalid value: \"" << defaultCxxStandard << "\".";
|
|
|
|
this->IssueMessage(cmake::INTERNAL_ERROR, e.str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-15 13:54:24 +04:00
|
|
|
bool needCxx98 = false;
|
|
|
|
bool needCxx11 = false;
|
2014-05-06 02:21:14 +04:00
|
|
|
bool needCxx14 = false;
|
|
|
|
this->CheckNeededCxxLanguage(feature, needCxx98, needCxx11, needCxx14);
|
2014-05-15 13:54:24 +04:00
|
|
|
|
|
|
|
const char *existingCxxStandard = target->GetProperty("CXX_STANDARD");
|
|
|
|
if (!existingCxxStandard)
|
|
|
|
{
|
2015-01-27 00:42:36 +03:00
|
|
|
existingCxxStandard = defaultCxxStandard;
|
2014-05-15 13:54:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS),
|
|
|
|
cmStrCmp(existingCxxStandard)) == cmArrayEnd(CXX_STANDARDS))
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2014-05-15 13:54:24 +04:00
|
|
|
e << "The CXX_STANDARD property on target \"" << target->GetName()
|
|
|
|
<< "\" contained an invalid value: \"" << existingCxxStandard << "\".";
|
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * const *existingCxxIt = existingCxxStandard
|
|
|
|
? std::find_if(cmArrayBegin(CXX_STANDARDS),
|
|
|
|
cmArrayEnd(CXX_STANDARDS),
|
|
|
|
cmStrCmp(existingCxxStandard))
|
|
|
|
: cmArrayEnd(CXX_STANDARDS);
|
|
|
|
|
|
|
|
if (needCxx11 && existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS),
|
|
|
|
cmArrayEnd(CXX_STANDARDS),
|
|
|
|
cmStrCmp("11")))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(needCxx98 && existingCxxIt <
|
|
|
|
std::find_if(cmArrayBegin(CXX_STANDARDS),
|
|
|
|
cmArrayEnd(CXX_STANDARDS),
|
|
|
|
cmStrCmp("98")))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-15 13:49:02 +04:00
|
|
|
void cmMakefile::CheckNeededCxxLanguage(const std::string& feature,
|
|
|
|
bool& needCxx98,
|
2014-05-06 02:21:14 +04:00
|
|
|
bool& needCxx11,
|
|
|
|
bool& needCxx14) const
|
2013-11-04 04:15:43 +04:00
|
|
|
{
|
2014-04-06 13:40:11 +04:00
|
|
|
if (const char *propCxx98 =
|
|
|
|
this->GetDefinition("CMAKE_CXX98_COMPILE_FEATURES"))
|
|
|
|
{
|
|
|
|
std::vector<std::string> props;
|
|
|
|
cmSystemTools::ExpandListArgument(propCxx98, props);
|
|
|
|
needCxx98 = std::find(props.begin(), props.end(), feature) != props.end();
|
|
|
|
}
|
2014-04-02 17:57:15 +04:00
|
|
|
if (const char *propCxx11 =
|
|
|
|
this->GetDefinition("CMAKE_CXX11_COMPILE_FEATURES"))
|
|
|
|
{
|
|
|
|
std::vector<std::string> props;
|
|
|
|
cmSystemTools::ExpandListArgument(propCxx11, props);
|
|
|
|
needCxx11 = std::find(props.begin(), props.end(), feature) != props.end();
|
|
|
|
}
|
2014-05-06 02:21:14 +04:00
|
|
|
if (const char *propCxx14 =
|
|
|
|
this->GetDefinition("CMAKE_CXX14_COMPILE_FEATURES"))
|
|
|
|
{
|
|
|
|
std::vector<std::string> props;
|
|
|
|
cmSystemTools::ExpandListArgument(propCxx14, props);
|
|
|
|
needCxx14 = std::find(props.begin(), props.end(), feature) != props.end();
|
|
|
|
}
|
2014-05-15 13:49:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmMakefile::
|
|
|
|
AddRequiredTargetCxxFeature(cmTarget *target,
|
|
|
|
const std::string& feature) const
|
|
|
|
{
|
|
|
|
bool needCxx98 = false;
|
|
|
|
bool needCxx11 = false;
|
2014-05-06 02:21:14 +04:00
|
|
|
bool needCxx14 = false;
|
2014-05-15 13:49:02 +04:00
|
|
|
|
2014-05-06 02:21:14 +04:00
|
|
|
this->CheckNeededCxxLanguage(feature, needCxx98, needCxx11, needCxx14);
|
2014-04-02 17:57:15 +04:00
|
|
|
|
|
|
|
const char *existingCxxStandard = target->GetProperty("CXX_STANDARD");
|
|
|
|
if (existingCxxStandard)
|
|
|
|
{
|
|
|
|
if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS),
|
|
|
|
cmStrCmp(existingCxxStandard)) == cmArrayEnd(CXX_STANDARDS))
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2014-04-02 17:57:15 +04:00
|
|
|
e << "The CXX_STANDARD property on target \"" << target->GetName()
|
|
|
|
<< "\" contained an invalid value: \"" << existingCxxStandard << "\".";
|
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const char * const *existingCxxIt = existingCxxStandard
|
|
|
|
? std::find_if(cmArrayBegin(CXX_STANDARDS),
|
|
|
|
cmArrayEnd(CXX_STANDARDS),
|
|
|
|
cmStrCmp(existingCxxStandard))
|
|
|
|
: cmArrayEnd(CXX_STANDARDS);
|
|
|
|
|
2014-04-06 13:40:11 +04:00
|
|
|
bool setCxx98 = needCxx98 && !existingCxxStandard;
|
2014-04-02 17:57:15 +04:00
|
|
|
bool setCxx11 = needCxx11 && !existingCxxStandard;
|
2014-05-06 02:21:14 +04:00
|
|
|
bool setCxx14 = needCxx14 && !existingCxxStandard;
|
2014-04-02 17:57:15 +04:00
|
|
|
|
2014-05-06 02:21:14 +04:00
|
|
|
if (needCxx14 && existingCxxStandard && existingCxxIt <
|
|
|
|
std::find_if(cmArrayBegin(CXX_STANDARDS),
|
|
|
|
cmArrayEnd(CXX_STANDARDS),
|
|
|
|
cmStrCmp("14")))
|
|
|
|
{
|
|
|
|
setCxx14 = true;
|
|
|
|
}
|
|
|
|
else if (needCxx11 && existingCxxStandard && existingCxxIt <
|
2014-04-02 17:57:15 +04:00
|
|
|
std::find_if(cmArrayBegin(CXX_STANDARDS),
|
|
|
|
cmArrayEnd(CXX_STANDARDS),
|
|
|
|
cmStrCmp("11")))
|
|
|
|
{
|
|
|
|
setCxx11 = true;
|
|
|
|
}
|
2014-04-06 13:40:11 +04:00
|
|
|
else if(needCxx98 && existingCxxStandard && existingCxxIt <
|
|
|
|
std::find_if(cmArrayBegin(CXX_STANDARDS),
|
|
|
|
cmArrayEnd(CXX_STANDARDS),
|
|
|
|
cmStrCmp("98")))
|
|
|
|
{
|
|
|
|
setCxx98 = true;
|
|
|
|
}
|
2014-04-02 17:57:15 +04:00
|
|
|
|
2014-05-06 02:21:14 +04:00
|
|
|
if (setCxx14)
|
|
|
|
{
|
|
|
|
target->SetProperty("CXX_STANDARD", "14");
|
|
|
|
}
|
|
|
|
else if (setCxx11)
|
2014-04-02 17:57:15 +04:00
|
|
|
{
|
|
|
|
target->SetProperty("CXX_STANDARD", "11");
|
|
|
|
}
|
2014-04-06 13:40:11 +04:00
|
|
|
else if (setCxx98)
|
|
|
|
{
|
|
|
|
target->SetProperty("CXX_STANDARD", "98");
|
|
|
|
}
|
2014-04-02 17:57:15 +04:00
|
|
|
return true;
|
|
|
|
}
|
2013-11-04 04:15:43 +04:00
|
|
|
|
2014-05-15 13:49:02 +04:00
|
|
|
void cmMakefile::CheckNeededCLanguage(const std::string& feature,
|
|
|
|
bool& needC90,
|
|
|
|
bool& needC99,
|
|
|
|
bool& needC11) const
|
2013-11-04 04:15:43 +04:00
|
|
|
{
|
|
|
|
if (const char *propC90 =
|
|
|
|
this->GetDefinition("CMAKE_C90_COMPILE_FEATURES"))
|
|
|
|
{
|
|
|
|
std::vector<std::string> props;
|
|
|
|
cmSystemTools::ExpandListArgument(propC90, props);
|
|
|
|
needC90 = std::find(props.begin(), props.end(), feature) != props.end();
|
|
|
|
}
|
|
|
|
if (const char *propC99 =
|
|
|
|
this->GetDefinition("CMAKE_C99_COMPILE_FEATURES"))
|
|
|
|
{
|
|
|
|
std::vector<std::string> props;
|
|
|
|
cmSystemTools::ExpandListArgument(propC99, props);
|
|
|
|
needC99 = std::find(props.begin(), props.end(), feature) != props.end();
|
|
|
|
}
|
|
|
|
if (const char *propC11 =
|
|
|
|
this->GetDefinition("CMAKE_C11_COMPILE_FEATURES"))
|
|
|
|
{
|
|
|
|
std::vector<std::string> props;
|
|
|
|
cmSystemTools::ExpandListArgument(propC11, props);
|
|
|
|
needC11 = std::find(props.begin(), props.end(), feature) != props.end();
|
|
|
|
}
|
2014-05-15 13:49:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmMakefile::
|
|
|
|
AddRequiredTargetCFeature(cmTarget *target, const std::string& feature) const
|
|
|
|
{
|
|
|
|
bool needC90 = false;
|
|
|
|
bool needC99 = false;
|
|
|
|
bool needC11 = false;
|
|
|
|
|
|
|
|
this->CheckNeededCLanguage(feature, needC90, needC99, needC11);
|
2013-11-04 04:15:43 +04:00
|
|
|
|
|
|
|
const char *existingCStandard = target->GetProperty("C_STANDARD");
|
|
|
|
if (existingCStandard)
|
|
|
|
{
|
|
|
|
if (std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS),
|
|
|
|
cmStrCmp(existingCStandard)) == cmArrayEnd(C_STANDARDS))
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2013-11-04 04:15:43 +04:00
|
|
|
e << "The C_STANDARD property on target \"" << target->GetName()
|
|
|
|
<< "\" contained an invalid value: \"" << existingCStandard << "\".";
|
2014-10-15 16:54:05 +04:00
|
|
|
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
2013-11-04 04:15:43 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const char * const *existingCIt = existingCStandard
|
|
|
|
? std::find_if(cmArrayBegin(C_STANDARDS),
|
|
|
|
cmArrayEnd(C_STANDARDS),
|
|
|
|
cmStrCmp(existingCStandard))
|
|
|
|
: cmArrayEnd(C_STANDARDS);
|
|
|
|
|
|
|
|
bool setC90 = needC90 && !existingCStandard;
|
|
|
|
bool setC99 = needC99 && !existingCStandard;
|
|
|
|
bool setC11 = needC11 && !existingCStandard;
|
|
|
|
|
|
|
|
if (needC11 && existingCStandard && existingCIt <
|
|
|
|
std::find_if(cmArrayBegin(C_STANDARDS),
|
|
|
|
cmArrayEnd(C_STANDARDS),
|
|
|
|
cmStrCmp("11")))
|
|
|
|
{
|
|
|
|
setC11 = true;
|
|
|
|
}
|
|
|
|
else if(needC99 && existingCStandard && existingCIt <
|
|
|
|
std::find_if(cmArrayBegin(C_STANDARDS),
|
|
|
|
cmArrayEnd(C_STANDARDS),
|
|
|
|
cmStrCmp("99")))
|
|
|
|
{
|
|
|
|
setC99 = true;
|
|
|
|
}
|
|
|
|
else if(needC90 && existingCStandard && existingCIt <
|
|
|
|
std::find_if(cmArrayBegin(C_STANDARDS),
|
|
|
|
cmArrayEnd(C_STANDARDS),
|
|
|
|
cmStrCmp("90")))
|
|
|
|
{
|
|
|
|
setC90 = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setC11)
|
|
|
|
{
|
|
|
|
target->SetProperty("C_STANDARD", "11");
|
|
|
|
}
|
|
|
|
else if (setC99)
|
|
|
|
{
|
|
|
|
target->SetProperty("C_STANDARD", "99");
|
|
|
|
}
|
|
|
|
else if (setC90)
|
|
|
|
{
|
|
|
|
target->SetProperty("C_STANDARD", "90");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-05-31 19:19:58 +03:00
|
|
|
|
|
|
|
|
|
|
|
cmMakefile::FunctionPushPop::FunctionPushPop(cmMakefile* mf,
|
2015-05-31 20:37:08 +03:00
|
|
|
const std::string& fileName,
|
2015-05-31 19:19:58 +03:00
|
|
|
cmPolicies::PolicyMap const& pm)
|
|
|
|
: Makefile(mf), ReportError(true)
|
|
|
|
{
|
2015-05-31 20:37:08 +03:00
|
|
|
this->Makefile->PushFunctionScope(fileName, pm);
|
2015-05-31 19:19:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmMakefile::FunctionPushPop::~FunctionPushPop()
|
|
|
|
{
|
|
|
|
this->Makefile->PopFunctionScope(this->ReportError);
|
|
|
|
}
|
2015-05-31 19:32:01 +03:00
|
|
|
|
|
|
|
|
|
|
|
cmMakefile::MacroPushPop::MacroPushPop(cmMakefile* mf,
|
2015-05-31 20:37:08 +03:00
|
|
|
const std::string& fileName,
|
2015-05-31 19:32:01 +03:00
|
|
|
const cmPolicies::PolicyMap& pm)
|
|
|
|
: Makefile(mf), ReportError(true)
|
|
|
|
{
|
2015-05-31 20:37:08 +03:00
|
|
|
this->Makefile->PushMacroScope(fileName, pm);
|
2015-05-31 19:32:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmMakefile::MacroPushPop::~MacroPushPop()
|
|
|
|
{
|
|
|
|
this->Makefile->PopMacroScope(this->ReportError);
|
|
|
|
}
|