From 8979e7aaab8e736b6c078a489dcdd6e6fe879c9d Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Fri, 25 Oct 2024 10:29:03 +0200 Subject: [PATCH] add_custom_command(DEPFILE): avoid duplicate entries in dependencies Fixes: #26399 --- Source/cmDependsCompiler.cxx | 9 ++------- Tests/RunCMake/BuildDepends/CustomCommandDepfile.cmake | 9 +++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Source/cmDependsCompiler.cxx b/Source/cmDependsCompiler.cxx index 17ec43bf14..408f19f5c7 100644 --- a/Source/cmDependsCompiler.cxx +++ b/Source/cmDependsCompiler.cxx @@ -4,7 +4,6 @@ #include "cmDependsCompiler.h" #include -#include #include #include #include @@ -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) { diff --git a/Tests/RunCMake/BuildDepends/CustomCommandDepfile.cmake b/Tests/RunCMake/BuildDepends/CustomCommandDepfile.cmake index c3725a4d1a..331d21d828 100644 --- a/Tests/RunCMake/BuildDepends/CustomCommandDepfile.cmake +++ b/Tests/RunCMake/BuildDepends/CustomCommandDepfile.cmake @@ -77,5 +77,14 @@ if(check_step EQUAL 3) \"${CMAKE_BINARY_DIR}/step3.timestamp|$\" \"${CMAKE_BINARY_DIR}/step3.timestamp|$\" ) + + 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() ")