cmState: Initialize default definitions immediately.

Don't leave this as cmMakefile responsibility.
This commit is contained in:
Stephen Kelly 2015-10-13 21:48:46 +02:00
parent 841164cb36
commit 20b95ef8c8
15 changed files with 66 additions and 56 deletions

View File

@ -717,6 +717,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
cmake cm; cmake cm;
cm.SetHomeDirectory(""); cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory(""); cm.SetHomeOutputDirectory("");
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cm.AddCMakePaths(); cm.AddCMakePaths();
cm.SetProgressCallback(cmCPackGeneratorProgress, this); cm.SetProgressCallback(cmCPackGeneratorProgress, this);
cmGlobalGenerator gg(&cm); cmGlobalGenerator gg(&cm);

View File

@ -199,6 +199,7 @@ int main (int argc, char const* const* argv)
cmake cminst; cmake cminst;
cminst.SetHomeDirectory(""); cminst.SetHomeDirectory("");
cminst.SetHomeOutputDirectory(""); cminst.SetHomeOutputDirectory("");
cminst.GetCurrentSnapshot().SetDefaultDefinitions();
cminst.GetState()->RemoveUnscriptableCommands(); cminst.GetState()->RemoveUnscriptableCommands();
cmGlobalGenerator cmgg(&cminst); cmGlobalGenerator cmgg(&cminst);
cmsys::auto_ptr<cmMakefile> globalMF( cmsys::auto_ptr<cmMakefile> globalMF(

View File

@ -736,6 +736,7 @@ void cmCTestLaunch::LoadConfig()
cmake cm; cmake cm;
cm.SetHomeDirectory(""); cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory(""); cm.SetHomeOutputDirectory("");
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator gg(&cm); cmGlobalGenerator gg(&cm);
cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot())); cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
std::string fname = this->LogDir; std::string fname = this->LogDir;

View File

@ -314,6 +314,7 @@ void cmCTestScriptHandler::CreateCMake()
this->CMake = new cmake; this->CMake = new cmake;
this->CMake->SetHomeDirectory(""); this->CMake->SetHomeDirectory("");
this->CMake->SetHomeOutputDirectory(""); this->CMake->SetHomeOutputDirectory("");
this->CMake->GetCurrentSnapshot().SetDefaultDefinitions();
this->CMake->AddCMakePaths(); this->CMake->AddCMakePaths();
this->GlobalGenerator = new cmGlobalGenerator(this->CMake); this->GlobalGenerator = new cmGlobalGenerator(this->CMake);

View File

@ -1590,6 +1590,7 @@ void cmCTestTestHandler::GetListOfTests()
cmake cm; cmake cm;
cm.SetHomeDirectory(""); cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory(""); cm.SetHomeOutputDirectory("");
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator gg(&cm); cmGlobalGenerator gg(&cm);
cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot())); cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
mf->AddDefinition("CTEST_CONFIGURATION_TYPE", mf->AddDefinition("CTEST_CONFIGURATION_TYPE",

View File

@ -517,6 +517,7 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
cmake cm; cmake cm;
cm.SetHomeDirectory(""); cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory(""); cm.SetHomeOutputDirectory("");
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator gg(&cm); cmGlobalGenerator gg(&cm);
cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot())); cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
if ( !this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(), if ( !this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(),

View File

@ -589,6 +589,7 @@ void cmGlobalUnixMakefileGenerator3
(this->CMakeInstance->GetHomeDirectory()); (this->CMakeInstance->GetHomeDirectory());
snapshot.GetDirectory().SetCurrentBinary snapshot.GetDirectory().SetCurrentBinary
(this->CMakeInstance->GetHomeOutputDirectory()); (this->CMakeInstance->GetHomeOutputDirectory());
snapshot.SetDefaultDefinitions();
mf = new cmMakefile(this, snapshot); mf = new cmMakefile(this, snapshot);
} }

View File

@ -67,6 +67,7 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
cmake cm; cmake cm;
cm.SetHomeDirectory(""); cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory(""); cm.SetHomeOutputDirectory("");
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator ggi(&cm); cmGlobalGenerator ggi(&cm);
cmsys::auto_ptr<cmMakefile> mf( cmsys::auto_ptr<cmMakefile> mf(
new cmMakefile(&ggi, cm.GetCurrentSnapshot())); new cmMakefile(&ggi, cm.GetCurrentSnapshot()));

