diff options
author | Brad King <brad.king@kitware.com> | 2014-09-05 18:25:27 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-09-05 18:38:05 (GMT) |
commit | 0f1f1271e6ddcea9074afe79685a731d4295c1f5 (patch) | |
tree | 4012664a0c9ff485740fe5bf4a5982072597f323 /Source | |
parent | 4f7d0c421abf047c052cb8d459c8249310cf4f3a (diff) | |
download | CMake-0f1f1271e6ddcea9074afe79685a731d4295c1f5.zip CMake-0f1f1271e6ddcea9074afe79685a731d4295c1f5.tar.gz CMake-0f1f1271e6ddcea9074afe79685a731d4295c1f5.tar.bz2 |
CMake: Add CMAKE_GENERATOR_PLATFORM option
Reject the option by default. It will be implemented on a per-generator
basis. Pass the setting into try_compile project generation. Add cache
entry CMAKE_GENERATOR_PLATFORM and associated variable documentation to
hold the value persistently.
Add a RunCMake.GeneratorPlatform test to cover basic use cases for the
option. Verify that CMAKE_GENERATOR_PLATFORM is empty by default, and
that it is rejected when the generator does not support a user setting.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 29 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 4 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 1 | ||||
-rw-r--r-- | Source/cmake.cxx | 28 | ||||
-rw-r--r-- | Source/cmake.h | 9 |
5 files changed, 71 insertions, 0 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 42efec2..90fd3f3 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -76,6 +76,27 @@ cmGlobalGenerator::~cmGlobalGenerator() } } +bool cmGlobalGenerator::SetGeneratorPlatform(std::string const& p, + cmMakefile* mf) +{ + if(p.empty()) + { + return true; + } + else + { + cmOStringStream e; + e << + "Generator\n" + " " << this->GetName() << "\n" + "does not support platform specification, but platform\n" + " " << p << "\n" + "was specified."; + mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + return false; + } +} + bool cmGlobalGenerator::SetGeneratorToolset(std::string const& ts, cmMakefile* mf) { @@ -459,6 +480,14 @@ cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages, return; } + // Tell the generator about the platform, if any. + std::string platform = mf->GetSafeDefinition("CMAKE_GENERATOR_PLATFORM"); + if(!this->SetGeneratorPlatform(platform, mf)) + { + cmSystemTools::SetFatalErrorOccured(); + return; + } + // Tell the generator about the toolset, if any. std::string toolset = mf->GetSafeDefinition("CMAKE_GENERATOR_TOOLSET"); if(!this->SetGeneratorToolset(toolset, mf)) diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index f80c3c7..f166789 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -65,6 +65,10 @@ public: virtual bool SetSystemName(std::string const&, cmMakefile*) { return true; } + /** Set the generator-specific platform name. Returns true if platform + is supported and false otherwise. */ + virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf); + /** Set the generator-specific toolset name. Returns true if toolset is supported and false otherwise. */ virtual bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 04b2d27..efdaeec 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -3548,6 +3548,7 @@ int cmMakefile::TryCompile(const std::string& srcdir, cm.SetHomeOutputDirectory(bindir); cm.SetStartDirectory(srcdir); cm.SetStartOutputDirectory(bindir); + cm.SetGeneratorPlatform(this->GetCMakeInstance()->GetGeneratorPlatform()); cm.SetGeneratorToolset(this->GetCMakeInstance()->GetGeneratorToolset()); cm.LoadCache(); if(!gg->IsMultiConfig()) diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 6cc3b81..c9c63c7 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -1445,6 +1445,34 @@ int cmake::ActualConfigure() cmCacheManager::INTERNAL); } + if(const char* platformName = + this->CacheManager->GetCacheValue("CMAKE_GENERATOR_PLATFORM")) + { + if(this->GeneratorPlatform.empty()) + { + this->GeneratorPlatform = platformName; + } + else if(this->GeneratorPlatform != platformName) + { + std::string message = "Error: generator platform: "; + message += this->GeneratorPlatform; + message += "\nDoes not match the platform used previously: "; + message += platformName; + message += + "\nEither remove the CMakeCache.txt file and CMakeFiles " + "directory or choose a different binary directory."; + cmSystemTools::Error(message.c_str()); + return -2; + } + } + else + { + this->CacheManager->AddCacheEntry("CMAKE_GENERATOR_PLATFORM", + this->GeneratorPlatform.c_str(), + "Name of generator platform.", + cmCacheManager::INTERNAL); + } + if(const char* tsName = this->CacheManager->GetCacheValue("CMAKE_GENERATOR_TOOLSET")) { diff --git a/Source/cmake.h b/Source/cmake.h index 2d04902..919fc24 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -191,6 +191,14 @@ class cmake ///! Get the names of the current registered generators void GetRegisteredGenerators(std::vector<std::string>& names); + ///! Set the name of the selected generator-specific platform. + void SetGeneratorPlatform(std::string const& ts) + { this->GeneratorPlatform = ts; } + + ///! Get the name of the selected generator-specific platform. + std::string const& GetGeneratorPlatform() const + { return this->GeneratorPlatform; } + ///! Set the name of the selected generator-specific toolset. void SetGeneratorToolset(std::string const& ts) { this->GeneratorToolset = ts; } @@ -403,6 +411,7 @@ protected: std::string StartOutputDirectory; bool SuppressDevWarnings; bool DoSuppressDevWarnings; + std::string GeneratorPlatform; std::string GeneratorToolset; ///! read in a cmake list file to initialize the cache |