From 64ea1a272c87fda1de948d69130c7872ff01c39e Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 15 Apr 2022 15:47:10 -0400 Subject: messages: remove screamake from comments and errors --- Source/cmEnableTestingCommand.h | 4 ++-- Source/cmExportBuildAndroidMKGenerator.h | 2 +- Source/cmExportBuildFileGenerator.h | 2 +- Source/cmTryCompileCommand.cxx | 2 +- Source/cmTryRunCommand.cxx | 20 ++++++++++---------- Tests/CMakeLists.txt | 2 +- Tests/TryCompile/CMakeLists.txt | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Source/cmEnableTestingCommand.h b/Source/cmEnableTestingCommand.h index 1722511..a1374f3 100644 --- a/Source/cmEnableTestingCommand.h +++ b/Source/cmEnableTestingCommand.h @@ -14,10 +14,10 @@ class cmExecutionStatus; * * Produce the output testfile. This produces a file in the build directory * called CMakeTestfile with a syntax similar to CMakeLists.txt. It contains - * the SUBDIRS() and ADD_TEST() commands from the source CMakeLists.txt + * the subdirs() and add_test() commands from the source CMakeLists.txt * file with CMake variables expanded. Only the subdirs and tests * within the valid control structures are replicated in Testfile - * (i.e. SUBDIRS() and ADD_TEST() commands within IF() commands that are + * (i.e. subdirs() and add_test() commands within IF() commands that are * not entered by CMake are not replicated in Testfile). * Note that CTest expects to find this file in the build directory root; * therefore, this command should be in the source directory root too. diff --git a/Source/cmExportBuildAndroidMKGenerator.h b/Source/cmExportBuildAndroidMKGenerator.h index 410d4c3..1a9a626 100644 --- a/Source/cmExportBuildAndroidMKGenerator.h +++ b/Source/cmExportBuildAndroidMKGenerator.h @@ -20,7 +20,7 @@ class cmGeneratorTarget; * a build tree. This exports the targets to the Android ndk build tool * makefile format for prebuilt libraries. * - * This is used to implement the EXPORT() command. + * This is used to implement the export() command. */ class cmExportBuildAndroidMKGenerator : public cmExportBuildFileGenerator { diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h index 3db8719..5681e8f 100644 --- a/Source/cmExportBuildFileGenerator.h +++ b/Source/cmExportBuildFileGenerator.h @@ -28,7 +28,7 @@ class cmTargetExport; * a build tree. A single file exports information for all * configurations built. * - * This is used to implement the EXPORT() command. + * This is used to implement the export() command. */ class cmExportBuildFileGenerator : public cmExportFileGenerator { diff --git a/Source/cmTryCompileCommand.cxx b/Source/cmTryCompileCommand.cxx index 05b3f05..130c228 100644 --- a/Source/cmTryCompileCommand.cxx +++ b/Source/cmTryCompileCommand.cxx @@ -20,7 +20,7 @@ bool cmTryCompileCommand::InitialPass(std::vector const& argv, cmake::FIND_PACKAGE_MODE) { this->Makefile->IssueMessage( MessageType::FATAL_ERROR, - "The TRY_COMPILE() command is not supported in --find-package mode."); + "The try_compile() command is not supported in --find-package mode."); return false; } diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index cd468b9..c82ac64 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -31,7 +31,7 @@ bool cmTryRunCommand::InitialPass(std::vector const& argv, cmake::FIND_PACKAGE_MODE) { this->Makefile->IssueMessage( MessageType::FATAL_ERROR, - "The TRY_RUN() command is not supported in --find-package mode."); + "The try_run() command is not supported in --find-package mode."); return false; } @@ -217,7 +217,7 @@ void cmTryRunCommand::RunExecutable(const std::string& runArgs, retStr = "FAILED_TO_RUN"; } this->Makefile->AddCacheDefinition(this->RunResultVariable, retStr, - "Result of TRY_RUN", + "Result of try_run()", cmStateEnums::INTERNAL); } @@ -230,7 +230,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, std::string* out) { // copy the executable out of the CMakeFiles/ directory, so it is not - // removed at the end of TRY_RUN and the user can run it manually + // removed at the end of try_run() and the user can run it manually // on the target platform. std::string copyDest = cmStrCat(this->Makefile->GetHomeOutputDirectory(), "/CMakeFiles/", @@ -252,7 +252,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, // if the variables doesn't exist, create it with a helpful error text // and mark it as advanced std::string comment = - cmStrCat("Run result of TRY_RUN(), indicates whether the executable " + cmStrCat("Run result of try_run(), indicates whether the executable " "would have been able to run on its target platform.\n", detailsString); this->Makefile->AddCacheDefinition(this->RunResultVariable, @@ -274,7 +274,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, // if the variables doesn't exist, create it with a helpful error text // and mark it as advanced std::string comment = cmStrCat( - "Output of TRY_RUN(), contains the text, which the executable " + "Output of try_run(), contains the text, which the executable " "would have printed on stdout and stderr on its target platform.\n", detailsString); @@ -299,7 +299,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, if (firstTryRun) { /* clang-format off */ file << "# This file was generated by CMake because it detected " - "TRY_RUN() commands\n" + "try_run() commands\n" "# in crosscompiling mode. It will be overwritten by the next " "CMake run.\n" "# Copy it to a safe location, set the variables to " @@ -332,7 +332,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, } comment += "The "; comment += this->CompileResultVariable; - comment += " variable holds the build result for this TRY_RUN().\n\n" + comment += " variable holds the build result for this try_run().\n\n" "Source file : "; comment += srcFile + "\n"; comment += "Executable : "; @@ -346,19 +346,19 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, file << "set( " << this->RunResultVariable << " \n \"" << this->Makefile->GetSafeDefinition(this->RunResultVariable) - << "\"\n CACHE STRING \"Result from TRY_RUN\" FORCE)\n\n"; + << "\"\n CACHE STRING \"Result from try_run\" FORCE)\n\n"; if (out) { file << "set( " << internalRunOutputName << " \n \"" << this->Makefile->GetSafeDefinition(internalRunOutputName) - << "\"\n CACHE STRING \"Output from TRY_RUN\" FORCE)\n\n"; + << "\"\n CACHE STRING \"Output from try_run\" FORCE)\n\n"; } file.close(); } firstTryRun = false; std::string errorMessage = - cmStrCat("TRY_RUN() invoked in cross-compiling mode, " + cmStrCat("try_run() invoked in cross-compiling mode, " "please set the following cache variables " "appropriately:\n ", this->RunResultVariable, " (advanced)\n"); diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 6ceb832..9a4910f 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -528,7 +528,7 @@ if(BUILD_TESTING) PASS_REGULAR_EXPRESSION "CMake Error: CMake can not determine linker language for target: test") ADD_TEST_MACRO(CrossCompile CrossCompile) set_tests_properties(CrossCompile PROPERTIES - PASS_REGULAR_EXPRESSION "TRY_RUN.. invoked in cross-compiling mode") + PASS_REGULAR_EXPRESSION "try_run.. invoked in cross-compiling mode") if("${CMAKE_GENERATOR}" MATCHES "Make") ADD_TEST_MACRO(Policy0002 Policy0002) endif() diff --git a/Tests/TryCompile/CMakeLists.txt b/Tests/TryCompile/CMakeLists.txt index 594f37a..000fd2c 100644 --- a/Tests/TryCompile/CMakeLists.txt +++ b/Tests/TryCompile/CMakeLists.txt @@ -201,7 +201,7 @@ add_executable(TryCompile pass.c) ###################################### -# now two tests for TRY_RUN +# now two tests for try_run() # try to run a file that should compile and run without error # also check that OUTPUT_VARIABLE contains both the compile output -- cgit v0.12 From c89580487b38d365dad56afea587f698ae101947 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 7 Apr 2022 13:53:03 -0400 Subject: cmTarget: pass candidate strings by const-ref This avoids having to copy the `std::string` overload. --- Source/cmTarget.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index a01321d..e85cc33 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1227,16 +1227,16 @@ std::string ConvertToString(cmValue value) } template -bool StringIsEmpty(ValueType value); +bool StringIsEmpty(ValueType const& value); template <> -bool StringIsEmpty(const char* value) +bool StringIsEmpty(const char* const& value) { return cmValue::IsEmpty(value); } template <> -bool StringIsEmpty(cmValue value) +bool StringIsEmpty(cmValue const& value) { return value.IsEmpty(); } -- cgit v0.12 From 5da4fe30a994208bb188c347ac9d0e394498dcc2 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 5 Apr 2022 15:43:39 -0400 Subject: cmTarget: factor out fileset property manipulation --- Source/cmTarget.cxx | 230 ++++++++++++++++++++++++++-------------------------- 1 file changed, 114 insertions(+), 116 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index e85cc33..fc4d9f4 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -216,6 +217,19 @@ public: std::string const& value) const; std::string ProcessSourceItemCMP0049(const std::string& s) const; + + template + void AddDirectoryToFileSet(cmTarget* self, std::string const& fileSetName, + ValueType value, cm::string_view description, + bool clear); + template + void AddPathToFileSet(cmTarget* self, std::string const& fileSetName, + ValueType value, cm::string_view description, + bool clear); + cmValue GetFileSetDirectories(cmTarget const* self, + std::string const& fileSetName) const; + cmValue GetFileSetPaths(cmTarget const* self, + std::string const& fileSetName) const; }; namespace { @@ -1240,6 +1254,12 @@ bool StringIsEmpty(cmValue const& value) { return value.IsEmpty(); } + +template <> +bool StringIsEmpty(std::string const& value) +{ + return value.empty(); +} } template @@ -1423,31 +1443,11 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) this->impl->LanguageStandardProperties.erase(prop); } } else if (prop == propHEADER_DIRS) { - auto* fileSet = this->GetFileSet("HEADERS"); - if (!fileSet) { - this->impl->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - "The default header set has not yet been created."); - return; - } - fileSet->ClearDirectoryEntries(); - if (!StringIsEmpty(value)) { - fileSet->AddDirectoryEntry( - BT(value, this->impl->Makefile->GetBacktrace())); - } + this->impl->AddDirectoryToFileSet(this, "HEADERS", value, + "The default header set"_s, true); } else if (prop == propHEADER_SET) { - auto* fileSet = this->GetFileSet("HEADERS"); - if (!fileSet) { - this->impl->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - "The default header set has not yet been created."); - return; - } - fileSet->ClearFileEntries(); - if (!StringIsEmpty(value)) { - fileSet->AddFileEntry( - BT(value, this->impl->Makefile->GetBacktrace())); - } + this->impl->AddPathToFileSet(this, "HEADERS", value, + "The default header set"_s, true); } else if (cmHasLiteralPrefix(prop, "HEADER_DIRS_")) { auto fileSetName = prop.substr(cmStrLen("HEADER_DIRS_")); if (fileSetName.empty()) { @@ -1455,19 +1455,9 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) "Header set name cannot be empty."); return; } - auto* fileSet = this->GetFileSet(fileSetName); - if (!fileSet) { - this->impl->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Header set \"", fileSetName, - "\" has not yet been created.")); - return; - } - fileSet->ClearDirectoryEntries(); - if (!StringIsEmpty(value)) { - fileSet->AddDirectoryEntry( - BT(value, this->impl->Makefile->GetBacktrace())); - } + this->impl->AddDirectoryToFileSet( + this, fileSetName, value, cmStrCat("Header set \"", fileSetName, "\""), + true); } else if (cmHasLiteralPrefix(prop, "HEADER_SET_")) { auto fileSetName = prop.substr(cmStrLen("HEADER_SET_")); if (fileSetName.empty()) { @@ -1475,19 +1465,9 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) "Header set name cannot be empty."); return; } - auto* fileSet = this->GetFileSet(fileSetName); - if (!fileSet) { - this->impl->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Header set \"", fileSetName, - "\" has not yet been created.")); - return; - } - fileSet->ClearFileEntries(); - if (!StringIsEmpty(value)) { - fileSet->AddFileEntry( - BT(value, this->impl->Makefile->GetBacktrace())); - } + this->impl->AddPathToFileSet(this, fileSetName, value, + cmStrCat("Header set \"", fileSetName, "\""), + true); } else if (prop == propHEADER_SETS) { this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, "HEADER_SETS property is read-only\n"); @@ -1608,15 +1588,8 @@ void cmTarget::AppendProperty(const std::string& prop, this->impl->Makefile->IssueMessage( MessageType::FATAL_ERROR, prop + " property may not be appended."); } else if (prop == "HEADER_DIRS") { - auto* fileSet = this->GetFileSet("HEADERS"); - if (!fileSet) { - this->impl->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - "The default header set has not yet been created."); - return; - } - fileSet->AddDirectoryEntry( - BT(value, this->impl->Makefile->GetBacktrace())); + this->impl->AddDirectoryToFileSet(this, "HEADERS", value, + "The default header set"_s, false); } else if (cmHasLiteralPrefix(prop, "HEADER_DIRS_")) { auto fileSetName = prop.substr(cmStrLen("HEADER_DIRS_")); if (fileSetName.empty()) { @@ -1624,26 +1597,12 @@ void cmTarget::AppendProperty(const std::string& prop, "Header set name cannot be empty."); return; } - auto* fileSet = this->GetFileSet(fileSetName); - if (!fileSet) { - this->impl->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Header set \"", fileSetName, - "\" has not yet been created.")); - return; - } - fileSet->AddDirectoryEntry( - BT(value, this->impl->Makefile->GetBacktrace())); + this->impl->AddDirectoryToFileSet( + this, fileSetName, value, cmStrCat("Header set \"", fileSetName, "\""), + false); } else if (prop == "HEADER_SET") { - auto* fileSet = this->GetFileSet("HEADERS"); - if (!fileSet) { - this->impl->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - "The default header set has not yet been created."); - return; - } - fileSet->AddFileEntry( - BT(value, this->impl->Makefile->GetBacktrace())); + this->impl->AddPathToFileSet(this, "HEADERS", value, + "The default header set"_s, false); } else if (cmHasLiteralPrefix(prop, "HEADER_SET_")) { auto fileSetName = prop.substr(cmStrLen("HEADER_SET_")); if (fileSetName.empty()) { @@ -1651,16 +1610,9 @@ void cmTarget::AppendProperty(const std::string& prop, "Header set name cannot be empty."); return; } - auto* fileSet = this->GetFileSet(fileSetName); - if (!fileSet) { - this->impl->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Header set \"", fileSetName, - "\" has not yet been created.")); - return; - } - fileSet->AddFileEntry( - BT(value, this->impl->Makefile->GetBacktrace())); + this->impl->AddPathToFileSet(this, fileSetName, value, + cmStrCat("Header set \"", fileSetName, "\""), + false); } else if (prop == "HEADER_SETS") { this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, "HEADER_SETS property is read-only\n"); @@ -1684,6 +1636,76 @@ void cmTarget::SetProperty(const std::string& prop, cmValue value) this->StoreProperty(prop, value); } +template +void cmTargetInternals::AddDirectoryToFileSet(cmTarget* self, + std::string const& fileSetName, + ValueType value, + cm::string_view description, + bool clear) +{ + auto* fileSet = self->GetFileSet(fileSetName); + if (!fileSet) { + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat(description, "has not yet been created.")); + return; + } + if (clear) { + fileSet->ClearDirectoryEntries(); + } + if (!StringIsEmpty(value)) { + fileSet->AddDirectoryEntry( + BT(value, this->Makefile->GetBacktrace())); + } +} + +template +void cmTargetInternals::AddPathToFileSet(cmTarget* self, + std::string const& fileSetName, + ValueType value, + cm::string_view description, + bool clear) +{ + auto* fileSet = self->GetFileSet(fileSetName); + if (!fileSet) { + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat(description, "has not yet been created.")); + return; + } + if (clear) { + fileSet->ClearFileEntries(); + } + if (!StringIsEmpty(value)) { + fileSet->AddFileEntry( + BT(value, this->Makefile->GetBacktrace())); + } +} + +cmValue cmTargetInternals::GetFileSetDirectories( + cmTarget const* self, std::string const& fileSetName) const +{ + auto const* fileSet = self->GetFileSet(fileSetName); + if (!fileSet) { + return nullptr; + } + static std::string output; + output = cmJoin(fileSet->GetDirectoryEntries(), ";"_s); + return cmValue(output); +} + +cmValue cmTargetInternals::GetFileSetPaths( + cmTarget const* self, std::string const& fileSetName) const +{ + auto const* fileSet = self->GetFileSet(fileSetName); + if (!fileSet) { + return nullptr; + } + static std::string output; + output = cmJoin(fileSet->GetFileEntries(), ";"_s); + return cmValue(output); +} + void cmTarget::AppendBuildInterfaceIncludes() { if (this->GetType() != cmStateEnums::SHARED_LIBRARY && @@ -2076,22 +2098,10 @@ cmValue cmTarget::GetProperty(const std::string& prop) const .GetCurrentSource()); } if (prop == propHEADER_DIRS) { - auto const* fileSet = this->GetFileSet("HEADERS"); - if (!fileSet) { - return nullptr; - } - static std::string output; - output = cmJoin(fileSet->GetDirectoryEntries(), ";"_s); - return cmValue(output); + return this->impl->GetFileSetDirectories(this, "HEADERS"); } if (prop == propHEADER_SET) { - auto const* fileSet = this->GetFileSet("HEADERS"); - if (!fileSet) { - return nullptr; - } - static std::string output; - output = cmJoin(fileSet->GetFileEntries(), ";"_s); - return cmValue(output); + return this->impl->GetFileSetPaths(this, "HEADERS"); } if (prop == propHEADER_SETS) { std::vector set_names; @@ -2122,26 +2132,14 @@ cmValue cmTarget::GetProperty(const std::string& prop) const if (fileSetName.empty()) { return nullptr; } - auto const* fileSet = this->GetFileSet(fileSetName); - if (!fileSet) { - return nullptr; - } - static std::string output; - output = cmJoin(fileSet->GetDirectoryEntries(), ";"_s); - return cmValue(output); + return this->impl->GetFileSetDirectories(this, fileSetName); } if (cmHasLiteralPrefix(prop, "HEADER_SET_")) { std::string fileSetName = prop.substr(cmStrLen("HEADER_SET_")); if (fileSetName.empty()) { return nullptr; } - auto const* fileSet = this->GetFileSet(fileSetName); - if (!fileSet) { - return nullptr; - } - static std::string output; - output = cmJoin(fileSet->GetFileEntries(), ";"_s); - return cmValue(output); + return this->impl->GetFileSetPaths(this, fileSetName); } cmValue retVal = this->impl->Properties.GetPropertyValue(prop); -- cgit v0.12 From d74f9599f6089e30f9bd175d00e5510f378ec935 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 5 Apr 2022 15:46:24 -0400 Subject: cmTarget: require filesets to be of the right type With new types being proposed for C++ modules, requiring filesets to be of the right type is now pertinent. No tests can be added yet as only `HEADERS` is supported right now. --- Source/cmTarget.cxx | 95 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 34 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index fc4d9f4..a3746ab 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -220,16 +220,17 @@ public: template void AddDirectoryToFileSet(cmTarget* self, std::string const& fileSetName, - ValueType value, cm::string_view description, - bool clear); + ValueType value, cm::string_view fileSetType, + cm::string_view description, bool clear); template void AddPathToFileSet(cmTarget* self, std::string const& fileSetName, - ValueType value, cm::string_view description, - bool clear); + ValueType value, cm::string_view fileSetType, + cm::string_view description, bool clear); cmValue GetFileSetDirectories(cmTarget const* self, - std::string const& fileSetName) const; - cmValue GetFileSetPaths(cmTarget const* self, - std::string const& fileSetName) const; + std::string const& fileSetName, + cm::string_view fileSetType) const; + cmValue GetFileSetPaths(cmTarget const* self, std::string const& fileSetName, + cm::string_view fileSetType) const; }; namespace { @@ -1443,10 +1444,10 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) this->impl->LanguageStandardProperties.erase(prop); } } else if (prop == propHEADER_DIRS) { - this->impl->AddDirectoryToFileSet(this, "HEADERS", value, + this->impl->AddDirectoryToFileSet(this, "HEADERS", value, "HEADERS"_s, "The default header set"_s, true); } else if (prop == propHEADER_SET) { - this->impl->AddPathToFileSet(this, "HEADERS", value, + this->impl->AddPathToFileSet(this, "HEADERS", value, "HEADERS"_s, "The default header set"_s, true); } else if (cmHasLiteralPrefix(prop, "HEADER_DIRS_")) { auto fileSetName = prop.substr(cmStrLen("HEADER_DIRS_")); @@ -1456,8 +1457,8 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) return; } this->impl->AddDirectoryToFileSet( - this, fileSetName, value, cmStrCat("Header set \"", fileSetName, "\""), - true); + this, fileSetName, value, "HEADERS"_s, + cmStrCat("Header set \"", fileSetName, "\""), true); } else if (cmHasLiteralPrefix(prop, "HEADER_SET_")) { auto fileSetName = prop.substr(cmStrLen("HEADER_SET_")); if (fileSetName.empty()) { @@ -1465,7 +1466,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) "Header set name cannot be empty."); return; } - this->impl->AddPathToFileSet(this, fileSetName, value, + this->impl->AddPathToFileSet(this, fileSetName, value, "HEADERS"_s, cmStrCat("Header set \"", fileSetName, "\""), true); } else if (prop == propHEADER_SETS) { @@ -1588,7 +1589,7 @@ void cmTarget::AppendProperty(const std::string& prop, this->impl->Makefile->IssueMessage( MessageType::FATAL_ERROR, prop + " property may not be appended."); } else if (prop == "HEADER_DIRS") { - this->impl->AddDirectoryToFileSet(this, "HEADERS", value, + this->impl->AddDirectoryToFileSet(this, "HEADERS", value, "HEADERS"_s, "The default header set"_s, false); } else if (cmHasLiteralPrefix(prop, "HEADER_DIRS_")) { auto fileSetName = prop.substr(cmStrLen("HEADER_DIRS_")); @@ -1598,10 +1599,10 @@ void cmTarget::AppendProperty(const std::string& prop, return; } this->impl->AddDirectoryToFileSet( - this, fileSetName, value, cmStrCat("Header set \"", fileSetName, "\""), - false); + this, fileSetName, value, "HEADERS"_s, + cmStrCat("Header set \"", fileSetName, "\""), false); } else if (prop == "HEADER_SET") { - this->impl->AddPathToFileSet(this, "HEADERS", value, + this->impl->AddPathToFileSet(this, "HEADERS", value, "HEADERS"_s, "The default header set"_s, false); } else if (cmHasLiteralPrefix(prop, "HEADER_SET_")) { auto fileSetName = prop.substr(cmStrLen("HEADER_SET_")); @@ -1610,7 +1611,7 @@ void cmTarget::AppendProperty(const std::string& prop, "Header set name cannot be empty."); return; } - this->impl->AddPathToFileSet(this, fileSetName, value, + this->impl->AddPathToFileSet(this, fileSetName, value, "HEADERS"_s, cmStrCat("Header set \"", fileSetName, "\""), false); } else if (prop == "HEADER_SETS") { @@ -1637,11 +1638,9 @@ void cmTarget::SetProperty(const std::string& prop, cmValue value) } template -void cmTargetInternals::AddDirectoryToFileSet(cmTarget* self, - std::string const& fileSetName, - ValueType value, - cm::string_view description, - bool clear) +void cmTargetInternals::AddDirectoryToFileSet( + cmTarget* self, std::string const& fileSetName, ValueType value, + cm::string_view fileSetType, cm::string_view description, bool clear) { auto* fileSet = self->GetFileSet(fileSetName); if (!fileSet) { @@ -1650,6 +1649,13 @@ void cmTargetInternals::AddDirectoryToFileSet(cmTarget* self, cmStrCat(description, "has not yet been created.")); return; } + if (fileSet->GetType() != fileSetType) { + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, + cmStrCat("File set \"", fileSetName, + "\" is not of type \"", fileSetType, + "\".")); + return; + } if (clear) { fileSet->ClearDirectoryEntries(); } @@ -1660,11 +1666,9 @@ void cmTargetInternals::AddDirectoryToFileSet(cmTarget* self, } template -void cmTargetInternals::AddPathToFileSet(cmTarget* self, - std::string const& fileSetName, - ValueType value, - cm::string_view description, - bool clear) +void cmTargetInternals::AddPathToFileSet( + cmTarget* self, std::string const& fileSetName, ValueType value, + cm::string_view fileSetType, cm::string_view description, bool clear) { auto* fileSet = self->GetFileSet(fileSetName); if (!fileSet) { @@ -1673,6 +1677,13 @@ void cmTargetInternals::AddPathToFileSet(cmTarget* self, cmStrCat(description, "has not yet been created.")); return; } + if (fileSet->GetType() != fileSetType) { + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, + cmStrCat("File set \"", fileSetName, + "\" is not of type \"", fileSetType, + "\".")); + return; + } if (clear) { fileSet->ClearFileEntries(); } @@ -1683,24 +1694,40 @@ void cmTargetInternals::AddPathToFileSet(cmTarget* self, } cmValue cmTargetInternals::GetFileSetDirectories( - cmTarget const* self, std::string const& fileSetName) const + cmTarget const* self, std::string const& fileSetName, + cm::string_view fileSetType) const { auto const* fileSet = self->GetFileSet(fileSetName); if (!fileSet) { return nullptr; } + if (fileSet->GetType() != fileSetType) { + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, + cmStrCat("File set \"", fileSetName, + "\" is not of type \"", fileSetType, + "\".")); + return nullptr; + } static std::string output; output = cmJoin(fileSet->GetDirectoryEntries(), ";"_s); return cmValue(output); } -cmValue cmTargetInternals::GetFileSetPaths( - cmTarget const* self, std::string const& fileSetName) const +cmValue cmTargetInternals::GetFileSetPaths(cmTarget const* self, + std::string const& fileSetName, + cm::string_view fileSetType) const { auto const* fileSet = self->GetFileSet(fileSetName); if (!fileSet) { return nullptr; } + if (fileSet->GetType() != fileSetType) { + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, + cmStrCat("File set \"", fileSetName, + "\" is not of type \"", fileSetType, + "\".")); + return nullptr; + } static std::string output; output = cmJoin(fileSet->GetFileEntries(), ";"_s); return cmValue(output); @@ -2098,10 +2125,10 @@ cmValue cmTarget::GetProperty(const std::string& prop) const .GetCurrentSource()); } if (prop == propHEADER_DIRS) { - return this->impl->GetFileSetDirectories(this, "HEADERS"); + return this->impl->GetFileSetDirectories(this, "HEADERS", "HEADERS"_s); } if (prop == propHEADER_SET) { - return this->impl->GetFileSetPaths(this, "HEADERS"); + return this->impl->GetFileSetPaths(this, "HEADERS", "HEADERS"_s); } if (prop == propHEADER_SETS) { std::vector set_names; @@ -2132,14 +2159,14 @@ cmValue cmTarget::GetProperty(const std::string& prop) const if (fileSetName.empty()) { return nullptr; } - return this->impl->GetFileSetDirectories(this, fileSetName); + return this->impl->GetFileSetDirectories(this, fileSetName, "HEADERS"_s); } if (cmHasLiteralPrefix(prop, "HEADER_SET_")) { std::string fileSetName = prop.substr(cmStrLen("HEADER_SET_")); if (fileSetName.empty()) { return nullptr; } - return this->impl->GetFileSetPaths(this, fileSetName); + return this->impl->GetFileSetPaths(this, fileSetName, "HEADERS"_s); } cmValue retVal = this->impl->Properties.GetPropertyValue(prop); -- cgit v0.12 From 79d6b928a3efe7ca8a6665de8f9358c794be4f9f Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 6 Apr 2022 10:46:08 -0400 Subject: RunCMake/target_sources: test `HEADERS` file sets via generic props --- Tests/RunCMake/target_sources/FileSetImport.cmake | 5 +++++ Tests/RunCMake/target_sources/FileSetProperties.cmake | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/Tests/RunCMake/target_sources/FileSetImport.cmake b/Tests/RunCMake/target_sources/FileSetImport.cmake index 8ef8e7d..c7acc5f 100644 --- a/Tests/RunCMake/target_sources/FileSetImport.cmake +++ b/Tests/RunCMake/target_sources/FileSetImport.cmake @@ -19,10 +19,13 @@ 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;dir3;e;f;g") assert_prop_eq(export::lib1 HEADER_SET "${CMAKE_CURRENT_SOURCE_DIR}/error.c") +assert_prop_eq(export::lib1 HEADER_SET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/error.c") if (_multi_config) assert_prop_eq(export::lib1 HEADER_DIRS "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}") + assert_prop_eq(export::lib1 HEADER_DIRS_HEADERS "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}") else () assert_prop_eq(export::lib1 HEADER_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") + assert_prop_eq(export::lib1 HEADER_DIRS_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}") endif () assert_prop_eq(export::lib1 HEADER_SET_b "${CMAKE_CURRENT_SOURCE_DIR}/h2.h") if (_multi_config) @@ -72,6 +75,8 @@ assert_prop_eq(install::lib1 HEADER_SETS "") 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_HEADERS "${export_build_dir}/install/include/error.c") +assert_prop_eq(install::lib1 HEADER_DIRS_HEADERS "${export_build_dir}/install/include") assert_prop_eq(install::lib1 HEADER_SET_b "${export_build_dir}/install/include/h2.h") assert_prop_eq(install::lib1 HEADER_DIRS_b "${export_build_dir}/install/include") assert_prop_eq(install::lib1 HEADER_SET_c "${export_build_dir}/install/include/dir/dir.h") diff --git a/Tests/RunCMake/target_sources/FileSetProperties.cmake b/Tests/RunCMake/target_sources/FileSetProperties.cmake index 74487fe..a9a32b2 100644 --- a/Tests/RunCMake/target_sources/FileSetProperties.cmake +++ b/Tests/RunCMake/target_sources/FileSetProperties.cmake @@ -60,6 +60,8 @@ target_sources(lib1 PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DI 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 HEADER_DIRS_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}") +assert_prop_eq(lib1 HEADER_SET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/h1.h") assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$;$;$") assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$;$;$;$") @@ -67,5 +69,7 @@ target_sources(lib1 PUBLIC FILE_SET HEADERS FILES h2.h) 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 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 INCLUDE_DIRECTORIES "$;$;$") assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$;$;$;$") -- cgit v0.12 From 9916d4dd44dcb86571ff51a4e4fabb6fe14cec17 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 6 Apr 2022 21:32:40 -0400 Subject: cmTarget: factor out fileset type handling This allows for new fileset types to be added more easily by factoring out the declarative information into a structure. --- Source/cmTarget.cxx | 335 +++++++++++++-------- Tests/RunCMake/target_sources/FileSetImport.cmake | 4 +- .../target_sources/FileSetProperties.cmake | 4 +- 3 files changed, 207 insertions(+), 136 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index a3746ab..446964c 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -165,6 +165,66 @@ cmValue cmTargetPropertyComputer::GetSources(cmTarget const* tgt, return cmValue(srcs); } +namespace { +struct FileSetEntries +{ + FileSetEntries(cm::static_string_view propertyName) + : PropertyName(propertyName) + { + } + + cm::static_string_view const PropertyName; + std::vector> Entries; +}; + +struct FileSetType +{ + FileSetType(cm::static_string_view typeName, + cm::static_string_view defaultDirectoryProperty, + cm::static_string_view defaultPathProperty, + cm::static_string_view directoryPrefix, + cm::static_string_view pathPrefix, + cm::static_string_view typeDescription, + cm::static_string_view defaultDescription, + cm::static_string_view arbitraryDescription, + FileSetEntries selfEntries, FileSetEntries interfaceEntries) + : TypeName(typeName) + , DefaultDirectoryProperty(defaultDirectoryProperty) + , DefaultPathProperty(defaultPathProperty) + , DirectoryPrefix(directoryPrefix) + , PathPrefix(pathPrefix) + , TypeDescription(typeDescription) + , DefaultDescription(defaultDescription) + , ArbitraryDescription(arbitraryDescription) + , SelfEntries(std::move(selfEntries)) + , InterfaceEntries(std::move(interfaceEntries)) + { + } + + cm::static_string_view const TypeName; + cm::static_string_view const DefaultDirectoryProperty; + cm::static_string_view const DefaultPathProperty; + cm::static_string_view const DirectoryPrefix; + cm::static_string_view const PathPrefix; + cm::static_string_view const TypeDescription; + cm::static_string_view const DefaultDescription; + cm::static_string_view const ArbitraryDescription; + + FileSetEntries SelfEntries; + FileSetEntries InterfaceEntries; + + template + bool WriteProperties(cmTarget* tgt, cmTargetInternals* impl, + const std::string& prop, ValueType value, bool clear); + std::pair ReadProperties(cmTarget const* tgt, + cmTargetInternals const* impl, + const std::string& prop) const; + + void AddFileSet(const std::string& name, cmFileSetVisibility vis, + cmListFileBacktrace bt); +}; +} + class cmTargetInternals { public: @@ -206,13 +266,15 @@ public: std::vector> LinkInterfacePropertyEntries; std::vector> LinkInterfaceDirectPropertyEntries; std::vector> LinkInterfaceDirectExcludePropertyEntries; - std::vector> HeaderSetsEntries; - std::vector> InterfaceHeaderSetsEntries; std::vector> TLLCommands; std::map FileSets; cmListFileBacktrace Backtrace; + FileSetType HeadersFileSets; + + cmTargetInternals(); + bool CheckImportedLibName(std::string const& prop, std::string const& value) const; @@ -233,6 +295,123 @@ public: cm::string_view fileSetType) const; }; +cmTargetInternals::cmTargetInternals() + : HeadersFileSets("HEADERS"_s, "HEADER_DIRS"_s, "HEADER_SET"_s, + "HEADER_DIRS_"_s, "HEADER_SET_"_s, "Header"_s, + "The default header set"_s, "Header set"_s, + FileSetEntries("HEADER_SETS"_s), + FileSetEntries("INTERFACE_HEADER_SETS"_s)) +{ +} + +template +bool FileSetType::WriteProperties(cmTarget* tgt, cmTargetInternals* impl, + const std::string& prop, ValueType value, + bool clear) +{ + if (prop == this->DefaultDirectoryProperty) { + impl->AddDirectoryToFileSet(tgt, std::string(this->TypeName), value, + this->TypeName, this->DefaultDescription, + clear); + return true; + } + if (prop == this->DefaultPathProperty) { + impl->AddPathToFileSet(tgt, std::string(this->TypeName), value, + this->TypeName, this->DefaultDescription, clear); + return true; + } + if (cmHasPrefix(prop, this->DirectoryPrefix)) { + auto fileSetName = prop.substr(this->DirectoryPrefix.size()); + if (fileSetName.empty()) { + impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat(this->ArbitraryDescription, " name cannot be empty.")); + } else { + impl->AddDirectoryToFileSet( + tgt, fileSetName, value, this->TypeName, + cmStrCat(this->ArbitraryDescription, " \"", fileSetName, "\""), clear); + } + return true; + } + if (cmHasPrefix(prop, this->PathPrefix)) { + auto fileSetName = prop.substr(this->PathPrefix.size()); + if (fileSetName.empty()) { + impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat(this->ArbitraryDescription, " name cannot be empty.")); + } else { + impl->AddPathToFileSet( + tgt, fileSetName, value, this->TypeName, + cmStrCat(this->ArbitraryDescription, " \"", fileSetName, "\""), clear); + } + return true; + } + if (prop == this->SelfEntries.PropertyName) { + impl->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat(this->SelfEntries.PropertyName, " property is read-only\n")); + return true; + } + if (prop == this->InterfaceEntries.PropertyName) { + impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, + cmStrCat(this->InterfaceEntries.PropertyName, + " property is read-only\n")); + return true; + } + return false; +} + +std::pair FileSetType::ReadProperties( + cmTarget const* tgt, cmTargetInternals const* impl, + const std::string& prop) const +{ + bool did_read = false; + cmValue value = nullptr; + if (prop == this->DefaultDirectoryProperty) { + value = impl->GetFileSetDirectories(tgt, std::string(this->TypeName), + this->TypeName); + did_read = true; + } else if (prop == this->DefaultPathProperty) { + value = + impl->GetFileSetPaths(tgt, std::string(this->TypeName), this->TypeName); + did_read = true; + } else if (prop == this->SelfEntries.PropertyName) { + static std::string output; + output = cmJoin(this->SelfEntries.Entries, ";"_s); + value = cmValue(output); + did_read = true; + } else if (prop == this->InterfaceEntries.PropertyName) { + static std::string output; + output = cmJoin(this->InterfaceEntries.Entries, ";"_s); + value = cmValue(output); + did_read = true; + } else if (cmHasPrefix(prop, this->DirectoryPrefix)) { + std::string fileSetName = prop.substr(this->DirectoryPrefix.size()); + if (!fileSetName.empty()) { + value = impl->GetFileSetDirectories(tgt, fileSetName, this->TypeName); + } + did_read = true; + } else if (cmHasPrefix(prop, this->PathPrefix)) { + std::string fileSetName = prop.substr(this->PathPrefix.size()); + if (!fileSetName.empty()) { + value = impl->GetFileSetPaths(tgt, fileSetName, this->TypeName); + } + did_read = true; + } + return { did_read, value }; +} + +void FileSetType::AddFileSet(const std::string& name, cmFileSetVisibility vis, + cmListFileBacktrace bt) +{ + if (cmFileSetVisibilityIsForSelf(vis)) { + this->SelfEntries.Entries.emplace_back(name, bt); + } + if (cmFileSetVisibilityIsForInterface(vis)) { + this->InterfaceEntries.Entries.emplace_back(name, std::move(bt)); + } +} + namespace { #define SETUP_COMMON_LANGUAGE_PROPERTIES(lang) \ initProp(#lang "_COMPILER_LAUNCHER"); \ @@ -1177,12 +1356,12 @@ cmBTStringRange cmTarget::GetLinkInterfaceDirectExcludeEntries() const cmBTStringRange cmTarget::GetHeaderSetsEntries() const { - return cmMakeRange(this->impl->HeaderSetsEntries); + return cmMakeRange(this->impl->HeadersFileSets.SelfEntries.Entries); } cmBTStringRange cmTarget::GetInterfaceHeaderSetsEntries() const { - return cmMakeRange(this->impl->InterfaceHeaderSetsEntries); + return cmMakeRange(this->impl->HeadersFileSets.InterfaceEntries.Entries); } namespace { @@ -1214,10 +1393,6 @@ MAKE_PROP(BINARY_DIR); MAKE_PROP(SOURCE_DIR); MAKE_PROP(FALSE); MAKE_PROP(TRUE); -MAKE_PROP(HEADER_DIRS); -MAKE_PROP(HEADER_SET); -MAKE_PROP(HEADER_SETS); -MAKE_PROP(INTERFACE_HEADER_SETS); MAKE_PROP(INTERFACE_LINK_LIBRARIES); MAKE_PROP(INTERFACE_LINK_LIBRARIES_DIRECT); MAKE_PROP(INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE); @@ -1392,7 +1567,9 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) } } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME") && !this->impl->CheckImportedLibName( - prop, value ? value : std::string{})) { + prop, + value ? value + : std::string{})) { // NOLINT(bugprone-branch-clone) /* error was reported by check method */ } else if (prop == propCUDA_PTX_COMPILATION && this->GetType() != cmStateEnums::OBJECT_LIBRARY) { @@ -1443,41 +1620,9 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) } else { this->impl->LanguageStandardProperties.erase(prop); } - } else if (prop == propHEADER_DIRS) { - this->impl->AddDirectoryToFileSet(this, "HEADERS", value, "HEADERS"_s, - "The default header set"_s, true); - } else if (prop == propHEADER_SET) { - this->impl->AddPathToFileSet(this, "HEADERS", value, "HEADERS"_s, - "The default header set"_s, true); - } else if (cmHasLiteralPrefix(prop, "HEADER_DIRS_")) { - auto fileSetName = prop.substr(cmStrLen("HEADER_DIRS_")); - if (fileSetName.empty()) { - this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, - "Header set name cannot be empty."); - return; - } - this->impl->AddDirectoryToFileSet( - this, fileSetName, value, "HEADERS"_s, - cmStrCat("Header set \"", fileSetName, "\""), true); - } else if (cmHasLiteralPrefix(prop, "HEADER_SET_")) { - auto fileSetName = prop.substr(cmStrLen("HEADER_SET_")); - if (fileSetName.empty()) { - this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, - "Header set name cannot be empty."); - return; - } - this->impl->AddPathToFileSet(this, fileSetName, value, "HEADERS"_s, - cmStrCat("Header set \"", fileSetName, "\""), - true); - } else if (prop == propHEADER_SETS) { - this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, - "HEADER_SETS property is read-only\n"); - return; - } else if (prop == propINTERFACE_HEADER_SETS) { - this->impl->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - "INTERFACE_HEADER_SETS property is read-only\n"); - return; + } else if (this->impl->HeadersFileSets.WriteProperties( + this, this->impl.get(), prop, value, true)) { + /* Handled in the `if` condition. */ } else { this->impl->Properties.SetProperty(prop, value); } @@ -1588,41 +1733,9 @@ void cmTarget::AppendProperty(const std::string& prop, prop == "OBJC_STANDARD" || prop == "OBJCXX_STANDARD") { this->impl->Makefile->IssueMessage( MessageType::FATAL_ERROR, prop + " property may not be appended."); - } else if (prop == "HEADER_DIRS") { - this->impl->AddDirectoryToFileSet(this, "HEADERS", value, "HEADERS"_s, - "The default header set"_s, false); - } else if (cmHasLiteralPrefix(prop, "HEADER_DIRS_")) { - auto fileSetName = prop.substr(cmStrLen("HEADER_DIRS_")); - if (fileSetName.empty()) { - this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, - "Header set name cannot be empty."); - return; - } - this->impl->AddDirectoryToFileSet( - this, fileSetName, value, "HEADERS"_s, - cmStrCat("Header set \"", fileSetName, "\""), false); - } else if (prop == "HEADER_SET") { - this->impl->AddPathToFileSet(this, "HEADERS", value, "HEADERS"_s, - "The default header set"_s, false); - } else if (cmHasLiteralPrefix(prop, "HEADER_SET_")) { - auto fileSetName = prop.substr(cmStrLen("HEADER_SET_")); - if (fileSetName.empty()) { - this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, - "Header set name cannot be empty."); - return; - } - this->impl->AddPathToFileSet(this, fileSetName, value, "HEADERS"_s, - cmStrCat("Header set \"", fileSetName, "\""), - false); - } else if (prop == "HEADER_SETS") { - this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, - "HEADER_SETS property is read-only\n"); - return; - } else if (prop == "INTERFACE_HEADER_SETS") { - this->impl->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - "INTERFACE_HEADER_SETS property is read-only\n"); - return; + } else if (this->impl->HeadersFileSets.WriteProperties( + this, this->impl.get(), prop, value, false)) { + /* Handled in the `if` condition. */ } else { this->impl->Properties.AppendProperty(prop, value, asString); } @@ -1964,10 +2077,6 @@ cmValue cmTarget::GetProperty(const std::string& prop) const propBINARY_DIR, propSOURCE_DIR, propSOURCES, - propHEADER_DIRS, - propHEADER_SET, - propHEADER_SETS, - propINTERFACE_HEADER_SETS, propINTERFACE_LINK_LIBRARIES, propINTERFACE_LINK_LIBRARIES_DIRECT, propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE, @@ -2124,49 +2233,15 @@ cmValue cmTarget::GetProperty(const std::string& prop) const .GetDirectory() .GetCurrentSource()); } - if (prop == propHEADER_DIRS) { - return this->impl->GetFileSetDirectories(this, "HEADERS", "HEADERS"_s); - } - if (prop == propHEADER_SET) { - return this->impl->GetFileSetPaths(this, "HEADERS", "HEADERS"_s); - } - 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(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(set_names, ";"_s); - return cmValue(output); - } } - if (cmHasLiteralPrefix(prop, "HEADER_DIRS_")) { - std::string fileSetName = prop.substr(cmStrLen("HEADER_DIRS_")); - if (fileSetName.empty()) { - return nullptr; - } - return this->impl->GetFileSetDirectories(this, fileSetName, "HEADERS"_s); - } - if (cmHasLiteralPrefix(prop, "HEADER_SET_")) { - std::string fileSetName = prop.substr(cmStrLen("HEADER_SET_")); - if (fileSetName.empty()) { - return nullptr; + + // Check fileset properties. + { + auto headers = + this->impl->HeadersFileSets.ReadProperties(this, this->impl.get(), prop); + if (headers.first) { + return headers.second; } - return this->impl->GetFileSetPaths(this, fileSetName, "HEADERS"_s); } cmValue retVal = this->impl->Properties.GetPropertyValue(prop); @@ -2441,13 +2516,9 @@ 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()); + auto bt = this->impl->Makefile->GetBacktrace(); + if (type == this->impl->HeadersFileSets.TypeName) { + this->impl->HeadersFileSets.AddFileSet(name, vis, std::move(bt)); } } return std::make_pair(&result.first->second, result.second); @@ -2481,7 +2552,7 @@ std::vector cmTarget::GetAllInterfaceFileSets() const } }; - appendEntries(this->impl->InterfaceHeaderSetsEntries); + appendEntries(this->impl->HeadersFileSets.InterfaceEntries.Entries); return result; } diff --git a/Tests/RunCMake/target_sources/FileSetImport.cmake b/Tests/RunCMake/target_sources/FileSetImport.cmake index c7acc5f..db82ca8 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;dir3;e;f;g") +assert_prop_eq(export::lib1 INTERFACE_HEADER_SETS "HEADERS;b;c;d;e;f;g;dir3") assert_prop_eq(export::lib1 HEADER_SET "${CMAKE_CURRENT_SOURCE_DIR}/error.c") assert_prop_eq(export::lib1 HEADER_SET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/error.c") if (_multi_config) @@ -72,7 +72,7 @@ else () endif () assert_prop_eq(install::lib1 HEADER_SETS "") -assert_prop_eq(install::lib1 INTERFACE_HEADER_SETS "HEADERS;b;c;d;dir3;e;f;g") +assert_prop_eq(install::lib1 INTERFACE_HEADER_SETS "HEADERS;b;c;d;e;f;g;dir3") 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_HEADERS "${export_build_dir}/install/include/error.c") diff --git a/Tests/RunCMake/target_sources/FileSetProperties.cmake b/Tests/RunCMake/target_sources/FileSetProperties.cmake index a9a32b2..56cce08 100644 --- a/Tests/RunCMake/target_sources/FileSetProperties.cmake +++ b/Tests/RunCMake/target_sources/FileSetProperties.cmake @@ -57,7 +57,7 @@ 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 "HEADERS;a;c;d") +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_DIRS_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}") @@ -66,7 +66,7 @@ assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$;$;$;$") target_sources(lib1 PUBLIC FILE_SET HEADERS FILES h2.h) -assert_prop_eq(lib1 INTERFACE_HEADER_SETS "HEADERS;a;c;d") +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_DIRS_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}") -- cgit v0.12