View File

@ -87,8 +87,6 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator,
this->DefineFlags = " "; this->DefineFlags = " ";
this->AddDefaultDefinitions();
this->cmDefineRegex.compile("#cmakedefine[ \t]+([A-Za-z_0-9]*)"); this->cmDefineRegex.compile("#cmakedefine[ \t]+([A-Za-z_0-9]*)");
this->cmDefine01Regex.compile("#cmakedefine01[ \t]+([A-Za-z_0-9]*)"); this->cmDefine01Regex.compile("#cmakedefine01[ \t]+([A-Za-z_0-9]*)");
this->cmAtVarRegex.compile("(@[A-Za-z_0-9/.+-]+@)"); this->cmAtVarRegex.compile("(@[A-Za-z_0-9/.+-]+@)");
@ -3123,59 +3121,6 @@ void cmMakefile::RemoveVariablesInString(std::string& source,
} }
} }
/**
* Add the default definitions to the makefile. These values must not
* be dependent on anything that isn't known when this cmMakefile instance
* is constructed.
*/
void cmMakefile::AddDefaultDefinitions()
{
/* Up to CMake 2.4 here only WIN32, UNIX and APPLE were set.
With CMake must separate between target and host platform. In most cases
the tests for WIN32, UNIX and APPLE will be for the target system, so an
additional set of variables for the host system is required ->
CMAKE_HOST_WIN32, CMAKE_HOST_UNIX, CMAKE_HOST_APPLE.
WIN32, UNIX and APPLE are now set in the platform files in
Modules/Platforms/.
To keep cmake scripts (-P) and custom language and compiler modules
working, these variables are still also set here in this place, but they
will be reset in CMakeSystemSpecificInformation.cmake before the platform
files are executed. */
#if defined(_WIN32)
this->StateSnapshot.SetDefinition("WIN32", "1");
this->StateSnapshot.SetDefinition("CMAKE_HOST_WIN32", "1");
#else
this->StateSnapshot.SetDefinition("UNIX", "1");
this->StateSnapshot.SetDefinition("CMAKE_HOST_UNIX", "1");
#endif
#if defined(__CYGWIN__)
if(cmSystemTools::IsOn(cmSystemTools::GetEnv("CMAKE_LEGACY_CYGWIN_WIN32")))
{
this->StateSnapshot.SetDefinition("WIN32", "1");
this->StateSnapshot.SetDefinition("CMAKE_HOST_WIN32", "1");
}
#endif
#if defined(__APPLE__)
this->StateSnapshot.SetDefinition("APPLE", "1");
this->StateSnapshot.SetDefinition("CMAKE_HOST_APPLE", "1");
#endif
char temp[1024];
sprintf(temp, "%d", cmVersion::GetMinorVersion());
this->StateSnapshot.SetDefinition("CMAKE_MINOR_VERSION", temp);
sprintf(temp, "%d", cmVersion::GetMajorVersion());
this->StateSnapshot.SetDefinition("CMAKE_MAJOR_VERSION", temp);
sprintf(temp, "%d", cmVersion::GetPatchVersion());
this->StateSnapshot.SetDefinition("CMAKE_PATCH_VERSION", temp);
sprintf(temp, "%d", cmVersion::GetTweakVersion());
this->StateSnapshot.SetDefinition("CMAKE_TWEAK_VERSION", temp);
this->StateSnapshot.SetDefinition("CMAKE_VERSION",
cmVersion::GetCMakeVersion());
this->StateSnapshot.SetDefinition("CMAKE_FILES_DIRECTORY",
cmake::GetCMakeFilesDirectory());
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string std::string
cmMakefile::GetConfigurations(std::vector<std::string>& configs, cmMakefile::GetConfigurations(std::vector<std::string>& configs,

View File

@ -867,7 +867,6 @@ private:
friend class cmMakeDepend; // make depend needs direct access friend class cmMakeDepend; // make depend needs direct access
// to the Sources array // to the Sources array
void AddDefaultDefinitions();
typedef std::vector<cmFunctionBlocker*> FunctionBlockersType; typedef std::vector<cmFunctionBlocker*> FunctionBlockersType;
FunctionBlockersType FunctionBlockers; FunctionBlockersType FunctionBlockers;
std::vector<FunctionBlockersType::size_type> FunctionBlockerBarriers; std::vector<FunctionBlockersType::size_type> FunctionBlockerBarriers;

View File

@ -175,6 +175,7 @@ bool cmQtAutoGenerators::Run(const std::string& targetDirectory,
cmake cm; cmake cm;
cm.SetHomeOutputDirectory(targetDirectory); cm.SetHomeOutputDirectory(targetDirectory);
cm.SetHomeDirectory(targetDirectory); cm.SetHomeDirectory(targetDirectory);
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator gg(&cm); cmGlobalGenerator gg(&cm);
cmState::Snapshot snapshot = cm.GetCurrentSnapshot(); cmState::Snapshot snapshot = cm.GetCurrentSnapshot();

View File

@ -12,6 +12,7 @@
#include "cmState.h" #include "cmState.h"
#include "cmake.h" #include "cmake.h"
#include "cmVersion.h"
#include "cmCacheManager.h" #include "cmCacheManager.h"
#include "cmCommand.h" #include "cmCommand.h"
#include "cmAlgorithms.h" #include "cmAlgorithms.h"
@ -847,6 +848,7 @@ cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
cmState::Snapshot snapshot = cmState::Snapshot(this, pos); cmState::Snapshot snapshot = cmState::Snapshot(this, pos);
originSnapshot.Position->BuildSystemDirectory->Children.push_back(snapshot); originSnapshot.Position->BuildSystemDirectory->Children.push_back(snapshot);
snapshot.SetDefaultDefinitions();
snapshot.InitializeFromParent(); snapshot.InitializeFromParent();
snapshot.SetDirectoryDefinitions(); snapshot.SetDirectoryDefinitions();
return snapshot; return snapshot;
@ -1333,6 +1335,54 @@ void InitializeContentFromParent(T& parentContent,
contentEndPosition = thisContent.size(); contentEndPosition = thisContent.size();
} }
void cmState::Snapshot::SetDefaultDefinitions()
{
/* Up to CMake 2.4 here only WIN32, UNIX and APPLE were set.
With CMake must separate between target and host platform. In most cases
the tests for WIN32, UNIX and APPLE will be for the target system, so an
additional set of variables for the host system is required ->
CMAKE_HOST_WIN32, CMAKE_HOST_UNIX, CMAKE_HOST_APPLE.
WIN32, UNIX and APPLE are now set in the platform files in
Modules/Platforms/.
To keep cmake scripts (-P) and custom language and compiler modules
working, these variables are still also set here in this place, but they
will be reset in CMakeSystemSpecificInformation.cmake before the platform
files are executed. */
#if defined(_WIN32)
this->SetDefinition("WIN32", "1");
this->SetDefinition("CMAKE_HOST_WIN32", "1");
#else
this->SetDefinition("UNIX", "1");
this->SetDefinition("CMAKE_HOST_UNIX", "1");
#endif
#if defined(__CYGWIN__)
if(cmSystemTools::IsOn(cmSystemTools::GetEnv("CMAKE_LEGACY_CYGWIN_WIN32")))
{
this->SetDefinition("WIN32", "1");
this->SetDefinition("CMAKE_HOST_WIN32", "1");
}
#endif
#if defined(__APPLE__)
this->SetDefinition("APPLE", "1");
this->SetDefinition("CMAKE_HOST_APPLE", "1");
#endif
char temp[1024];
sprintf(temp, "%d", cmVersion::GetMinorVersion());
this->SetDefinition("CMAKE_MINOR_VERSION", temp);
sprintf(temp, "%d", cmVersion::GetMajorVersion());
this->SetDefinition("CMAKE_MAJOR_VERSION", temp);
sprintf(temp, "%d", cmVersion::GetPatchVersion());
this->SetDefinition("CMAKE_PATCH_VERSION", temp);
sprintf(temp, "%d", cmVersion::GetTweakVersion());
this->SetDefinition("CMAKE_TWEAK_VERSION", temp);
this->SetDefinition("CMAKE_VERSION",
cmVersion::GetCMakeVersion());
this->SetDefinition("CMAKE_FILES_DIRECTORY",
cmake::GetCMakeFilesDirectory());
}
void cmState::Snapshot::SetDirectoryDefinitions() void cmState::Snapshot::SetDirectoryDefinitions()
{ {
this->SetDefinition("CMAKE_SOURCE_DIR", this->SetDefinition("CMAKE_SOURCE_DIR",

View File

@ -97,6 +97,7 @@ public:
}; };
void SetDirectoryDefinitions(); void SetDirectoryDefinitions();
void SetDefaultDefinitions();
private: private:
friend bool operator==(const cmState::Snapshot& lhs, friend bool operator==(const cmState::Snapshot& lhs,

View File

@ -186,6 +186,7 @@ void cmake::CleanupCommandsAndMacros()
{ {
this->CurrentSnapshot = this->State->Reset(); this->CurrentSnapshot = this->State->Reset();
this->State->RemoveUserDefinedCommands(); this->State->RemoveUserDefinedCommands();
this->CurrentSnapshot.SetDefaultDefinitions();
} }
// Parse the args // Parse the args
@ -378,6 +379,7 @@ void cmake::ReadListFile(const std::vector<std::string>& args,
(cmSystemTools::GetCurrentWorkingDirectory()); (cmSystemTools::GetCurrentWorkingDirectory());
snapshot.GetDirectory().SetCurrentSource snapshot.GetDirectory().SetCurrentSource
(cmSystemTools::GetCurrentWorkingDirectory()); (cmSystemTools::GetCurrentWorkingDirectory());
snapshot.SetDefaultDefinitions();
cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(gg, snapshot)); cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(gg, snapshot));
if (this->GetWorkingMode() != NORMAL_MODE) if (this->GetWorkingMode() != NORMAL_MODE)
{ {
@ -420,6 +422,7 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
snapshot.GetDirectory().SetCurrentSource snapshot.GetDirectory().SetCurrentSource
(cmSystemTools::GetCurrentWorkingDirectory()); (cmSystemTools::GetCurrentWorkingDirectory());
// read in the list file to fill the cache // read in the list file to fill the cache
snapshot.SetDefaultDefinitions();
cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(gg, snapshot)); cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(gg, snapshot));
cmsys::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator(mf.get())); cmsys::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator(mf.get()));
@ -1928,6 +1931,7 @@ int cmake::CheckBuildSystem()
cmake cm; cmake cm;
cm.SetHomeDirectory(""); cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory(""); cm.SetHomeOutputDirectory("");
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator gg(&cm); cmGlobalGenerator gg(&cm);
cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot())); cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
if(!mf->ReadListFile(this->CheckBuildSystemArgument.c_str()) || if(!mf->ReadListFile(this->CheckBuildSystemArgument.c_str()) ||
@ -1958,6 +1962,7 @@ int cmake::CheckBuildSystem()
ggd(this->CreateGlobalGenerator(genName)); ggd(this->CreateGlobalGenerator(genName));
if(ggd.get()) if(ggd.get())
{ {
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmsys::auto_ptr<cmMakefile> mfd(new cmMakefile(ggd.get(), cmsys::auto_ptr<cmMakefile> mfd(new cmMakefile(ggd.get(),
cm.GetCurrentSnapshot())); cm.GetCurrentSnapshot()));
cmsys::auto_ptr<cmLocalGenerator> lgd( cmsys::auto_ptr<cmLocalGenerator> lgd(

View File

@ -765,6 +765,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
startOutDir = cmSystemTools::CollapseFullPath(startOutDir); startOutDir = cmSystemTools::CollapseFullPath(startOutDir);
cm.SetHomeDirectory(homeDir); cm.SetHomeDirectory(homeDir);
cm.SetHomeOutputDirectory(homeOutDir); cm.SetHomeOutputDirectory(homeOutDir);
cm.GetCurrentSnapshot().SetDefaultDefinitions();
if(cmGlobalGenerator* ggd = cm.CreateGlobalGenerator(gen)) if(cmGlobalGenerator* ggd = cm.CreateGlobalGenerator(gen))
{ {
cm.SetGlobalGenerator(ggd); cm.SetGlobalGenerator(ggd);