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