1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmGccDepfileReader.h"
11 #include "cmGccDepfileLexerHelper.h"
12 #include "cmStringAlgorithms.h"
13 #include "cmSystemTools.h"
15 cm::optional<cmGccDepfileContent> cmReadGccDepfile(
16 const char* filePath, const std::string& prefix,
17 GccDepfilePrependPaths prependPaths)
19 cmGccDepfileLexerHelper helper;
20 if (!helper.readFile(filePath)) {
23 auto deps = cm::make_optional(std::move(helper).extractContent());
25 for (auto& dep : *deps) {
26 for (auto& rule : dep.rules) {
27 if (prependPaths == GccDepfilePrependPaths::All && !prefix.empty() &&
28 !cmSystemTools::FileIsFullPath(rule)) {
29 rule = cmStrCat(prefix, '/', rule);
31 if (cmSystemTools::FileIsFullPath(rule)) {
32 rule = cmSystemTools::CollapseFullPath(rule);
34 cmSystemTools::ConvertToLongPath(rule);
36 for (auto& path : dep.paths) {
37 if (!prefix.empty() && !cmSystemTools::FileIsFullPath(path)) {
38 path = cmStrCat(prefix, '/', path);
40 if (cmSystemTools::FileIsFullPath(path)) {
41 path = cmSystemTools::CollapseFullPath(path);
43 cmSystemTools::ConvertToLongPath(path);