|
19 | 19 |
|
20 | 20 | #include<filesystem> |
21 | 21 |
|
| 22 | +#include"schema/path.h" |
| 23 | + |
22 | 24 | namespacefs= std::filesystem; |
23 | 25 |
|
24 | 26 | namespacebuildcc::internal { |
25 | 27 |
|
26 | 28 | // Requires |
27 | | -// - TargetStorer |
28 | | -// - TargetConfig |
29 | | -// - TargetEnv |
| 29 | +// Toolchain |
| 30 | +// User::Headers |
| 31 | +// User::IncludeDirs |
| 32 | +// TargetEnv |
30 | 33 | template<typename T>classIncludeApi { |
31 | 34 | public: |
| 35 | +const fs_unordered_set &GetHeaderFiles()const { |
| 36 | +constauto &t =static_cast<const T &>(*this); |
| 37 | +return t.user_.headers; |
| 38 | + } |
| 39 | + |
| 40 | +const fs_unordered_set &GetIncludeDirs()const { |
| 41 | +constauto &t =static_cast<const T &>(*this); |
| 42 | +return t.user_.include_dirs; |
| 43 | + } |
| 44 | + |
| 45 | +voidAddHeaderAbsolute(const fs::path &absolute_filepath) { |
| 46 | +auto &t =static_cast<T &>(*this); |
| 47 | + |
| 48 | + t.toolchain_.GetConfig().ExpectsValidHeader(absolute_filepath); |
| 49 | + t.user_.headers.insert(absolute_filepath); |
| 50 | + } |
| 51 | + |
| 52 | +voidGlobHeadersAbsolute(const fs::path &absolute_path) { |
| 53 | +auto &t =static_cast<T &>(*this); |
| 54 | + |
| 55 | +for (constauto &p :fs::directory_iterator(absolute_path)) { |
| 56 | +if (t.toolchain_.GetConfig().IsValidHeader(p.path())) { |
| 57 | +AddHeaderAbsolute(p.path()); |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | +voidAddIncludeDirAbsolute(const fs::path &absolute_include_dir, |
| 63 | +bool glob_headers =false) { |
| 64 | +auto &t =static_cast<T &>(*this); |
| 65 | + |
| 66 | + t.user_.include_dirs.insert(absolute_include_dir); |
| 67 | + |
| 68 | +if (glob_headers) { |
| 69 | +GlobHeadersAbsolute(absolute_include_dir); |
| 70 | + } |
| 71 | + } |
| 72 | + |
32 | 73 | voidAddHeader(const fs::path &relative_filename, |
33 | | -const fs::path &relative_to_target_path =""); |
34 | | -voidAddHeaderAbsolute(const fs::path &absolute_filepath); |
| 74 | +const fs::path &relative_to_target_path ="") { |
| 75 | +auto &t =static_cast<T &>(*this); |
| 76 | + |
| 77 | +// Check Source |
| 78 | + fs::path absolute_filepath = |
| 79 | + t.env_.GetTargetRootDir() / relative_to_target_path / relative_filename; |
| 80 | +AddHeaderAbsolute(absolute_filepath); |
| 81 | + } |
35 | 82 |
|
36 | | -voidGlobHeaders(const fs::path &relative_to_target_path =""); |
37 | | -voidGlobHeadersAbsolute(const fs::path &absolute_path); |
| 83 | +voidGlobHeaders(const fs::path &relative_to_target_path ="") { |
| 84 | +auto &t =static_cast<T &>(*this); |
| 85 | + |
| 86 | + fs::path absolute_path = |
| 87 | + t.env_.GetTargetRootDir() / relative_to_target_path; |
| 88 | +GlobHeadersAbsolute(absolute_path); |
| 89 | + } |
38 | 90 |
|
39 | 91 | voidAddIncludeDir(const fs::path &relative_include_dir, |
40 | | -bool glob_headers =false); |
41 | | -voidAddIncludeDirAbsolute(const fs::path &absolute_include_dir, |
42 | | -bool glob_headers =false); |
| 92 | +bool glob_headers =false) { |
| 93 | +auto &t =static_cast<T &>(*this); |
| 94 | + |
| 95 | +const fs::path absolute_include_dir = |
| 96 | + t.env_.GetTargetRootDir() / relative_include_dir; |
| 97 | +AddIncludeDirAbsolute(absolute_include_dir, glob_headers); |
| 98 | + } |
43 | 99 | }; |
44 | 100 |
|
45 | 101 | }// namespace buildcc::internal |
|