Rework how the config file is read
Still need to remove reduntant code and test it much more thoroughly.
This commit is contained in:
+356
-162
@@ -7,33 +7,321 @@
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
ConfigFile::ConfigFile()
|
||||
: outputdir("bin/"), srcdir("src/"), outputname(""), projectname(FileUtils::GetCurrentDirectory()), hFile(projectname+".h"), executable(true), shared(true), generateHFile(false)
|
||||
ConfigFile::ConfigFile(const std::string& path, int)
|
||||
: configPath{path}
|
||||
{
|
||||
// Converts project name (current directory) to lowercase
|
||||
// and replace whitespace with underscore
|
||||
std::transform(
|
||||
projectname.begin(),
|
||||
projectname.end(),
|
||||
std::back_inserter(outputname),
|
||||
[](unsigned char c)
|
||||
{
|
||||
if(c == ' ')
|
||||
return '_';
|
||||
return (char)std::tolower(c);
|
||||
});
|
||||
// Create xml
|
||||
XMLObject makegen("makegen", {}, std::map<std::string, std::vector<XMLObject>>{});
|
||||
|
||||
// Removes all other characters
|
||||
std::remove_if(
|
||||
outputdir.begin(),
|
||||
outputdir.end(),
|
||||
[](unsigned char c)
|
||||
{
|
||||
return (c < 'a' || c > 'z') && c != '_';
|
||||
});
|
||||
// Version, target and configuration is probably going to be used in the future
|
||||
makegen.AddXMLObject(XMLObject("version", {}, "v1.3.0"));
|
||||
makegen.AddXMLObject(XMLObject("target", {}, "Release"));
|
||||
|
||||
// Add suffix
|
||||
outputname += ".out";
|
||||
XMLObject configuration("configuration", {{"name", "Release"}}, std::map<std::string, std::vector<XMLObject>>{});
|
||||
configuration.AddXMLObject(XMLObject("projectname", {}, ConfigUtils::GetDefaultProjectName(configPath)));
|
||||
configuration.AddXMLObject(XMLObject("outputname", {}, ConfigUtils::GetDefaultOutputName(configPath)));
|
||||
configuration.AddXMLObject(XMLObject("srcdir", {}, "src/"));
|
||||
configuration.AddXMLObject(XMLObject("outputdir", {}, "bin/"));
|
||||
configuration.AddXMLObject(XMLObject("hfilename", {}, ConfigUtils::GetDefaultHFileName(configPath)));
|
||||
configuration.AddXMLObject(XMLObject("outputtype", {}, "executable"));
|
||||
configuration.AddXMLObject(XMLObject("generatehfile", {}, "false"));
|
||||
|
||||
makegen.AddXMLObject(configuration);
|
||||
config = makegen;
|
||||
Init();
|
||||
}
|
||||
|
||||
ConfigFile::ConfigFile(const std::string& path)
|
||||
: config{XML::FromFile(path + CONFIG_FILENAME)}, configPath{path}
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
ConfigFile::ConfigFile(XMLObject& config, const std::string& path)
|
||||
: config{config}, configPath{path}
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
void ConfigFile::Init()
|
||||
{
|
||||
const std::vector<XMLObject>* targetXml = config.GetObjectPtr("target");
|
||||
target = "Release";
|
||||
if(!targetXml || targetXml->size() == 0)
|
||||
{
|
||||
LOG_ERROR("No target found in config file. Using target=", target);
|
||||
return;
|
||||
}
|
||||
|
||||
if(targetXml->size() > 1)
|
||||
LOG_ERROR("To many targets in config file. Using target=", (*targetXml)[0].GetText());
|
||||
if(targetXml->size() > 0)
|
||||
target = (*targetXml)[0].GetText();
|
||||
}
|
||||
|
||||
std::string& ConfigFile::GetSettingString(ConfigSetting setting)
|
||||
{
|
||||
// Adding it to the cache since we need to return a reference
|
||||
if(!ConfigUtils::IsStringSetting(setting))
|
||||
{
|
||||
LOG_ERROR("Invalid string setting");
|
||||
return cache.strings.emplace("invalid", "").first->second;
|
||||
}
|
||||
|
||||
std::string sSetting = ConfigUtils::GetSettingName(setting);
|
||||
auto it = cache.strings.find(sSetting);
|
||||
if(it != cache.strings.end())
|
||||
return it->second;
|
||||
|
||||
const std::vector<XMLObject>* values = GetConfiguration().GetObjectPtr(sSetting);
|
||||
|
||||
// No value found, using default
|
||||
if(values == nullptr)
|
||||
return cache.strings.emplace(sSetting, ConfigUtils::GetDefaultSettingString(setting, configPath)).first->second;
|
||||
|
||||
if(values->size() != 1)
|
||||
{
|
||||
LOG_ERROR("To many arguments for setting using first: ", (int)setting, "=", (*values)[0].GetText());
|
||||
}
|
||||
std::string s = (*values)[0].GetText();
|
||||
if(ConfigUtils::IsDirectory(setting) && s[s.size()-1] != '/')
|
||||
s += '/';
|
||||
return cache.strings.emplace(sSetting, s).first->second;
|
||||
}
|
||||
|
||||
bool ConfigFile::GetSettingBool(ConfigSetting setting)
|
||||
{
|
||||
if(setting == ConfigSetting::Invalid)
|
||||
{
|
||||
LOG_ERROR("Invalid config setting");
|
||||
return false;
|
||||
}
|
||||
std::string sSetting = ConfigUtils::GetSettingName(setting);
|
||||
auto it = cache.bools.find(sSetting);
|
||||
if(it != cache.bools.end())
|
||||
return it->second;
|
||||
|
||||
const std::vector<XMLObject>* values = GetConfiguration().GetObjectPtr(sSetting);//,
|
||||
|
||||
if(values == nullptr)
|
||||
return cache.bools.emplace(sSetting, ConfigUtils::GetDefaultSettingBool(setting)).first->second;
|
||||
|
||||
if(values->size() != 1)
|
||||
{
|
||||
LOG_ERROR("To many arguments for setting using first: ", (int)setting, "=", (*values)[0].GetText());
|
||||
}
|
||||
return cache.bools.emplace(sSetting, (*values)[0].GetText() == "true").first->second;
|
||||
}
|
||||
|
||||
std::vector<std::string>& ConfigFile::GetSettingVectorString(ConfigSetting setting)
|
||||
{
|
||||
std::string sSetting = ConfigUtils::GetSettingName(setting);
|
||||
auto it = cache.vecStrings.find(sSetting);
|
||||
if(it != cache.vecStrings.end())
|
||||
return it->second;
|
||||
|
||||
const std::vector<XMLObject>* values = GetConfiguration().GetObjectPtr(sSetting);
|
||||
if(values == nullptr)
|
||||
return cache.vecStrings.emplace(sSetting, std::vector<std::string>{}).first->second;
|
||||
|
||||
std::vector<std::string> strings;
|
||||
strings.reserve(values->size());
|
||||
for(auto it = values->begin(); it != values->end(); ++it)
|
||||
{
|
||||
if(it->GetText() == "")
|
||||
continue;
|
||||
std::string s = it->GetText();
|
||||
if(ConfigUtils::IsDirectory(setting) && s[s.size()-1] != '/')
|
||||
s += '/';
|
||||
strings.push_back(s);
|
||||
}
|
||||
|
||||
return cache.vecStrings.emplace(sSetting, strings).first->second;
|
||||
}
|
||||
|
||||
std::vector<std::string> ConfigFile::GetSetting(ConfigSetting setting)
|
||||
{
|
||||
if(ConfigUtils::IsStringSetting(setting))
|
||||
return {GetSettingString(setting)};
|
||||
else if(ConfigUtils::IsVectorSetting(setting))
|
||||
return GetSettingVectorString(setting);
|
||||
else if(ConfigUtils::IsBoolSetting(setting))
|
||||
return {GetSettingBool(setting) ? "true" : "false"};
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Invalid config setting");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
bool ConfigFile::SetSettingString(ConfigSetting setting, const std::string& value)
|
||||
{
|
||||
// Check if valid enum
|
||||
std::string s = value;
|
||||
std::string sSetting = ConfigUtils::GetSettingName(setting);
|
||||
if(ConfigUtils::IsStringSetting(setting))
|
||||
{
|
||||
if(ConfigUtils::IsDirectory(setting) && s[s.size()-1] != '/')
|
||||
{
|
||||
s += '/';
|
||||
}
|
||||
auto it = cache.strings.find(sSetting);
|
||||
// Update cache
|
||||
if(it != cache.strings.end())
|
||||
it->second = s;
|
||||
else
|
||||
cache.strings.emplace(sSetting, s);
|
||||
}
|
||||
else if(ConfigUtils::IsBoolSetting(setting))
|
||||
{
|
||||
if(s == "true" || s == "t" || s == "yes" || s == "y")
|
||||
s = "true";
|
||||
else if(s == "false" || s == "f" || s == "no" || s == "n")
|
||||
s = "false";
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Invalid boolean value: ", s);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto it = cache.bools.find(sSetting);
|
||||
// Update cache
|
||||
if(it != cache.bools.end())
|
||||
it->second = s == "true";
|
||||
else
|
||||
cache.bools.emplace(sSetting, value == "true");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Not a string setting");
|
||||
return false;
|
||||
}
|
||||
|
||||
XMLObject& configuration = GetConfiguration();
|
||||
std::vector<XMLObject>* values = configuration.GetObjectPtr(sSetting);
|
||||
if(values == nullptr)
|
||||
configuration.AddXMLObject({sSetting, {}, s});
|
||||
else if(values->size() > 1)
|
||||
LOG_ERROR("Multiple values of setting, changing first: ", sSetting, "=", s);
|
||||
else
|
||||
(*values)[0].SetText(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConfigFile::AddSettingVectorString(ConfigSetting setting, const std::string& value)
|
||||
{
|
||||
// Check if valid enum
|
||||
if(ConfigUtils::IsVectorSetting(setting))
|
||||
{
|
||||
std::string s = value;
|
||||
if(ConfigUtils::IsDirectory(setting) && s[s.size()-1] != '/')
|
||||
{
|
||||
s += '/';
|
||||
}
|
||||
std::string sSetting = ConfigUtils::GetSettingName(setting);
|
||||
auto it = cache.vecStrings.find(sSetting);
|
||||
|
||||
// Update cache
|
||||
if(it != cache.vecStrings.end())
|
||||
it->second.push_back(s);
|
||||
else
|
||||
cache.vecStrings.emplace(sSetting, std::vector<std::string>{s});
|
||||
|
||||
GetConfiguration().AddXMLObject({sSetting, {}, s});
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Not a vector setting");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConfigFile::RemoveSettingVectorString(ConfigSetting setting, const std::string& value)
|
||||
{
|
||||
// Check if valid enum
|
||||
if(ConfigUtils::IsVectorSetting(setting))
|
||||
{
|
||||
std::string s = value;
|
||||
if(ConfigUtils::IsDirectory(setting) && s[s.size()-1] != '/')
|
||||
{
|
||||
s += '/';
|
||||
}
|
||||
std::string sSetting = ConfigUtils::GetSettingName(setting);
|
||||
|
||||
auto it = cache.vecStrings.find(sSetting);
|
||||
if(it != cache.vecStrings.end())
|
||||
{
|
||||
// Update cache
|
||||
for(auto itVec = it->second.begin(); itVec != it->second.end(); ++itVec)
|
||||
{
|
||||
if(*itVec == s)
|
||||
{
|
||||
it->second.erase(itVec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<XMLObject>* values = GetConfiguration().GetObjectPtr(sSetting);
|
||||
bool found = false;
|
||||
for(auto it = values->begin(); it != values->end();++it)
|
||||
{
|
||||
if(it->GetText() == s)
|
||||
{
|
||||
values->erase(it);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
{
|
||||
LOG_ERROR("Couldn't find value: ", s);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Not a vector setting");
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
XMLObject& ConfigFile::GetConfiguration()
|
||||
{
|
||||
std::vector<XMLObject>* configurations = config.GetObjectPtr("configuration");
|
||||
if(configurations == nullptr || configurations->size() == 0)
|
||||
{
|
||||
LOG_ERROR("No configuration in makegen.xml");
|
||||
assert(false);
|
||||
}
|
||||
for(auto it = configurations->begin(); it != configurations->end(); ++it)
|
||||
{
|
||||
if(!it->HasAttribute("name"))
|
||||
{
|
||||
LOG_ERROR("No name attribute in configuration tag");
|
||||
continue;
|
||||
}
|
||||
if(it->GetAttribute("name") == target)
|
||||
{
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
|
||||
LOG_ERROR("Couldn\'t find given target in config file. Using target=", (*configurations)[0].HasAttribute("name") ? (*configurations)[0].GetAttribute("name") : "");
|
||||
return (*configurations)[0];
|
||||
}
|
||||
|
||||
const std::string& ConfigFile::GetConfigPath() const
|
||||
{
|
||||
return configPath;;
|
||||
}
|
||||
|
||||
ConfigFile& ConfigFile::GetDependencyConfig(size_t i)
|
||||
{
|
||||
return dependencyConfigs[i];
|
||||
}
|
||||
|
||||
std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath)
|
||||
@@ -55,38 +343,35 @@ std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath,
|
||||
std::ifstream f(filepath + CONFIG_FILENAME);
|
||||
if(!f.good())
|
||||
{
|
||||
ConfigFileConf::CreateXMLFile(realPath);
|
||||
// try to read an old config file
|
||||
f.close();
|
||||
f = std::ifstream(filepath + "makegen.conf");
|
||||
oldFile = true;
|
||||
f = std::ifstream(filepath + CONFIG_FILENAME);
|
||||
}
|
||||
|
||||
// Check if the file exists
|
||||
if(f.good())
|
||||
{
|
||||
f.close();
|
||||
std::optional<ConfigFile> conf;
|
||||
if(oldFile)
|
||||
conf = ConfigFileConf::Load(realPath);
|
||||
else
|
||||
conf = ConfigFile::Load(realPath);
|
||||
if(!conf)
|
||||
ConfigFile conf = ConfigFile(filepath);
|
||||
if(conf.hasInitError)
|
||||
return {};
|
||||
loadedConfigs.emplace(realPath, *conf);
|
||||
loadedConfigs.emplace(realPath, conf);
|
||||
|
||||
std::vector<std::string>& dependencies = conf.GetSettingVectorString(ConfigSetting::Dependency);
|
||||
// Create dependency config files.
|
||||
for(size_t i = 0; i < conf->dependencies.size();++i)
|
||||
for(size_t i = 0; i < dependencies.size();++i)
|
||||
{
|
||||
std::optional<ConfigFile> dep = GetConfigFile(conf->configPath + conf->dependencies[i], loadedConfigs);
|
||||
std::optional<ConfigFile> dep = GetConfigFile(conf.configPath + dependencies[i], loadedConfigs);
|
||||
if(dep)
|
||||
{
|
||||
conf->dependencyConfigs.push_back(*dep);
|
||||
conf->dependencies[i] = dep->configPath;
|
||||
conf.dependencyConfigs.push_back(*dep);
|
||||
dependencies[i] = dep->configPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove the dependency since it is already accounted for
|
||||
conf->dependencies.erase(conf->dependencies.begin() + i);
|
||||
dependencies.erase(dependencies.begin() + i);
|
||||
--i;
|
||||
}
|
||||
}
|
||||
@@ -95,103 +380,6 @@ std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath,
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
std::optional<ConfigFile> ConfigFile::Load(const std::string& filedir)
|
||||
{
|
||||
XMLObject object{XML::FromFile(filedir + CONFIG_FILENAME)};
|
||||
|
||||
const std::string& target = object.GetObject("target", {XMLObject{"target", {}, "Release"}})[0].GetText();
|
||||
const std::vector<XMLObject>& configurations = object.GetObject("configuration");
|
||||
const XMLObject* configuration = nullptr;
|
||||
for(auto it = configurations.begin(); it != configurations.end(); ++it)
|
||||
{
|
||||
if(!it->HasAttribute("name"))
|
||||
{
|
||||
LOG_ERROR("No name attribute in configuration tag");
|
||||
continue;
|
||||
}
|
||||
if(it->GetAttribute("name") == target)
|
||||
{
|
||||
configuration = &(*it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(configuration == nullptr)
|
||||
{
|
||||
LOG_ERROR("No configuration matching target: ", target);
|
||||
return {};
|
||||
}
|
||||
|
||||
ConfigFile conf;
|
||||
conf.configPath = filedir;
|
||||
conf.projectname = configuration->GetObject("projectname",
|
||||
{XMLObject{"projectname", {}, conf.projectname}})[0].GetText();
|
||||
conf.outputname = configuration->GetObject("outputname",
|
||||
{XMLObject{"outputname", {}, conf.outputname}})[0].GetText();
|
||||
conf.srcdir = configuration->GetObject("srcdir",
|
||||
{XMLObject{"srcdir", {}, conf.srcdir}})[0].GetText();
|
||||
conf.outputdir = configuration->GetObject("outputdir",
|
||||
{XMLObject{"outputdir", {}, conf.outputdir}})[0].GetText();
|
||||
conf.hFile = configuration->GetObject("hfile",
|
||||
{XMLObject{"hfile", {}, conf.hFile}})[0].GetText();
|
||||
std::string outputtype = configuration->GetObject("outputtype",
|
||||
{XMLObject{"outputtype", {}, "executable"}})[0].GetText();
|
||||
|
||||
if(conf.srcdir[conf.srcdir.size()-1] != '/')
|
||||
conf.srcdir += '/';
|
||||
if(conf.outputdir[conf.srcdir.size()-1] != '/')
|
||||
conf.outputdir += '/';
|
||||
|
||||
if(outputtype == "executable")
|
||||
conf.executable = true;
|
||||
else if(outputtype == "staticlibrary")
|
||||
{
|
||||
conf.executable = false;
|
||||
conf.shared = false;
|
||||
}
|
||||
else if(outputtype == "sharedlibrary")
|
||||
{
|
||||
conf.executable = false;
|
||||
conf.shared = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Invalid outputtype: ", outputtype);
|
||||
LOG_ERROR("Valid arguments are executable, staticlibrary and sharedlibrary");
|
||||
}
|
||||
conf.generateHFile = configuration->GetObject("generatehfile",
|
||||
{XMLObject{"generatehfile", {}, conf.generateHFile ? "true" : "false"}})[0].GetText() == "true";
|
||||
|
||||
const int vectorCount = 6;
|
||||
std::tuple<std::vector<XMLObject>, std::vector<std::string>*, bool> vectors[vectorCount] = {
|
||||
{configuration->GetObject("library"), &conf.libs, false},
|
||||
{configuration->GetObject("libdir"), &conf.libdirs, true},
|
||||
{configuration->GetObject("includedir"), &conf.includedirs, true},
|
||||
{configuration->GetObject("define"), &conf.defines, false},
|
||||
{configuration->GetObject("compileflag"), &conf.flags, false},
|
||||
{configuration->GetObject("dependency"), &conf.dependencies, true}
|
||||
};
|
||||
|
||||
for(int i = 0;i<vectorCount;++i)
|
||||
{
|
||||
const std::vector<XMLObject>& xmls = std::get<0>(vectors[i]);
|
||||
std::vector<std::string>* vec = std::get<1>(vectors[i]);
|
||||
bool isDir = std::get<2>(vectors[i]);
|
||||
for(auto it = xmls.begin(); it != xmls.end();++it)
|
||||
{
|
||||
if(it->GetText() != "")
|
||||
{
|
||||
std::string s = it->GetText();
|
||||
if(isDir && s[s.size()-1] != '/')
|
||||
s += '/';
|
||||
vec->push_back(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
return conf;
|
||||
}
|
||||
|
||||
void ConfigFile::InputBoolean(const std::string& inputText, bool& b)
|
||||
{
|
||||
std::string input;
|
||||
@@ -238,38 +426,39 @@ void ConfigFile::InputMultiple(const std::string& inputText, std::vector<std::st
|
||||
|
||||
ConfigFile ConfigFile::Gen()
|
||||
{
|
||||
ConfigFile conf;
|
||||
InputBoolean("Should it be compiled as an executable? (y/n)", conf.executable);
|
||||
bool executable, shared, generateHFile;
|
||||
std::vector<std::string> libs, libdirs, includedirs, defines, compileFlags, dependencies;
|
||||
std::string srcdir, outputdir, projectname, outputname, hFile;
|
||||
|
||||
InputBoolean("Should it be compiled as an executable? (y/n)", executable);
|
||||
// If it isn't an executable there is not need to have libraries
|
||||
if(conf.executable)
|
||||
if(executable)
|
||||
{
|
||||
InputMultiple("Enter library:", conf.libs,false);
|
||||
InputMultiple("Enter library directory:", conf.libdirs,true);
|
||||
InputMultiple("Enter project dependencies:", conf.dependencies,true);
|
||||
InputMultiple("Enter library:", libs,false);
|
||||
InputMultiple("Enter library directory:", libdirs,true);
|
||||
InputMultiple("Enter project dependencies:", dependencies,true);
|
||||
}
|
||||
else
|
||||
{
|
||||
InputBoolean("Should it be compiled as a shared library? (y/n)", conf.shared);
|
||||
InputBoolean("Should it compile a project h-file? (y/n):", conf.generateHFile);
|
||||
if(conf.generateHFile)
|
||||
InputBoolean("Should it be compiled as a shared library? (y/n)", shared);
|
||||
InputBoolean("Should it compile a project h-file? (y/n):", generateHFile);
|
||||
if(generateHFile)
|
||||
{
|
||||
InputString("Enter the project h-file name (relative to source directory): ", conf.hFile, false, false);
|
||||
InputString("Enter the project h-file name (relative to source directory): ", hFile, false, false);
|
||||
}
|
||||
}
|
||||
InputMultiple("Enter include directory:", conf.includedirs, true);
|
||||
InputString("Enter source directories:", conf.srcdir, true, false);
|
||||
InputMultiple("Enter preprocessor definitions:", conf.defines, false);
|
||||
InputMultiple("Enter compile flags:", conf.flags, false);
|
||||
InputString("Enter output directory (default: bin):", conf.outputdir, true, true);
|
||||
if(conf.outputdir == "")
|
||||
conf.outputdir = "bin/";
|
||||
InputString("Enter a name for the project:", conf.projectname, false, false);
|
||||
InputString("Enter a name for the output file:", conf.outputname, false, false);
|
||||
return conf;
|
||||
}
|
||||
InputMultiple("Enter include directory:", includedirs, true);
|
||||
InputString("Enter source directories:", srcdir, true, false);
|
||||
InputMultiple("Enter preprocessor definitions:", defines, false);
|
||||
InputMultiple("Enter compile flags:", compileFlags, false);
|
||||
InputString("Enter output directory (default: bin):", outputdir, true, true);
|
||||
if(outputdir == "")
|
||||
outputdir = "bin/";
|
||||
InputString("Enter a name for the project:", projectname, false, false);
|
||||
InputString("Enter a name for the output file:", outputname, false, false);
|
||||
|
||||
void ConfigFile::Save() const
|
||||
{
|
||||
|
||||
// Create xml
|
||||
XMLObject makegen("makegen", {}, std::map<std::string, std::vector<XMLObject>>{});
|
||||
|
||||
// Version, target and configuration is probably going to be used in the future
|
||||
@@ -281,7 +470,7 @@ void ConfigFile::Save() const
|
||||
configuration.AddXMLObject(XMLObject("outputname", {}, outputname));
|
||||
configuration.AddXMLObject(XMLObject("srcdir", {}, srcdir));
|
||||
configuration.AddXMLObject(XMLObject("outputdir", {}, outputdir));
|
||||
configuration.AddXMLObject(XMLObject("hfile", {}, hFile));
|
||||
configuration.AddXMLObject(XMLObject("hfilename", {}, hFile));
|
||||
configuration.AddXMLObject(XMLObject("outputtype", {},
|
||||
executable ? "executable" : (shared ? "sharedlibrary" : "staticlibrary")));
|
||||
configuration.AddXMLObject(XMLObject("generatehfile", {}, generateHFile ? "true" : "false"));
|
||||
@@ -289,17 +478,22 @@ void ConfigFile::Save() const
|
||||
for(auto it = libs.begin();it != libs.end(); ++it)
|
||||
configuration.AddXMLObject({"library",{},*it});
|
||||
for(auto it = libdirs.begin();it != libdirs.end(); ++it)
|
||||
configuration.AddXMLObject({"libdir",{},*it});
|
||||
configuration.AddXMLObject({"librarydir",{},*it});
|
||||
for(auto it = includedirs.begin();it != includedirs.end(); ++it)
|
||||
configuration.AddXMLObject({"includedir",{},*it});
|
||||
for(auto it = defines.begin();it != defines.end(); ++it)
|
||||
configuration.AddXMLObject({"define",{},*it});
|
||||
for(auto it = flags.begin();it != flags.end(); ++it)
|
||||
configuration.AddXMLObject({"compileflag",{},*it});
|
||||
for(auto it = compileFlags.begin();it != compileFlags.end(); ++it)
|
||||
configuration.AddXMLObject({"cflag",{},*it});
|
||||
for(auto it = dependencies.begin();it != dependencies.end(); ++it)
|
||||
configuration.AddXMLObject({"dependency",{},*it});
|
||||
|
||||
makegen.AddXMLObject(configuration);
|
||||
std::ofstream file("makegen.xml");
|
||||
file << makegen;
|
||||
return ConfigFile{makegen, FileUtils::GetRealPath("./")};
|
||||
}
|
||||
|
||||
void ConfigFile::Save() const
|
||||
{
|
||||
std::ofstream file("makegen.xml");
|
||||
file << config;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user