better trycompile and enable langiages
This commit is contained in:
parent
c1da4c9570
commit
6132184cc3
|
@ -21,7 +21,6 @@
|
|||
|
||||
cmGlobalGenerator::cmGlobalGenerator()
|
||||
{
|
||||
m_LanguagesEnabled = false;
|
||||
}
|
||||
|
||||
cmGlobalGenerator::~cmGlobalGenerator()
|
||||
|
@ -52,9 +51,6 @@ void cmGlobalGenerator::ClearEnabledLanguages()
|
|||
|
||||
void cmGlobalGenerator::Configure()
|
||||
{
|
||||
// reset theLanguages
|
||||
m_LanguagesEnabled = false;
|
||||
|
||||
// Delete any existing cmLocalGenerators
|
||||
unsigned int i;
|
||||
for (i = 0; i < m_LocalGenerators.size(); ++i)
|
||||
|
@ -186,3 +182,16 @@ cmLocalGenerator *cmGlobalGenerator::CreateLocalGenerator()
|
|||
lg->SetGlobalGenerator(this);
|
||||
return lg;
|
||||
}
|
||||
|
||||
void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator *gen,
|
||||
cmMakefile *mf)
|
||||
{
|
||||
// for each existing language call enable Language
|
||||
std::map<cmStdString, bool>::const_iterator i =
|
||||
gen->m_LanguageEnabled.begin();
|
||||
for (;i != gen->m_LanguageEnabled.end(); ++i)
|
||||
{
|
||||
this->EnableLanguage(i->first.c_str(),mf);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -76,6 +76,12 @@ public:
|
|||
*/
|
||||
virtual void EnableLanguage(const char*, cmMakefile *) {};
|
||||
|
||||
/**
|
||||
* Try to determine system infomation, get it from another generator
|
||||
*/
|
||||
virtual void EnableLanguagesFromGenerator(cmGlobalGenerator *gen,
|
||||
cmMakefile *mf);
|
||||
|
||||
/**
|
||||
* Try running cmake and building a file. This is used for dynalically
|
||||
* loaded commands, not as part of the usual build process.
|
||||
|
@ -92,7 +98,6 @@ public:
|
|||
return this->m_CMakeInstance; };
|
||||
|
||||
protected:
|
||||
bool m_LanguagesEnabled;
|
||||
cmake *m_CMakeInstance;
|
||||
std::vector<cmLocalGenerator *> m_LocalGenerators;
|
||||
|
||||
|
|
|
@ -40,6 +40,16 @@ public:
|
|||
* extension, pthreads, byte order etc.
|
||||
*/
|
||||
virtual void EnableLanguage(const char*,cmMakefile *mf);
|
||||
|
||||
/**
|
||||
* Try to determine system infomation from another generator
|
||||
*/
|
||||
virtual void EnableLanguagesFromGenerator(cmGlobalGenerator *gen,
|
||||
cmMakefile *mf)
|
||||
{
|
||||
this->cmGlobalGenerator::EnableLanguageFromGenerator(gen,mf);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -23,32 +23,21 @@
|
|||
void cmGlobalUnixMakefileGenerator::EnableLanguage(const char* lang,
|
||||
cmMakefile *mf)
|
||||
{
|
||||
if (!m_LanguagesEnabled)
|
||||
// only do for global runs
|
||||
if (!m_CMakeInstance->GetLocal())
|
||||
{
|
||||
m_LanguagesEnabled = true;
|
||||
|
||||
// only do for global runs
|
||||
if (!m_CMakeInstance->GetLocal())
|
||||
std::string output;
|
||||
std::string root
|
||||
= cmSystemTools::ConvertToOutputPath(mf->GetDefinition("CMAKE_ROOT"));
|
||||
// if no lang specified use CXX
|
||||
if(!lang )
|
||||
{
|
||||
lang = "CXX";
|
||||
}
|
||||
// if CXX or C, then enable C
|
||||
if((!this->GetLanguageEnabled("C") && lang[0] == 'C'))
|
||||
{
|
||||
// see man putenv for explaination of this stupid code....
|
||||
static char envCXX[5000];
|
||||
static char envCC[5000];
|
||||
if(mf->GetDefinition("CMAKE_CXX_COMPILER"))
|
||||
{
|
||||
#if !defined(_WIN32) && defined(__COMO__)
|
||||
std::string env = "${CMAKE_CXX_COMPILER}";
|
||||
mf->ExpandVariablesInString(env);
|
||||
strncpy(envCXX, env.c_str(), 4999);
|
||||
envCXX[4999] = 0;
|
||||
setenv("CXX", envCXX, 1);
|
||||
#else
|
||||
std::string env = "CXX=${CMAKE_CXX_COMPILER}";
|
||||
mf->ExpandVariablesInString(env);
|
||||
strncpy(envCXX, env.c_str(), 4999);
|
||||
envCXX[4999] = 0;
|
||||
putenv(envCXX);
|
||||
#endif
|
||||
}
|
||||
if(mf->GetDefinition("CMAKE_C_COMPILER"))
|
||||
{
|
||||
#if !defined(_WIN32) && defined(__COMO__)
|
||||
|
@ -65,43 +54,57 @@ void cmGlobalUnixMakefileGenerator::EnableLanguage(const char* lang,
|
|||
putenv(envCC);
|
||||
#endif
|
||||
}
|
||||
std::string output;
|
||||
std::string root
|
||||
= cmSystemTools::ConvertToOutputPath(mf->GetDefinition("CMAKE_ROOT"));
|
||||
// if no lang specified use CXX
|
||||
if(!lang )
|
||||
std::string cmd = root;
|
||||
cmd += "/Templates/cconfigure";
|
||||
cmSystemTools::RunCommand(cmd.c_str(), output,
|
||||
cmSystemTools::ConvertToOutputPath(mf->GetHomeOutputDirectory()).c_str());
|
||||
std::string fpath = mf->GetHomeOutputDirectory();
|
||||
fpath += "/CCMakeSystemConfig.cmake";
|
||||
mf->ReadListFile(0,fpath.c_str());
|
||||
this->SetLanguageEnabled("C");
|
||||
}
|
||||
// if CXX
|
||||
if(!this->GetLanguageEnabled("CXX") && strcmp(lang, "CXX") == 0)
|
||||
{
|
||||
// see man putenv for explaination of this stupid code....
|
||||
static char envCXX[5000];
|
||||
if(mf->GetDefinition("CMAKE_CXX_COMPILER"))
|
||||
{
|
||||
lang = "CXX";
|
||||
#if !defined(_WIN32) && defined(__COMO__)
|
||||
std::string env = "${CMAKE_CXX_COMPILER}";
|
||||
mf->ExpandVariablesInString(env);
|
||||
strncpy(envCXX, env.c_str(), 4999);
|
||||
envCXX[4999] = 0;
|
||||
setenv("CXX", envCXX, 1);
|
||||
#else
|
||||
std::string env = "CXX=${CMAKE_CXX_COMPILER}";
|
||||
mf->ExpandVariablesInString(env);
|
||||
strncpy(envCXX, env.c_str(), 4999);
|
||||
envCXX[4999] = 0;
|
||||
putenv(envCXX);
|
||||
#endif
|
||||
}
|
||||
// if CXX or C, then enable C
|
||||
if((!this->GetLanguageEnabled(lang) && lang[0] == 'C'))
|
||||
std::string cmd = root;
|
||||
cmd += "/Templates/cxxconfigure";
|
||||
cmSystemTools::RunCommand(cmd.c_str(), output,
|
||||
cmSystemTools::ConvertToOutputPath(mf->GetHomeOutputDirectory()).c_str());
|
||||
std::string fpath = mf->GetHomeOutputDirectory();
|
||||
fpath += "/CXXCMakeSystemConfig.cmake";
|
||||
mf->ReadListFile(0,fpath.c_str());
|
||||
this->SetLanguageEnabled("CXX");
|
||||
|
||||
// for old versions of CMake ListFiles
|
||||
if (!m_CMakeInstance->GetIsInTryCompile())
|
||||
{
|
||||
std::string cmd = root;
|
||||
cmd += "/Templates/cconfigure";
|
||||
cmSystemTools::RunCommand(cmd.c_str(), output,
|
||||
cmSystemTools::ConvertToOutputPath(mf->GetHomeOutputDirectory()).c_str());
|
||||
std::string fpath = mf->GetHomeOutputDirectory();
|
||||
fpath += "/CCMakeSystemConfig.cmake";
|
||||
mf->ReadListFile(0,fpath.c_str());
|
||||
this->SetLanguageEnabled("C");
|
||||
}
|
||||
// if CXX
|
||||
if(!this->GetLanguageEnabled(lang) || strcmp(lang, "CXX") == 0)
|
||||
{
|
||||
std::string cmd = root;
|
||||
cmd += "/Templates/cxxconfigure";
|
||||
cmSystemTools::RunCommand(cmd.c_str(), output,
|
||||
cmSystemTools::ConvertToOutputPath(mf->GetHomeOutputDirectory()).c_str());
|
||||
std::string fpath = mf->GetHomeOutputDirectory();
|
||||
fpath += "/CXXCMakeSystemConfig.cmake";
|
||||
mf->ReadListFile(0,fpath.c_str());
|
||||
this->SetLanguageEnabled("CXX");
|
||||
const char* versionValue
|
||||
= mf->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
|
||||
if (!versionValue || atof(versionValue) <= 1.4)
|
||||
{
|
||||
fpath = root + "/Modules/TestForANSIStreamHeaders.cmake";
|
||||
mf->ReadListFile(NULL,fpath.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_CMakeInstance->GetLocal())
|
||||
{
|
||||
// if we are from the top, always define this
|
||||
mf->AddDefinition("RUN_CONFIGURE", true);
|
||||
}
|
||||
|
@ -115,3 +118,33 @@ cmLocalGenerator *cmGlobalUnixMakefileGenerator::CreateLocalGenerator()
|
|||
return lg;
|
||||
}
|
||||
|
||||
void cmGlobalUnixMakefileGenerator::EnableLanguagesFromGenerator(
|
||||
cmGlobalGenerator *gen, cmMakefile *mf)
|
||||
{
|
||||
// for UNIX we just want to read in the configured files
|
||||
cmLocalGenerator *lg = this->CreateLocalGenerator();
|
||||
|
||||
// set the Start directories
|
||||
lg->GetMakefile()->SetStartDirectory(m_CMakeInstance->GetStartDirectory());
|
||||
lg->GetMakefile()->SetStartOutputDirectory(m_CMakeInstance->GetStartOutputDirectory());
|
||||
lg->GetMakefile()->MakeStartDirectoriesCurrent();
|
||||
|
||||
// if C, then enable C
|
||||
if(gen->GetLanguageEnabled("C"))
|
||||
{
|
||||
std::string fpath = mf->GetHomeOutputDirectory();
|
||||
fpath += "/CCMakeSystemConfig.cmake";
|
||||
lg->GetMakefile()->ReadListFile(0,fpath.c_str());
|
||||
this->SetLanguageEnabled("C");
|
||||
}
|
||||
|
||||
// if CXX
|
||||
if(gen->GetLanguageEnabled("CXX"))
|
||||
{
|
||||
std::string fpath = mf->GetHomeOutputDirectory();
|
||||
fpath += "/CXXCMakeSystemConfig.cmake";
|
||||
lg->GetMakefile()->ReadListFile(0,fpath.c_str());
|
||||
this->SetLanguageEnabled("CXX");
|
||||
}
|
||||
delete lg;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,11 @@ public:
|
|||
*/
|
||||
virtual void EnableLanguage(const char*, cmMakefile *mf);
|
||||
|
||||
/**
|
||||
* Try to determine system infomation, get it from another generator
|
||||
*/
|
||||
virtual void EnableLanguagesFromGenerator(cmGlobalGenerator *, cmMakefile *);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -22,25 +22,20 @@
|
|||
void cmGlobalVisualStudio6Generator::EnableLanguage(const char*,
|
||||
cmMakefile *mf)
|
||||
{
|
||||
if (!m_LanguagesEnabled)
|
||||
// now load the settings
|
||||
if(!mf->GetDefinition("CMAKE_ROOT"))
|
||||
{
|
||||
m_LanguagesEnabled = true;
|
||||
|
||||
// now load the settings
|
||||
if(!mf->GetDefinition("CMAKE_ROOT"))
|
||||
{
|
||||
cmSystemTools::Error(
|
||||
"CMAKE_ROOT has not been defined, bad GUI or driver program");
|
||||
return;
|
||||
}
|
||||
if(!this->GetLanguageEnabled("CXX"))
|
||||
{
|
||||
std::string fpath =
|
||||
mf->GetDefinition("CMAKE_ROOT");
|
||||
fpath += "/Templates/CMakeWindowsSystemConfig.cmake";
|
||||
mf->ReadListFile(NULL,fpath.c_str());
|
||||
this->SetLanguageEnabled("CXX");
|
||||
}
|
||||
cmSystemTools::Error(
|
||||
"CMAKE_ROOT has not been defined, bad GUI or driver program");
|
||||
return;
|
||||
}
|
||||
if(!this->GetLanguageEnabled("CXX"))
|
||||
{
|
||||
std::string fpath =
|
||||
mf->GetDefinition("CMAKE_ROOT");
|
||||
fpath += "/Templates/CMakeWindowsSystemConfig.cmake";
|
||||
mf->ReadListFile(NULL,fpath.c_str());
|
||||
this->SetLanguageEnabled("CXX");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,25 +23,20 @@
|
|||
void cmGlobalVisualStudio7Generator::EnableLanguage(const char*,
|
||||
cmMakefile *mf)
|
||||
{
|
||||
if (!m_LanguagesEnabled)
|
||||
// now load the settings
|
||||
if(!mf->GetDefinition("CMAKE_ROOT"))
|
||||
{
|
||||
m_LanguagesEnabled = true;
|
||||
|
||||
// now load the settings
|
||||
if(!mf->GetDefinition("CMAKE_ROOT"))
|
||||
{
|
||||
cmSystemTools::Error(
|
||||
"CMAKE_ROOT has not been defined, bad GUI or driver program");
|
||||
return;
|
||||
}
|
||||
if(!this->GetLanguageEnabled("CXX"))
|
||||
{
|
||||
std::string fpath =
|
||||
mf->GetDefinition("CMAKE_ROOT");
|
||||
fpath += "/Templates/CMakeDotNetSystemConfig.cmake";
|
||||
mf->ReadListFile(NULL,fpath.c_str());
|
||||
this->SetLanguageEnabled("CXX");
|
||||
}
|
||||
cmSystemTools::Error(
|
||||
"CMAKE_ROOT has not been defined, bad GUI or driver program");
|
||||
return;
|
||||
}
|
||||
if(!this->GetLanguageEnabled("CXX"))
|
||||
{
|
||||
std::string fpath =
|
||||
mf->GetDefinition("CMAKE_ROOT");
|
||||
fpath += "/Templates/CMakeDotNetSystemConfig.cmake";
|
||||
mf->ReadListFile(NULL,fpath.c_str());
|
||||
this->SetLanguageEnabled("CXX");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1354,7 +1354,7 @@ int cmMakefile::TryCompile(const char *srcdir, const char *bindir,
|
|||
cmake cm;
|
||||
cm.SetIsInTryCompile(true);
|
||||
cmGlobalGenerator *gg =
|
||||
cm.CreateGlobalGenerator(this->m_LocalGenerator->GetGlobalGenerator()->GetName());
|
||||
cm.CreateGlobalGenerator(m_LocalGenerator->GetGlobalGenerator()->GetName());
|
||||
if (!gg)
|
||||
{
|
||||
cmSystemTools::Error(
|
||||
|
@ -1371,6 +1371,10 @@ int cmMakefile::TryCompile(const char *srcdir, const char *bindir,
|
|||
cm.SetStartDirectory(srcdir);
|
||||
cm.SetStartOutputDirectory(bindir);
|
||||
|
||||
// to save time we pass the EnableLanguage info directly
|
||||
gg->EnableLanguagesFromGenerator(m_LocalGenerator->GetGlobalGenerator(),
|
||||
this);
|
||||
|
||||
if (cm.Configure(cmakeCommand.c_str()) != 0)
|
||||
{
|
||||
cmSystemTools::Error(
|
||||
|
@ -1390,7 +1394,10 @@ int cmMakefile::TryCompile(const char *srcdir, const char *bindir,
|
|||
}
|
||||
|
||||
// finally call the generator to actually build the resulting project
|
||||
int ret = gg->TryCompile(srcdir,bindir,projectName, targetName);
|
||||
int ret =
|
||||
m_LocalGenerator->GetGlobalGenerator()->TryCompile(srcdir,bindir,
|
||||
projectName,
|
||||
targetName);
|
||||
|
||||
cmSystemTools::ChangeDirectory(cwd.c_str());
|
||||
return ret;
|
||||
|
|
|
@ -94,8 +94,13 @@ bool cmTryCompileCommand::InitialPass(std::vector<std::string> const& argv)
|
|||
m_Makefile->AddDefinition(argv[0].c_str(), (res == 0 ? "TRUE" : "FALSE"));
|
||||
|
||||
// if we created a directory etc, then cleanup after ourselves
|
||||
// Actually right now lets not clean up after ourselves, removing
|
||||
// a directory is tricky and putting that code in could be a risk
|
||||
cmDirectory dir;
|
||||
dir.Load(binaryDirectory);
|
||||
size_t fileNum;
|
||||
for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum)
|
||||
{
|
||||
cmSystemTools::RemoveFile(dir.GetFile(fileNum));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue