ENH: add OPTIONAL keyword to ENABLE_LANGUAGE, so it will be possible to do

something like this:

ENABLE_LANGUAGE(ASM-ATT)
IF(CMAKE_ASM-ATT_COMPILER_WORKS)
  ... do assembler stufff
ELSE(CMAKE_ASM-ATT_COMPILER_WORKS)
  ... fallback to generic C/C++
ENDIF(CMAKE_ASM-ATT_COMPILER_WORKS)

Alex
This commit is contained in:
Alexander Neundorf 2007-06-28 09:09:26 -04:00
parent 53f39ad566
commit 43de8c8628
28 changed files with 77 additions and 42 deletions

View File

@ -20,13 +20,29 @@
bool cmEnableLanguageCommand bool cmEnableLanguageCommand
::InitialPass(std::vector<std::string> const& args) ::InitialPass(std::vector<std::string> const& args)
{ {
bool optional = false;
std::vector<std::string> languages;
if(args.size() < 1 ) if(args.size() < 1 )
{ {
this->SetError this->SetError
("ENABLE_LANGUAGE called with incorrect number of arguments"); ("ENABLE_LANGUAGE called with incorrect number of arguments");
return false; return false;
} }
this->Makefile->EnableLanguage(args); for (std::vector<std::string>::const_iterator it = args.begin();
it != args.end();
++it)
{
if ((*it) == "OPTIONAL")
{
optional = true;
}
else
{
languages.push_back(*it);
}
}
this->Makefile->EnableLanguage(languages, optional);
return true; return true;
} }

View File

@ -63,11 +63,13 @@ public:
virtual const char* GetFullDocumentation() virtual const char* GetFullDocumentation()
{ {
return return
" ENABLE_LANGUAGE(languageName)\n" " ENABLE_LANGUAGE(languageName [OPTIONAL] )\n"
"This command enables support for the named language in CMake. " "This command enables support for the named language in CMake. "
"This is the same as the project command but does not create " "This is the same as the project command but does not create "
"any of the extra varaibles that are created by the project command. " "any of the extra varaibles that are created by the project command. "
"Example languages are CXX, C, Fortran."; "Example languages are CXX, C, Fortran.\n"
"If OPTIONAL is used, use the CMAKE_<languageName>_COMPILER_WORKS "
"variable to check whether the language has been enabled successfully.";
} }
cmTypeMacro(cmEnableLanguageCommand, cmCommand); cmTypeMacro(cmEnableLanguageCommand, cmCommand);

View File

@ -30,13 +30,15 @@ cmGlobalBorlandMakefileGenerator::cmGlobalBorlandMakefileGenerator()
void cmGlobalBorlandMakefileGenerator void cmGlobalBorlandMakefileGenerator
::EnableLanguage(std::vector<std::string>const& l, cmMakefile *mf) ::EnableLanguage(std::vector<std::string>const& l,
cmMakefile *mf,
bool optional)
{ {
std::string outdir = this->CMakeInstance->GetStartOutputDirectory(); std::string outdir = this->CMakeInstance->GetStartOutputDirectory();
mf->AddDefinition("BORLAND", "1"); mf->AddDefinition("BORLAND", "1");
mf->AddDefinition("CMAKE_GENERATOR_CC", "bcc32"); mf->AddDefinition("CMAKE_GENERATOR_CC", "bcc32");
mf->AddDefinition("CMAKE_GENERATOR_CXX", "bcc32"); mf->AddDefinition("CMAKE_GENERATOR_CXX", "bcc32");
this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf); this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
} }
///! Create a local generator appropriate to this Global Generator ///! Create a local generator appropriate to this Global Generator

View File

@ -47,7 +47,7 @@ public:
* extension, pthreads, byte order etc. * extension, pthreads, byte order etc.
*/ */
virtual void EnableLanguage(std::vector<std::string>const& languages, virtual void EnableLanguage(std::vector<std::string>const& languages,
cmMakefile *); cmMakefile *, bool optional);
}; };
#endif #endif

