better trycompile and enable langiages
This commit is contained in:
parent
c1da4c9570
commit
6132184cc3
@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
cmGlobalGenerator::cmGlobalGenerator()
|
cmGlobalGenerator::cmGlobalGenerator()
|
||||||
{
|
{
|
||||||
m_LanguagesEnabled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmGlobalGenerator::~cmGlobalGenerator()
|
cmGlobalGenerator::~cmGlobalGenerator()
|
||||||
@ -52,9 +51,6 @@ void cmGlobalGenerator::ClearEnabledLanguages()
|
|||||||
|
|
||||||
void cmGlobalGenerator::Configure()
|
void cmGlobalGenerator::Configure()
|
||||||
{
|
{
|
||||||
// reset theLanguages
|
|
||||||
m_LanguagesEnabled = false;
|
|
||||||
|
|
||||||
// Delete any existing cmLocalGenerators
|
// Delete any existing cmLocalGenerators
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
for (i = 0; i < m_LocalGenerators.size(); ++i)
|
for (i = 0; i < m_LocalGenerators.size(); ++i)
|
||||||
@ -186,3 +182,16 @@ cmLocalGenerator *cmGlobalGenerator::CreateLocalGenerator()
|
|||||||
lg->SetGlobalGenerator(this);
|
lg->SetGlobalGenerator(this);
|
||||||
return lg;
|
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 *) {};
|
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
|
* Try running cmake and building a file. This is used for dynalically
|
||||||
* loaded commands, not as part of the usual build process.
|
* loaded commands, not as part of the usual build process.
|
||||||
@ -92,7 +98,6 @@ public:
|
|||||||
return this->m_CMakeInstance; };
|
return this->m_CMakeInstance; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_LanguagesEnabled;
|
|
||||||
cmake *m_CMakeInstance;
|
cmake *m_CMakeInstance;
|
||||||
std::vector<cmLocalGenerator *> m_LocalGenerators;
|
std::vector<cmLocalGenerator *> m_LocalGenerators;
|
||||||
|
|
||||||
|
@ -40,6 +40,16 @@ public:
|
|||||||
* extension, pthreads, byte order etc.
|
* extension, pthreads, byte order etc.
|
||||||
*/
|
*/
|
||||||
virtual void EnableLanguage(const char*,cmMakefile *mf);
|
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
|
#endif
|
||||||
|
@ -23,32 +23,21 @@
|
|||||||
void cmGlobalUnixMakefileGenerator::EnableLanguage(const char* lang,
|
void cmGlobalUnixMakefileGenerator::EnableLanguage(const char* lang,
|
||||||
cmMakefile *mf)
|
cmMakefile *mf)
|
||||||
{
|
{
|
||||||
if (!m_LanguagesEnabled)
|
// only do for global runs
|
||||||
|
if (!m_CMakeInstance->GetLocal())
|
||||||
{
|
{
|
||||||
m_LanguagesEnabled = true;
|
std::string output;
|
||||||
|
std::string root
|
||||||
// only do for global runs
|
= cmSystemTools::ConvertToOutputPath(mf->GetDefinition("CMAKE_ROOT"));
|
||||||
if (!m_CMakeInstance->GetLocal())
|
// 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];
|
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(mf->GetDefinition("CMAKE_C_COMPILER"))
|
||||||
{
|
{
|
||||||
#if !defined(_WIN32) && defined(__COMO__)
|
#if !defined(_WIN32) && defined(__COMO__)
|
||||||
@ -65,43 +54,57 @@ void cmGlobalUnixMakefileGenerator::EnableLanguage(const char* lang,
|
|||||||
putenv(envCC);
|
putenv(envCC);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
std::string output;
|
std::string cmd = root;
|
||||||
std::string root
|
cmd += "/Templates/cconfigure";
|
||||||
= cmSystemTools::ConvertToOutputPath(mf->GetDefinition("CMAKE_ROOT"));
|
cmSystemTools::RunCommand(cmd.c_str(), output,
|
||||||
// if no lang specified use CXX
|
cmSystemTools::ConvertToOutputPath(mf->GetHomeOutputDirectory()).c_str());
|
||||||
if(!lang )
|
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
|
std::string cmd = root;
|
||||||
if((!this->GetLanguageEnabled(lang) && lang[0] == 'C'))
|
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;
|
const char* versionValue
|
||||||
cmd += "/Templates/cconfigure";
|
= mf->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
|
||||||
cmSystemTools::RunCommand(cmd.c_str(), output,
|
if (!versionValue || atof(versionValue) <= 1.4)
|
||||||
cmSystemTools::ConvertToOutputPath(mf->GetHomeOutputDirectory()).c_str());
|
{
|
||||||
std::string fpath = mf->GetHomeOutputDirectory();
|
fpath = root + "/Modules/TestForANSIStreamHeaders.cmake";
|
||||||
fpath += "/CCMakeSystemConfig.cmake";
|
mf->ReadListFile(NULL,fpath.c_str());
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_CMakeInstance->GetLocal())
|
|
||||||
{
|
|
||||||
// if we are from the top, always define this
|
// if we are from the top, always define this
|
||||||
mf->AddDefinition("RUN_CONFIGURE", true);
|
mf->AddDefinition("RUN_CONFIGURE", true);
|
||||||
}
|
}
|
||||||
@ -115,3 +118,33 @@ cmLocalGenerator *cmGlobalUnixMakefileGenerator::CreateLocalGenerator()
|
|||||||
return lg;
|
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);
|
virtual void EnableLanguage(const char*, cmMakefile *mf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to determine system infomation, get it from another generator
|
||||||
|
*/
|
||||||
|
virtual void EnableLanguagesFromGenerator(cmGlobalGenerator *, cmMakefile *);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,25 +22,20 @@
|
|||||||
void cmGlobalVisualStudio6Generator::EnableLanguage(const char*,
|
void cmGlobalVisualStudio6Generator::EnableLanguage(const char*,
|
||||||
cmMakefile *mf)
|
cmMakefile *mf)
|
||||||
{
|
{
|
||||||
if (!m_LanguagesEnabled)
|
// now load the settings
|
||||||
|
if(!mf->GetDefinition("CMAKE_ROOT"))
|
||||||
{
|
{
|
||||||
m_LanguagesEnabled = true;
|
cmSystemTools::Error(
|
||||||
|
"CMAKE_ROOT has not been defined, bad GUI or driver program");
|
||||||
// now load the settings
|
return;
|
||||||
if(!mf->GetDefinition("CMAKE_ROOT"))
|
}
|
||||||
{
|
if(!this->GetLanguageEnabled("CXX"))
|
||||||
cmSystemTools::Error(
|
{
|
||||||
"CMAKE_ROOT has not been defined, bad GUI or driver program");
|
std::string fpath =
|
||||||
return;
|
mf->GetDefinition("CMAKE_ROOT");
|
||||||
}
|
fpath += "/Templates/CMakeWindowsSystemConfig.cmake";
|
||||||
if(!this->GetLanguageEnabled("CXX"))
|
mf->ReadListFile(NULL,fpath.c_str());
|
||||||
{
|
this->SetLanguageEnabled("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*,
|
void cmGlobalVisualStudio7Generator::EnableLanguage(const char*,
|
||||||
cmMakefile *mf)
|
cmMakefile *mf)
|
||||||
{
|
{
|
||||||
if (!m_LanguagesEnabled)
|
// now load the settings
|
||||||
|
if(!mf->GetDefinition("CMAKE_ROOT"))
|
||||||
{
|
{
|
||||||
m_LanguagesEnabled = true;
|
cmSystemTools::Error(
|
||||||
|
"CMAKE_ROOT has not been defined, bad GUI or driver program");
|
||||||
// now load the settings
|
return;
|
||||||
if(!mf->GetDefinition("CMAKE_ROOT"))
|
}
|
||||||
{
|
if(!this->GetLanguageEnabled("CXX"))
|
||||||
cmSystemTools::Error(
|
{
|
||||||
"CMAKE_ROOT has not been defined, bad GUI or driver program");
|
std::string fpath =
|
||||||
return;
|
mf->GetDefinition("CMAKE_ROOT");
|
||||||
}
|
fpath += "/Templates/CMakeDotNetSystemConfig.cmake";
|
||||||
if(!this->GetLanguageEnabled("CXX"))
|
mf->ReadListFile(NULL,fpath.c_str());
|
||||||
{
|
this->SetLanguageEnabled("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;
|
cmake cm;
|
||||||
cm.SetIsInTryCompile(true);
|
cm.SetIsInTryCompile(true);
|
||||||
cmGlobalGenerator *gg =
|
cmGlobalGenerator *gg =
|
||||||
cm.CreateGlobalGenerator(this->m_LocalGenerator->GetGlobalGenerator()->GetName());
|
cm.CreateGlobalGenerator(m_LocalGenerator->GetGlobalGenerator()->GetName());
|
||||||
if (!gg)
|
if (!gg)
|
||||||
{
|
{
|
||||||
cmSystemTools::Error(
|
cmSystemTools::Error(
|
||||||
@ -1371,6 +1371,10 @@ int cmMakefile::TryCompile(const char *srcdir, const char *bindir,
|
|||||||
cm.SetStartDirectory(srcdir);
|
cm.SetStartDirectory(srcdir);
|
||||||
cm.SetStartOutputDirectory(bindir);
|
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)
|
if (cm.Configure(cmakeCommand.c_str()) != 0)
|
||||||
{
|
{
|
||||||
cmSystemTools::Error(
|
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
|
// 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());
|
cmSystemTools::ChangeDirectory(cwd.c_str());
|
||||||
return ret;
|
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"));
|
m_Makefile->AddDefinition(argv[0].c_str(), (res == 0 ? "TRUE" : "FALSE"));
|
||||||
|
|
||||||
// if we created a directory etc, then cleanup after ourselves
|
// if we created a directory etc, then cleanup after ourselves
|
||||||
// Actually right now lets not clean up after ourselves, removing
|
cmDirectory dir;
|
||||||
// a directory is tricky and putting that code in could be a risk
|
dir.Load(binaryDirectory);
|
||||||
|
size_t fileNum;
|
||||||
|
for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum)
|
||||||
|
{
|
||||||
|
cmSystemTools::RemoveFile(dir.GetFile(fileNum));
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user