Attached are 2 patches for caching the defines&flags and introducing the options.
I'll look into testing next, any hints for what to look out for would be appreciated ;) Cheers, /Manuel On Fri, Jan 14, 2011 at 2:54 PM, Brad King <brad.k...@kitware.com> wrote: > On 01/14/2011 05:46 PM, Manuel Klimek wrote: >> I'm currently trying to figure out the best point where to add that >> option... > > In the cmMakefileTargetGenerator you can test for the option with > > this->Makefile->IsOn("...") > >> Is there a good example I can base it on? So far I followed >> CMAKE_BUILD_TYPE through the code base, which suggests that I need to >> - find a .cmake file in modules in which I can put the option >> - document it in cmDocumentVariables > > Probably like CMAKE_VERBOSE_MAKEFILE which is another option to the > Makefile generator. See CMakeGenericSystem.cmake. Surround it by > > if("${CMAKE_GENERATOR}" MATCHES "Make") > ... > endif() > > so that it only shows up for Makefile generators. > > -Brad > -- Manuel Klimek (http://go/klimek)
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 52b6bb7..07f5014 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -250,59 +250,66 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules() //---------------------------------------------------------------------------- std::string cmMakefileTargetGenerator::GetFlags(const std::string &l) { - std::string flags; - const char *lang = l.c_str(); + std::pair<std::map<std::string, std::string>::iterator, bool> + insert_result = this->FlagsByLanguage.insert(std::make_pair(l, "")); + if (insert_result.second) { + std::string& flags = insert_result.first->second; + const char *lang = l.c_str(); - bool shared = ((this->Target->GetType() == cmTarget::SHARED_LIBRARY) || - (this->Target->GetType() == cmTarget::MODULE_LIBRARY)); + bool shared = ((this->Target->GetType() == cmTarget::SHARED_LIBRARY) || + (this->Target->GetType() == cmTarget::MODULE_LIBRARY)); - // Add language feature flags. - this->AddFeatureFlags(flags, lang); + // Add language feature flags. + this->AddFeatureFlags(flags, lang); - this->LocalGenerator->AddArchitectureFlags(flags, this->Target, - lang, this->ConfigName); + this->LocalGenerator->AddArchitectureFlags(flags, this->Target, + lang, this->ConfigName); - // Fortran-specific flags computed for this target. - if(l == "Fortran") - { - this->AddFortranFlags(flags); - } - - // Add shared-library flags if needed. - this->LocalGenerator->AddSharedFlags(flags, lang, shared); + // Fortran-specific flags computed for this target. + if(l == "Fortran") + { + this->AddFortranFlags(flags); + } - // Add include directory flags. - this->LocalGenerator-> - AppendFlags(flags, this->LocalGenerator->GetIncludeFlags(lang)); - // Add include directory flags. - this->LocalGenerator-> - AppendFlags(flags,this->GetFrameworkFlags().c_str()); + // Add shared-library flags if needed. + this->LocalGenerator->AddSharedFlags(flags, lang, shared); - return flags; + // Add include directory flags. + this->LocalGenerator-> + AppendFlags(flags, this->LocalGenerator->GetIncludeFlags(lang)); + // Add include directory flags. + this->LocalGenerator-> + AppendFlags(flags,this->GetFrameworkFlags().c_str()); + } + return insert_result.first->second; } std::string cmMakefileTargetGenerator::GetDefines(const std::string &l) { - std::string defines; - const char *lang = l.c_str(); - // Add the export symbol definition for shared library objects. - if(const char* exportMacro = this->Target->GetExportMacro()) - { - this->LocalGenerator->AppendDefines(defines, exportMacro, lang); - } + std::pair<std::map<std::string, std::string>::iterator, bool> + insert_result = this->DefinesByLanguage.insert(std::make_pair(l, "")); + if (insert_result.second) { + std::string &defines = insert_result.first->second; + const char *lang = l.c_str(); + // Add the export symbol definition for shared library objects. + if(const char* exportMacro = this->Target->GetExportMacro()) + { + this->LocalGenerator->AppendDefines(defines, exportMacro, lang); + } - // Add preprocessor definitions for this target and configuration. - this->LocalGenerator->AppendDefines - (defines, this->Makefile->GetProperty("COMPILE_DEFINITIONS"), lang); - this->LocalGenerator->AppendDefines - (defines, this->Target->GetProperty("COMPILE_DEFINITIONS"), lang); - std::string defPropName = "COMPILE_DEFINITIONS_"; - defPropName += - cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName); - this->LocalGenerator->AppendDefines - (defines, this->Makefile->GetProperty(defPropName.c_str()), lang); - this->LocalGenerator->AppendDefines - (defines, this->Target->GetProperty(defPropName.c_str()), lang); - return defines; + // Add preprocessor definitions for this target and configuration. + this->LocalGenerator->AppendDefines + (defines, this->Makefile->GetProperty("COMPILE_DEFINITIONS"), lang); + this->LocalGenerator->AppendDefines + (defines, this->Target->GetProperty("COMPILE_DEFINITIONS"), lang); + std::string defPropName = "COMPILE_DEFINITIONS_"; + defPropName += + cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName); + this->LocalGenerator->AppendDefines + (defines, this->Makefile->GetProperty(defPropName.c_str()), lang); + this->LocalGenerator->AppendDefines + (defines, this->Target->GetProperty(defPropName.c_str()), lang); + } + return insert_result.first->second; } void cmMakefileTargetGenerator::WriteTargetLanguageFlags() diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index 12dbb25..0ed58e5 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -213,7 +213,9 @@ protected: std::set<cmStdString> MacContentFolders; std::string GetFlags(const std::string &l); + std::map<std::string, std::string> FlagsByLanguage; std::string GetDefines(const std::string &l); + std::map<std::string, std::string> DefinesByLanguage; // Target-wide Fortran module output directory. bool FortranModuleDirectoryComputed;
diff --git a/Modules/CMakeGenericSystem.cmake b/Modules/CMakeGenericSystem.cmake index b5d3072..e64d0ba 100644 --- a/Modules/CMakeGenericSystem.cmake +++ b/Modules/CMakeGenericSystem.cmake @@ -50,6 +50,9 @@ IF(CMAKE_GENERATOR MATCHES "Makefiles") IF(DEFINED CMAKE_RULE_MESSAGES) SET_PROPERTY(GLOBAL PROPERTY RULE_MESSAGES ${CMAKE_RULE_MESSAGES}) ENDIF(DEFINED CMAKE_RULE_MESSAGES) + SET(CMAKE_EXPORT_COMPILE_COMMANDS OFF CACHE BOOL + "Enable/Disable output of compile commands during generation." + ) ENDIF(CMAKE_GENERATOR MATCHES "Makefiles") diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 92f87c9..54f2b03 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -216,7 +216,7 @@ void cmGlobalUnixMakefileGenerator3::AddCXXCompileCommand( { std::string commandDatabaseName = std::string(this->GetCMakeInstance()->GetHomeOutputDirectory()) - + "/cxx_commands.json"; + + "/compile_commands.json"; this->CommandDatabase = new cmGeneratedFileStream(commandDatabaseName.c_str()); *this->CommandDatabase << "[" << std::endl; diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 4e52b7f..4f09ee1 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -665,7 +665,8 @@ cmMakefileTargetGenerator std::vector<std::string> compileCommands; cmSystemTools::ExpandListArgument(compileRule, compileCommands); - if (lang_is_c_or_cxx && compileCommands.size() == 1) + if (this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS") && + lang_is_c_or_cxx && compileCommands.size() == 1) { std::string compileCommand = compileCommands[0]; this->LocalGenerator->ExpandRuleVariables(compileCommand, vars);
_______________________________________________ cmake-developers mailing list cmake-developers@cmake.org http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers