mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 13:20:47 -06:00
Merge topic 'per-config-source-TARGET_FILE' into release-3.19
cd33bfcad5 add_custom_command: Properly recognize if sources depend on config
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5410
This commit is contained in:
@@ -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<cmCompiledGeneratorExpression> cge = ge.Parse(cl);
|
||||
cge->SetQuiet(true);
|
||||
cge->Evaluate(this->GeneratorTarget->GetLocalGenerator(), "");
|
||||
std::set<cmGeneratorTarget*> geTargets = cge->GetTargets();
|
||||
targets.insert(geTargets.begin(), geTargets.end());
|
||||
std::vector<std::string> const& configs =
|
||||
this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
|
||||
for (std::string const& c : configs) {
|
||||
for (std::string const& cl : cCmdLine) {
|
||||
const std::unique_ptr<cmCompiledGeneratorExpression> cge =
|
||||
ge.Parse(cl);
|
||||
cge->SetQuiet(true);
|
||||
cge->Evaluate(this->GeneratorTarget->GetLocalGenerator(), c);
|
||||
std::set<cmGeneratorTarget*> geTargets = cge->GetTargets();
|
||||
targets.insert(geTargets.begin(), geTargets.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,3 +91,16 @@ target_compile_definitions(ObjLibFromGeneratedSources PRIVATE OBJ_SHARED)
|
||||
target_sources(ObjLibFromGeneratedSources PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/config_$<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_$<CONFIG>.cpp
|
||||
)
|
||||
add_custom_command(TARGET SharedLibFromGeneratedSources POST_BUILD
|
||||
COMMAND "${CMAKE_COMMAND}" "-E" "echo" "$<TARGET_FILE:SharedLibFromGeneratedSources>"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user