summaryrefslogtreecommitdiffstats
path: root/Source/cmGccDepfileReader.cxx
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2021-07-01 09:47:52 (GMT)
committerBrad King <brad.king@kitware.com>2021-07-02 13:24:57 (GMT)
commit6a6efdcaedc6f87fbafd40af5305cabdced450c4 (patch)
tree12a340462fe5feb9db32a03e8627caea0f0ca41d /Source/cmGccDepfileReader.cxx
parentefa5e1f367ac76cb7aa919929ece1f4799cdc4b2 (diff)
downloadCMake-6a6efdcaedc6f87fbafd40af5305cabdced450c4.zip
CMake-6a6efdcaedc6f87fbafd40af5305cabdced450c4.tar.gz
CMake-6a6efdcaedc6f87fbafd40af5305cabdced450c4.tar.bz2
Makefiles: Normalize compiler-generated depfile paths
Even though Makefile generators pass source files and include directories by absolute path to the compiler, the compiler may generate depfile paths relative to the current working directory. For example, `ccache` with `CCACHE_BASEDIR` may transform paths this way. When reading a depfile, convert relative dependencies to absolute paths before placing them in `compiler_depend.make`, which is later evaluated in the top-level build directory. Fixes: #22364
Diffstat (limited to 'Source/cmGccDepfileReader.cxx')
-rw-r--r--Source/cmGccDepfileReader.cxx8
1 files changed, 5 insertions, 3 deletions
diff --git a/Source/cmGccDepfileReader.cxx b/Source/cmGccDepfileReader.cxx
index 6436baa..d30dbc3 100644
--- a/Source/cmGccDepfileReader.cxx
+++ b/Source/cmGccDepfileReader.cxx
@@ -12,8 +12,9 @@
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
-cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath,
- const std::string& prefix)
+cm::optional<cmGccDepfileContent> cmReadGccDepfile(
+ const char* filePath, const std::string& prefix,
+ GccDepfilePrependPaths prependPaths)
{
cmGccDepfileLexerHelper helper;
if (!helper.readFile(filePath)) {
@@ -23,7 +24,8 @@ cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath,
for (auto& dep : *deps) {
for (auto& rule : dep.rules) {
- if (!prefix.empty() && !cmSystemTools::FileIsFullPath(rule)) {
+ if (prependPaths == GccDepfilePrependPaths::All && !prefix.empty() &&
+ !cmSystemTools::FileIsFullPath(rule)) {
rule = cmStrCat(prefix, '/', rule);
}
if (cmSystemTools::FileIsFullPath(rule)) {