MCPcopy Create free account
hub / github.com/Kitware/CMake / cmAuxSourceDirectoryCommand

Function cmAuxSourceDirectoryCommand

Source/cmAuxSourceDirectoryCommand.cxx:21–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19#include "cmake.h"
20
21bool cmAuxSourceDirectoryCommand(std::vector<std::string> const& args,
22 cmExecutionStatus& status)
23{
24 if (args.size() != 2) {
25 status.SetError("called with incorrect number of arguments");
26 return false;
27 }
28
29 cmMakefile& mf = status.GetMakefile();
30 std::string sourceListValue;
31 std::string const& templateDirectory = args[0];
32 std::string tdir;
33 if (!cmSystemTools::FileIsFullPath(templateDirectory)) {
34 tdir = cmStrCat(mf.GetCurrentSourceDirectory(), '/', templateDirectory);
35 } else {
36 tdir = templateDirectory;
37 }
38
39 // was the list already populated
40 sourceListValue = mf.GetSafeDefinition(args[1]);
41
42 std::vector<std::string> files;
43
44 // Load all the files in the directory
45 cmsys::Directory dir;
46 if (dir.Load(tdir)) {
47 size_t numfiles = dir.GetNumberOfFiles();
48 for (size_t i = 0; i < numfiles; ++i) {
49 std::string file = dir.GetFile(static_cast<unsigned long>(i));
50 // Split the filename into base and extension
51 std::string::size_type dotpos = file.rfind('.');
52 if (dotpos != std::string::npos) {
53 auto ext = cm::string_view(file).substr(dotpos + 1);
54 // Process only source files
55 auto* cm = mf.GetCMakeInstance();
56 if (dotpos > 0 && cm->IsACLikeSourceExtension(ext)) {
57 std::string fullname = cmStrCat(templateDirectory, '/', file);
58 // add the file as a class file so
59 // depends can be done
60 cmSourceFile* sf = mf.GetOrCreateSource(fullname);
61 sf->SetProperty("ABSTRACT", "0");
62 files.push_back(std::move(fullname));
63 }
64 }
65 }
66 }
67 std::sort(files.begin(), files.end());
68 if (!sourceListValue.empty()) {
69 sourceListValue += ";";
70 }
71 sourceListValue += cmList::to_string(files);
72 mf.AddDefinition(args[1], sourceListValue);
73 return true;
74}

Callers

nothing calls this directly

Calls 15

moveFunction · 0.85
to_stringFunction · 0.85
rfindMethod · 0.80
GetOrCreateSourceMethod · 0.80
push_backMethod · 0.80
cmStrCatFunction · 0.70
sizeMethod · 0.45
SetErrorMethod · 0.45
GetMakefileMethod · 0.45
LoadMethod · 0.45
substrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…