1313#include " toml_ext.hpp"
1414#include " util.hpp"
1515
16- enum class LinkType {
17- STATIC,
18- SHARED
19- };
20-
2116struct Feature {
2217 std::unordered_set<std::string> defines;
2318 std::unordered_set<std::string> undefines;
@@ -42,6 +37,15 @@ inline void force_oneline(toml::value& v) {
4237 if constexpr (Derived::enable_##enable_macro) \
4338 maybe_set (out, #field_name, field_name)
4439
40+ // / Serializes and globs a vector of source files to a TOML array.
41+ #define SERIALIZE_GLOB_SOURCES (field ) \
42+ if constexpr (Derived::enable_##field) { \
43+ toml::array arr; \
44+ for (const auto & s : expand_glob_sources (field)) \
45+ arr.push_back (s.serialize ()); \
46+ maybe_set (out, #field, arr); \
47+ }
48+
4549struct Dependency {
4650 std::string name;
4751 std::string git_url;
@@ -125,18 +129,8 @@ struct BaseFields {
125129 }
126130
127131 void serialize (toml::value& out) const {
128- if constexpr (Derived::enable_modules) {
129- toml::array module_array;
130- for (const auto & s : expand_glob_sources (modules))
131- module_array.push_back (s.serialize ());
132- maybe_set (out, " modules" , module_array);
133- }
134- if constexpr (Derived::enable_sources) {
135- toml::array src_array;
136- for (const auto & s : expand_glob_sources (sources))
137- src_array.push_back (s.serialize ());
138- maybe_set (out, " sources" , src_array);
139- }
132+ SERIALIZE_GLOB_SOURCES (modules);
133+ SERIALIZE_GLOB_SOURCES (sources);
140134
141135 MAYBE_SET_FIELD (include, include);
142136 MAYBE_SET_FIELD (defines, defines);
@@ -171,7 +165,7 @@ struct BaseFields {
171165 merge (libs, other.libs );
172166 }
173167
174- std::vector<source_file> parse_sources (const toml::value& section, const std::string& base_path, const std::string& key = " sources" ) {
168+ static std::vector<source_file> parse_sources (const toml::value& section, const std::string& base_path, const std::string& key = " sources" ) {
175169 std::vector<source_file> temp_sources;
176170 if (!section.contains (key))
177171 return temp_sources;
@@ -195,7 +189,10 @@ struct BaseFields {
195189 file_path = source_entry;
196190 }
197191
198- std::filesystem::path full_path = std::filesystem::path (base_path) / file_path;
192+ std::filesystem::path full_path = std::filesystem::path (file_path);
193+ if (!full_path.is_absolute ())
194+ full_path = std::filesystem::path (base_path) / full_path;
195+
199196 temp_sources.emplace_back (
200197 util::file_system::to_linux_path (full_path.lexically_normal ().string ()),
201198 extracted_cflags);
@@ -210,9 +207,9 @@ struct BaseFields {
210207 for (const auto & s : input_sources) {
211208 try {
212209 std::vector<std::filesystem::path> globbed_paths = glob::glob (s.path );
213- for (const auto & path : globbed_paths) {
210+ for (const auto & path : globbed_paths)
214211 expanded.emplace_back (util::file_system::to_linux_path (path.string ()), s.cflags );
215- }
212+
216213 } catch (const std::exception& e) {
217214 muuk::logger::warn (" Error while globbing '{}': {}" , s.path , e.what ());
218215 }
@@ -302,28 +299,4 @@ struct ProfileConfig : BaseConfig<ProfileConfig> {
302299 const std::string& base_path);
303300
304301 void serialize (toml::value& out) const ;
305- };
306-
307- struct Library : BaseConfig<Library> {
308- std::string name;
309- std::string version;
310- std::unordered_set<std::string> profiles;
311-
312- static constexpr bool enable_compilers = false ;
313- static constexpr bool enable_platforms = false ;
314- static constexpr bool enable_dependencies = false ;
315-
316- struct External {
317- std::string type, path;
318- std::vector<std::string> args;
319- std::vector<std::string> outputs;
320-
321- void load (const toml::value& v);
322- void serialize (toml::value& out) const ;
323- };
324-
325- External external;
326-
327- void load (const std::string& name_, const std::string& version_, const std::string& base_path_, const toml::value& v);
328- void serialize (toml::value& out, Platforms platforms, Compilers compilers) const ;
329- };
302+ };
0 commit comments