diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2018-01-09 08:40:48 -0500 |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2018-01-10 11:21:11 -0500 |
commit | b0716fbcc5be83ecd082e8b6d101f1137d6f16f8 (patch) | |
tree | f93425efeb3e11cb4cd2af9c771e1b5632571fa9 /Source | |
parent | ddc4f9a3c05fa24240fde1ba6c0ab28b7d2e91ea (diff) | |
download | cmake-b0716fbcc5be83ecd082e8b6d101f1137d6f16f8.tar.gz |
cmSourceFileLocation: allow skipping ambiguous extensions
The ambiguous extension logic is an old behavior that ends up taking
lots of extra compute cycles to execute. This is triggered by various
CMake codepaths which pass extension-less paths down when CMake actually
knows that they are not ambiguous. These codepaths will be indicated in
upcoming changes.
Various APIs have gained a cmSourceFileLocationKind parameter, but they
are all optional and default to the existing behavior.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 17 | ||||
-rw-r--r-- | Source/cmMakefile.h | 15 | ||||
-rw-r--r-- | Source/cmSourceFile.cxx | 5 | ||||
-rw-r--r-- | Source/cmSourceFile.h | 4 | ||||
-rw-r--r-- | Source/cmSourceFileLocation.cxx | 10 | ||||
-rw-r--r-- | Source/cmSourceFileLocation.h | 6 | ||||
-rw-r--r-- | Source/cmSourceFileLocationKind.h | 15 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 1 |
9 files changed, 56 insertions, 18 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 7031d5ad08..1b46377f84 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -327,6 +327,7 @@ set(SRCS cmSourceFile.h cmSourceFileLocation.cxx cmSourceFileLocation.h + cmSourceFileLocationKind.h cmSourceGroup.cxx cmSourceGroup.h cmState.cxx diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index d069a5c935..5e32e153f3 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -3132,9 +3132,10 @@ void cmMakefile::SetArgcArgv(const std::vector<std::string>& args) } } -cmSourceFile* cmMakefile::GetSource(const std::string& sourceName) const +cmSourceFile* cmMakefile::GetSource(const std::string& sourceName, + cmSourceFileLocationKind kind) const { - cmSourceFileLocation sfl(this, sourceName); + cmSourceFileLocation sfl(this, sourceName, kind); auto name = this->GetCMakeInstance()->StripExtension(sfl.GetName()); #if defined(_WIN32) || defined(__APPLE__) name = cmSystemTools::LowerCase(name); @@ -3151,9 +3152,10 @@ cmSourceFile* cmMakefile::GetSource(const std::string& sourceName) const } cmSourceFile* cmMakefile::CreateSource(const std::string& sourceName, - bool generated) + bool generated, + cmSourceFileLocationKind kind) { - cmSourceFile* sf = new cmSourceFile(this, sourceName); + cmSourceFile* sf = new cmSourceFile(this, sourceName, kind); if (generated) { sf->SetProperty("GENERATED", "1"); } @@ -3170,12 +3172,13 @@ cmSourceFile* cmMakefile::CreateSource(const std::string& sourceName, } cmSourceFile* cmMakefile::GetOrCreateSource(const std::string& sourceName, - bool generated) + bool generated, + cmSourceFileLocationKind kind) { - if (cmSourceFile* esf = this->GetSource(sourceName)) { + if (cmSourceFile* esf = this->GetSource(sourceName, kind)) { return esf; } - return this->CreateSource(sourceName, generated); + return this->CreateSource(sourceName, generated, kind); } void cmMakefile::AddTargetObject(std::string const& tgtName, diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index c92424b085..f06e2ff45c 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -20,6 +20,7 @@ #include "cmListFileCache.h" #include "cmNewLineStyle.h" #include "cmPolicies.h" +#include "cmSourceFileLocationKind.h" #include "cmStateSnapshot.h" #include "cmStateTypes.h" #include "cmTarget.h" @@ -387,22 +388,26 @@ public: /** Get a cmSourceFile pointer for a given source name, if the name is * not found, then a null pointer is returned. */ - cmSourceFile* GetSource(const std::string& sourceName) const; + cmSourceFile* GetSource( + const std::string& sourceName, + cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous) const; /** Create the source file and return it. generated * indicates if it is a generated file, this is used in determining * how to create the source file instance e.g. name */ - cmSourceFile* CreateSource(const std::string& sourceName, - bool generated = false); + cmSourceFile* CreateSource( + const std::string& sourceName, bool generated = false, + cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous); /** Get a cmSourceFile pointer for a given source name, if the name is * not found, then create the source file and return it. generated * indicates if it is a generated file, this is used in determining * how to create the source file instance e.g. name */ - cmSourceFile* GetOrCreateSource(const std::string& sourceName, - bool generated = false); + cmSourceFile* GetOrCreateSource( + const std::string& sourceName, bool generated = false, + cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous); void AddTargetObject(std::string const& tgtName, std::string const& objFile); diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index d5475d2196..215f9743bf 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -12,8 +12,9 @@ #include "cmSystemTools.h" #include "cmake.h" -cmSourceFile::cmSourceFile(cmMakefile* mf, const std::string& name) - : Location(mf, name) +cmSourceFile::cmSourceFile(cmMakefile* mf, const std::string& name, + cmSourceFileLocationKind kind) + : Location(mf, name, kind) { this->CustomCommand = nullptr; this->FindFullPathFailed = false; diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index da722eaf20..ab40da3d35 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -27,7 +27,9 @@ public: * Construct with the makefile storing the source and the initial * name referencing it. */ - cmSourceFile(cmMakefile* mf, const std::string& name); + cmSourceFile( + cmMakefile* mf, const std::string& name, + cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous); ~cmSourceFile(); diff --git a/Source/cmSourceFileLocation.cxx b/Source/cmSourceFileLocation.cxx index 6add7b3040..5558ef3404 100644 --- a/Source/cmSourceFileLocation.cxx +++ b/Source/cmSourceFileLocation.cxx @@ -27,7 +27,8 @@ cmSourceFileLocation::cmSourceFileLocation(const cmSourceFileLocation& loc) } cmSourceFileLocation::cmSourceFileLocation(cmMakefile const* mf, - const std::string& name) + const std::string& name, + cmSourceFileLocationKind kind) : Makefile(mf) { this->AmbiguousDirectory = !cmSystemTools::FileIsFullPath(name.c_str()); @@ -37,7 +38,12 @@ cmSourceFileLocation::cmSourceFileLocation(cmMakefile const* mf, this->Directory = cmSystemTools::CollapseFullPath(this->Directory); } this->Name = cmSystemTools::GetFilenameName(name); - this->UpdateExtension(name); + if (kind == cmSourceFileLocationKind::Known) { + this->DirectoryUseSource(); + this->AmbiguousExtension = false; + } else { + this->UpdateExtension(name); + } } void cmSourceFileLocation::Update(cmSourceFileLocation const& loc) diff --git a/Source/cmSourceFileLocation.h b/Source/cmSourceFileLocation.h index a6819bdc83..f325e547a4 100644 --- a/Source/cmSourceFileLocation.h +++ b/Source/cmSourceFileLocation.h @@ -7,6 +7,8 @@ #include <string> +#include "cmSourceFileLocationKind.h" + class cmMakefile; /** \class cmSourceFileLocation @@ -26,7 +28,9 @@ public: * Construct for a source file created in a given cmMakefile * instance with an initial name. */ - cmSourceFileLocation(cmMakefile const* mf, const std::string& name); + cmSourceFileLocation( + cmMakefile const* mf, const std::string& name, + cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous); cmSourceFileLocation(); cmSourceFileLocation(const cmSourceFileLocation& loc); diff --git a/Source/cmSourceFileLocationKind.h b/Source/cmSourceFileLocationKind.h new file mode 100644 index 0000000000..dd4c6dd4fe --- /dev/null +++ b/Source/cmSourceFileLocationKind.h @@ -0,0 +1,15 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmSourceFileLocationKind_h +#define cmSourceFileLocationKind_h + +enum class cmSourceFileLocationKind +{ + // The location is user-specified and may be ambiguous. + Ambiguous, + // The location is known to be at the given location; do not try to guess at + // extensions or absolute path. + Known +}; + +#endif diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index de23b08f59..55b2c518c0 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -23,6 +23,7 @@ #include "cmProperty.h" #include "cmSourceFile.h" #include "cmSourceFileLocation.h" +#include "cmSourceFileLocationKind.h" #include "cmState.h" #include "cmStateDirectory.h" #include "cmStateSnapshot.h" |