From 05783b168d47c2062817d58cb0a905dd6893cf8b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 7 Apr 2022 16:49:07 -0400 Subject: cmFileSet: store visibility with the fileset The visibility is intrinsic to the fileset, so store it with it. This avoids recalculating it on every addition to the fileset. --- Source/cmFileSet.cxx | 62 ++++++++++++++++++++++++++++++++++++++- Source/cmFileSet.h | 21 ++++++++++++- Source/cmTarget.cxx | 6 ++-- Source/cmTarget.h | 5 ++-- Source/cmTargetSourcesCommand.cxx | 43 +++++++-------------------- 5 files changed, 97 insertions(+), 40 deletions(-) diff --git a/Source/cmFileSet.cxx b/Source/cmFileSet.cxx index 2c06dc6..1d1d29e 100644 --- a/Source/cmFileSet.cxx +++ b/Source/cmFileSet.cxx @@ -7,19 +7,79 @@ #include #include +#include + #include "cmsys/RegularExpression.hxx" #include "cmGeneratorExpression.h" #include "cmListFileCache.h" #include "cmLocalGenerator.h" +#include "cmMakefile.h" #include "cmMessageType.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmake.h" -cmFileSet::cmFileSet(std::string name, std::string type) +cm::static_string_view cmFileSetVisibilityToName(cmFileSetVisibility vis) +{ + switch (vis) { + case cmFileSetVisibility::Interface: + return "INTERFACE"_s; + case cmFileSetVisibility::Public: + return "PUBLIC"_s; + case cmFileSetVisibility::Private: + return "PRIVATE"_s; + } + return ""_s; +} + +cmFileSetVisibility cmFileSetVisibilityFromName(cm::string_view name, + cmMakefile* mf) +{ + if (name == "INTERFACE"_s) { + return cmFileSetVisibility::Interface; + } + if (name == "PUBLIC"_s) { + return cmFileSetVisibility::Public; + } + if (name == "PRIVATE"_s) { + return cmFileSetVisibility::Private; + } + mf->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("File set visibility \"", name, "\" is not valid.")); + return cmFileSetVisibility::Private; +} + +bool cmFileSetVisibilityIsForSelf(cmFileSetVisibility vis) +{ + switch (vis) { + case cmFileSetVisibility::Interface: + return false; + case cmFileSetVisibility::Public: + case cmFileSetVisibility::Private: + return true; + } + return false; +} + +bool cmFileSetVisibilityIsForInterface(cmFileSetVisibility vis) +{ + switch (vis) { + case cmFileSetVisibility::Interface: + case cmFileSetVisibility::Public: + return true; + case cmFileSetVisibility::Private: + return false; + } + return false; +} + +cmFileSet::cmFileSet(std::string name, std::string type, + cmFileSetVisibility visibility) : Name(std::move(name)) , Type(std::move(type)) + , Visibility(visibility) { } diff --git a/Source/cmFileSet.h b/Source/cmFileSet.h index 3aad75f..5357e77 100644 --- a/Source/cmFileSet.h +++ b/Source/cmFileSet.h @@ -7,20 +7,38 @@ #include #include +#include +#include + #include "cmListFileCache.h" class cmCompiledGeneratorExpression; struct cmGeneratorExpressionDAGChecker; class cmGeneratorTarget; class cmLocalGenerator; +class cmMakefile; + +enum class cmFileSetVisibility +{ + Private, + Public, + Interface, +}; +cm::static_string_view cmFileSetVisibilityToName(cmFileSetVisibility vis); +cmFileSetVisibility cmFileSetVisibilityFromName(cm::string_view name, + cmMakefile* mf); +bool cmFileSetVisibilityIsForSelf(cmFileSetVisibility vis); +bool cmFileSetVisibilityIsForInterface(cmFileSetVisibility vis); class cmFileSet { public: - cmFileSet(std::string name, std::string type); + cmFileSet(std::string name, std::string type, + cmFileSetVisibility visibility); const std::string& GetName() const { return this->Name; } const std::string& GetType() const { return this->Type; } + cmFileSetVisibility GetVisibility() const { return this->Visibility; } void ClearDirectoryEntries(); void AddDirectoryEntry(BT directories); @@ -61,6 +79,7 @@ public: private: std::string Name; std::string Type; + cmFileSetVisibility Visibility; std::vector> DirectoryEntries; std::vector> FileEntries; }; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index e1a9667..3bcc4a4 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -2342,10 +2342,10 @@ cmFileSet* cmTarget::GetFileSet(const std::string& name) } std::pair cmTarget::GetOrCreateFileSet( - const std::string& name, const std::string& type) + const std::string& name, const std::string& type, cmFileSetVisibility vis) { - auto result = - this->impl->FileSets.emplace(std::make_pair(name, cmFileSet(name, type))); + auto result = this->impl->FileSets.emplace( + std::make_pair(name, cmFileSet(name, type, vis))); return std::make_pair(&result.first->second, result.second); } diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 1bbd0b0..3623854 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -12,6 +12,7 @@ #include #include "cmAlgorithms.h" +#include "cmFileSet.h" #include "cmPolicies.h" #include "cmStateTypes.h" #include "cmStringAlgorithms.h" @@ -19,7 +20,6 @@ #include "cmValue.h" class cmCustomCommand; -class cmFileSet; class cmGlobalGenerator; class cmInstallTargetGenerator; class cmListFileBacktrace; @@ -285,7 +285,8 @@ public: const cmFileSet* GetFileSet(const std::string& name) const; cmFileSet* GetFileSet(const std::string& name); std::pair GetOrCreateFileSet(const std::string& name, - const std::string& type); + const std::string& type, + cmFileSetVisibility vis); std::vector GetAllInterfaceFileSets() const; diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx index 9173a34..bf57cc7 100644 --- a/Source/cmTargetSourcesCommand.cxx +++ b/Source/cmTargetSourcesCommand.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmTargetSourcesCommand.h" -#include #include #include @@ -239,7 +238,11 @@ bool TargetSourcesImpl::HandleOneFileSet( (args.Type.empty() && args.FileSet[0] >= 'A' && args.FileSet[0] <= 'Z'); std::string type = isDefault ? args.FileSet : args.Type; - auto fileSet = this->Target->GetOrCreateFileSet(args.FileSet, type); + cmFileSetVisibility visibility = + cmFileSetVisibilityFromName(scope, this->Makefile); + + auto fileSet = + this->Target->GetOrCreateFileSet(args.FileSet, type, visibility); if (fileSet.second) { if (!isDefault) { if (!cmFileSet::IsValidName(args.FileSet)) { @@ -279,37 +282,11 @@ bool TargetSourcesImpl::HandleOneFileSet( return false; } - std::string existingScope = "PRIVATE"; - - auto const fileSetsProperty = cmTarget::GetFileSetsPropertyName(type); - auto const interfaceFileSetsProperty = - cmTarget::GetInterfaceFileSetsPropertyName(type); - std::vector fileSets; - std::vector interfaceFileSets; - cmExpandList(this->Target->GetSafeProperty(fileSetsProperty), fileSets); - cmExpandList(this->Target->GetSafeProperty(interfaceFileSetsProperty), - interfaceFileSets); - - if (std::find(interfaceFileSets.begin(), interfaceFileSets.end(), - args.FileSet) != interfaceFileSets.end()) { - existingScope = "INTERFACE"; - } - if (std::find(fileSets.begin(), fileSets.end(), args.FileSet) != - fileSets.end()) { - if (existingScope == "INTERFACE"_s) { - existingScope = "PUBLIC"; - } - } else if (existingScope != "INTERFACE"_s) { - this->SetError(cmStrCat("File set \"", args.FileSet, "\" is not in ", - fileSetsProperty, " or ", - interfaceFileSetsProperty)); - return false; - } - - if (scope != existingScope) { + if (visibility != fileSet.first->GetVisibility()) { this->SetError( cmStrCat("Scope ", scope, " for file set \"", args.FileSet, - "\" does not match original scope ", existingScope)); + "\" does not match original scope ", + cmFileSetVisibilityToName(fileSet.first->GetVisibility()))); return false; } } @@ -330,11 +307,11 @@ bool TargetSourcesImpl::HandleOneFileSet( for (auto const& dir : cmExpandedList(baseDirectories)) { auto interfaceDirectoriesGenex = cmStrCat("$"); - if (scope == "PRIVATE"_s || scope == "PUBLIC"_s) { + if (cmFileSetVisibilityIsForSelf(visibility)) { this->Target->AppendProperty("INCLUDE_DIRECTORIES", interfaceDirectoriesGenex); } - if (scope == "INTERFACE"_s || scope == "PUBLIC"_s) { + if (cmFileSetVisibilityIsForInterface(visibility)) { this->Target->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES", interfaceDirectoriesGenex); } -- cgit v0.12 From c5d4812f20b61982494c11412190f040a6178be6 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 11 Apr 2022 14:06:15 -0400 Subject: cmTarget: make HEADER_SETS and INTERFACE_HEADER_SETS read-only There is no reason to allow these properties to be manipulated by user code. Instead, use the stored visibility on the fileset objects to derive what these properties should contain. --- Help/prop_tgt/HEADER_SETS.rst | 12 +-- Help/prop_tgt/INTERFACE_HEADER_SETS.rst | 7 +- Help/release/3.23.rst | 4 +- Source/cmTarget.cxx | 91 ++++++++++------------ Source/cmTargetSourcesCommand.cxx | 9 --- Tests/RunCMake/target_sources/FileSetImport.cmake | 4 +- .../FileSetNoExistInterface-result.txt | 1 - .../FileSetNoExistInterface-stderr.txt | 4 - .../target_sources/FileSetNoExistInterface.cmake | 7 -- .../FileSetNoExistPrivate-result.txt | 1 - .../FileSetNoExistPrivate-stderr.txt | 4 - .../target_sources/FileSetNoExistPrivate.cmake | 7 -- .../target_sources/FileSetNoScope-result.txt | 1 - .../target_sources/FileSetNoScope-stderr.txt | 4 - Tests/RunCMake/target_sources/FileSetNoScope.cmake | 6 -- .../target_sources/FileSetProperties.cmake | 4 +- .../FileSetReadOnlyInterface-result.txt | 1 + .../FileSetReadOnlyInterface-stderr.txt | 5 ++ .../target_sources/FileSetReadOnlyInterface.cmake | 4 + .../FileSetReadOnlyPrivate-result.txt | 1 + .../FileSetReadOnlyPrivate-stderr.txt | 5 ++ .../target_sources/FileSetReadOnlyPrivate.cmake | 4 + Tests/RunCMake/target_sources/RunCMakeTest.cmake | 5 +- 23 files changed, 73 insertions(+), 118 deletions(-) delete mode 100644 Tests/RunCMake/target_sources/FileSetNoExistInterface-result.txt delete mode 100644 Tests/RunCMake/target_sources/FileSetNoExistInterface-stderr.txt delete mode 100644 Tests/RunCMake/target_sources/FileSetNoExistInterface.cmake delete mode 100644 Tests/RunCMake/target_sources/FileSetNoExistPrivate-result.txt delete mode 100644 Tests/RunCMake/target_sources/FileSetNoExistPrivate-stderr.txt delete mode 100644 Tests/RunCMake/target_sources/FileSetNoExistPrivate.cmake delete mode 100644 Tests/RunCMake/target_sources/FileSetNoScope-result.txt delete mode 100644 Tests/RunCMake/target_sources/FileSetNoScope-stderr.txt delete mode 100644 Tests/RunCMake/target_sources/FileSetNoScope.cmake create mode 100644 Tests/RunCMake/target_sources/FileSetReadOnlyInterface-result.txt create mode 100644 Tests/RunCMake/target_sources/FileSetReadOnlyInterface-stderr.txt create mode 100644 Tests/RunCMake/target_sources/FileSetReadOnlyInterface.cmake create mode 100644 Tests/RunCMake/target_sources/FileSetReadOnlyPrivate-result.txt create mode 100644 Tests/RunCMake/target_sources/FileSetReadOnlyPrivate-stderr.txt create mode 100644 Tests/RunCMake/target_sources/FileSetReadOnlyPrivate.cmake diff --git a/Help/prop_tgt/HEADER_SETS.rst b/Help/prop_tgt/HEADER_SETS.rst index fcf723e..eaec79f 100644 --- a/Help/prop_tgt/HEADER_SETS.rst +++ b/Help/prop_tgt/HEADER_SETS.rst @@ -3,14 +3,10 @@ HEADER_SETS .. versionadded:: 3.23 -List of the target's ``PRIVATE`` and ``PUBLIC`` header sets (i.e. all -file sets with the type ``HEADERS``). Files listed in these file sets -are treated as source files for the purpose of IDE integration. -The files also have their :prop_sf:`HEADER_FILE_ONLY` property set to -``TRUE``. - -This property is normally only set by :command:`target_sources(FILE_SET)` -rather than being manipulated directly. +Read-only list of the target's ``PRIVATE`` and ``PUBLIC`` header sets (i.e. +all file sets with the type ``HEADERS``). Files listed in these file sets are +treated as source files for the purpose of IDE integration. The files also +have their :prop_sf:`HEADER_FILE_ONLY` property set to ``TRUE``. See also :prop_tgt:`HEADER_SET_`, :prop_tgt:`HEADER_SET` and :prop_tgt:`INTERFACE_HEADER_SETS`. diff --git a/Help/prop_tgt/INTERFACE_HEADER_SETS.rst b/Help/prop_tgt/INTERFACE_HEADER_SETS.rst index 62db5b3..498dc31 100644 --- a/Help/prop_tgt/INTERFACE_HEADER_SETS.rst +++ b/Help/prop_tgt/INTERFACE_HEADER_SETS.rst @@ -3,12 +3,9 @@ INTERFACE_HEADER_SETS .. versionadded:: 3.23 -List of the target's ``INTERFACE`` and ``PUBLIC`` header sets (i.e. all -file sets with the type ``HEADERS``). Files listed in these header sets +Read-only list of the target's ``INTERFACE`` and ``PUBLIC`` header sets (i.e. +all file sets with the type ``HEADERS``). Files listed in these header sets can be installed with :command:`install(TARGETS)` and exported with :command:`install(EXPORT)` and :command:`export`. -This property is normally only set by :command:`target_sources(FILE_SET)` -rather than being manipulated directly. - See also :prop_tgt:`HEADER_SETS`. diff --git a/Help/release/3.23.rst b/Help/release/3.23.rst index 257c3d5..97b0920 100644 --- a/Help/release/3.23.rst +++ b/Help/release/3.23.rst @@ -114,8 +114,8 @@ Variables Properties ---------- -* The :prop_tgt:`HEADER_SETS` and :prop_tgt:`INTERFACE_HEADER_SETS` target - properties were added to list header sets associated with a target. +* The :prop_tgt:`HEADER_SETS` and :prop_tgt:`INTERFACE_HEADER_SETS` read-only + target properties were added to list header sets associated with a target. * The :prop_tgt:`HEADER_SET` and :prop_tgt:`HEADER_SET_` target properties were added to list files in the default header set diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 3bcc4a4..57e31b9 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1456,37 +1456,14 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) BT(value, this->impl->Makefile->GetBacktrace())); } } else if (prop == propHEADER_SETS) { - if (value) { - for (auto const& name : cmExpandedList(value)) { - if (!this->GetFileSet(name)) { - this->impl->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Header set \"", name, "\" has not yet been created.")); - return; - } - } - } - this->impl->HeaderSetsEntries.clear(); - if (!StringIsEmpty(value)) { - this->impl->HeaderSetsEntries.emplace_back( - value, this->impl->Makefile->GetBacktrace()); - } + this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, + "HEADER_SETS property is read-only\n"); + return; } else if (prop == propINTERFACE_HEADER_SETS) { - if (value) { - for (auto const& name : cmExpandedList(value)) { - if (!this->GetFileSet(name)) { - this->impl->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Header set \"", name, "\" has not yet been created.")); - return; - } - } - } - this->impl->InterfaceHeaderSetsEntries.clear(); - if (!StringIsEmpty(value)) { - this->impl->InterfaceHeaderSetsEntries.emplace_back( - value, this->impl->Makefile->GetBacktrace()); - } + this->impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + "INTERFACE_HEADER_SETS property is read-only\n"); + return; } else { this->impl->Properties.SetProperty(prop, value); } @@ -1641,27 +1618,14 @@ void cmTarget::AppendProperty(const std::string& prop, fileSet->AddFileEntry( BT(value, this->impl->Makefile->GetBacktrace())); } else if (prop == "HEADER_SETS") { - for (auto const& name : cmExpandedList(value)) { - if (!this->GetFileSet(name)) { - this->impl->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Header set \"", name, "\" has not yet been created.")); - return; - } - } - this->impl->HeaderSetsEntries.emplace_back( - value, this->impl->Makefile->GetBacktrace()); + this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, + "HEADER_SETS property is read-only\n"); + return; } else if (prop == "INTERFACE_HEADER_SETS") { - for (auto const& name : cmExpandedList(value)) { - if (!this->GetFileSet(name)) { - this->impl->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Header set \"", name, "\" has not yet been created.")); - return; - } - } - this->impl->InterfaceHeaderSetsEntries.emplace_back( - value, this->impl->Makefile->GetBacktrace()); + this->impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + "INTERFACE_HEADER_SETS property is read-only\n"); + return; } else { this->impl->Properties.AppendProperty(prop, value, asString); } @@ -2038,13 +2002,26 @@ cmValue cmTarget::GetProperty(const std::string& prop) const return cmValue(output); } if (prop == propHEADER_SETS) { + std::vector set_names; + for (auto const& file_set : this->impl->FileSets) { + if (cmFileSetVisibilityIsForSelf(file_set.second.GetVisibility())) { + set_names.push_back(file_set.second.GetName()); + } + } static std::string output; - output = cmJoin(this->impl->HeaderSetsEntries, ";"_s); + output = cmJoin(set_names, ";"_s); return cmValue(output); } if (prop == propINTERFACE_HEADER_SETS) { + std::vector set_names; + for (auto const& file_set : this->impl->FileSets) { + if (cmFileSetVisibilityIsForInterface( + file_set.second.GetVisibility())) { + set_names.push_back(file_set.second.GetName()); + } + } static std::string output; - output = cmJoin(this->impl->InterfaceHeaderSetsEntries, ";"_s); + output = cmJoin(set_names, ";"_s); return cmValue(output); } } @@ -2346,6 +2323,16 @@ std::pair cmTarget::GetOrCreateFileSet( { auto result = this->impl->FileSets.emplace( std::make_pair(name, cmFileSet(name, type, vis))); + if (result.second) { + if (cmFileSetVisibilityIsForSelf(vis)) { + this->impl->HeaderSetsEntries.emplace_back( + name, this->impl->Makefile->GetBacktrace()); + } + if (cmFileSetVisibilityIsForInterface(vis)) { + this->impl->InterfaceHeaderSetsEntries.emplace_back( + name, this->impl->Makefile->GetBacktrace()); + } + } return std::make_pair(&result.first->second, result.second); } diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx index bf57cc7..b1367e1 100644 --- a/Source/cmTargetSourcesCommand.cxx +++ b/Source/cmTargetSourcesCommand.cxx @@ -264,15 +264,6 @@ bool TargetSourcesImpl::HandleOneFileSet( if (args.BaseDirs.empty()) { args.BaseDirs.emplace_back(this->Makefile->GetCurrentSourceDirectory()); } - - if (scope == "PRIVATE"_s || scope == "PUBLIC"_s) { - this->Target->AppendProperty(cmTarget::GetFileSetsPropertyName(type), - args.FileSet); - } - if (scope == "INTERFACE"_s || scope == "PUBLIC"_s) { - this->Target->AppendProperty( - cmTarget::GetInterfaceFileSetsPropertyName(type), args.FileSet); - } } else { type = fileSet.first->GetType(); if (!args.Type.empty() && args.Type != type) { diff --git a/Tests/RunCMake/target_sources/FileSetImport.cmake b/Tests/RunCMake/target_sources/FileSetImport.cmake index 9c7358a..7e790c7 100644 --- a/Tests/RunCMake/target_sources/FileSetImport.cmake +++ b/Tests/RunCMake/target_sources/FileSetImport.cmake @@ -17,7 +17,7 @@ include("${export_build_dir}/export.cmake") include("${export_build_dir}/install/lib/cmake/export.cmake") assert_prop_eq(export::lib1 HEADER_SETS "") -assert_prop_eq(export::lib1 INTERFACE_HEADER_SETS "HEADERS;b;c;d;e;f;g;dir3") +assert_prop_eq(export::lib1 INTERFACE_HEADER_SETS "HEADERS;b;c;d;dir3;e;f;g") assert_prop_eq(export::lib1 HEADER_SET "${CMAKE_CURRENT_SOURCE_DIR}/error.c") assert_prop_eq(export::lib1 HEADER_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") assert_prop_eq(export::lib1 HEADER_SET_b "${CMAKE_CURRENT_SOURCE_DIR}/h2.h") @@ -35,7 +35,7 @@ assert_prop_eq(export::lib1 HEADER_DIRS_g "${CMAKE_CURRENT_SOURCE_DIR}/dir1;${CM assert_prop_eq(export::lib1 INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR};$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/$,debug,release>;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/dir1;${CMAKE_CURRENT_SOURCE_DIR}/dir2;${CMAKE_CURRENT_SOURCE_DIR}/dir3;$;$;$>;$;$,debug,release>>;$;$;$;$") assert_prop_eq(install::lib1 HEADER_SETS "") -assert_prop_eq(install::lib1 INTERFACE_HEADER_SETS "HEADERS;b;c;d;e;f;g;dir3") +assert_prop_eq(install::lib1 INTERFACE_HEADER_SETS "HEADERS;b;c;d;dir3;e;f;g") assert_prop_eq(install::lib1 HEADER_SET "${export_build_dir}/install/include/error.c") assert_prop_eq(install::lib1 HEADER_DIRS "${export_build_dir}/install/include") assert_prop_eq(install::lib1 HEADER_SET_b "${export_build_dir}/install/include/h2.h") diff --git a/Tests/RunCMake/target_sources/FileSetNoExistInterface-result.txt b/Tests/RunCMake/target_sources/FileSetNoExistInterface-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/target_sources/FileSetNoExistInterface-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/target_sources/FileSetNoExistInterface-stderr.txt b/Tests/RunCMake/target_sources/FileSetNoExistInterface-stderr.txt deleted file mode 100644 index 3972c89..0000000 --- a/Tests/RunCMake/target_sources/FileSetNoExistInterface-stderr.txt +++ /dev/null @@ -1,4 +0,0 @@ -^CMake Error at FileSetNoExistInterface\.cmake:[0-9]+ \(set_property\): - Header set "a" has not yet been created\. -Call Stack \(most recent call first\): - CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetNoExistInterface.cmake b/Tests/RunCMake/target_sources/FileSetNoExistInterface.cmake deleted file mode 100644 index 266bc61..0000000 --- a/Tests/RunCMake/target_sources/FileSetNoExistInterface.cmake +++ /dev/null @@ -1,7 +0,0 @@ -enable_language(C) - -add_library(lib1 STATIC empty.c) -set_property(TARGET lib1 PROPERTY INTERFACE_HEADER_SETS "a") - -# Error happens at configure-time, so this doesn't help. -target_sources(lib1 INTERFACE FILE_SET a TYPE HEADERS) diff --git a/Tests/RunCMake/target_sources/FileSetNoExistPrivate-result.txt b/Tests/RunCMake/target_sources/FileSetNoExistPrivate-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/target_sources/FileSetNoExistPrivate-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/target_sources/FileSetNoExistPrivate-stderr.txt b/Tests/RunCMake/target_sources/FileSetNoExistPrivate-stderr.txt deleted file mode 100644 index 336bafe..0000000 --- a/Tests/RunCMake/target_sources/FileSetNoExistPrivate-stderr.txt +++ /dev/null @@ -1,4 +0,0 @@ -^CMake Error at FileSetNoExistPrivate\.cmake:[0-9]+ \(set_property\): - Header set "a" has not yet been created\. -Call Stack \(most recent call first\): - CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetNoExistPrivate.cmake b/Tests/RunCMake/target_sources/FileSetNoExistPrivate.cmake deleted file mode 100644 index f501912..0000000 --- a/Tests/RunCMake/target_sources/FileSetNoExistPrivate.cmake +++ /dev/null @@ -1,7 +0,0 @@ -enable_language(C) - -add_library(lib1 STATIC empty.c) -set_property(TARGET lib1 PROPERTY HEADER_SETS "a") - -# Error happens at configure-time, so this doesn't help. -target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS) diff --git a/Tests/RunCMake/target_sources/FileSetNoScope-result.txt b/Tests/RunCMake/target_sources/FileSetNoScope-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/target_sources/FileSetNoScope-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/target_sources/FileSetNoScope-stderr.txt b/Tests/RunCMake/target_sources/FileSetNoScope-stderr.txt deleted file mode 100644 index 835ffe7..0000000 --- a/Tests/RunCMake/target_sources/FileSetNoScope-stderr.txt +++ /dev/null @@ -1,4 +0,0 @@ -^CMake Error at FileSetNoScope\.cmake:[0-9]+ \(target_sources\): - target_sources File set "a" is not in HEADER_SETS or INTERFACE_HEADER_SETS -Call Stack \(most recent call first\): - CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetNoScope.cmake b/Tests/RunCMake/target_sources/FileSetNoScope.cmake deleted file mode 100644 index 79ff341..0000000 --- a/Tests/RunCMake/target_sources/FileSetNoScope.cmake +++ /dev/null @@ -1,6 +0,0 @@ -enable_language(C) - -add_library(lib1 STATIC empty.c) -target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES h1.h) -set_property(TARGET lib1 PROPERTY HEADER_SETS) -target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS FILES h2.h) diff --git a/Tests/RunCMake/target_sources/FileSetProperties.cmake b/Tests/RunCMake/target_sources/FileSetProperties.cmake index a671ab3..74487fe 100644 --- a/Tests/RunCMake/target_sources/FileSetProperties.cmake +++ b/Tests/RunCMake/target_sources/FileSetProperties.cmake @@ -57,14 +57,14 @@ assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$;$;$") target_sources(lib1 PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES h1.h) -assert_prop_eq(lib1 INTERFACE_HEADER_SETS "a;c;d;HEADERS") +assert_prop_eq(lib1 INTERFACE_HEADER_SETS "HEADERS;a;c;d") 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 INCLUDE_DIRECTORIES "$;$;$") assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$;$;$;$") target_sources(lib1 PUBLIC FILE_SET HEADERS FILES h2.h) -assert_prop_eq(lib1 INTERFACE_HEADER_SETS "a;c;d;HEADERS") +assert_prop_eq(lib1 INTERFACE_HEADER_SETS "HEADERS;a;c;d") 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 INCLUDE_DIRECTORIES "$;$;$") diff --git a/Tests/RunCMake/target_sources/FileSetReadOnlyInterface-result.txt b/Tests/RunCMake/target_sources/FileSetReadOnlyInterface-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetReadOnlyInterface-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetReadOnlyInterface-stderr.txt b/Tests/RunCMake/target_sources/FileSetReadOnlyInterface-stderr.txt new file mode 100644 index 0000000..2307d13 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetReadOnlyInterface-stderr.txt @@ -0,0 +1,5 @@ +^CMake Error at FileSetReadOnlyInterface\.cmake:[0-9]+ \(set_property\): + INTERFACE_HEADER_SETS property is read-only + +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetReadOnlyInterface.cmake b/Tests/RunCMake/target_sources/FileSetReadOnlyInterface.cmake new file mode 100644 index 0000000..468ef91 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetReadOnlyInterface.cmake @@ -0,0 +1,4 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +set_property(TARGET lib1 PROPERTY INTERFACE_HEADER_SETS "a") diff --git a/Tests/RunCMake/target_sources/FileSetReadOnlyPrivate-result.txt b/Tests/RunCMake/target_sources/FileSetReadOnlyPrivate-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetReadOnlyPrivate-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetReadOnlyPrivate-stderr.txt b/Tests/RunCMake/target_sources/FileSetReadOnlyPrivate-stderr.txt new file mode 100644 index 0000000..5f955da --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetReadOnlyPrivate-stderr.txt @@ -0,0 +1,5 @@ +^CMake Error at FileSetReadOnlyPrivate\.cmake:[0-9]+ \(set_property\): + HEADER_SETS property is read-only + +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetReadOnlyPrivate.cmake b/Tests/RunCMake/target_sources/FileSetReadOnlyPrivate.cmake new file mode 100644 index 0000000..eda92c1 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetReadOnlyPrivate.cmake @@ -0,0 +1,4 @@ +enable_language(C) + +add_library(lib1 STATIC empty.c) +set_property(TARGET lib1 PROPERTY HEADER_SETS "a") diff --git a/Tests/RunCMake/target_sources/RunCMakeTest.cmake b/Tests/RunCMake/target_sources/RunCMakeTest.cmake index 743879e..8429c96 100644 --- a/Tests/RunCMake/target_sources/RunCMakeTest.cmake +++ b/Tests/RunCMake/target_sources/RunCMakeTest.cmake @@ -33,9 +33,8 @@ run_cmake(FileSetWrongBaseDirsRelative) run_cmake(FileSetOverlappingBaseDirs) run_cmake(FileSetInstallMissingSetsPrivate) run_cmake(FileSetInstallMissingSetsInterface) -run_cmake(FileSetNoScope) -run_cmake(FileSetNoExistPrivate) -run_cmake(FileSetNoExistInterface) +run_cmake(FileSetReadOnlyPrivate) +run_cmake(FileSetReadOnlyInterface) run_cmake(FileSetNoExistInstall) run_cmake(FileSetDirectories) run_cmake(FileSetCustomTarget) -- cgit v0.12 From 5fa15ec9f34d69b2a6b1ce08a6102f16c5d7ab9b Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 12 Apr 2022 08:47:45 -0400 Subject: Help: Document that target_sources defines [INTERFACE_]HEADER_SETS --- Help/prop_tgt/HEADER_SETS.rst | 3 +++ Help/prop_tgt/INTERFACE_HEADER_SETS.rst | 3 +++ Help/release/3.23.rst | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/Help/prop_tgt/HEADER_SETS.rst b/Help/prop_tgt/HEADER_SETS.rst index eaec79f..ceb1df5 100644 --- a/Help/prop_tgt/HEADER_SETS.rst +++ b/Help/prop_tgt/HEADER_SETS.rst @@ -8,5 +8,8 @@ all file sets with the type ``HEADERS``). Files listed in these file sets are treated as source files for the purpose of IDE integration. The files also have their :prop_sf:`HEADER_FILE_ONLY` property set to ``TRUE``. +Header sets may be defined using the :command:`target_sources` command +``FILE_SET`` option with type ``HEADERS``. + See also :prop_tgt:`HEADER_SET_`, :prop_tgt:`HEADER_SET` and :prop_tgt:`INTERFACE_HEADER_SETS`. diff --git a/Help/prop_tgt/INTERFACE_HEADER_SETS.rst b/Help/prop_tgt/INTERFACE_HEADER_SETS.rst index 498dc31..2d3bdac 100644 --- a/Help/prop_tgt/INTERFACE_HEADER_SETS.rst +++ b/Help/prop_tgt/INTERFACE_HEADER_SETS.rst @@ -8,4 +8,7 @@ all file sets with the type ``HEADERS``). Files listed in these header sets can be installed with :command:`install(TARGETS)` and exported with :command:`install(EXPORT)` and :command:`export`. +Header sets may be defined using the :command:`target_sources` command +``FILE_SET`` option with type ``HEADERS``. + See also :prop_tgt:`HEADER_SETS`. diff --git a/Help/release/3.23.rst b/Help/release/3.23.rst index 97b0920..2febbec 100644 --- a/Help/release/3.23.rst +++ b/Help/release/3.23.rst @@ -278,3 +278,7 @@ Changes made since CMake 3.23.0 include the following. targets. Pending further work in a future version of CMake, it is now an error to add a ``FILE_SET`` of type ``HEADERS`` to such targets on Apple platforms. + +* The :prop_tgt:`HEADER_SETS` and :prop_tgt:`INTERFACE_HEADER_SETS` target + properties added in CMake 3.23.0 are now read-only records of the header + sets created by the :command:`target_sources` command. -- cgit v0.12