summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorKen Martin <ken.martin@kitware.com>2002-09-13 14:42:50 (GMT)
committerKen Martin <ken.martin@kitware.com>2002-09-13 14:42:50 (GMT)
commit6132184cc3a3832463308fa45d7fda17f3df067e (patch)
tree59c853ecf53c4332fc28b5fec6061ba8690e6212 /Source
parentc1da4c9570d57f641f35038bbadb926398d4236c (diff)
downloadCMake-6132184cc3a3832463308fa45d7fda17f3df067e.zip
CMake-6132184cc3a3832463308fa45d7fda17f3df067e.tar.gz
CMake-6132184cc3a3832463308fa45d7fda17f3df067e.tar.bz2
better trycompile and enable langiages
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGlobalGenerator.cxx17
-rw-r--r--Source/cmGlobalGenerator.h7
-rw-r--r--Source/cmGlobalNMakeMakefileGenerator.h10
-rw-r--r--Source/cmGlobalUnixMakefileGenerator.cxx143
-rw-r--r--Source/cmGlobalUnixMakefileGenerator.h5
-rw-r--r--Source/cmGlobalVisualStudio6Generator.cxx31
-rw-r--r--Source/cmGlobalVisualStudio7Generator.cxx31
-rw-r--r--Source/cmMakefile.cxx11
-rw-r--r--Source/cmTryCompileCommand.cxx9
9 files changed, 164 insertions, 100 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 164a138..869f6cb 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -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);
+ }
+}
+
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index f219f67..4f994fb 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -77,6 +77,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;
diff --git a/Source/cmGlobalNMakeMakefileGenerator.h b/Source/cmGlobalNMakeMakefileGenerator.h
index 43124ce..9057715 100644
--- a/Source/cmGlobalNMakeMakefileGenerator.h
+++ b/Source/cmGlobalNMakeMakefileGenerator.h
@@ -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
diff --git a/Source/cmGlobalUnixMakefileGenerator.cxx b/Source/cmGlobalUnixMakefileGenerator.cxx
index 883e7c2..5da658d 100644
--- a/Source/cmGlobalUnixMakefileGenerator.cxx
+++ b/Source/cmGlobalUnixMakefileGenerator.cxx
@@ -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 )
- {
- lang = "CXX";
- }
- // if CXX or C, then enable C
- if((!this->GetLanguageEnabled(lang) && lang[0] == 'C'))
+ 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"))
{
- 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 !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
- 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");
+
+ // for old versions of CMake ListFiles
+ if (!m_CMakeInstance->GetIsInTryCompile())
{
- 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;
+}
diff --git a/Source/cmGlobalUnixMakefileGenerator.h b/Source/cmGlobalUnixMakefileGenerator.h
index f65d7c2..53ce691 100644
--- a/Source/cmGlobalUnixMakefileGenerator.h
+++ b/Source/cmGlobalUnixMakefileGenerator.h
@@ -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
diff --git a/Source/cmGlobalVisualStudio6Generator.cxx b/Source/cmGlobalVisualStudio6Generator.cxx
index 79dbba7..9a03c15 100644
--- a/Source/cmGlobalVisualStudio6Generator.cxx
+++ b/Source/cmGlobalVisualStudio6Generator.cxx
@@ -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");
}
}
diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx
index 01ab1ba..bd2adb3 100644
--- a/Source/cmGlobalVisualStudio7Generator.cxx
+++ b/Source/cmGlobalVisualStudio7Generator.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");
}
}
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 4c4cd6b..fc7622c 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.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;
diff --git a/Source/cmTryCompileCommand.cxx b/Source/cmTryCompileCommand.cxx
index eba8ca6..087d000 100644
--- a/Source/cmTryCompileCommand.cxx
+++ b/Source/cmTryCompileCommand.cxx
@@ -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;
}