diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2011-09-10 02:52:53 (GMT) |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2011-10-02 17:30:43 (GMT) |
commit | 557956f3489dbc75c7b6d26ed531c7c577aac146 (patch) | |
tree | 80fa2c836025db6388a555e80ed2cb19bf374b9e /Source/cmGlobalGenerator.cxx | |
parent | 5b114c9bee735eebf3e6b4d6ef18e4c732ac55f0 (diff) | |
download | CMake-557956f3489dbc75c7b6d26ed531c7c577aac146.zip CMake-557956f3489dbc75c7b6d26ed531c7c577aac146.tar.gz CMake-557956f3489dbc75c7b6d26ed531c7c577aac146.tar.bz2 |
Introduce a cmGlobalGenerator::ResolveLanguageCompiler function
It is factored out of cmGlobalUnixMakefileGenerator3::EnableLanguage,
and may be used by other generators to resolve CMAKE_*_COMPILER
settings.
Diffstat (limited to 'Source/cmGlobalGenerator.cxx')
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index d62fb44..124519a 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -77,6 +77,79 @@ cmGlobalGenerator::~cmGlobalGenerator() this->ClearExportSets(); } +void cmGlobalGenerator::ResolveLanguageCompiler(const std::string &lang, + cmMakefile *mf, + bool optional) { + std::string langComp = "CMAKE_"; + langComp += lang; + langComp += "_COMPILER"; + + if(!mf->GetDefinition(langComp.c_str())) + { + if(!optional) + { + cmSystemTools::Error(langComp.c_str(), + " not set, after EnableLanguage"); + } + return; + } + const char* name = mf->GetRequiredDefinition(langComp.c_str()); + std::string path; + if(!cmSystemTools::FileIsFullPath(name)) + { + path = cmSystemTools::FindProgram(name); + } + else + { + path = name; + } + if((path.size() == 0 || !cmSystemTools::FileExists(path.c_str())) + && (optional==false)) + { + std::string message = "your "; + message += lang; + message += " compiler: \""; + message += name; + message += "\" was not found. Please set "; + message += langComp; + message += " to a valid compiler path or name."; + cmSystemTools::Error(message.c_str()); + path = name; + } + std::string doc = lang; + doc += " compiler."; + const char* cname = this->GetCMakeInstance()-> + GetCacheManager()->GetCacheValue(langComp.c_str()); + std::string changeVars; + if(cname && (path != cname) && (optional==false)) + { + std::string cnameString = cname; + std::string pathString = path; + // get rid of potentially multiple slashes: + cmSystemTools::ConvertToUnixSlashes(cnameString); + cmSystemTools::ConvertToUnixSlashes(pathString); + if (cnameString != pathString) + { + const char* cvars = + this->GetCMakeInstance()->GetProperty( + "__CMAKE_DELETE_CACHE_CHANGE_VARS_"); + if(cvars) + { + changeVars += cvars; + changeVars += ";"; + } + changeVars += langComp; + changeVars += ";"; + changeVars += cname; + this->GetCMakeInstance()->SetProperty( + "__CMAKE_DELETE_CACHE_CHANGE_VARS_", + changeVars.c_str()); + } + } + mf->AddCacheDefinition(langComp.c_str(), path.c_str(), + doc.c_str(), cmCacheManager::FILEPATH); +} + // Find the make program for the generator, required for try compiles void cmGlobalGenerator::FindMakeProgram(cmMakefile* mf) { |