mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 16:32:14 -06:00
Fix per-config sources in multi-config generators when first config adds none
Since commit b1c3ae33ea (cmTarget: Short-circuit language computation if
context independent., 2014-04-09, v3.1.0-rc1~669^2~1) we've tried to
avoid repeating computation of the list of sources for a target for
every configuration in the case that a per-config source (or object
library) contributes zero sources. However, it is possible that an
entry contributes zero sources in the first configuration processed but
at least one source in other configurations.
Fixes: #25400
This commit is contained in:
@@ -1833,32 +1833,31 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
|
||||
AddInterfaceEntries(this, config, "INTERFACE_SOURCES", std::string(),
|
||||
&dagChecker, linkInterfaceSourcesEntries,
|
||||
IncludeRuntimeInterface::No, LinkInterfaceFor::Usage);
|
||||
std::vector<std::string>::size_type numFilesBefore = files.size();
|
||||
bool contextDependentInterfaceSources = processSources(
|
||||
this, linkInterfaceSourcesEntries, files, uniqueSrcs, debugSources);
|
||||
|
||||
// Collect TARGET_OBJECTS of direct object link-dependencies.
|
||||
bool contextDependentObjects = false;
|
||||
std::vector<std::string>::size_type numFilesBefore2 = files.size();
|
||||
if (this->GetType() != cmStateEnums::OBJECT_LIBRARY) {
|
||||
EvaluatedTargetPropertyEntries linkObjectsEntries;
|
||||
AddObjectEntries(this, config, &dagChecker, linkObjectsEntries);
|
||||
contextDependentObjects = processSources(this, linkObjectsEntries, files,
|
||||
uniqueSrcs, debugSources);
|
||||
// Note that for imported targets or multi-config generators supporting
|
||||
// cross-config builds the paths to the object files must be per-config,
|
||||
// so contextDependentObjects will be true here even if object libraries
|
||||
// are specified without per-config generator expressions.
|
||||
}
|
||||
|
||||
// Collect this target's file sets.
|
||||
std::vector<std::string>::size_type numFilesBefore3 = files.size();
|
||||
EvaluatedTargetPropertyEntries fileSetEntries;
|
||||
AddFileSetEntries(this, config, &dagChecker, fileSetEntries);
|
||||
bool contextDependentFileSets =
|
||||
processSources(this, fileSetEntries, files, uniqueSrcs, debugSources);
|
||||
|
||||
// Determine if sources are context-dependent or not.
|
||||
if (!contextDependentDirectSources &&
|
||||
!(contextDependentInterfaceSources && numFilesBefore < files.size()) &&
|
||||
!(contextDependentObjects && numFilesBefore2 < files.size()) &&
|
||||
!(contextDependentFileSets && numFilesBefore3 < files.size())) {
|
||||
if (!contextDependentDirectSources && !contextDependentInterfaceSources &&
|
||||
!contextDependentObjects && !contextDependentFileSets) {
|
||||
this->SourcesAreContextDependent = Tribool::False;
|
||||
} else {
|
||||
this->SourcesAreContextDependent = Tribool::True;
|
||||
|
||||
@@ -154,7 +154,15 @@ else()
|
||||
endif()
|
||||
add_library(OneConfigOnly OBJECT "$<$<CONFIG:${one_config}>:${CMAKE_CURRENT_SOURCE_DIR}/iface_src.cpp>")
|
||||
set_property(TARGET OneConfigOnly PROPERTY LINKER_LANGUAGE CXX)
|
||||
add_executable(ConfigSourcesUseOne main_one_config.cpp)
|
||||
target_compile_definitions(ConfigSourcesUseOne PRIVATE "$<$<CONFIG:${one_config}>:CFG_ONE>")
|
||||
target_link_libraries(ConfigSourcesUseOne PRIVATE "$<$<CONFIG:${one_config}>:OneConfigOnly>")
|
||||
|
||||
add_library(OneConfigOnlyIface INTERFACE)
|
||||
target_sources(OneConfigOnlyIface INTERFACE "$<$<CONFIG:${one_config}>:${CMAKE_CURRENT_SOURCE_DIR}/iface_src.cpp>")
|
||||
add_executable(ConfigSourcesUseOneIface main_one_config.cpp)
|
||||
target_compile_definitions(ConfigSourcesUseOneIface PRIVATE "$<$<CONFIG:${one_config}>:CFG_ONE>")
|
||||
target_link_libraries(ConfigSourcesUseOneIface PRIVATE "$<$<CONFIG:${one_config}>:OneConfigOnlyIface>")
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Makes sure that each configuration uses the correct generated file.
|
||||
|
||||
8
Tests/ConfigSources/main_one_config.cpp
Normal file
8
Tests/ConfigSources/main_one_config.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "iface.h"
|
||||
int main()
|
||||
{
|
||||
#ifdef CFG_ONE
|
||||
iface_src();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user