From 731369ef9cfaa68dfb8582e8db873929a4cd645a Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Fri, 27 Aug 2004 08:41:07 -0400 Subject: ENH: try to initialize all languages at the same time --- Source/cmGlobalBorlandMakefileGenerator.cxx | 3 +- Source/cmGlobalBorlandMakefileGenerator.h | 2 +- Source/cmGlobalCodeWarriorGenerator.cxx | 2 +- Source/cmGlobalCodeWarriorGenerator.h | 2 +- Source/cmGlobalGenerator.cxx | 210 +++++++++++++++------------- Source/cmGlobalGenerator.h | 2 +- Source/cmGlobalNMakeMakefileGenerator.cxx | 2 +- Source/cmGlobalNMakeMakefileGenerator.h | 3 +- Source/cmGlobalUnixMakefileGenerator.cxx | 49 +++---- Source/cmGlobalUnixMakefileGenerator.h | 2 +- Source/cmGlobalVisualStudio6Generator.cxx | 2 +- Source/cmGlobalVisualStudio6Generator.h | 3 +- Source/cmGlobalVisualStudio7Generator.cxx | 2 +- Source/cmGlobalVisualStudio7Generator.h | 2 +- Source/cmMakefile.cxx | 2 +- Source/cmMakefile.h | 2 +- Source/cmProjectCommand.cxx | 8 +- 17 files changed, 148 insertions(+), 150 deletions(-) diff --git a/Source/cmGlobalBorlandMakefileGenerator.cxx b/Source/cmGlobalBorlandMakefileGenerator.cxx index 0fd068d..4f5eef7 100644 --- a/Source/cmGlobalBorlandMakefileGenerator.cxx +++ b/Source/cmGlobalBorlandMakefileGenerator.cxx @@ -24,7 +24,8 @@ cmGlobalBorlandMakefileGenerator::cmGlobalBorlandMakefileGenerator() m_ForceUnixPaths = false; } -void cmGlobalBorlandMakefileGenerator::EnableLanguage(const char* l, + +void cmGlobalBorlandMakefileGenerator::EnableLanguage(std::vectorconst& l, cmMakefile *mf) { std::string outdir = m_CMakeInstance->GetStartOutputDirectory(); diff --git a/Source/cmGlobalBorlandMakefileGenerator.h b/Source/cmGlobalBorlandMakefileGenerator.h index 6f5b64e..08928c0 100644 --- a/Source/cmGlobalBorlandMakefileGenerator.h +++ b/Source/cmGlobalBorlandMakefileGenerator.h @@ -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::vectorconst& languages, cmMakefile *); }; #endif diff --git a/Source/cmGlobalCodeWarriorGenerator.cxx b/Source/cmGlobalCodeWarriorGenerator.cxx index 735c5c8..fff678a 100644 --- a/Source/cmGlobalCodeWarriorGenerator.cxx +++ b/Source/cmGlobalCodeWarriorGenerator.cxx @@ -20,7 +20,7 @@ #include "cmake.h" #include "cmTarget.h" -void cmGlobalCodeWarriorGenerator::EnableLanguage(const char*, +void cmGlobalCodeWarriorGenerator::EnableLanguage(std::vectorconst& l, cmMakefile *mf) { // now load the settings diff --git a/Source/cmGlobalCodeWarriorGenerator.h b/Source/cmGlobalCodeWarriorGenerator.h index 3c6dee2..4549f68 100644 --- a/Source/cmGlobalCodeWarriorGenerator.h +++ b/Source/cmGlobalCodeWarriorGenerator.h @@ -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::vectorconst& languages, cmMakefile *); /** * Try running cmake and building a file. This is used for dynalically diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 1b416be..2e69656 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -98,10 +98,10 @@ void cmGlobalGenerator::FindMakeProgram(cmMakefile* mf) // enable the given language -void cmGlobalGenerator::EnableLanguage(const char* lang, +void cmGlobalGenerator::EnableLanguage(std::vectorconst& 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()); + // **** Step 4, foreach language + // load the CMakeDetermine(LANG)Compiler.cmake file to find + // the compiler + for(std::vector::const_iterator l = languages.begin(); + l != languages.end(); ++l) + { + 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()); } - - 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())) + // **** 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())) { - cmSystemTools::Error("Could not find cmake module file:", fpath.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()); + for(std::vector::const_iterator l = languages.begin(); + l != languages.end(); ++l) + { + 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())) + { + 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) + // **** 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 (!m_CMakeInstance->GetIsInTryCompile()) + if(needTestLanguage) { - std::string testLang = "CMakeTest"; - testLang += lang; - testLang += "Compiler.cmake"; - std::string ifpath = mf->GetModulesFile(testLang.c_str()); - if(!mf->ReadListFile(0,ifpath.c_str())) + if (!m_CMakeInstance->GetIsInTryCompile()) { - 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) + std::string testLang = "CMakeTest"; + testLang += lang; + testLang += "Compiler.cmake"; + std::string ifpath = mf->GetModulesFile(testLang.c_str()); + if(!mf->ReadListFile(0,ifpath.c_str())) { - ifpath = mf->GetModulesFile("CMakeBackwardCompatibilityC.cmake"); - mf->ReadListFile(0,ifpath.c_str()); + cmSystemTools::Error("Could not find cmake module file:", ifpath.c_str()); } - if(strcmp(lang, "CXX") == 0) + // **** 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) { - ifpath = mf->GetModulesFile("CMakeBackwardCompatibilityCXX.cmake"); - mf->ReadListFile(0,ifpath.c_str()); + 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()); + } + } - } } + } - } } diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 71b1859..82b0405 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -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::vectorconst& languages, cmMakefile *); /** * Try to determine system infomation, get it from another generator diff --git a/Source/cmGlobalNMakeMakefileGenerator.cxx b/Source/cmGlobalNMakeMakefileGenerator.cxx index ccba3a4..5d6d82f 100644 --- a/Source/cmGlobalNMakeMakefileGenerator.cxx +++ b/Source/cmGlobalNMakeMakefileGenerator.cxx @@ -25,7 +25,7 @@ cmGlobalNMakeMakefileGenerator::cmGlobalNMakeMakefileGenerator() m_ForceUnixPaths = false; } -void cmGlobalNMakeMakefileGenerator::EnableLanguage(const char* l, +void cmGlobalNMakeMakefileGenerator::EnableLanguage(std::vectorconst& l, cmMakefile *mf) { // pick a default diff --git a/Source/cmGlobalNMakeMakefileGenerator.h b/Source/cmGlobalNMakeMakefileGenerator.h index 4647c2d..863d0b8 100644 --- a/Source/cmGlobalNMakeMakefileGenerator.h +++ b/Source/cmGlobalNMakeMakefileGenerator.h @@ -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::vectorconst& languages, cmMakefile *); }; #endif diff --git a/Source/cmGlobalUnixMakefileGenerator.cxx b/Source/cmGlobalUnixMakefileGenerator.cxx index 170c97b..b4b472d 100644 --- a/Source/cmGlobalUnixMakefileGenerator.cxx +++ b/Source/cmGlobalUnixMakefileGenerator.cxx @@ -27,24 +27,32 @@ cmGlobalUnixMakefileGenerator::cmGlobalUnixMakefileGenerator() m_FindMakeProgramFile = "CMakeUnixFindMake.cmake"; } -void cmGlobalUnixMakefileGenerator::EnableLanguage(const char* lang, +void cmGlobalUnixMakefileGenerator::EnableLanguage(std::vectorconst& 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::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; @@ -54,33 +62,10 @@ 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()); } } } diff --git a/Source/cmGlobalUnixMakefileGenerator.h b/Source/cmGlobalUnixMakefileGenerator.h index 77a781e..a8af431 100644 --- a/Source/cmGlobalUnixMakefileGenerator.h +++ b/Source/cmGlobalUnixMakefileGenerator.h @@ -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::vectorconst& languages, cmMakefile *); }; diff --git a/Source/cmGlobalVisualStudio6Generator.cxx b/Source/cmGlobalVisualStudio6Generator.cxx index dc25c7e..a85ea61 100644 --- a/Source/cmGlobalVisualStudio6Generator.cxx +++ b/Source/cmGlobalVisualStudio6Generator.cxx @@ -24,7 +24,7 @@ cmGlobalVisualStudio6Generator::cmGlobalVisualStudio6Generator() m_FindMakeProgramFile = "CMakeVS6FindMake.cmake"; } -void cmGlobalVisualStudio6Generator::EnableLanguage(const char* lang, +void cmGlobalVisualStudio6Generator::EnableLanguage(std::vectorconst& lang, cmMakefile *mf) { mf->AddDefinition("CMAKE_CFG_INTDIR","$(IntDir)"); diff --git a/Source/cmGlobalVisualStudio6Generator.h b/Source/cmGlobalVisualStudio6Generator.h index 97338a1..d1dec83 100644 --- a/Source/cmGlobalVisualStudio6Generator.h +++ b/Source/cmGlobalVisualStudio6Generator.h @@ -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::vectorconst& languages, cmMakefile *); /** * Try running cmake and building a file. This is used for dynalically * loaded commands, not as part of the usual build process. diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index fc46ddb..26f16db 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -28,7 +28,7 @@ cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator() } -void cmGlobalVisualStudio7Generator::EnableLanguage(const char* lang, +void cmGlobalVisualStudio7Generator::EnableLanguage(std::vectorconst & lang, cmMakefile *mf) { mf->AddDefinition("CMAKE_CFG_INTDIR","$(IntDir)"); diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index 2c4db0e..0f9e814 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -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::vectorconst& languages, cmMakefile *); /** * Try running cmake and building a file. This is used for dynalically diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index c03254a..cd0069c 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2006,7 +2006,7 @@ cmSourceFile* cmMakefile::AddSource(cmSourceFile const&sf) } -void cmMakefile::EnableLanguage(const char* lang) +void cmMakefile::EnableLanguage(std::vector const & lang) { m_LocalGenerator->GetGlobalGenerator()->EnableLanguage(lang, this); } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 4452622..f374e66 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -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::vectorconst& languages); /** * Set/Get the name of the parent directories CMakeLists file diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx index 41592e7..f62d8bd 100644 --- a/Source/cmProjectCommand.cxx +++ b/Source/cmProjectCommand.cxx @@ -48,19 +48,21 @@ bool cmProjectCommand::InitialPass(std::vector const& args) m_Makefile->AddDefinition("PROJECT_NAME", args[0].c_str()); + std::vector 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; } -- cgit v0.12