ENH: define language extensions in cmake files and not hard coded, also fix trycompile problem
This commit is contained in:
parent
652823dc83
commit
c2ef51e181
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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_";
|
||||
|
@ -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,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cmGlobalGenerator::SetLanguageEnabled(const char* l)
|
||||
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, 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;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -2843,105 +2843,76 @@ 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)
|
||||
// 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)
|
||||
{
|
||||
case cmSystemTools::C_FILE_FORMAT:
|
||||
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");
|
||||
varString = "CMAKE_SHARED_LIBRARY_";
|
||||
varString += lang;
|
||||
varString += "_FLAGS";
|
||||
flags += m_Makefile->GetSafeDefinition(varString.c_str());
|
||||
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;
|
||||
}
|
||||
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")))
|
||||
{
|
||||
// use rc rule here if it is defined
|
||||
const char* rule = m_Makefile->GetDefinition("CMAKE_COMPILE_RESOURCE");
|
||||
if(rule)
|
||||
{
|
||||
rules.push_back(rule);
|
||||
}
|
||||
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)
|
||||
{
|
||||
case cmSystemTools::HEADER_FILE_FORMAT:
|
||||
return;
|
||||
case cmSystemTools::DEFINITION_FILE_FORMAT:
|
||||
return;
|
||||
case cmSystemTools::OBJECT_FILE_FORMAT:
|
||||
return;
|
||||
case cmSystemTools::RESOURCE_FILE_FORMAT:
|
||||
{
|
||||
// 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
|
||||
|
|
|
@ -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" );
|
||||
|
|
Loading…
Reference in New Issue