From cd33bfcad57eca7c32d3f8e3260d9a6682c5d516 Mon Sep 17 00:00:00 2001 From: Deniz Bahadir Date: Thu, 22 Oct 2020 23:00:49 +0200 Subject: add_custom_command: Properly recognize if sources depend on config Fixes: #21349 --- Source/cmGeneratorTarget.cxx | 17 +++++++++++------ Tests/ConfigSources/CMakeLists.txt | 13 +++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index bdea9fa..3560739 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -3098,12 +3098,17 @@ void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc) } // Check for target references in generator expressions. - for (std::string const& cl : cCmdLine) { - const std::unique_ptr cge = ge.Parse(cl); - cge->SetQuiet(true); - cge->Evaluate(this->GeneratorTarget->GetLocalGenerator(), ""); - std::set geTargets = cge->GetTargets(); - targets.insert(geTargets.begin(), geTargets.end()); + std::vector const& configs = + this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); + for (std::string const& c : configs) { + for (std::string const& cl : cCmdLine) { + const std::unique_ptr cge = + ge.Parse(cl); + cge->SetQuiet(true); + cge->Evaluate(this->GeneratorTarget->GetLocalGenerator(), c); + std::set geTargets = cge->GetTargets(); + targets.insert(geTargets.begin(), geTargets.end()); + } } } diff --git a/Tests/ConfigSources/CMakeLists.txt b/Tests/ConfigSources/CMakeLists.txt index 7b1a312..1db00cc 100644 --- a/Tests/ConfigSources/CMakeLists.txt +++ b/Tests/ConfigSources/CMakeLists.txt @@ -91,3 +91,16 @@ target_compile_definitions(ObjLibFromGeneratedSources PRIVATE OBJ_SHARED) target_sources(ObjLibFromGeneratedSources PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/config_$.cpp) add_library(SharedLibFromObjLibFromGeneratedSources SHARED shared.cpp) target_link_libraries(SharedLibFromObjLibFromGeneratedSources PRIVATE ObjLibFromGeneratedSources) + + +# --------------------------------------------------------------------------- +# Make sure that additional build-events do not confuse CMake when using generated files. +add_library(SharedLibFromGeneratedSources SHARED) +set_property(TARGET SharedLibFromGeneratedSources PROPERTY POSITION_INDEPENDENT_CODE 1) +target_sources(SharedLibFromGeneratedSources PRIVATE + shared.cpp + ${CMAKE_CURRENT_BINARY_DIR}/config_$.cpp + ) +add_custom_command(TARGET SharedLibFromGeneratedSources POST_BUILD + COMMAND "${CMAKE_COMMAND}" "-E" "echo" "$" + ) -- cgit v0.12