add_custom_command(DEPFILE): avoid duplicate entries in dependencies

Fixes: #26399
This commit is contained in:
Marc Chevrier
2024-10-25 10:29:03 +02:00
parent bd51803761
commit 8979e7aaab
2 changed files with 11 additions and 7 deletions

View File

@@ -4,7 +4,6 @@
#include "cmDependsCompiler.h"
#include <algorithm>
#include <iterator>
#include <map>
#include <string>
#include <unordered_set>
@@ -111,13 +110,9 @@ bool cmDependsCompiler::CheckDependencies(
// copy depends for each target, except first one, which can be
// moved
for (auto index = entry.rules.size() - 1; index > 0; --index) {
auto& rule_deps = dependencies[entry.rules[index]];
rule_deps.insert(rule_deps.end(), depends.cbegin(),
depends.cend());
dependencies[entry.rules[index]] = depends;
}
auto& rule_deps = dependencies[entry.rules.front()];
std::move(depends.cbegin(), depends.cend(),
std::back_inserter(rule_deps));
dependencies[entry.rules.front()] = std::move(depends);
}
} else {
if (format == "msvc"_s) {

View File

@@ -77,5 +77,14 @@ if(check_step EQUAL 3)
\"${CMAKE_BINARY_DIR}/step3.timestamp|$<TARGET_FILE:subexe>\"
\"${CMAKE_BINARY_DIR}/step3.timestamp|$<TARGET_FILE:sublib>\"
)
if (RunCMake_GENERATOR MATCHES \"Make\")
file(STRINGS \"${CMAKE_BINARY_DIR}/CMakeFiles/topcc.dir/compiler_depend.internal\" deps REGEX \"^.*topccdep\\\\.txt$\")
list(LENGTH deps count)
if (NOT count EQUAL 1)
string(APPEND RunCMake_TEST_FAILED \"dependencies are duplicated\\n\")
set(RunCMake_TEST_FAILED \"\${RunCMake_TEST_FAILED}\" PARENT_SCOPE)
endif()
endif()
endif()
")