From f59e87792943904dcb11e16380883e87395d115f Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 6 Oct 2016 18:01:36 +0200 Subject: [PATCH 1/2] cmGlobalGenerator: Add API to get settings from top-level cmMakefile At generate-time, definitions are sometimes read from a nearby cmMakefile, making the value directory-specific because they are read once per directory. Often however, the intention is more often to create a 'global' setting, such that the user writes for example: set(CMAKE_IMPORT_LIBRARY_SUFFIX something) once at the top level of their project. Many of these are also set by internal platform files, such as CMAKE_EXTRA_LINK_EXTENSIONS. The set() definitions are not really suitable for 'global' settings because they can be different for each directory, and code consuming the settings must assume they are different for each directory, and read it freshly each time with new allocations. CMake has other variable types which are global in scope, such as global properties, and cache variables. These are less convenient to populate for users, so establish a convention and API using the value as it is at the end of the top-level CMakeLists file. --- Source/cmGlobalGenerator.cxx | 19 +++++++++++++++++++ Source/cmGlobalGenerator.h | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index a446862c9..7132ade19 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1007,6 +1007,25 @@ void cmGlobalGenerator::FillExtensionToLanguageMap(const std::string& l, } } +const char* cmGlobalGenerator::GetGlobalSetting(std::string const& name) const +{ + assert(!this->Makefiles.empty()); + return this->Makefiles[0]->GetDefinition(name); +} + +bool cmGlobalGenerator::GlobalSettingIsOn(std::string const& name) const +{ + assert(!this->Makefiles.empty()); + return this->Makefiles[0]->IsOn(name); +} + +const char* cmGlobalGenerator::GetSafeGlobalSetting( + std::string const& name) const +{ + assert(!this->Makefiles.empty()); + return this->Makefiles[0]->GetSafeDefinition(name); +} + bool cmGlobalGenerator::IgnoreFile(const char* ext) const { if (!this->GetLanguageFromExtension(ext).empty()) { diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 4120b52ea..add2b92a0 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -194,6 +194,10 @@ public: cmExportSetMap& GetExportSets() { return this->ExportSets; } + const char* GetGlobalSetting(std::string const& name) const; + bool GlobalSettingIsOn(std::string const& name) const; + const char* GetSafeGlobalSetting(std::string const& name) const; + /** Add a file to the manifest of generated targets for a configuration. */ void AddToManifest(std::string const& f); From 80574a38e6cb6ac33630e878d9633f1267b53d2b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 6 Oct 2016 18:35:02 +0200 Subject: [PATCH 2/2] Codelite: Consume the CMAKE_CODELITE_USE_TARGETS setting globally --- Help/variable/CMAKE_CODELITE_USE_TARGETS.rst | 5 +++-- Source/cmExtraCodeLiteGenerator.cxx | 4 +--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Help/variable/CMAKE_CODELITE_USE_TARGETS.rst b/Help/variable/CMAKE_CODELITE_USE_TARGETS.rst index 4aede0361..33cdf6ca6 100644 --- a/Help/variable/CMAKE_CODELITE_USE_TARGETS.rst +++ b/Help/variable/CMAKE_CODELITE_USE_TARGETS.rst @@ -3,5 +3,6 @@ CMAKE_CODELITE_USE_TARGETS Change the way the CodeLite generator creates projectfiles. -If this variable is set to ``ON`` the generator creates projectfiles -based on targets rather than projects. +If this variable evaluates to ``ON`` at the end of the top-level +``CMakeLists.txt`` file, the generator creates projectfiles based on targets +rather than projects. diff --git a/Source/cmExtraCodeLiteGenerator.cxx b/Source/cmExtraCodeLiteGenerator.cxx index 629c5b6a3..360c85237 100644 --- a/Source/cmExtraCodeLiteGenerator.cxx +++ b/Source/cmExtraCodeLiteGenerator.cxx @@ -60,7 +60,6 @@ void cmExtraCodeLiteGenerator::Generate() // loop projects and locate the root project. // and extract the information for creating the worspace // root makefile - const cmMakefile* rmf = CM_NULLPTR; for (std::map >::const_iterator it = projectMap.begin(); it != projectMap.end(); ++it) { @@ -75,7 +74,6 @@ void cmExtraCodeLiteGenerator::Generate() workspaceFileName = workspaceOutputDir + "/"; workspaceFileName += workspaceProjectName + ".workspace"; this->WorkspacePath = it->second[0]->GetCurrentBinaryDirectory(); - rmf = it->second[0]->GetMakefile(); ; break; } @@ -89,7 +87,7 @@ void cmExtraCodeLiteGenerator::Generate() xml.Attribute("Name", workspaceProjectName); bool const targetsAreProjects = - rmf && rmf->IsOn("CMAKE_CODELITE_USE_TARGETS"); + this->GlobalGenerator->GlobalSettingIsOn("CMAKE_CODELITE_USE_TARGETS"); std::vector ProjectNames; if (targetsAreProjects) {