summaryrefslogtreecommitdiffstats
path: root/Source/cmLocalUnixMakefileGenerator3.cxx
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2020-11-23 10:51:11 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2020-11-28 15:02:58 (GMT)
commitb6068ce407e541b13fc0484bc6b84e896c9913e8 (patch)
treefc30dd518d39f020bfaf75fb01044177a2ce1635 /Source/cmLocalUnixMakefileGenerator3.cxx
parent3401403f69033446a5dcefd60dd8c375eaa58a44 (diff)
downloadCMake-b6068ce407e541b13fc0484bc6b84e896c9913e8.zip
CMake-b6068ce407e541b13fc0484bc6b84e896c9913e8.tar.gz
CMake-b6068ce407e541b13fc0484bc6b84e896c9913e8.tar.bz2
Refactoring: enhance include file filtering
In preparation of support of 'CMAKE_DEPENDS_IN_PROJECT_ONLY' when dependencies are generated by the compiler.
Diffstat (limited to 'Source/cmLocalUnixMakefileGenerator3.cxx')
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.cxx38
1 files changed, 14 insertions, 24 deletions
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
index e06dfac..3654e8f 100644
--- a/Source/cmLocalUnixMakefileGenerator3.cxx
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -9,12 +9,14 @@
#include <utility>
#include <cm/memory>
+#include <cm/string_view>
#include <cm/vector>
#include <cmext/algorithm>
#include "cmsys/FStream.hxx"
#include "cmsys/Terminal.h"
+#include "cmCMakePath.h"
#include "cmCustomCommand.h" // IWYU pragma: keep
#include "cmCustomCommandGenerator.h"
#include "cmFileTimeCache.h"
@@ -1742,44 +1744,32 @@ class NotInProjectDir
{
public:
// Constructor with the source and binary directory's path
- NotInProjectDir(std::string sourceDir, std::string binaryDir)
- : SourceDir(std::move(sourceDir))
- , BinaryDir(std::move(binaryDir))
+ NotInProjectDir(cm::string_view sourceDir, cm::string_view binaryDir)
+ : SourceDir(sourceDir)
+ , BinaryDir(binaryDir)
{
}
// Operator evaluating the predicate
- bool operator()(const std::string& path) const
+ bool operator()(const std::string& p) const
{
+ auto path = cmCMakePath(p).Normal();
+
// Keep all relative paths:
- if (!cmSystemTools::FileIsFullPath(path)) {
+ if (path.IsRelative()) {
return false;
}
// If it's an absolute path, check if it starts with the source
// directory:
- return (
- !(IsInDirectory(SourceDir, path) || IsInDirectory(BinaryDir, path)));
+ return !(cmCMakePath(SourceDir).IsPrefix(path) ||
+ cmCMakePath(BinaryDir).IsPrefix(path));
}
private:
- // Helper function used by the predicate
- static bool IsInDirectory(const std::string& baseDir,
- const std::string& testDir)
- {
- // First check if the test directory "starts with" the base directory:
- if (!cmHasPrefix(testDir, baseDir)) {
- return false;
- }
- // If it does, then check that it's either the same string, or that the
- // next character is a slash:
- return ((testDir.size() == baseDir.size()) ||
- (testDir[baseDir.size()] == '/'));
- }
-
// The path to the source directory
- std::string SourceDir;
+ cm::string_view SourceDir;
// The path to the binary directory
- std::string BinaryDir;
+ cm::string_view BinaryDir;
};
}
@@ -1862,7 +1852,7 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
this->GetIncludeDirectories(includes, target, implicitLang.first,
this->GetConfigName());
- std::string binaryDir = this->GetState()->GetBinaryDirectory();
+ std::string const& binaryDir = this->GetState()->GetBinaryDirectory();
if (this->Makefile->IsOn("CMAKE_DEPENDS_IN_PROJECT_ONLY")) {
std::string const& sourceDir = this->GetState()->GetSourceDirectory();
cm::erase_if(includes, ::NotInProjectDir(sourceDir, binaryDir));