Skip to content

Commit

Permalink
Merge topic 'source_group-TREE-no-FILES'
Browse files Browse the repository at this point in the history
8778835 source_group: Add test/example for TREE without FILES
d85238a source_group: Fix TREE without FILES

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !8599
  • Loading branch information
bradking authored and kwrobot committed Jul 7, 2023
2 parents 10a1759 + 8778835 commit b8b53db
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
23 changes: 20 additions & 3 deletions Source/cmSourceGroupCommand.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

#include <cstddef>
#include <map>
#include <memory>
#include <set>
#include <utility>

#include <cmext/algorithm>

#include "cmExecutionStatus.h"
#include "cmMakefile.h"
#include "cmSourceFile.h"
#include "cmSourceFileLocation.h"
#include "cmSourceGroup.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Tests/SourceGroups/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ add_executable(SourceGroups main.c bar.c foo.c sub1/foo.c sub1/foobar.c baz.c
${tree_files_with_prefix} ${tree_files_without_prefix}
${tree_files_with_empty_prefix} README.txt
nested.c)

add_subdirectory(sub2)
4 changes: 4 additions & 0 deletions Tests/SourceGroups/sub2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_executable(SourceGroups2 main.c
qux.c subsub/qax.c)

source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" ) #PREFIX TheSubDir2 )
11 changes: 11 additions & 0 deletions Tests/SourceGroups/sub2/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdio.h>

extern int qax(void);
extern int qux(void);

int main()
{
printf("qux: %d qax: %d\n", qux(), qax());

return 0;
}
4 changes: 4 additions & 0 deletions Tests/SourceGroups/sub2/qux.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int qux(void)
{
return 1234;
}
4 changes: 4 additions & 0 deletions Tests/SourceGroups/sub2/subsub/qax.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int qax(void)
{
return 123;
}

0 comments on commit b8b53db

Please sign in to comment.