View File

@ -196,7 +196,7 @@ void cmGlobalGenerator::FindMakeProgram(cmMakefile* mf)
void void
cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages, cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages,
cmMakefile *mf) cmMakefile *mf, bool optional)
{ {
if(languages.size() == 0) if(languages.size() == 0)
{ {

View File

@ -77,7 +77,7 @@ public:
* extension, pthreads, byte order etc. * extension, pthreads, byte order etc.
*/ */
virtual void EnableLanguage(std::vector<std::string>const& languages, virtual void EnableLanguage(std::vector<std::string>const& languages,
cmMakefile *); cmMakefile *, bool optional);
/** /**
* Try to determine system infomation, get it from another generator * Try to determine system infomation, get it from another generator

View File

@ -50,7 +50,9 @@ cmGlobalMSYSMakefileGenerator::FindMinGW(std::string const& makeloc)
} }
void cmGlobalMSYSMakefileGenerator void cmGlobalMSYSMakefileGenerator
::EnableLanguage(std::vector<std::string>const& l, cmMakefile *mf) ::EnableLanguage(std::vector<std::string>const& l,
cmMakefile *mf,
bool optional)
{ {
this->FindMakeProgram(mf); this->FindMakeProgram(mf);
std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
@ -75,7 +77,7 @@ void cmGlobalMSYSMakefileGenerator
mf->AddDefinition("MSYS", "1"); mf->AddDefinition("MSYS", "1");
mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str()); mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str());
mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str()); mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str());
this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf); this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
if(!mf->IsSet("CMAKE_AR") && !this->CMakeInstance->GetIsInTryCompile()) if(!mf->IsSet("CMAKE_AR") && !this->CMakeInstance->GetIsInTryCompile())
{ {
cmSystemTools::Error cmSystemTools::Error

View File

@ -47,7 +47,7 @@ public:
* extension, pthreads, byte order etc. * extension, pthreads, byte order etc.
*/ */
virtual void EnableLanguage(std::vector<std::string>const& languages, virtual void EnableLanguage(std::vector<std::string>const& languages,
cmMakefile *); cmMakefile *, bool optional);
private: private:
std::string FindMinGW(std::string const& makeloc); std::string FindMinGW(std::string const& makeloc);

View File

@ -27,7 +27,9 @@ cmGlobalMinGWMakefileGenerator::cmGlobalMinGWMakefileGenerator()
} }
void cmGlobalMinGWMakefileGenerator void cmGlobalMinGWMakefileGenerator
::EnableLanguage(std::vector<std::string>const& l, cmMakefile *mf) ::EnableLanguage(std::vector<std::string>const& l,
cmMakefile *mf,
bool optional)
{ {
this->FindMakeProgram(mf); this->FindMakeProgram(mf);
std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
@ -49,7 +51,7 @@ void cmGlobalMinGWMakefileGenerator
} }
mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str()); mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str());
mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str()); mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str());
this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf); this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
} }
///! Create a local generator appropriate to this Global Generator ///! Create a local generator appropriate to this Global Generator

View File

@ -46,7 +46,7 @@ public:
* extension, pthreads, byte order etc. * extension, pthreads, byte order etc.
*/ */
virtual void EnableLanguage(std::vector<std::string>const& languages, virtual void EnableLanguage(std::vector<std::string>const& languages,
cmMakefile *); cmMakefile *, bool optional);
}; };
#endif #endif

View File

@ -27,12 +27,14 @@ cmGlobalNMakeMakefileGenerator::cmGlobalNMakeMakefileGenerator()
} }
void cmGlobalNMakeMakefileGenerator void cmGlobalNMakeMakefileGenerator
::EnableLanguage(std::vector<std::string>const& l, cmMakefile *mf) ::EnableLanguage(std::vector<std::string>const& l,
cmMakefile *mf,
bool optional)
{ {
// pick a default // pick a default
mf->AddDefinition("CMAKE_GENERATOR_CC", "cl"); mf->AddDefinition("CMAKE_GENERATOR_CC", "cl");
mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl"); mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl");
this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf); this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
} }
///! Create a local generator appropriate to this Global Generator ///! Create a local generator appropriate to this Global Generator

