c++modules: Avoid adding file to multiple file sets in synthetic targets

The introduction of file set type `SOURCES` can raise error on a
duplicate file due to erroneous synthetic targets definition.
This commit is contained in:
Marc Chevrier authored and Brad King committed 2026-04-02 11:32:52 -04:00
1 parent f5fc584bff
commit b001bc735a
4 files changed
+14 -1

No files matched your search

+2 -1
View File
@@ -5433,7 +5433,8 @@ bool cmGeneratorTarget::DiscoverSyntheticTargets(
// Copy file sets.
{
for (auto const* gfs : gt->GetAllFileSets()) {
for (auto const* gfs :
gt->GetInterfaceFileSets(cm::FileSetMetadata::CXX_MODULES)) {
auto* newFs =
tgt
->GetOrCreateFileSet(gfs->GetName(), gfs->GetType(),
@@ -164,6 +164,8 @@ if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION)
run_cxx_module_test(file-sets-with-dot)
run_cxx_module_test(vs-without-flags)
run_cxx_module_test(library library-static -DBUILD_SHARED_LIBS=OFF)
run_cxx_module_test(library library-static-file-set-SOURCES -DBUILD_SHARED_LIBS=OFF
-DWITH_FILE_SET_SOURCES=ON)
run_cxx_module_test(unity-build)
run_cxx_module_test(object-library)
run_cxx_module_test(generated)
@@ -23,6 +23,13 @@ target_sources(library
importable.cxx)
target_compile_features(library PUBLIC cxx_std_20)
if(WITH_FILE_SET_SOURCES)
target_sources(library
PUBLIC
FILE_SET SOURCES
FILES src.cpp)
endif()
add_executable(exe)
target_link_libraries(exe PRIVATE library)
target_sources(exe
@@ -0,0 +1,3 @@
void src()
{
}