ENH: try to initialize all languages at the same time

This commit is contained in:
Bill Hoffman 2004-08-27 08:41:07 -04:00
parent ad4f98f3cf
commit 731369ef9c
17 changed files with 158 additions and 160 deletions

View File

@ -24,7 +24,8 @@ cmGlobalBorlandMakefileGenerator::cmGlobalBorlandMakefileGenerator()
m_ForceUnixPaths = false;
}
void cmGlobalBorlandMakefileGenerator::EnableLanguage(const char* l,
void cmGlobalBorlandMakefileGenerator::EnableLanguage(std::vector<std::string>const& l,
cmMakefile *mf)
{
std::string outdir = m_CMakeInstance->GetStartOutputDirectory();

View File

@ -45,7 +45,7 @@ public:
* Try to determine system infomation such as shared library
* extension, pthreads, byte order etc.
*/
virtual void EnableLanguage(const char*,cmMakefile *mf);
virtual void EnableLanguage(std::vector<std::string>const& languages, cmMakefile *);
};
#endif

View File

@ -20,7 +20,7 @@
#include "cmake.h"
#include "cmTarget.h"
void cmGlobalCodeWarriorGenerator::EnableLanguage(const char*,
void cmGlobalCodeWarriorGenerator::EnableLanguage(std::vector<std::string>const& l,
cmMakefile *mf)
{
// now load the settings

View File

@ -46,7 +46,7 @@ public:
* Try to determine system infomation such as shared library
* extension, pthreads, byte order etc.
*/
virtual void EnableLanguage(const char*, cmMakefile *mf);
virtual void EnableLanguage(std::vector<std::string>const& languages, cmMakefile *);
/**
* Try running cmake and building a file. This is used for dynalically

View File

@ -98,10 +98,10 @@ void cmGlobalGenerator::FindMakeProgram(cmMakefile* mf)
// enable the given language
void cmGlobalGenerator::EnableLanguage(const char* lang,
void cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages,
cmMakefile *mf)
{
if(!lang)
if(languages.size() == 0)
{
cmSystemTools::Error("EnableLanguage must have a lang specified!");
cmSystemTools::SetFatalErrorOccured();
@ -126,7 +126,7 @@ void cmGlobalGenerator::EnableLanguage(const char* lang,
// **** Step 2, Load the CMakeDetermineSystem.cmake file and find out
// what platform we are running on
if (!isLocal && !this->GetLanguageEnabled(lang))
if (!isLocal && !mf->GetDefinition("CMAKE_SYSTEM_NAME"))
{
#if defined(_WIN32) && !defined(__CYGWIN__)
/* Windows version number data. */
@ -151,65 +151,72 @@ void cmGlobalGenerator::EnableLanguage(const char* lang,
fpath += "/CMakeSystem.cmake";
mf->ReadListFile(0,fpath.c_str());
}
// **** Step 4, load the CMakeDetermine(LANG)Compiler.cmake file to find
// the compiler
if(!isLocal && !this->GetLanguageEnabled(lang) )
{
if (m_CMakeInstance->GetIsInTryCompile())
{
cmSystemTools::Error("This should not have happen. "
"If you see this message, you are probably using a "
"broken CMakeLists.txt file or a problematic release of "
"CMake");
}
needTestLanguage = true; // must test a language after finding it
// read determine LANG compiler
std::string determinCompiler = "CMakeDetermine";
determinCompiler += lang;
determinCompiler += "Compiler.cmake";
std::string determineFile = mf->GetModulesFile(determinCompiler.c_str());
if(!mf->ReadListFile(0,determineFile.c_str()))
{
cmSystemTools::Error("Could not find cmake module file:", determineFile.c_str());
}
this->SetLanguageEnabled(lang);
// put ${CMake_(LANG)_COMPILER_ENV_VAR}=${CMAKE_(LANG)_COMPILER into the
// environment, in case user scripts want to run configure, or sub cmakes
std::string compilerName = "CMAKE_";
compilerName += lang;
compilerName += "_COMPILER";
std::string compilerEnv = "CMAKE_";
compilerEnv += lang;
compilerEnv += "_COMPILER_ENV_VAR";
std::string envVar = mf->GetRequiredDefinition(compilerEnv.c_str());
std::string envVarValue = mf->GetRequiredDefinition(compilerName.c_str());
std::string env = envVar;
env += "=";
env += envVarValue;
cmSystemTools::PutEnv(env.c_str());
}
// **** Step 5, Load the configured language compiler file, if not loaded.
// look to see if CMAKE_(LANG)_COMPILER_LOADED is set,
// if not then load the CMake(LANG)Compiler.cmake file from the
// binary tree, this is a configured file provided by
// CMakeDetermine(LANG)Compiler.cmake
std::string loadedLang = "CMAKE_";
loadedLang += lang;
loadedLang += "_COMPILER_LOADED";
if(!mf->GetDefinition(loadedLang.c_str()))
// **** Step 4, foreach language
// load the CMakeDetermine(LANG)Compiler.cmake file to find
// the compiler
for(std::vector<std::string>::const_iterator l = languages.begin();
l != languages.end(); ++l)
{
fpath = rootBin;
fpath += "/CMake";
fpath += lang;
fpath += "Compiler.cmake";
if(!mf->ReadListFile(0,fpath.c_str()))
{
cmSystemTools::Error("Could not find cmake module file:", fpath.c_str());
const char* lang = l->c_str();
if(!isLocal && !this->GetLanguageEnabled(lang) )
{
if (m_CMakeInstance->GetIsInTryCompile())
{
cmSystemTools::Error("This should not have happen. "
"If you see this message, you are probably using a "
"broken CMakeLists.txt file or a problematic release of "
"CMake");
}
needTestLanguage = true; // must test a language after finding it
// read determine LANG compiler
std::string determinCompiler = "CMakeDetermine";
determinCompiler += lang;
determinCompiler += "Compiler.cmake";
std::string determineFile = mf->GetModulesFile(determinCompiler.c_str());
if(!mf->ReadListFile(0,determineFile.c_str()))
{
cmSystemTools::Error("Could not find cmake module file:", determineFile.c_str());
}
this->SetLanguageEnabled(lang);
// put ${CMake_(LANG)_COMPILER_ENV_VAR}=${CMAKE_(LANG)_COMPILER into the
// environment, in case user scripts want to run configure, or sub cmakes
std::string compilerName = "CMAKE_";
compilerName += lang;
compilerName += "_COMPILER";
std::string compilerEnv = "CMAKE_";
compilerEnv += lang;
compilerEnv += "_COMPILER_ENV_VAR";
std::string envVar = mf->GetRequiredDefinition(compilerEnv.c_str());
std::string envVarValue = mf->GetRequiredDefinition(compilerName.c_str());
std::string env = envVar;
env += "=";
env += envVarValue;
cmSystemTools::PutEnv(env.c_str());
}
// **** Step 5, Load the configured language compiler file, if not loaded.
// look to see if CMAKE_(LANG)_COMPILER_LOADED is set,
// if not then load the CMake(LANG)Compiler.cmake file from the
// binary tree, this is a configured file provided by
// CMakeDetermine(LANG)Compiler.cmake
std::string loadedLang = "CMAKE_";
loadedLang += lang;
loadedLang += "_COMPILER_LOADED";
if(!mf->GetDefinition(loadedLang.c_str()))
{
fpath = rootBin;
fpath += "/CMake";
fpath += lang;
fpath += "Compiler.cmake";
if(!mf->ReadListFile(0,fpath.c_str()))
{
cmSystemTools::Error("Could not find cmake module file:", fpath.c_str());
}
this->SetLanguageEnabled(lang);
}
this->SetLanguageEnabled(lang);
}
// **** Step 6, Load the system specific information if not yet loaded
if (!mf->GetDefinition("CMAKE_SYSTEM_SPECIFIC_INFORMATION_LOADED"))
{
@ -219,60 +226,65 @@ void cmGlobalGenerator::EnableLanguage(const char* lang,
cmSystemTools::Error("Could not find cmake module file:", fpath.c_str());
}
}
std::string langLoadedVar = "CMAKE_";
langLoadedVar += lang;
langLoadedVar += "_INFORMATION_LOADED";
if (!mf->GetDefinition(langLoadedVar.c_str()))
{
fpath = "CMake";
fpath += lang;
fpath += "Information.cmake";
fpath = mf->GetModulesFile(fpath.c_str());
if(!mf->ReadListFile(0,fpath.c_str()))
{
cmSystemTools::Error("Could not find cmake module file:", fpath.c_str());
}
}
// **** Step 7, Test the compiler for the language just setup
// At this point we should have enough info for a try compile
// which is used in the backward stuff
if(!isLocal)
for(std::vector<std::string>::const_iterator l = languages.begin();
l != languages.end(); ++l)
{
if(needTestLanguage)
{
if (!m_CMakeInstance->GetIsInTryCompile())
const char* lang = l->c_str();
std::string langLoadedVar = "CMAKE_";
langLoadedVar += lang;
langLoadedVar += "_INFORMATION_LOADED";
if (!mf->GetDefinition(langLoadedVar.c_str()))
{
fpath = "CMake";
fpath += lang;
fpath += "Information.cmake";
fpath = mf->GetModulesFile(fpath.c_str());
if(!mf->ReadListFile(0,fpath.c_str()))
{
std::string testLang = "CMakeTest";
testLang += lang;
testLang += "Compiler.cmake";
std::string ifpath = mf->GetModulesFile(testLang.c_str());
if(!mf->ReadListFile(0,ifpath.c_str()))
{
cmSystemTools::Error("Could not find cmake module file:", ifpath.c_str());
}
// **** Step 8, load backwards compatibility stuff for C and CXX
// for old versions of CMake ListFiles C and CXX had some
// backwards compatibility files they have to load
const char* versionValue
= mf->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
if (atof(versionValue) <= 1.4)
{
if(strcmp(lang, "C") == 0)
{
ifpath = mf->GetModulesFile("CMakeBackwardCompatibilityC.cmake");
mf->ReadListFile(0,ifpath.c_str());
}
if(strcmp(lang, "CXX") == 0)
{
ifpath = mf->GetModulesFile("CMakeBackwardCompatibilityCXX.cmake");
mf->ReadListFile(0,ifpath.c_str());
}
}
cmSystemTools::Error("Could not find cmake module file:", fpath.c_str());
}
}
// **** Step 7, Test the compiler for the language just setup
// At this point we should have enough info for a try compile
// which is used in the backward stuff
if(!isLocal)
{
if(needTestLanguage)
{
if (!m_CMakeInstance->GetIsInTryCompile())
{
std::string testLang = "CMakeTest";
testLang += lang;
testLang += "Compiler.cmake";
std::string ifpath = mf->GetModulesFile(testLang.c_str());
if(!mf->ReadListFile(0,ifpath.c_str()))
{
cmSystemTools::Error("Could not find cmake module file:", ifpath.c_str());
}
// **** Step 8, load backwards compatibility stuff for C and CXX
// for old versions of CMake ListFiles C and CXX had some
// backwards compatibility files they have to load
const char* versionValue
= mf->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
if (atof(versionValue) <= 1.4)
{
if(strcmp(lang, "C") == 0)
{
ifpath = mf->GetModulesFile("CMakeBackwardCompatibilityC.cmake");
mf->ReadListFile(0,ifpath.c_str());
}
if(strcmp(lang, "CXX") == 0)
{
ifpath = mf->GetModulesFile("CMakeBackwardCompatibilityCXX.cmake");
mf->ReadListFile(0,ifpath.c_str());
}
}
}
}
}
}
}

View File

@ -77,7 +77,7 @@ public:
* Try to determine system infomation such as shared library
* extension, pthreads, byte order etc.
*/
virtual void EnableLanguage(const char*, cmMakefile *);
virtual void EnableLanguage(std::vector<std::string>const& languages, cmMakefile *);
/**
* Try to determine system infomation, get it from another generator

View File

@ -25,7 +25,7 @@ cmGlobalNMakeMakefileGenerator::cmGlobalNMakeMakefileGenerator()
m_ForceUnixPaths = false;
}
void cmGlobalNMakeMakefileGenerator::EnableLanguage(const char* l,
void cmGlobalNMakeMakefileGenerator::EnableLanguage(std::vector<std::string>const& l,
cmMakefile *mf)
{
// pick a default

View File

@ -44,8 +44,7 @@ public:
* Try to determine system infomation such as shared library
* extension, pthreads, byte order etc.
*/
virtual void EnableLanguage(const char*,cmMakefile *mf);
virtual void EnableLanguage(std::vector<std::string>const& languages, cmMakefile *);
};
#endif

View File

@ -27,24 +27,32 @@ cmGlobalUnixMakefileGenerator::cmGlobalUnixMakefileGenerator()
m_FindMakeProgramFile = "CMakeUnixFindMake.cmake";
}
void cmGlobalUnixMakefileGenerator::EnableLanguage(const char* lang,
void cmGlobalUnixMakefileGenerator::EnableLanguage(std::vector<std::string>const& languages,
cmMakefile *mf)
{
mf->AddDefinition("CMAKE_CFG_INTDIR",".");
this->cmGlobalGenerator::EnableLanguage(lang, mf);
this->cmGlobalGenerator::EnableLanguage(languages, mf);
std::string path;
if(strcmp(lang, "C") == 0)
for(std::vector<std::string>::const_iterator l = languages.begin();
l != languages.end(); ++l)
{
if(!mf->GetDefinition("CMAKE_C_COMPILER"))
const char* lang = l->c_str();
std::string langComp = "CMAKE_";
langComp += lang;
langComp += "_COMPILER";
if(!mf->GetDefinition(langComp.c_str()))
{
cmSystemTools::Error("CMAKE_C_COMPILER not set, after EnableLanguage");
return;
cmSystemTools::Error(langComp.c_str(), " not set, after EnableLanguage");
continue;
}
const char* cc = mf->GetRequiredDefinition("CMAKE_C_COMPILER");
const char* cc = mf->GetRequiredDefinition(langComp.c_str());
path = cmSystemTools::FindProgram(cc);
if(path.size() == 0)
{
std::string message = "your C compiler: ";
std::string message = "your ";
message += lang;
message += " compiler: ";
if(cc)
{
message += cc;
@ -53,34 +61,11 @@ void cmGlobalUnixMakefileGenerator::EnableLanguage(const char* lang,
{
message += "(NULL)";
}
message += " was not found in your path. "
"For CMake to correctly use try compile commands, the compiler must "
"be in your path. Please add the compiler to your PATH environment,"
" and re-run CMake.";
cmSystemTools::Error(message.c_str());
}
}
if(strcmp(lang, "CXX") == 0)
{
const char* cxx = mf->GetRequiredDefinition("CMAKE_CXX_COMPILER");
path = cmSystemTools::FindProgram(cxx);
if(path.size() == 0)
{
std::string message = "your C++ compiler: ";
if(cxx)
{
message += cxx;
}
else
{
message += "(NULL)";
}
message += " was not found in your path. "
"For CMake to correctly use try compile commands, the compiler must "
"be in your path. Please add the compiler to your PATH environment,"
" and re-run CMake.";
cmSystemTools::Error(message.c_str());
cmSystemTools::Error(message.c_str());
}
}
}

View File

@ -45,7 +45,7 @@ public:
* Try to determine system infomation such as shared library
* extension, pthreads, byte order etc.
*/
virtual void EnableLanguage(const char*, cmMakefile *mf);
virtual void EnableLanguage(std::vector<std::string>const& languages, cmMakefile *);
};

View File

@ -24,7 +24,7 @@ cmGlobalVisualStudio6Generator::cmGlobalVisualStudio6Generator()
m_FindMakeProgramFile = "CMakeVS6FindMake.cmake";
}
void cmGlobalVisualStudio6Generator::EnableLanguage(const char* lang,
void cmGlobalVisualStudio6Generator::EnableLanguage(std::vector<std::string>const& lang,
cmMakefile *mf)
{
mf->AddDefinition("CMAKE_CFG_INTDIR","$(IntDir)");

View File

@ -47,8 +47,7 @@ public:
* Try to determine system infomation such as shared library
* extension, pthreads, byte order etc.
*/
virtual void EnableLanguage(const char*, cmMakefile *mf);
virtual void EnableLanguage(std::vector<std::string>const& languages, cmMakefile *);
/**
* Try running cmake and building a file. This is used for dynalically
* loaded commands, not as part of the usual build process.

View File

@ -28,7 +28,7 @@ cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator()
}
void cmGlobalVisualStudio7Generator::EnableLanguage(const char* lang,
void cmGlobalVisualStudio7Generator::EnableLanguage(std::vector<std::string>const & lang,
cmMakefile *mf)
{
mf->AddDefinition("CMAKE_CFG_INTDIR","$(IntDir)");

View File

@ -47,7 +47,7 @@ public:
* Try to determine system infomation such as shared library
* extension, pthreads, byte order etc.
*/
virtual void EnableLanguage(const char*, cmMakefile *mf);
virtual void EnableLanguage(std::vector<std::string>const& languages, cmMakefile *);
/**
* Try running cmake and building a file. This is used for dynalically

View File

@ -2006,7 +2006,7 @@ cmSourceFile* cmMakefile::AddSource(cmSourceFile const&sf)
}
void cmMakefile::EnableLanguage(const char* lang)
void cmMakefile::EnableLanguage(std::vector<std::string> const & lang)
{
m_LocalGenerator->GetGlobalGenerator()->EnableLanguage(lang, this);
}

View File

@ -611,7 +611,7 @@ public:
void AddCommand(cmCommand* );
///! Enable support for the named language, if null then all languages are enabled.
void EnableLanguage(const char* );
virtual void EnableLanguage(std::vector<std::string>const& languages);
/**
* Set/Get the name of the parent directories CMakeLists file

View File

@ -48,19 +48,21 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args)
m_Makefile->AddDefinition("PROJECT_NAME", args[0].c_str());
std::vector<std::string> languages;
if(args.size() > 1)
{
for(size_t i =1; i < args.size(); ++i)
{
m_Makefile->EnableLanguage(args[i].c_str());
languages.push_back(args[i]);
}
}
else
{
// if no language is specified do c and c++
m_Makefile->EnableLanguage("C");
m_Makefile->EnableLanguage("CXX");
languages.push_back("C");
languages.push_back("CXX");
}
m_Makefile->EnableLanguage(languages);
return true;
}