View File

@ -46,7 +46,7 @@ public:
* extension, pthreads, byte order etc. * extension, pthreads, byte order etc.
*/ */
virtual void EnableLanguage(std::vector<std::string>const& languages, virtual void EnableLanguage(std::vector<std::string>const& languages,
cmMakefile *); cmMakefile *, bool optional);
}; };
#endif #endif

View File

@ -39,9 +39,11 @@ cmGlobalUnixMakefileGenerator3::cmGlobalUnixMakefileGenerator3()
} }
void cmGlobalUnixMakefileGenerator3 void cmGlobalUnixMakefileGenerator3
::EnableLanguage(std::vector<std::string>const& languages, cmMakefile *mf) ::EnableLanguage(std::vector<std::string>const& languages,
cmMakefile *mf,
bool optional)
{ {
this->cmGlobalGenerator::EnableLanguage(languages, mf); this->cmGlobalGenerator::EnableLanguage(languages, mf, optional);
std::string path; std::string path;
for(std::vector<std::string>::const_iterator l = languages.begin(); for(std::vector<std::string>::const_iterator l = languages.begin();
l != languages.end(); ++l) l != languages.end(); ++l)
@ -70,7 +72,8 @@ void cmGlobalUnixMakefileGenerator3
{ {
path = name; path = name;
} }
if(path.size() == 0 || !cmSystemTools::FileExists(path.c_str())) if((path.size() == 0 || !cmSystemTools::FileExists(path.c_str()))
&& (optional==false))
{ {
std::string message = "your "; std::string message = "your ";
message += lang; message += lang;

View File

@ -77,7 +77,7 @@ public:
* extension, pthreads, byte order etc. * extension, pthreads, byte order etc.
*/ */
virtual void EnableLanguage(std::vector<std::string>const& languages, virtual void EnableLanguage(std::vector<std::string>const& languages,
cmMakefile *); cmMakefile *, bool optional);
/** /**
* Generate the all required files for building this project/tree. This * Generate the all required files for building this project/tree. This

View File

@ -25,7 +25,9 @@ cmGlobalVisualStudio6Generator::cmGlobalVisualStudio6Generator()
} }
void cmGlobalVisualStudio6Generator void cmGlobalVisualStudio6Generator
::EnableLanguage(std::vector<std::string>const& lang, cmMakefile *mf) ::EnableLanguage(std::vector<std::string>const& lang,
cmMakefile *mf,
bool options)
{ {
mf->AddDefinition("CMAKE_GENERATOR_CC", "cl"); mf->AddDefinition("CMAKE_GENERATOR_CC", "cl");
mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl"); mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl");
@ -34,7 +36,7 @@ void cmGlobalVisualStudio6Generator
mf->AddDefinition("CMAKE_GENERATOR_Fortran", "ifort"); mf->AddDefinition("CMAKE_GENERATOR_Fortran", "ifort");
mf->AddDefinition("MSVC60", "1"); mf->AddDefinition("MSVC60", "1");
this->GenerateConfigurations(mf); this->GenerateConfigurations(mf);
this->cmGlobalGenerator::EnableLanguage(lang, mf); this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
} }
void cmGlobalVisualStudio6Generator::GenerateConfigurations(cmMakefile* mf) void cmGlobalVisualStudio6Generator::GenerateConfigurations(cmMakefile* mf)

View File

@ -49,7 +49,7 @@ public:
* extension, pthreads, byte order etc. * extension, pthreads, byte order etc.
*/ */
virtual void EnableLanguage(std::vector<std::string>const& languages, virtual void EnableLanguage(std::vector<std::string>const& languages,
cmMakefile *); cmMakefile *, bool optional);
/** /**
* Try running cmake and building a file. This is used for dynalically * Try running cmake and building a file. This is used for dynalically

View File

@ -29,7 +29,7 @@ cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator()
void cmGlobalVisualStudio7Generator void cmGlobalVisualStudio7Generator
::EnableLanguage(std::vector<std::string>const & lang, ::EnableLanguage(std::vector<std::string>const & lang,
cmMakefile *mf) cmMakefile *mf, bool optional)
{ {
mf->AddDefinition("CMAKE_GENERATOR_CC", "cl"); mf->AddDefinition("CMAKE_GENERATOR_CC", "cl");
mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl"); mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl");
@ -40,7 +40,7 @@ void cmGlobalVisualStudio7Generator
this->AddPlatformDefinitions(mf); this->AddPlatformDefinitions(mf);
// Create list of configurations requested by user's cache, if any. // Create list of configurations requested by user's cache, if any.
this->cmGlobalGenerator::EnableLanguage(lang, mf); this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
this->GenerateConfigurations(mf); this->GenerateConfigurations(mf);
// if this environment variable is set, then copy it to // if this environment variable is set, then copy it to

View File

@ -50,7 +50,7 @@ public:
* extension, pthreads, byte order etc. * extension, pthreads, byte order etc.
*/ */
virtual void EnableLanguage(std::vector<std::string>const& languages, virtual void EnableLanguage(std::vector<std::string>const& languages,
cmMakefile *); cmMakefile *, bool optional);
/** /**
* Try running cmake and building a file. This is used for dynalically * Try running cmake and building a file. This is used for dynalically

View File

@ -49,8 +49,8 @@ void cmGlobalVisualStudio8Win64Generator
void cmGlobalVisualStudio8Win64Generator void cmGlobalVisualStudio8Win64Generator
::EnableLanguage(std::vector<std::string>const & lang, ::EnableLanguage(std::vector<std::string>const & lang,
cmMakefile *mf) cmMakefile *mf, bool optional)
{ {
mf->AddDefinition("CMAKE_FORCE_WIN64", "TRUE"); mf->AddDefinition("CMAKE_FORCE_WIN64", "TRUE");
cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf); cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional);
} }

View File

@ -49,6 +49,6 @@ public:
* extension, pthreads, byte order etc. * extension, pthreads, byte order etc.
*/ */
virtual void EnableLanguage(std::vector<std::string>const& languages, virtual void EnableLanguage(std::vector<std::string>const& languages,
cmMakefile *); cmMakefile *, bool optional);
}; };
#endif #endif

View File

@ -28,7 +28,9 @@ cmGlobalWatcomWMakeGenerator::cmGlobalWatcomWMakeGenerator()
} }
void cmGlobalWatcomWMakeGenerator void cmGlobalWatcomWMakeGenerator
::EnableLanguage(std::vector<std::string>const& l, cmMakefile *mf) ::EnableLanguage(std::vector<std::string>const& l,
cmMakefile *mf,
bool optional)
{ {
// pick a default // pick a default
mf->AddDefinition("WATCOM", "1"); mf->AddDefinition("WATCOM", "1");
@ -39,7 +41,7 @@ void cmGlobalWatcomWMakeGenerator
mf->AddDefinition("CMAKE_NO_QUOTED_OBJECTS", "1"); mf->AddDefinition("CMAKE_NO_QUOTED_OBJECTS", "1");
mf->AddDefinition("CMAKE_GENERATOR_CC", "wcl386"); mf->AddDefinition("CMAKE_GENERATOR_CC", "wcl386");
mf->AddDefinition("CMAKE_GENERATOR_CXX", "wcl386"); mf->AddDefinition("CMAKE_GENERATOR_CXX", "wcl386");
this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf); this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
} }
///! Create a local generator appropriate to this Global Generator ///! Create a local generator appropriate to this Global Generator

