summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-11-14 14:09:05 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-11-14 14:09:15 (GMT)
commit380b324103da020d474b36db20595fff4072f895 (patch)
treec1979a867a84001da744be3e26f0102fe90f1cfc
parent8743ec0270843e75b50335655fba94c424bb9a99 (diff)
parent16c5977504cfcc25b6ffd331c493841d1e6dc1ec (diff)
downloadCMake-380b324103da020d474b36db20595fff4072f895.zip
CMake-380b324103da020d474b36db20595fff4072f895.tar.gz
CMake-380b324103da020d474b36db20595fff4072f895.tar.bz2
Merge topic 'sources-per-config'
16c5977504 Fix per-config sources in multi-config generators when first config adds none Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !8971
-rw-r--r--Source/cmGeneratorTarget.cxx13
-rw-r--r--Tests/ConfigSources/CMakeLists.txt8
-rw-r--r--Tests/ConfigSources/main_one_config.cpp8
3 files changed, 22 insertions, 7 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index d24867f..adca9ce 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -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;
diff --git a/Tests/ConfigSources/CMakeLists.txt b/Tests/ConfigSources/CMakeLists.txt
index 38475f8..770afb3 100644
--- a/Tests/ConfigSources/CMakeLists.txt
+++ b/Tests/ConfigSources/CMakeLists.txt
@@ -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.
diff --git a/Tests/ConfigSources/main_one_config.cpp b/Tests/ConfigSources/main_one_config.cpp
new file mode 100644
index 0000000..318944b
--- /dev/null
+++ b/Tests/ConfigSources/main_one_config.cpp
@@ -0,0 +1,8 @@
+#include "iface.h"
+int main()
+{
+#ifdef CFG_ONE
+ iface_src();
+#endif
+ return 0;
+}