From 167e903c15c7ab758e62609582764527a113baeb Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Fri, 6 Mar 2026 16:54:29 +0100 Subject: [PATCH] FILE_SET: enforce uniqueness of files A file should be unique for a target if specified as part of a file set. Issue: #27035 --- Help/command/target_sources.rst | 8 +++- Help/manual/cmake-policies.7.rst | 8 ++++ Help/policy/CMP0211.rst | 22 ++++++++++ .../dev/FILE_SET-enforce-files-unicity.rst | 5 +++ Source/cmDyndepCollation.cxx | 14 ------- Source/cmGeneratorFileSet.cxx | 14 +++++-- Source/cmGeneratorTarget_Sources.cxx | 42 +++++++++++++++---- Source/cmPolicies.h | 8 +++- .../duplicate-sources-stderr.txt | 8 ---- .../RunCMake/FileSetProperties/SOURCES.cmake | 18 ++++---- Tests/RunCMake/FileSetProperties/h1.h | 0 Tests/RunCMake/FileSetProperties/h2.h | 0 .../TargetPolicies/PolicyList-stderr.txt | 1 + .../target_sources/CMP0211-Common.cmake | 9 ++++ .../target_sources/CMP0211-NEW-result.txt | 1 + .../target_sources/CMP0211-NEW-stderr.txt | 14 +++++++ .../RunCMake/target_sources/CMP0211-NEW.cmake | 4 ++ .../RunCMake/target_sources/CMP0211-OLD.cmake | 4 ++ .../target_sources/CMP0211-WARN-stderr.txt | 23 ++++++++++ .../target_sources/CMP0211-WARN.cmake | 2 + .../FileSetDuplicateSource.cmake | 6 +++ .../target_sources/FileSetProperties.cmake | 12 +++--- .../target_sources/RunCMakeTest.cmake | 4 ++ Tests/RunCMake/target_sources/h4.h | 0 Tests/RunCMake/target_sources/h5.h | 0 25 files changed, 175 insertions(+), 52 deletions(-) create mode 100644 Help/policy/CMP0211.rst create mode 100644 Help/release/dev/FILE_SET-enforce-files-unicity.rst delete mode 100644 Tests/RunCMake/CXXModulesCompile/duplicate-sources-stderr.txt create mode 100644 Tests/RunCMake/FileSetProperties/h1.h create mode 100644 Tests/RunCMake/FileSetProperties/h2.h create mode 100644 Tests/RunCMake/target_sources/CMP0211-Common.cmake create mode 100644 Tests/RunCMake/target_sources/CMP0211-NEW-result.txt create mode 100644 Tests/RunCMake/target_sources/CMP0211-NEW-stderr.txt create mode 100644 Tests/RunCMake/target_sources/CMP0211-NEW.cmake create mode 100644 Tests/RunCMake/target_sources/CMP0211-OLD.cmake create mode 100644 Tests/RunCMake/target_sources/CMP0211-WARN-stderr.txt create mode 100644 Tests/RunCMake/target_sources/CMP0211-WARN.cmake create mode 100644 Tests/RunCMake/target_sources/FileSetDuplicateSource.cmake create mode 100644 Tests/RunCMake/target_sources/h4.h create mode 100644 Tests/RunCMake/target_sources/h5.h diff --git a/Help/command/target_sources.rst b/Help/command/target_sources.rst index 5fa4ef1988..158e69b881 100644 --- a/Help/command/target_sources.rst +++ b/Help/command/target_sources.rst @@ -77,7 +77,13 @@ File Sets Adds a file set to a target, or adds files to an existing file set. Targets have zero or more named file sets. Each file set has a name, a type, a scope of ``INTERFACE``, ``PUBLIC``, or ``PRIVATE``, one or more base directories, and -files within those directories. The acceptable types include: +files within those directories. + +.. versionchanged:: 4.4 + A file may only belong to at most one file set in a target. See policy + :policy:`CMP0211`. + + The acceptable types include: ``HEADERS`` diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst index a6340a9f68..8188f93fa9 100644 --- a/Help/manual/cmake-policies.7.rst +++ b/Help/manual/cmake-policies.7.rst @@ -94,6 +94,14 @@ Supported Policies The following policies are supported. +Policies Introduced by CMake 4.4 +-------------------------------- + +.. toctree:: + :maxdepth: 1 + + CMP0211: A file may belong to at most one file set in a target. + Policies Introduced by CMake 4.3 -------------------------------- diff --git a/Help/policy/CMP0211.rst b/Help/policy/CMP0211.rst new file mode 100644 index 0000000000..4ef04c8c50 --- /dev/null +++ b/Help/policy/CMP0211.rst @@ -0,0 +1,22 @@ +CMP0211 +------- + +.. versionadded:: 4.4 + +A file may belong to at most one :ref:`file set ` in a target. + +In CMake 4.3 and below, it was possible to specify the same file +in multiple file sets in a target. In CMake 4.4 and above, a file +may belong to at most one file set in a target. This policy provides +compatibility for projects that have not been updated accordingly. + +The ``OLD`` behavior for this policy is to accept the same file in +multiple file sets in a target. The ``NEW`` behavior for this policy +is to accept a given file in at most one file set in a target. + +.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 4.4 +.. |WARNS_OR_DOES_NOT_WARN| replace:: + warns when a file is part of multiple file sets in a target +.. include:: include/STANDARD_ADVICE.rst + +.. include:: include/DEPRECATED.rst diff --git a/Help/release/dev/FILE_SET-enforce-files-unicity.rst b/Help/release/dev/FILE_SET-enforce-files-unicity.rst new file mode 100644 index 0000000000..30e4ac4556 --- /dev/null +++ b/Help/release/dev/FILE_SET-enforce-files-unicity.rst @@ -0,0 +1,5 @@ +FILE_SET-enforce-files-unicity +------------------------------ + +* A file may belong to at most one :ref:`file set ` in a target. + See policy :policy:`CMP0211`. diff --git a/Source/cmDyndepCollation.cxx b/Source/cmDyndepCollation.cxx index 527fdbf3dc..24e43d12c0 100644 --- a/Source/cmDyndepCollation.cxx +++ b/Source/cmDyndepCollation.cxx @@ -119,24 +119,11 @@ TdiSourceInfo CollationInformationSources(cmGeneratorTarget const* gt, } } - // Detect duplicate sources. - std::set visited_sources; - for (auto const& files_per_dir : files_per_dirs.first) { for (auto const& file : files_per_dir.second) { auto const full_file = cmSystemTools::CollapseFullPath(file); auto lookup = sf_map.find(full_file); if (lookup == sf_map.end()) { - if (visited_sources.count(full_file)) { - // Duplicate source; raise an author warning. - gt->Makefile->IssueMessage( - MessageType::AUTHOR_WARNING, - cmStrCat("Target \"", tgt->GetName(), "\" has source file\n ", - file, "\nin a \"FILE_SET TYPE ", - cm::FileSetMetadata::CXX_MODULES, - "\" multiple times.")); - continue; - } gt->Makefile->IssueMessage(MessageType::FATAL_ERROR, cmStrCat("Target \"", tgt->GetName(), "\" has source file\n ", file, @@ -146,7 +133,6 @@ TdiSourceInfo CollationInformationSources(cmGeneratorTarget const* gt, "scheduled for compilation.")); continue; } - visited_sources.insert(full_file); auto const* sf = lookup->second.first; CompileType const ct = lookup->second.second; diff --git a/Source/cmGeneratorFileSet.cxx b/Source/cmGeneratorFileSet.cxx index 76e041dd7b..483ae13bfc 100644 --- a/Source/cmGeneratorFileSet.cxx +++ b/Source/cmGeneratorFileSet.cxx @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -144,14 +145,19 @@ std::vector> const& cmGeneratorFileSet::GetFileEntries() const std::vector> const& cmGeneratorFileSet::CompileFileEntries() const { + std::unordered_set uniqueSrcs; + if (this->CompiledFileEntries.empty() && !this->FileSet->GetFileEntries().empty()) { for (auto const& entry : this->FileSet->GetFileEntries()) { for (auto const& ex : cmList{ entry.Value }) { - cmGeneratorExpression ge( - *this->FileSet->GetMakefile()->GetCMakeInstance(), entry.Backtrace); - auto cge = ge.Parse(ex); - this->CompiledFileEntries.push_back(std::move(cge)); + if (uniqueSrcs.insert(ex).second) { + cmGeneratorExpression ge( + *this->FileSet->GetMakefile()->GetCMakeInstance(), + entry.Backtrace); + auto cge = ge.Parse(ex); + this->CompiledFileEntries.push_back(std::move(cge)); + } } } } diff --git a/Source/cmGeneratorTarget_Sources.cxx b/Source/cmGeneratorTarget_Sources.cxx index 9f31bd4231..ad34864491 100644 --- a/Source/cmGeneratorTarget_Sources.cxx +++ b/Source/cmGeneratorTarget_Sources.cxx @@ -4,6 +4,8 @@ #include "cmGeneratorTarget.h" /* clang-format on */ +#include "cmConfigure.h" + #include #include #include @@ -34,6 +36,7 @@ #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" +#include "cmPolicies.h" #include "cmSourceFile.h" #include "cmSourceFileLocation.h" #include "cmSourceGroup.h" @@ -93,7 +96,7 @@ void AddFileSetEntries(cmGeneratorTarget const* headTarget, EvaluateTargetPropertyEntries(headTarget, context, dagChecker, sources); } -bool processSources(cmGeneratorTarget const* tgt, +bool processSources(cmGeneratorTarget const* tgt, std::string const& config, EvaluatedTargetPropertyEntries& entries, std::vector>& srcs, std::unordered_set& uniqueSrcs, @@ -155,6 +158,28 @@ bool processSources(cmGeneratorTarget const* tgt, if (debugSources) { usedSources += cmStrCat(" * ", src, '\n'); } + } else { + if (auto const* fileSet = + tgt->GetGeneratorFileSets()->GetFileSetForSource(config, src)) { + switch (tgt->GetPolicyStatusCMP0211()) { + case cmPolicies::WARN: + tgt->GetLocalGenerator()->IssueMessage( + MessageType::AUTHOR_WARNING, + cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0211), + "\nIn target \"", tgt->GetName(), "\" the file\n ", + src, "\nalready belongs to file set \"", + fileSet->GetName(), "\".")); + CM_FALLTHROUGH; + case cmPolicies::OLD: + break; + default: + tgt->GetLocalGenerator()->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("In target \"", tgt->GetName(), "\" the file\n ", + src, "\nalready belongs to file set \"", + fileSet->GetName(), "\".")); + } + } } } if (!usedSources.empty()) { @@ -193,23 +218,24 @@ std::vector> cmGeneratorTarget::GetSourceFilePaths( std::unordered_set uniqueSrcs; bool contextDependentDirectSources = - processSources(this, entries, files, uniqueSrcs, debugSources); + processSources(this, config, entries, files, uniqueSrcs, debugSources); // Collect INTERFACE_SOURCES of all direct link-dependencies. EvaluatedTargetPropertyEntries linkInterfaceSourcesEntries; AddInterfaceEntries(this, "INTERFACE_SOURCES", context, &dagChecker, linkInterfaceSourcesEntries, IncludeRuntimeInterface::No, UseTo::Compile); - bool contextDependentInterfaceSources = processSources( - this, linkInterfaceSourcesEntries, files, uniqueSrcs, debugSources); + bool contextDependentInterfaceSources = + processSources(this, config, linkInterfaceSourcesEntries, files, + uniqueSrcs, debugSources); // Collect TARGET_OBJECTS of direct object link-dependencies. bool contextDependentObjects = false; if (this->GetType() != cmStateEnums::OBJECT_LIBRARY) { EvaluatedTargetPropertyEntries linkObjectsEntries; AddObjectEntries(this, context, &dagChecker, linkObjectsEntries); - contextDependentObjects = processSources(this, linkObjectsEntries, files, - uniqueSrcs, debugSources); + contextDependentObjects = processSources(this, config, 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 @@ -243,8 +269,8 @@ std::vector> cmGeneratorTarget::GetSourceFilePaths( #endif }; bool contextDependentFileSets = - processSources(this, fileSetEntries, files, uniqueSrcs, debugSources, - processFileSetEntry); + processSources(this, config, fileSetEntries, files, uniqueSrcs, + debugSources, processFileSetEntry); // Determine if sources are context-dependent or not. if (!contextDependentDirectSources && !contextDependentInterfaceSources && diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 8afb04b1c1..3f54a1e1ac 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -629,7 +629,10 @@ class cmMakefile; 4, 3, 0, WARN) \ SELECT(POLICY, CMP0210, \ "CMAKE__LINK_FLAGS adds link flags to all target types.", 4, \ - 3, 0, WARN) + 3, 0, WARN) \ + SELECT(POLICY, CMP0211, \ + "A file may belong to at most one file set in a target.", 4, 4, 0, \ + WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ @@ -684,7 +687,8 @@ class cmMakefile; F(CMP0203) \ F(CMP0204) \ F(CMP0209) \ - F(CMP0210) + F(CMP0210) \ + F(CMP0211) #define CM_FOR_EACH_CUSTOM_COMMAND_POLICY(F) \ F(CMP0116) \ diff --git a/Tests/RunCMake/CXXModulesCompile/duplicate-sources-stderr.txt b/Tests/RunCMake/CXXModulesCompile/duplicate-sources-stderr.txt deleted file mode 100644 index 1dfe3d3688..0000000000 --- a/Tests/RunCMake/CXXModulesCompile/duplicate-sources-stderr.txt +++ /dev/null @@ -1,8 +0,0 @@ -CMake Warning \(dev\) in CMakeLists\.txt: - Target "duplicate_sources" has source file - - [^ -]*/Tests/RunCMake/CXXModulesCompile/duplicate-sources/duplicate\.cxx - - in a "FILE_SET TYPE CXX_MODULES" multiple times\. -This warning is for project developers\. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/FileSetProperties/SOURCES.cmake b/Tests/RunCMake/FileSetProperties/SOURCES.cmake index 376460d258..c6b36cfd4e 100644 --- a/Tests/RunCMake/FileSetProperties/SOURCES.cmake +++ b/Tests/RunCMake/FileSetProperties/SOURCES.cmake @@ -40,11 +40,11 @@ if(NOT srcs MATCHES "[^;]*bar.h;[^;]*foo.h$") endif() -target_sources(foo PRIVATE FILE_SET foo TYPE HEADERS FILES foo.h) +target_sources(foo PRIVATE FILE_SET foo TYPE HEADERS FILES h1.h) get_property(srcs FILE_SET foo TARGET foo PROPERTY SOURCES) -if(NOT srcs MATCHES ".*/foo.h$") - message(SEND_ERROR "wrong sources: '${srcs}' instead of 'foo.h'") +if(NOT srcs MATCHES ".*/h1.h$") + message(SEND_ERROR "wrong sources: '${srcs}' instead of 'h1.h'") endif() get_property(srcs FILE_SET foo TARGET foo PROPERTY INTERFACE_SOURCES) if(srcs) @@ -52,11 +52,11 @@ if(srcs) endif() -set_property(FILE_SET foo TARGET foo PROPERTY SOURCES bar.h) +set_property(FILE_SET foo TARGET foo PROPERTY SOURCES h2.h) get_property(srcs FILE_SET foo TARGET foo PROPERTY SOURCES) -if(NOT srcs MATCHES "[^;]*bar.h$") - message(SEND_ERROR "wrong sources: '${srcs}' instead of 'bar.h'") +if(NOT srcs MATCHES "[^;]*h2.h$") + message(SEND_ERROR "wrong sources: '${srcs}' instead of 'h2.h'") endif() get_property(srcs FILE_SET foo TARGET foo PROPERTY INTERFACE_SOURCES) if(srcs) @@ -64,11 +64,11 @@ if(srcs) endif() -set_property(FILE_SET foo TARGET foo PROPERTY INTERFACE_SOURCES foo.h) +set_property(FILE_SET foo TARGET foo PROPERTY INTERFACE_SOURCES h2.h) get_property(srcs FILE_SET foo TARGET foo PROPERTY SOURCES) -if(NOT srcs MATCHES "[^;]*bar.h$") - message(SEND_ERROR "wrong sources: '${srcs}' instead of 'bar.h'") +if(NOT srcs MATCHES "[^;]*h2.h$") + message(SEND_ERROR "wrong sources: '${srcs}' instead of 'h2.h'") endif() get_property(srcs FILE_SET foo TARGET foo PROPERTY INTERFACE_SOURCES) if(srcs) diff --git a/Tests/RunCMake/FileSetProperties/h1.h b/Tests/RunCMake/FileSetProperties/h1.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/RunCMake/FileSetProperties/h2.h b/Tests/RunCMake/FileSetProperties/h2.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt index 79b1ff8255..ad6c6764b9 100644 --- a/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt +++ b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt @@ -54,6 +54,7 @@ \* CMP0204 \* CMP0209 \* CMP0210 + \* CMP0211 Call Stack \(most recent call first\): CMakeLists\.txt:3 \(include\) diff --git a/Tests/RunCMake/target_sources/CMP0211-Common.cmake b/Tests/RunCMake/target_sources/CMP0211-Common.cmake new file mode 100644 index 0000000000..6a8978b516 --- /dev/null +++ b/Tests/RunCMake/target_sources/CMP0211-Common.cmake @@ -0,0 +1,9 @@ + +enable_language(C) + +add_library(foo1 STATIC lib1.c) +target_sources(foo1 PRIVATE FILE_SET h1 TYPE HEADERS FILES h1.h) +target_sources(foo1 PRIVATE FILE_SET h2 TYPE HEADERS FILES h1.h) + +add_library(foo2 STATIC lib1.c h1.h) +target_sources(foo2 PRIVATE FILE_SET h1 TYPE HEADERS FILES h1.h) diff --git a/Tests/RunCMake/target_sources/CMP0211-NEW-result.txt b/Tests/RunCMake/target_sources/CMP0211-NEW-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/target_sources/CMP0211-NEW-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/CMP0211-NEW-stderr.txt b/Tests/RunCMake/target_sources/CMP0211-NEW-stderr.txt new file mode 100644 index 0000000000..4ba13b3def --- /dev/null +++ b/Tests/RunCMake/target_sources/CMP0211-NEW-stderr.txt @@ -0,0 +1,14 @@ +CMake Error in CMakeLists\.txt: + In target "foo1" the file + + .+/Tests/RunCMake/target_sources/h1\.h + + already belongs to file set "h2"\. + + +CMake Error in CMakeLists\.txt: + In target "foo2" the file + + .+/Tests/RunCMake/target_sources/h1\.h + + already belongs to file set "h1"\. diff --git a/Tests/RunCMake/target_sources/CMP0211-NEW.cmake b/Tests/RunCMake/target_sources/CMP0211-NEW.cmake new file mode 100644 index 0000000000..4d42024fe3 --- /dev/null +++ b/Tests/RunCMake/target_sources/CMP0211-NEW.cmake @@ -0,0 +1,4 @@ + +cmake_policy(SET CMP0211 NEW) + +include(CMP0211-Common.cmake) diff --git a/Tests/RunCMake/target_sources/CMP0211-OLD.cmake b/Tests/RunCMake/target_sources/CMP0211-OLD.cmake new file mode 100644 index 0000000000..4e32f390e4 --- /dev/null +++ b/Tests/RunCMake/target_sources/CMP0211-OLD.cmake @@ -0,0 +1,4 @@ + +cmake_policy(SET CMP0211 OLD) + +include(CMP0211-Common.cmake) diff --git a/Tests/RunCMake/target_sources/CMP0211-WARN-stderr.txt b/Tests/RunCMake/target_sources/CMP0211-WARN-stderr.txt new file mode 100644 index 0000000000..4f7664fc5d --- /dev/null +++ b/Tests/RunCMake/target_sources/CMP0211-WARN-stderr.txt @@ -0,0 +1,23 @@ +CMake Warning \(dev\) in CMakeLists\.txt: + Policy CMP0211 is not set: A file may belong to at most one file set in a + target\. Run "cmake --help-policy CMP0211" for policy details\. Use the + cmake_policy command to set the policy and suppress this warning\. + + In target "foo1" the file + + .+/Tests/RunCMake/target_sources/h1\.h + + already belongs to file set "h2"\. +This warning is for project developers\. Use -Wno-dev to suppress it\. + +CMake Warning \(dev\) in CMakeLists\.txt: + Policy CMP0211 is not set: A file may belong to at most one file set in a + target\. Run "cmake --help-policy CMP0211" for policy details\. Use the + cmake_policy command to set the policy and suppress this warning\. + + In target "foo2" the file + + .+/Tests/RunCMake/target_sources/h1\.h + + already belongs to file set "h1"\. +This warning is for project developers\. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/target_sources/CMP0211-WARN.cmake b/Tests/RunCMake/target_sources/CMP0211-WARN.cmake new file mode 100644 index 0000000000..78fa4b3b8d --- /dev/null +++ b/Tests/RunCMake/target_sources/CMP0211-WARN.cmake @@ -0,0 +1,2 @@ + +include(CMP0211-Common.cmake) diff --git a/Tests/RunCMake/target_sources/FileSetDuplicateSource.cmake b/Tests/RunCMake/target_sources/FileSetDuplicateSource.cmake new file mode 100644 index 0000000000..6fb1ab377d --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetDuplicateSource.cmake @@ -0,0 +1,6 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) + +# files are silently de-duplicated +target_sources(lib1 PRIVATE FILE_SET HEADERS FILES h1.h h1.h) diff --git a/Tests/RunCMake/target_sources/FileSetProperties.cmake b/Tests/RunCMake/target_sources/FileSetProperties.cmake index 56cce08dd8..8753eb6667 100644 --- a/Tests/RunCMake/target_sources/FileSetProperties.cmake +++ b/Tests/RunCMake/target_sources/FileSetProperties.cmake @@ -56,20 +56,20 @@ assert_prop_eq(lib1 HEADER_SET_d "") assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$;$") assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$;$;$") -target_sources(lib1 PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES h1.h) +target_sources(lib1 PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES h4.h) assert_prop_eq(lib1 INTERFACE_HEADER_SETS "a;c;d;HEADERS") assert_prop_eq(lib1 HEADER_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") -assert_prop_eq(lib1 HEADER_SET "${CMAKE_CURRENT_SOURCE_DIR}/h1.h") +assert_prop_eq(lib1 HEADER_SET "${CMAKE_CURRENT_SOURCE_DIR}/h4.h") assert_prop_eq(lib1 HEADER_DIRS_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}") -assert_prop_eq(lib1 HEADER_SET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/h1.h") +assert_prop_eq(lib1 HEADER_SET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/h4.h") assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$;$;$") assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$;$;$;$") -target_sources(lib1 PUBLIC FILE_SET HEADERS FILES h2.h) +target_sources(lib1 PUBLIC FILE_SET HEADERS FILES h5.h) assert_prop_eq(lib1 INTERFACE_HEADER_SETS "a;c;d;HEADERS") assert_prop_eq(lib1 HEADER_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") -assert_prop_eq(lib1 HEADER_SET "${CMAKE_CURRENT_SOURCE_DIR}/h1.h;${CMAKE_CURRENT_SOURCE_DIR}/h2.h") +assert_prop_eq(lib1 HEADER_SET "${CMAKE_CURRENT_SOURCE_DIR}/h4.h;${CMAKE_CURRENT_SOURCE_DIR}/h5.h") assert_prop_eq(lib1 HEADER_DIRS_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}") -assert_prop_eq(lib1 HEADER_SET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/h1.h;${CMAKE_CURRENT_SOURCE_DIR}/h2.h") +assert_prop_eq(lib1 HEADER_SET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/h4.h;${CMAKE_CURRENT_SOURCE_DIR}/h5.h") assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$;$;$") assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$;$;$;$") diff --git a/Tests/RunCMake/target_sources/RunCMakeTest.cmake b/Tests/RunCMake/target_sources/RunCMakeTest.cmake index 57e8b8928c..89324b303c 100644 --- a/Tests/RunCMake/target_sources/RunCMakeTest.cmake +++ b/Tests/RunCMake/target_sources/RunCMakeTest.cmake @@ -43,9 +43,13 @@ run_cmake(FileSetCustomTarget) run_cmake(FileSetBadName) run_cmake(FileSetWrongSyntax) run_cmake(FileSetDirect) +run_cmake(FileSetDuplicateSource) if(APPLE) run_cmake(FileSetFramework) endif() +run_cmake(CMP0211-OLD) +run_cmake(CMP0211-NEW) +run_cmake(CMP0211-WARN) set(RunCMake_TEST_NO_CLEAN 1) set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/FileSetGeneratedDependency-build") diff --git a/Tests/RunCMake/target_sources/h4.h b/Tests/RunCMake/target_sources/h4.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/RunCMake/target_sources/h5.h b/Tests/RunCMake/target_sources/h5.h new file mode 100644 index 0000000000..e69de29bb2