From d1077c1ce6310f02c93962cbb89e82dc57a6dd31 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 25 Jul 2018 12:08:19 +0200 Subject: cmLocalGenerator: Style change: Use return value of std::set::insert Code style change in ``cmLocalGenerator::GetIncludeDirectories()``. Use the return value of ``std::set::insert`` instead of testing if the entry already exists in the set using ``std::find``. --- Source/cmLocalGenerator.cxx | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 072b958..f0db28d 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -846,10 +846,8 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, const std::string& config, bool stripImplicitInclDirs) const { - // Need to decide whether to automatically include the source and - // binary directories at the beginning of the include path. - bool includeSourceDir = false; - bool includeBinaryDir = false; + // Do not repeat an include path. + std::set emitted; // When automatic include directories are requested for a build then // include the source and binary directories at the beginning of the @@ -859,26 +857,21 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, // cannot fix this because not all native build tools support // per-source-file include paths. if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR")) { - includeSourceDir = true; - includeBinaryDir = true; - } - - // Do not repeat an include path. - std::set emitted; - - // Store the automatic include paths. - if (includeBinaryDir) { - std::string binDir = this->StateSnapshot.GetDirectory().GetCurrentBinary(); - if (emitted.find(binDir) == emitted.end()) { - dirs.push_back(binDir); - emitted.insert(binDir); + // Current binary directory + { + std::string binDir = + this->StateSnapshot.GetDirectory().GetCurrentBinary(); + if (emitted.insert(binDir).second) { + dirs.push_back(std::move(binDir)); + } } - } - if (includeSourceDir) { - std::string srcDir = this->StateSnapshot.GetDirectory().GetCurrentSource(); - if (emitted.find(srcDir) == emitted.end()) { - dirs.push_back(srcDir); - emitted.insert(srcDir); + // Current source directory + { + std::string srcDir = + this->StateSnapshot.GetDirectory().GetCurrentSource(); + if (emitted.insert(srcDir).second) { + dirs.push_back(std::move(srcDir)); + } } } -- cgit v0.12 From 3713dc9b8e0662279e7f84133d5953998dcfe254 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 25 Jul 2018 12:11:58 +0200 Subject: cmLocalGenerator: Style change: Wrap temporary strings and code in braces Code style change in ``cmLocalGenerator::GetIncludeDirectories``. Embrace ``{}`` temporary strings and code that uses them to minimize their lifetime. --- Source/cmLocalGenerator.cxx | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index f0db28d..0c50759 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -879,28 +879,31 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, return; } - std::string rootPath; - if (const char* sysrootCompile = - this->Makefile->GetDefinition("CMAKE_SYSROOT_COMPILE")) { - rootPath = sysrootCompile; - } else { - rootPath = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT"); - } - + // Implicit include directories std::vector implicitDirs; - // Load implicit include directories for this language. - std::string impDirVar = "CMAKE_"; - impDirVar += lang; - impDirVar += "_IMPLICIT_INCLUDE_DIRECTORIES"; - if (const char* value = this->Makefile->GetDefinition(impDirVar)) { - std::vector impDirVec; - cmSystemTools::ExpandListArgument(value, impDirVec); - for (std::string const& i : impDirVec) { - std::string d = rootPath + i; - cmSystemTools::ConvertToUnixSlashes(d); - emitted.insert(std::move(d)); - if (!stripImplicitInclDirs) { - implicitDirs.push_back(i); + { + std::string rootPath; + if (const char* sysrootCompile = + this->Makefile->GetDefinition("CMAKE_SYSROOT_COMPILE")) { + rootPath = sysrootCompile; + } else { + rootPath = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT"); + } + + // Load implicit include directories for this language. + std::string key = "CMAKE_"; + key += lang; + key += "_IMPLICIT_INCLUDE_DIRECTORIES"; + if (const char* value = this->Makefile->GetDefinition(key)) { + std::vector impDirVec; + cmSystemTools::ExpandListArgument(value, impDirVec); + for (std::string const& i : impDirVec) { + std::string d = rootPath + i; + cmSystemTools::ConvertToUnixSlashes(d); + emitted.insert(std::move(d)); + if (!stripImplicitInclDirs) { + implicitDirs.push_back(i); + } } } } -- cgit v0.12 From db866d05deb1d345793aff4152211f7651451213 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 25 Jul 2018 12:18:49 +0200 Subject: cmLocalGenerator: Style change: Wrap temporary strings and code in braces Code style change in ``cmLocalGenerator::GetIncludeDirectories``. Embrace ``{}`` temporary strings and code that uses them to minimize their lifetime. --- Source/cmLocalGenerator.cxx | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 0c50759..826ff84 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -909,9 +909,8 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, } // Get the target-specific include directories. - std::vector includes; - - includes = target->GetIncludeDirectories(config, lang); + std::vector includes = + target->GetIncludeDirectories(config, lang); // Support putting all the in-project include directories first if // it is requested by the project. @@ -942,17 +941,21 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, this->MoveSystemIncludesToEnd(dirs, config, lang, target); // Add standard include directories for this language. - // We do not filter out implicit directories here. - std::string const standardIncludesVar = - "CMAKE_" + lang + "_STANDARD_INCLUDE_DIRECTORIES"; - std::string const standardIncludes = - this->Makefile->GetSafeDefinition(standardIncludesVar); - std::vector::size_type const before = includes.size(); - cmSystemTools::ExpandListArgument(standardIncludes, includes); - for (std::vector::iterator i = includes.begin() + before; - i != includes.end(); ++i) { - cmSystemTools::ConvertToUnixSlashes(*i); - dirs.push_back(*i); + { + std::vector::size_type const before = includes.size(); + { + std::string key = "CMAKE_"; + key += lang; + key += "_STANDARD_INCLUDE_DIRECTORIES"; + std::string const value = this->Makefile->GetSafeDefinition(key); + cmSystemTools::ExpandListArgument(value, includes); + } + for (std::vector::iterator i = includes.begin() + before, + ie = includes.end(); + i != ie; ++i) { + cmSystemTools::ConvertToUnixSlashes(*i); + dirs.push_back(*i); + } } for (std::string const& i : implicitDirs) { -- cgit v0.12 From 1f36652ef4062d784620caa59e3ddd5de06cd976 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 25 Jul 2018 12:26:25 +0200 Subject: cmLocalGenerator: Style changes: Private local variable renames Code style change in ``cmLocalGenerator::GetIncludeDirectories``. Rename a variable to reflect its purpose a little bit better. --- Source/cmLocalGenerator.cxx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 826ff84..3df701e 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -909,7 +909,7 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, } // Get the target-specific include directories. - std::vector includes = + std::vector userDirs = target->GetIncludeDirectories(config, lang); // Support putting all the in-project include directories first if @@ -917,7 +917,7 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, if (this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE")) { std::string const &topSourceDir = this->GetState()->GetSourceDirectory(), &topBinaryDir = this->GetState()->GetBinaryDirectory(); - for (std::string const& i : includes) { + for (std::string const& i : userDirs) { // Emit this directory only if it is a subdirectory of the // top-level source or binary tree. if (cmSystemTools::ComparePath(i, topSourceDir) || @@ -932,7 +932,7 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, } // Construct the final ordered include directory list. - for (std::string const& i : includes) { + for (std::string const& i : userDirs) { if (emitted.insert(i).second) { dirs.push_back(i); } @@ -942,16 +942,16 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, // Add standard include directories for this language. { - std::vector::size_type const before = includes.size(); + std::vector::size_type const before = userDirs.size(); { std::string key = "CMAKE_"; key += lang; key += "_STANDARD_INCLUDE_DIRECTORIES"; std::string const value = this->Makefile->GetSafeDefinition(key); - cmSystemTools::ExpandListArgument(value, includes); + cmSystemTools::ExpandListArgument(value, userDirs); } - for (std::vector::iterator i = includes.begin() + before, - ie = includes.end(); + for (std::vector::iterator i = userDirs.begin() + before, + ie = userDirs.end(); i != ie; ++i) { cmSystemTools::ConvertToUnixSlashes(*i); dirs.push_back(*i); @@ -959,7 +959,7 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, } for (std::string const& i : implicitDirs) { - if (std::find(includes.begin(), includes.end(), i) != includes.end()) { + if (std::find(userDirs.begin(), userDirs.end(), i) != userDirs.end()) { dirs.push_back(i); } } -- cgit v0.12 From b0b820ea39fe4edaf0672ba899a7042ef93a20d2 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 25 Jul 2018 12:45:10 +0200 Subject: cmLocalGenerator: Extend the functionality of ``GetIncludeDirectories()`` What ``cmLocalGenerator::GetIncludeDirectories`` does ----------------------------------------------------- In general it concatenates the 1. ``target->GetIncludeDirectories(LANG)`` and the 2. ``CMAKE__STANDARD_INCLUDE_DIRECTORIES``. Additionally it performs some sorting and special treatment of the - ``CMAKE__IMPLICIT_INCLUDE_DIRECTORIES``. By default all ``CMAKE__IMPLICIT_INCLUDE_DIRECTORIES`` are stripped from the result list. When explicitly requested (by setting ``stripImplicitInclDirs=false``) *some* implicit directories are appended to the result list. The implicit directories that *are* appended are those that were requested to be included by 1. ``target->GetIncludeDirectories(LANG)`` or 2. ``CMAKE__STANDARD_INCLUDE_DIRECTORIES``. All other implicit directories are still stripped from the result list. The reason to not simply append all implicit directories is that Qt4's moc has problems to parse some headers that might be found in the implicit system include directories (See commit d2536579d51e77827b8e55f39123316324314781 and [QTBUG-28045](https://bugreports.qt.io/browse/QTBUG-28045) ). That has been solved in Qt5's moc though. Extension request to ``cmLocalGenerator::GetIncludeDirectories`` ---------------------------------------------------------------- For Qt5's moc we like to have an option that allows to append *all* implict include directories to the result list, not just those that were user requested. Changes to ``cmLocalGenerator::GetIncludeDirectories`` ------------------------------------------------------ - Shorten the function parameter name ``stripImplicitInclDirs`` to ``stripImplicitDirs``. - Add new boolean function parameter ``appendAllImplicitDirs`` with a default value ``false``. The old default behavior of the function stays the same, but a specialized behavior can be requested by AUTOMOC for Qt4/Qt5 respectively. --- Source/cmLocalGenerator.cxx | 31 ++++++++++++++++++++++--------- Source/cmLocalGenerator.h | 10 ++++++++-- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 3df701e..647697a 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -844,7 +844,8 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, cmGeneratorTarget const* target, const std::string& lang, const std::string& config, - bool stripImplicitInclDirs) const + bool stripImplicitDirs, + bool appendAllImplicitDirs) const { // Do not repeat an include path. std::set emitted; @@ -898,12 +899,12 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, std::vector impDirVec; cmSystemTools::ExpandListArgument(value, impDirVec); for (std::string const& i : impDirVec) { - std::string d = rootPath + i; - cmSystemTools::ConvertToUnixSlashes(d); - emitted.insert(std::move(d)); - if (!stripImplicitInclDirs) { - implicitDirs.push_back(i); + { + std::string d = rootPath + i; + cmSystemTools::ConvertToUnixSlashes(d); + emitted.insert(std::move(d)); } + implicitDirs.push_back(i); } } } @@ -958,9 +959,21 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, } } - for (std::string const& i : implicitDirs) { - if (std::find(userDirs.begin(), userDirs.end(), i) != userDirs.end()) { - dirs.push_back(i); + if (!stripImplicitDirs) { + if (!appendAllImplicitDirs) { + // Append only those implicit directories that were requested by the user + for (std::string const& i : implicitDirs) { + if (std::find(userDirs.begin(), userDirs.end(), i) != userDirs.end()) { + dirs.push_back(i); + } + } + } else { + // Append all implicit directories + for (std::string const& i : implicitDirs) { + if (std::find(dirs.begin(), dirs.end(), i) == dirs.end()) { + dirs.push_back(i); + } + } } } } diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 9ba62cc..52f0396 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -237,12 +237,18 @@ public: return true; } - /** Get the include flags for the current makefile and language. */ + /** @brief Get the include directories for the current makefile and language. + * @arg stripImplicitDirs Strip all directories found in + * CMAKE__IMPLICIT_INCLUDE_DIRECTORIES from the result. + * @arg appendAllImplicitDirs Append all directories found in + * CMAKE__IMPLICIT_INCLUDE_DIRECTORIES to the result. + */ void GetIncludeDirectories(std::vector& dirs, cmGeneratorTarget const* target, const std::string& lang = "C", const std::string& config = "", - bool stripImplicitInclDirs = true) const; + bool stripImplicitDirs = true, + bool appendAllImplicitDirs = false) const; void AddCompileOptions(std::string& flags, cmGeneratorTarget* target, const std::string& lang, const std::string& config); void AddCompileDefinitions(std::set& defines, -- cgit v0.12