diff options
-rw-r--r-- | Modules/CMakeCCompiler.cmake.in | 1 | ||||
-rw-r--r-- | Modules/CMakeCXXCompiler.cmake.in | 1 | ||||
-rw-r--r-- | Modules/CMakeFortranCompiler.cmake.in | 1 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 64 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 5 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 7 | ||||
-rw-r--r-- | Source/cmLocalGenerator.h | 1 | ||||
-rw-r--r-- | Source/cmLocalUnixMakefileGenerator.cxx | 153 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 3 |
9 files changed, 132 insertions, 104 deletions
diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in index ad748ee..9ee5e59 100644 --- a/Modules/CMakeCCompiler.cmake.in +++ b/Modules/CMakeCCompiler.cmake.in @@ -14,3 +14,4 @@ IF(CMAKE_COMPILER_IS_MINGW) SET(MINGW 1) ENDIF(CMAKE_COMPILER_IS_MINGW) SET(CMAKE_COMPILER_IS_GNUCC_RUN 1) +SET(CMAKE_C_SOURCE_FILE_EXTENSIONS c) diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in index 4324b98..fb533e4 100644 --- a/Modules/CMakeCXXCompiler.cmake.in +++ b/Modules/CMakeCXXCompiler.cmake.in @@ -3,3 +3,4 @@ SET(CMAKE_COMPILER_IS_GNUCXX @CMAKE_COMPILER_IS_GNUCXX@) SET(CMAKE_CXX_COMPILER_LOADED 1) SET(CMAKE_COMPILER_IS_GNUCC_RUN 1) +SET(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;m;mm) diff --git a/Modules/CMakeFortranCompiler.cmake.in b/Modules/CMakeFortranCompiler.cmake.in index 21a5f0d..6f7740b 100644 --- a/Modules/CMakeFortranCompiler.cmake.in +++ b/Modules/CMakeFortranCompiler.cmake.in @@ -14,3 +14,4 @@ IF(CMAKE_COMPILER_IS_MINGW) SET(MINGW 1) ENDIF(CMAKE_COMPILER_IS_MINGW) SET(CMAKE_COMPILER_IS_GNUG77_RUN 1) +SET(CMAKE_Fortran_SOURCE_FILE_EXTENSIONS f;F;f77;f90;for;f95) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 2e69656..1c3be92 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -96,7 +96,6 @@ void cmGlobalGenerator::FindMakeProgram(cmMakefile* mf) } - // enable the given language void cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages, cmMakefile *mf) @@ -116,8 +115,30 @@ void cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages, } bool needTestLanguage = false; std::string rootBin = mf->GetHomeOutputDirectory(); + // If the configuration files path has been set, + // then we are in a try compile and need to copy the enable language + // files into the try compile directory if(m_ConfiguredFilesPath.size()) { + std::string src = m_ConfiguredFilesPath; + src += "/CMakeSystem.cmake"; + std::string dst = rootBin; + dst += "/CMakeSystem.cmake"; + cmSystemTools::CopyFileIfDifferent(src.c_str(), dst.c_str()); + for(std::vector<std::string>::const_iterator l = languages.begin(); + l != languages.end(); ++l) + { + const char* lang = l->c_str(); + std::string src = m_ConfiguredFilesPath; + src += "/CMake"; + src += lang; + src += "Compiler.cmake"; + std::string dst = rootBin; + dst += "/CMake"; + dst += lang; + dst += "Compiler.cmake"; + cmSystemTools::CopyFileIfDifferent(src.c_str(), dst.c_str()); + } rootBin = m_ConfiguredFilesPath; } @@ -178,7 +199,6 @@ void cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages, 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_"; @@ -194,7 +214,7 @@ void cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages, 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 @@ -213,7 +233,7 @@ void cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages, { cmSystemTools::Error("Could not find cmake module file:", fpath.c_str()); } - this->SetLanguageEnabled(lang); + this->SetLanguageEnabled(lang, mf); } } @@ -244,7 +264,6 @@ void cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages, 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 @@ -283,15 +302,38 @@ void cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages, } } } - } } } +const char* cmGlobalGenerator::GetLanguageFromExtension(const char* ext) +{ + if(m_ExtensionToLanguage.count(ext) > 0) + { + return m_ExtensionToLanguage[ext].c_str(); + } + return 0; +} -void cmGlobalGenerator::SetLanguageEnabled(const char* l) +void cmGlobalGenerator::SetLanguageEnabled(const char* l, cmMakefile* mf) { + if(m_LanguageEnabled.count(l) > 0) + { + return; + } + std::string extensionsVar = std::string("CMAKE_") + + std::string(l) + std::string("_SOURCE_FILE_EXTENSIONS"); + std::string exts = mf->GetSafeDefinition(extensionsVar.c_str()); + std::vector<std::string> extensionList; + cmSystemTools::ExpandListArgument(exts, extensionList); + for(std::vector<std::string>::iterator i = extensionList.begin(); + i != extensionList.end(); ++i) + { + m_ExtensionToLanguage[*i] = l; + } + m_LanguageEnabled[l] = true; + } bool cmGlobalGenerator::GetLanguageEnabled(const char* l) @@ -560,11 +602,9 @@ void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator *gen ) this->GetCMakeInstance()->AddCacheEntry("CMAKE_MAKE_PROGRAM", make, "make program", cmCacheManager::FILEPATH); - for(std::map<cmStdString, bool>::iterator i = gen->m_LanguageEnabled.begin(); - i != gen->m_LanguageEnabled.end(); ++i) - { - this->SetLanguageEnabled(i->first.c_str()); - } + // copy the enabled languages + this->m_LanguageEnabled = gen->m_LanguageEnabled; + this->m_ExtensionToLanguage = gen->m_ExtensionToLanguage; } //---------------------------------------------------------------------------- diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 82b0405..ed31cc1 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -69,7 +69,7 @@ public: /** * Set/Get and Clear the enabled languages. */ - void SetLanguageEnabled(const char*); + void SetLanguageEnabled(const char*, cmMakefile* mf); bool GetLanguageEnabled(const char*); void ClearEnabledLanguages(); @@ -105,6 +105,8 @@ public: static int s_TryCompileTimeout; bool GetForceUnixPaths() {return m_ForceUnixPaths;} + ///! return the language for the given extension + const char* GetLanguageFromExtension(const char* ext); protected: bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen); void FindMakeProgram(cmMakefile*); @@ -120,6 +122,7 @@ protected: private: std::map<cmStdString, bool> m_LanguageEnabled; + std::map<cmStdString, cmStdString> m_ExtensionToLanguage; }; #endif diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 16d0609..131c6ff 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -517,3 +517,10 @@ std::string cmLocalGenerator::ConvertToRelativeOutputPath(const char* p) ret = cmSystemTools::ConvertToOutputPath(ret.c_str()); return ret; } + + +const char* cmLocalGenerator::GetFileLanguage(const char* ext) +{ + // fill a map of languages enabled + return 0; +} diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 792d8e1..e4de6d2 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -91,6 +91,7 @@ public: cmLocalGenerator* GetParent(){return m_Parent;} void SetParent(cmLocalGenerator* g) { m_Parent = g;} + const char* GetFileLanguage(const char*); protected: virtual void AddInstallRule(std::ostream& fout, const char* dest, int type, const char* files, bool optional = false, const char* properties = 0); diff --git a/Source/cmLocalUnixMakefileGenerator.cxx b/Source/cmLocalUnixMakefileGenerator.cxx index b00b7e4..c760e98 100644 --- a/Source/cmLocalUnixMakefileGenerator.cxx +++ b/Source/cmLocalUnixMakefileGenerator.cxx @@ -2843,106 +2843,77 @@ OutputBuildObjectFromSource(std::ostream& fout, this->ConvertToRelativeOutputPath(source.GetFullPath().c_str()); std::string buildType = m_Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); buildType = cmSystemTools::UpperCase(buildType); - switch(format) - { - case cmSystemTools::C_FILE_FORMAT: + // find out what language the source file is + const char* lang = + m_GlobalGenerator->GetLanguageFromExtension(source.GetSourceExtension().c_str()); + // for now if the lang is defined add the rules and flags for it + if(lang) + { + std::string varString = "CMAKE_"; + varString += lang; + varString += "_COMPILE_OBJECT"; + rules.push_back(m_Makefile->GetRequiredDefinition(varString.c_str())); + varString = "CMAKE_"; + varString += lang; + varString += "_FLAGS"; + flags += m_Makefile->GetSafeDefinition(varString.c_str()); + flags += " "; + if(buildType.size()) { - rules.push_back(m_Makefile->GetRequiredDefinition("CMAKE_C_COMPILE_OBJECT")); - flags += m_Makefile->GetSafeDefinition("CMAKE_C_FLAGS"); + varString += "_"; + varString += buildType; + flags += m_Makefile->GetSafeDefinition(varString.c_str()); flags += " "; - if(buildType.size()) - { - std::string build = "CMAKE_C_FLAGS_"; - build += buildType; - flags += m_Makefile->GetSafeDefinition(build.c_str()); - flags += " "; - } - if(shared) - { - flags += m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_C_FLAGS"); - flags += " "; - } - if(cmSystemTools::IsOn(m_Makefile->GetDefinition("BUILD_SHARED_LIBS"))) - { - flags += m_Makefile->GetSafeDefinition("CMAKE_SHARED_BUILD_C_FLAGS"); - flags += " "; - } - break; } - case cmSystemTools::CXX_FILE_FORMAT: + if(shared) { - rules.push_back(m_Makefile->GetRequiredDefinition("CMAKE_CXX_COMPILE_OBJECT")); - flags += m_Makefile->GetSafeDefinition("CMAKE_CXX_FLAGS"); - flags += " "; - if(buildType.size()) - { - std::string build = "CMAKE_CXX_FLAGS_"; - build += buildType; - flags += m_Makefile->GetSafeDefinition(build.c_str()); - flags += " "; - } - if(shared) - { - flags += m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_CXX_FLAGS"); - flags += " "; - } - if(cmSystemTools::IsOn(m_Makefile->GetDefinition("BUILD_SHARED_LIBS"))) - { - flags += m_Makefile->GetSafeDefinition("CMAKE_SHARED_BUILD_CXX_FLAGS"); - flags += " "; - } - break; + varString = "CMAKE_SHARED_LIBRARY_"; + varString += lang; + varString += "_FLAGS"; + flags += m_Makefile->GetSafeDefinition(varString.c_str()); + flags += " "; } - case cmSystemTools::FORTRAN_FILE_FORMAT: - { - rules.push_back(m_Makefile->GetRequiredDefinition("CMAKE_Fortran_COMPILE_OBJECT")); - flags += m_Makefile->GetSafeDefinition("CMAKE_Fortran_FLAGS"); - flags += " "; - if(buildType.size()) - { - std::string build = "CMAKE_Fortran_FLAGS_"; - build += buildType; - flags += m_Makefile->GetSafeDefinition(build.c_str()); - flags += " "; - } - if(shared) - { - flags += m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_Fortran_FLAGS"); - flags += " "; - } - if(cmSystemTools::IsOn(m_Makefile->GetDefinition("BUILD_SHARED_LIBS"))) - { - flags += m_Makefile->GetSafeDefinition("CMAKE_SHARED_BUILD_Fortran_FLAGS"); - flags += " "; - } - break; - } - case cmSystemTools::HEADER_FILE_FORMAT: - return; - case cmSystemTools::DEFINITION_FILE_FORMAT: - return; - case cmSystemTools::OBJECT_FILE_FORMAT: - return; - case cmSystemTools::RESOURCE_FILE_FORMAT: + if(cmSystemTools::IsOn(m_Makefile->GetDefinition("BUILD_SHARED_LIBS"))) + { + varString = "CMAKE_SHARED_BUILD_"; + varString += lang; + varString += "_FLAGS"; + flags += m_Makefile->GetSafeDefinition(varString.c_str()); + flags += " "; + } + } + // the language is not defined, fall back on old stuff + else + { + switch(format) { - // use rc rule here if it is defined - const char* rule = m_Makefile->GetDefinition("CMAKE_COMPILE_RESOURCE"); - if(rule) + case cmSystemTools::HEADER_FILE_FORMAT: + return; + case cmSystemTools::DEFINITION_FILE_FORMAT: + return; + case cmSystemTools::OBJECT_FILE_FORMAT: + return; + case cmSystemTools::RESOURCE_FILE_FORMAT: { - rules.push_back(rule); + // use rc rule here if it is defined + const char* rule = m_Makefile->GetDefinition("CMAKE_COMPILE_RESOURCE"); + if(rule) + { + rules.push_back(rule); + } } - } - break; - case cmSystemTools::NO_FILE_FORMAT: - case cmSystemTools::JAVA_FILE_FORMAT: - case cmSystemTools::STATIC_LIBRARY_FILE_FORMAT: - case cmSystemTools::SHARED_LIBRARY_FILE_FORMAT: - case cmSystemTools::MODULE_FILE_FORMAT: - case cmSystemTools::UNKNOWN_FILE_FORMAT: - cmSystemTools::Error("Unexpected file type ", - sourceFile.c_str()); break; - } + case cmSystemTools::NO_FILE_FORMAT: + case cmSystemTools::JAVA_FILE_FORMAT: + case cmSystemTools::STATIC_LIBRARY_FILE_FORMAT: + case cmSystemTools::SHARED_LIBRARY_FILE_FORMAT: + case cmSystemTools::MODULE_FILE_FORMAT: + case cmSystemTools::UNKNOWN_FILE_FORMAT: + cmSystemTools::Error("Unexpected file type ", + sourceFile.c_str()); + break; + } + } flags += "$(INCLUDE_FLAGS) "; // expand multi-command semi-colon separated lists // of commands into separate commands diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index cd0069c..0d7c293 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -39,6 +39,9 @@ cmMakefile::cmMakefile() m_ComplainFileRegularExpression = "^$"; // Source and header file extensions that we can handle + // Set up a list of source and header extensions + // these are used to find files when the extension + // is not given // The "c" extension MUST precede the "C" extension. m_SourceFileExtensions.push_back( "c" ); m_SourceFileExtensions.push_back( "C" ); |