diff options
author | Alex Neundorf <neundorf@kde.org> | 2023-06-28 22:02:29 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-07-05 11:54:50 (GMT) |
commit | d85238a2f29c552041293f1f7e64e3de55e55907 (patch) | |
tree | e8fc8b19282ac0f872feef4d4aa32daa30ddc6e0 | |
parent | 8086ce2706dcbbea5d9ead0222666f2004826c53 (diff) | |
download | CMake-d85238a2f29c552041293f1f7e64e3de55e55907.zip CMake-d85238a2f29c552041293f1f7e64e3de55e55907.tar.gz CMake-d85238a2f29c552041293f1f7e64e3de55e55907.tar.bz2 |
source_group: Fix TREE without FILES
According to the documentation of `source_group()` the `FILES`
parameter is optional, but that was actually not the case.
When using `source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR})`
cmake did not previously create the source tree, but recognized
it as the old syntax. With this patch, cmake recognizes it as
`TREE` syntax if the first argument is TREE followed by a directory.
Then, if no files are given, it defaults to all files in the
directory. PREFIX works too.
Fixes: #24590
-rw-r--r-- | Source/cmSourceGroupCommand.cxx | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/Source/cmSourceGroupCommand.cxx b/Source/cmSourceGroupCommand.cxx index bb75a14..4b1685f 100644 --- a/Source/cmSourceGroupCommand.cxx +++ b/Source/cmSourceGroupCommand.cxx @@ -4,6 +4,7 @@ #include <cstddef> #include <map> +#include <memory> #include <set> #include <utility> @@ -11,6 +12,8 @@ #include "cmExecutionStatus.h" #include "cmMakefile.h" +#include "cmSourceFile.h" +#include "cmSourceFileLocation.h" #include "cmSourceGroup.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -194,7 +197,10 @@ bool cmSourceGroupCommand(std::vector<std::string> const& args, // If only two arguments are given, the pre-1.8 version of the // command is being invoked. - if (args.size() == 2 && args[1] != "FILES") { + bool isShortTreeSyntax = + ((args.size() == 2) && (args[0] == kTreeOptionName) && + cmSystemTools::FileIsDirectory(args[1])); + if (args.size() == 2 && args[1] != kFilesOptionName && !isShortTreeSyntax) { cmSourceGroup* sg = mf.GetOrCreateSourceGroup(args[0]); if (!sg) { @@ -274,8 +280,19 @@ static bool processTree(cmMakefile& mf, ParsedArguments& parsedArguments, ? "" : parsedArguments[kPrefixOptionName].front(); - const std::vector<std::string> filesVector = prepareFilesPathsForTree( - parsedArguments[kFilesOptionName], mf.GetCurrentSourceDirectory()); + std::vector<std::string> files = parsedArguments[kFilesOptionName]; + if (files.empty()) { + const std::vector<std::unique_ptr<cmSourceFile>>& srcFiles = + mf.GetSourceFiles(); + for (const auto& srcFile : srcFiles) { + if (!srcFile->GetIsGenerated()) { + files.push_back(srcFile->GetLocation().GetFullPath()); + } + } + } + + const std::vector<std::string> filesVector = + prepareFilesPathsForTree(files, mf.GetCurrentSourceDirectory()); if (!rootIsPrefix(root, filesVector, errorMsg)) { return false; |