View File

@ -45,7 +45,7 @@ public:
* extension, pthreads, byte order etc. * extension, pthreads, byte order etc.
*/ */
virtual void EnableLanguage(std::vector<std::string>const& languages, virtual void EnableLanguage(std::vector<std::string>const& languages,
cmMakefile *); cmMakefile *, bool optional);
}; };
#endif #endif

View File

@ -104,7 +104,7 @@ cmGlobalGenerator* cmGlobalXCodeGenerator::New()
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::EnableLanguage(std::vector<std::string>const& void cmGlobalXCodeGenerator::EnableLanguage(std::vector<std::string>const&
lang, lang,
cmMakefile * mf) cmMakefile * mf, bool optional)
{ {
mf->AddDefinition("XCODE","1"); mf->AddDefinition("XCODE","1");
if(this->XcodeVersion == 15) if(this->XcodeVersion == 15)
@ -125,7 +125,7 @@ void cmGlobalXCodeGenerator::EnableLanguage(std::vector<std::string>const&
mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1"); mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
// initialize Architectures so it can be used by // initialize Architectures so it can be used by
// GetTargetObjectFileDirectories // GetTargetObjectFileDirectories
this->cmGlobalGenerator::EnableLanguage(lang, mf); this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
const char* osxArch = const char* osxArch =
mf->GetDefinition("CMAKE_OSX_ARCHITECTURES"); mf->GetDefinition("CMAKE_OSX_ARCHITECTURES");
const char* sysroot = const char* sysroot =

View File

@ -53,7 +53,7 @@ public:
* extension, pthreads, byte order etc. * extension, pthreads, byte order etc.
*/ */
virtual void EnableLanguage(std::vector<std::string>const& languages, virtual void EnableLanguage(std::vector<std::string>const& languages,
cmMakefile *); cmMakefile *, bool optional);
/** /**
* 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.

View File

@ -1044,7 +1044,7 @@ void cmLocalVisualStudio6Generator
// Compute the proper name to use to link this library. // Compute the proper name to use to link this library.
std::string lib; std::string lib;
std::string libDebug; std::string libDebug;
cmTarget* tgt = this->GlobalGenerator->FindTarget(0, j->first.c_str(), cmTarget* tgt = this->GlobalGenerator->FindTarget(0, j->first.c_str(),
false); false);
if(tgt) if(tgt)
{ {

View File

@ -2150,11 +2150,13 @@ cmSourceFile* cmMakefile::GetOrCreateSource(const char* sourceName,
} }
} }
void cmMakefile::EnableLanguage(std::vector<std::string> const & lang) void cmMakefile::EnableLanguage(std::vector<std::string> const & lang,
bool optional)
{ {
this->AddDefinition("CMAKE_CFG_INTDIR", this->AddDefinition("CMAKE_CFG_INTDIR",
this->LocalGenerator->GetGlobalGenerator()->GetCMakeCFGInitDirectory()); this->LocalGenerator->GetGlobalGenerator()->GetCMakeCFGInitDirectory());
this->LocalGenerator->GetGlobalGenerator()->EnableLanguage(lang, this); this->LocalGenerator->GetGlobalGenerator()->EnableLanguage(lang, this,
optional);
} }
void cmMakefile::ExpandSourceListArguments( void cmMakefile::ExpandSourceListArguments(

View File

@ -633,7 +633,7 @@ public:
///! Enable support for named language, if nil then all languages are ///! Enable support for named language, if nil then all languages are
///enabled. ///enabled.
void EnableLanguage(std::vector<std::string>const& languages); void EnableLanguage(std::vector<std::string>const& languages, bool optional);
/** /**
* Set/Get the name of the parent directories CMakeLists file * Set/Get the name of the parent directories CMakeLists file

View File

@ -72,7 +72,7 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args)
languages.push_back("C"); languages.push_back("C");
languages.push_back("CXX"); languages.push_back("CXX");
} }
this->Makefile->EnableLanguage(languages); this->Makefile->EnableLanguage(languages, false);
return true; return true;
} }