Add --target=<target> flag
- Used to compile using a specific target, without the need of modifying the makegen.xml file
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
# This Makefile was generated using MakeGen v1.3.5 made by Tim Håkansson
|
# This Makefile was generated using MakeGen v1.3.6 made by Tim Håkansson
|
||||||
# and is licensed under MIT. Full source of the project can be found at
|
# and is licensed under MIT. Full source of the project can be found at
|
||||||
# https://github.com/Thraix/MakeGen
|
# https://github.com/Thraix/MakeGen
|
||||||
CC=@g++
|
CC=@g++
|
||||||
@@ -33,28 +33,28 @@ $(OUTPUT): $(OBJECTS)
|
|||||||
install: all
|
install: all
|
||||||
$(info Installing MakeGen to /usr/bin/)
|
$(info Installing MakeGen to /usr/bin/)
|
||||||
@cp $(OUTPUT) /usr/bin/makegen
|
@cp $(OUTPUT) /usr/bin/makegen
|
||||||
$(OBJPATH)/ConfigCLI.o : src/ConfigCLI.cpp src/Common.h src/ConfigCLI.h src/ConfigFile.h src/ConfigUtils.h src/FileUtils.h src/Utils.h src/xml/XMLObject.h
|
$(OBJPATH)/ConfigCLI.o : src/ConfigCLI.cpp src/Common.h src/ConfigCLI.h src/ConfigFile.h src/ConfigUtils.h src/FileUtils.h src/Utils.h src/FlagData.h src/xml/XMLObject.h
|
||||||
$(info -[10%]- $<)
|
$(info -[10%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/ConfigFile.o : src/ConfigFile.cpp src/ConfigFile.h src/ConfigUtils.h src/Common.h src/FileUtils.h src/Utils.h src/xml/XMLObject.h src/compatibility/ConfigFileConf.h src/xml/XML.h
|
$(OBJPATH)/ConfigFile.o : src/ConfigFile.cpp src/ConfigFile.h src/ConfigUtils.h src/Common.h src/FileUtils.h src/Utils.h src/FlagData.h src/xml/XMLObject.h src/compatibility/ConfigFileConf.h src/xml/XML.h
|
||||||
$(info -[20%]- $<)
|
$(info -[20%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/HFileGen.o : src/HFileGen.cpp src/FileUtils.h src/Common.h src/Utils.h src/HFileGen.h src/ConfigFile.h src/ConfigUtils.h src/xml/XMLObject.h
|
$(OBJPATH)/HFileGen.o : src/HFileGen.cpp src/FileUtils.h src/Common.h src/Utils.h src/HFileGen.h src/ConfigFile.h src/ConfigUtils.h src/FlagData.h src/xml/XMLObject.h
|
||||||
$(info -[30%]- $<)
|
$(info -[30%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/IncludeDeps.o : src/IncludeDeps.cpp src/Common.h src/IncludeDeps.h src/ConfigFile.h src/ConfigUtils.h src/FileUtils.h src/Utils.h src/xml/XMLObject.h
|
$(OBJPATH)/IncludeDeps.o : src/IncludeDeps.cpp src/Common.h src/IncludeDeps.h src/ConfigFile.h src/ConfigUtils.h src/FileUtils.h src/Utils.h src/FlagData.h src/xml/XMLObject.h
|
||||||
$(info -[40%]- $<)
|
$(info -[40%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/Makefile.o : src/Makefile.cpp src/Common.h src/IncludeDeps.h src/ConfigFile.h src/ConfigUtils.h src/FileUtils.h src/Utils.h src/xml/XMLObject.h src/Makefile.h
|
$(OBJPATH)/Makefile.o : src/Makefile.cpp src/Common.h src/IncludeDeps.h src/ConfigFile.h src/ConfigUtils.h src/FileUtils.h src/Utils.h src/FlagData.h src/xml/XMLObject.h src/Makefile.h
|
||||||
$(info -[50%]- $<)
|
$(info -[50%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/Utils.o : src/Utils.cpp src/ConfigFile.h src/ConfigUtils.h src/Common.h src/FileUtils.h src/Utils.h src/xml/XMLObject.h
|
$(OBJPATH)/Utils.o : src/Utils.cpp src/ConfigFile.h src/ConfigUtils.h src/Common.h src/FileUtils.h src/Utils.h src/FlagData.h src/xml/XMLObject.h
|
||||||
$(info -[60%]- $<)
|
$(info -[60%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/ConfigFileConf.o : src/compatibility/ConfigFileConf.cpp src/ConfigFile.h src/ConfigUtils.h src/Common.h src/FileUtils.h src/Utils.h src/xml/XMLObject.h src/compatibility/ConfigFileConf.h
|
$(OBJPATH)/ConfigFileConf.o : src/compatibility/ConfigFileConf.cpp src/ConfigFile.h src/ConfigUtils.h src/Common.h src/FileUtils.h src/Utils.h src/FlagData.h src/xml/XMLObject.h src/compatibility/ConfigFileConf.h
|
||||||
$(info -[70%]- $<)
|
$(info -[70%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/main.o : src/main.cpp src/Common.h src/ConfigCLI.h src/ConfigFile.h src/ConfigUtils.h src/FileUtils.h src/Utils.h src/xml/XMLObject.h src/HFileGen.h src/Makefile.h src/Timer.h
|
$(OBJPATH)/main.o : src/main.cpp src/Common.h src/ConfigCLI.h src/ConfigFile.h src/ConfigUtils.h src/FileUtils.h src/Utils.h src/FlagData.h src/xml/XMLObject.h src/HFileGen.h src/Makefile.h src/Timer.h
|
||||||
$(info -[80%]- $<)
|
$(info -[80%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/XML.o : src/xml/XML.cpp src/xml/XML.h src/xml/XMLObject.h src/xml/XMLException.h
|
$(OBJPATH)/XML.o : src/xml/XML.cpp src/xml/XML.h src/xml/XMLObject.h src/xml/XMLException.h
|
||||||
|
|||||||
+2
-1
@@ -14,7 +14,7 @@
|
|||||||
// Release, should be backwards compatible with any minor version
|
// Release, should be backwards compatible with any minor version
|
||||||
#define MAKEGEN_VERSION_RELEASE 3
|
#define MAKEGEN_VERSION_RELEASE 3
|
||||||
// Minor changes, generally bug fixes
|
// Minor changes, generally bug fixes
|
||||||
#define MAKEGEN_VERSION_MINOR 5
|
#define MAKEGEN_VERSION_MINOR 6
|
||||||
|
|
||||||
#define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR))
|
#define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR))
|
||||||
|
|
||||||
@@ -29,6 +29,7 @@ const static unsigned int FLAG_SINGLE_THREAD = BIT(7);
|
|||||||
const static unsigned int FLAG_DEPENDENCY = BIT(8);
|
const static unsigned int FLAG_DEPENDENCY = BIT(8);
|
||||||
const static unsigned int FLAG_SIMPLE = BIT(9);
|
const static unsigned int FLAG_SIMPLE = BIT(9);
|
||||||
const static unsigned int FLAG_CONFIG = BIT(10);
|
const static unsigned int FLAG_CONFIG = BIT(10);
|
||||||
|
const static unsigned int FLAG_TARGET = BIT(11);
|
||||||
|
|
||||||
|
|
||||||
#define LOG_INFO(...) LogHelper(__VA_ARGS__)
|
#define LOG_INFO(...) LogHelper(__VA_ARGS__)
|
||||||
|
|||||||
+4
-6
@@ -3,8 +3,6 @@
|
|||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "ConfigFile.h"
|
#include "ConfigFile.h"
|
||||||
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
void ConfigCLI::DisplayCLIHelp()
|
void ConfigCLI::DisplayCLIHelp()
|
||||||
{
|
{
|
||||||
LOG_INFO(1+(char*)R"(
|
LOG_INFO(1+(char*)R"(
|
||||||
@@ -174,12 +172,12 @@ int ConfigCLI::Gen(int argc, char** argv)
|
|||||||
std::string option = argv[1];
|
std::string option = argv[1];
|
||||||
if(option == "prompt")
|
if(option == "prompt")
|
||||||
{
|
{
|
||||||
ConfigFile::Gen().Save();
|
ConfigFile::Gen(FlagData{}).Save();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(option == "default")
|
if(option == "default")
|
||||||
{
|
{
|
||||||
ConfigFile{FileUtils::GetRealPath("."),0}.Save();
|
ConfigFile{FileUtils::GetRealPath("."), FlagData{}, 0}.Save();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -324,7 +322,7 @@ int ConfigCLI::Main(int argc, char** argv)
|
|||||||
DisplayCLIHelp();
|
DisplayCLIHelp();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
std::optional<ConfigFile> config = ConfigFile::GetConfigFile();
|
std::optional<ConfigFile> config = ConfigFile::GetConfigFile("./", FlagData{});
|
||||||
std::string command = argv[1];
|
std::string command = argv[1];
|
||||||
if(command == "gen")
|
if(command == "gen")
|
||||||
{
|
{
|
||||||
@@ -351,7 +349,7 @@ int ConfigCLI::Main(int argc, char** argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("There is no config file in the current directory");
|
LOG_ERROR("There is no config file in the current directory");
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "ConfigFile.h"
|
#include "ConfigFile.h"
|
||||||
|
|
||||||
struct ConfigCLI
|
struct ConfigCLI
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static int Main(int argc, char** argv);
|
static int Main(int argc, char** argv);
|
||||||
|
|||||||
+38
-25
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
ConfigFile::ConfigFile(const std::string& path, int)
|
ConfigFile::ConfigFile(const std::string& path, const FlagData& flagData, int)
|
||||||
: configPath{path}
|
: configPath{path}
|
||||||
{
|
{
|
||||||
// Converts project name (current directory) to lowercase
|
// Converts project name (current directory) to lowercase
|
||||||
@@ -16,7 +16,10 @@ ConfigFile::ConfigFile(const std::string& path, int)
|
|||||||
|
|
||||||
// Version, target and configuration is probably going to be used in the future
|
// Version, target and configuration is probably going to be used in the future
|
||||||
makegen.AddXMLObject(XMLObject("version", {}, "v1.3.0"));
|
makegen.AddXMLObject(XMLObject("version", {}, "v1.3.0"));
|
||||||
makegen.AddXMLObject(XMLObject("target", {}, "Release"));
|
if(flagData.flags & FLAG_TARGET)
|
||||||
|
makegen.AddXMLObject(XMLObject("target", {}, flagData.target));
|
||||||
|
else
|
||||||
|
makegen.AddXMLObject(XMLObject("target", {}, "Release"));
|
||||||
|
|
||||||
XMLObject configuration("configuration", {{"name", "Release"}}, std::map<std::string, std::vector<XMLObject>>{});
|
XMLObject configuration("configuration", {{"name", "Release"}}, std::map<std::string, std::vector<XMLObject>>{});
|
||||||
configuration.AddXMLObject(XMLObject("projectname", {}, ConfigUtils::GetDefaultProjectName(configPath)));
|
configuration.AddXMLObject(XMLObject("projectname", {}, ConfigUtils::GetDefaultProjectName(configPath)));
|
||||||
@@ -29,35 +32,42 @@ ConfigFile::ConfigFile(const std::string& path, int)
|
|||||||
|
|
||||||
makegen.AddXMLObject(configuration);
|
makegen.AddXMLObject(configuration);
|
||||||
config = makegen;
|
config = makegen;
|
||||||
Init();
|
Init(flagData);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigFile::ConfigFile(const std::string& path)
|
ConfigFile::ConfigFile(const std::string& path, const FlagData& flagData)
|
||||||
: config{XML::FromFile(path + CONFIG_FILENAME)}, configPath{path}
|
: config{XML::FromFile(path + CONFIG_FILENAME)}, configPath{path}
|
||||||
{
|
{
|
||||||
Init();
|
Init(flagData);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigFile::ConfigFile(XMLObject& config, const std::string& path)
|
ConfigFile::ConfigFile(XMLObject& config, const std::string& path, const FlagData& flagData)
|
||||||
: config{config}, configPath{path}
|
: config{config}, configPath{path}
|
||||||
{
|
{
|
||||||
Init();
|
Init(flagData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigFile::Init()
|
void ConfigFile::Init(const FlagData& flagData)
|
||||||
{
|
{
|
||||||
const std::vector<XMLObject>* targetXml = config.GetObjectPtr("target");
|
if (flagData.flags & FLAG_TARGET)
|
||||||
target = "Release";
|
|
||||||
if(!targetXml || targetXml->size() == 0)
|
|
||||||
{
|
{
|
||||||
LOG_ERROR("No target found in config file. Using target=", target);
|
target = flagData.target;
|
||||||
return;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
std::string& ConfigFile::GetSettingString(ConfigSetting setting)
|
||||||
@@ -323,13 +333,13 @@ ConfigFile& ConfigFile::GetDependencyConfig(size_t i)
|
|||||||
return dependencyConfigs[i];
|
return dependencyConfigs[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath)
|
std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath, const FlagData& flagData)
|
||||||
{
|
{
|
||||||
std::map<std::string, ConfigFile> loadedConfigs;
|
std::map<std::string, ConfigFile> loadedConfigs;
|
||||||
return GetConfigFile(filepath, loadedConfigs);
|
return GetConfigFile(filepath, loadedConfigs, flagData);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath, std::map<std::string, ConfigFile>& loadedConfigs)
|
std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath, std::map<std::string, ConfigFile>& loadedConfigs, const FlagData& flagData)
|
||||||
{
|
{
|
||||||
std::string realPath = FileUtils::GetRealPath(filepath);
|
std::string realPath = FileUtils::GetRealPath(filepath);
|
||||||
if(realPath == "")
|
if(realPath == "")
|
||||||
@@ -354,7 +364,7 @@ std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath,
|
|||||||
if(f.good())
|
if(f.good())
|
||||||
{
|
{
|
||||||
f.close();
|
f.close();
|
||||||
ConfigFile conf = ConfigFile(filepath);
|
ConfigFile conf = ConfigFile(filepath, flagData);
|
||||||
if(conf.hasInitError)
|
if(conf.hasInitError)
|
||||||
return {};
|
return {};
|
||||||
loadedConfigs.emplace(realPath, conf);
|
loadedConfigs.emplace(realPath, conf);
|
||||||
@@ -363,7 +373,7 @@ std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath,
|
|||||||
// Create dependency config files.
|
// Create dependency config files.
|
||||||
for(size_t i = 0; i < dependencies.size();++i)
|
for(size_t i = 0; i < dependencies.size();++i)
|
||||||
{
|
{
|
||||||
std::optional<ConfigFile> dep = GetConfigFile(conf.configPath + dependencies[i], loadedConfigs);
|
std::optional<ConfigFile> dep = GetConfigFile(conf.configPath + dependencies[i], loadedConfigs, flagData);
|
||||||
if(dep)
|
if(dep)
|
||||||
{
|
{
|
||||||
conf.dependencyConfigs.push_back(*dep);
|
conf.dependencyConfigs.push_back(*dep);
|
||||||
@@ -425,7 +435,7 @@ void ConfigFile::InputMultiple(const std::string& inputText, std::vector<std::st
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigFile ConfigFile::Gen()
|
ConfigFile ConfigFile::Gen(const FlagData& flagData)
|
||||||
{
|
{
|
||||||
bool executable, shared, generateHFile;
|
bool executable, shared, generateHFile;
|
||||||
std::vector<std::string> libs, libdirs, includedirs, defines, compileFlags, linkingFlags, dependencies, excludeSources, excludeHeaders;
|
std::vector<std::string> libs, libdirs, includedirs, defines, compileFlags, linkingFlags, dependencies, excludeSources, excludeHeaders;
|
||||||
@@ -467,7 +477,10 @@ ConfigFile ConfigFile::Gen()
|
|||||||
|
|
||||||
// Version, target and configuration is probably going to be used in the future
|
// Version, target and configuration is probably going to be used in the future
|
||||||
makegen.AddXMLObject(XMLObject("version", {}, "v1.3.0"));
|
makegen.AddXMLObject(XMLObject("version", {}, "v1.3.0"));
|
||||||
makegen.AddXMLObject(XMLObject("target", {}, "Release"));
|
if(flagData.flags & FLAG_TARGET)
|
||||||
|
makegen.AddXMLObject(XMLObject("target", {}, flagData.target));
|
||||||
|
else
|
||||||
|
makegen.AddXMLObject(XMLObject("target", {}, "Release"));
|
||||||
|
|
||||||
XMLObject configuration("configuration", {{"name", "Release"}}, std::map<std::string, std::vector<XMLObject>>{});
|
XMLObject configuration("configuration", {{"name", "Release"}}, std::map<std::string, std::vector<XMLObject>>{});
|
||||||
configuration.AddXMLObject(XMLObject("projectname", {}, projectname));
|
configuration.AddXMLObject(XMLObject("projectname", {}, projectname));
|
||||||
@@ -493,7 +506,7 @@ ConfigFile ConfigFile::Gen()
|
|||||||
configuration.AddXMLObject({"dependency",{},*it});
|
configuration.AddXMLObject({"dependency",{},*it});
|
||||||
|
|
||||||
makegen.AddXMLObject(configuration);
|
makegen.AddXMLObject(configuration);
|
||||||
return ConfigFile{makegen, FileUtils::GetRealPath(".")};
|
return ConfigFile{makegen, FileUtils::GetRealPath("."), flagData};
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigFile::Save() const
|
void ConfigFile::Save() const
|
||||||
|
|||||||
+8
-7
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ConfigUtils.h"
|
#include "ConfigUtils.h"
|
||||||
|
#include "FlagData.h"
|
||||||
#include "xml/XMLObject.h"
|
#include "xml/XMLObject.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -26,9 +27,9 @@ class ConfigFile
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Generates a new default config file
|
// Generates a new default config file
|
||||||
ConfigFile(const std::string& path, int);
|
ConfigFile(const std::string& path, const FlagData& flagData, int);
|
||||||
ConfigFile(const std::string& path);
|
ConfigFile(const std::string& path, const FlagData& flagData);
|
||||||
ConfigFile(XMLObject& config, const std::string& path);
|
ConfigFile(XMLObject& config, const std::string& path, const FlagData& flagData);
|
||||||
|
|
||||||
void Save() const;
|
void Save() const;
|
||||||
|
|
||||||
@@ -45,13 +46,13 @@ class ConfigFile
|
|||||||
const std::string& GetConfigPath() const;
|
const std::string& GetConfigPath() const;
|
||||||
ConfigFile& GetDependencyConfig(size_t i);
|
ConfigFile& GetDependencyConfig(size_t i);
|
||||||
private:
|
private:
|
||||||
void Init();
|
void Init(const FlagData& flagData);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static ConfigFile Gen();
|
static ConfigFile Gen(const FlagData& flagData);
|
||||||
static std::optional<ConfigFile> GetConfigFile(const std::string& filepath = "./");
|
static std::optional<ConfigFile> GetConfigFile(const std::string& filepath, const FlagData& flagData);
|
||||||
private:
|
private:
|
||||||
static std::optional<ConfigFile> GetConfigFile(const std::string& filepath, std::map<std::string, ConfigFile>& loadedConfigs);
|
static std::optional<ConfigFile> GetConfigFile(const std::string& filepath, std::map<std::string, ConfigFile>& loadedConfigs, const FlagData& flagData);
|
||||||
static std::optional<ConfigFile> Load(const std::string& filename);
|
static std::optional<ConfigFile> Load(const std::string& filename);
|
||||||
static void InputBoolean(const std::string& inputText, bool& b);
|
static void InputBoolean(const std::string& inputText, bool& b);
|
||||||
static void InputMultiple(const std::string& inputText, std::vector<std::string>& vec, bool needEnding);
|
static void InputMultiple(const std::string& inputText, std::vector<std::string>& vec, bool needEnding);
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
struct FlagData
|
||||||
|
{
|
||||||
|
unsigned int flags{0};
|
||||||
|
std::string target{""}; // Only set if flags contain FLAG_TARGET
|
||||||
|
};
|
||||||
@@ -32,6 +32,15 @@ bool Utils::IsHeaderFile(const std::string& filepath)
|
|||||||
return extension == "hpp" || extension == "h" || extension == "hxx";
|
return extension == "hpp" || extension == "h" || extension == "hxx";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Utils::StartsWith(const std::string& str, const std::string& prefix)
|
||||||
|
{
|
||||||
|
if (str.size() < prefix.size())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return str.compare(0, prefix.size(), prefix) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string Utils::CommonPrefix(const std::string& s1, const std::string& s2)
|
std::string Utils::CommonPrefix(const std::string& s1, const std::string& s2)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ struct Utils
|
|||||||
{
|
{
|
||||||
static bool IsSourceFile(const std::string& filepath);
|
static bool IsSourceFile(const std::string& filepath);
|
||||||
static bool IsHeaderFile(const std::string& filepath);
|
static bool IsHeaderFile(const std::string& filepath);
|
||||||
|
|
||||||
static std::string CommonPrefix(const std::string& s1, const std::string& s2);
|
static std::string CommonPrefix(const std::string& s1, const std::string& s2);
|
||||||
|
static bool StartsWith(const std::string& str, const std::string& prefix);
|
||||||
static void GetCppFiles(ConfigFile& conf, std::set<std::string>& cppFiles);
|
static void GetCppFiles(ConfigFile& conf, std::set<std::string>& cppFiles);
|
||||||
static void GetCppAndHFiles(ConfigFile& conf, std::set<HFile>& hFiles, std::set<std::string>& cppFiles);
|
static void GetCppAndHFiles(ConfigFile& conf, std::set<HFile>& hFiles, std::set<std::string>& cppFiles);
|
||||||
static void GetHFiles(const std::string& dependencyDir, ConfigFile& conf, std::set<HFile>& hFiles);
|
static void GetHFiles(const std::string& dependencyDir, ConfigFile& conf, std::set<HFile>& hFiles);
|
||||||
|
|||||||
+56
-43
@@ -2,6 +2,7 @@
|
|||||||
#include "ConfigCLI.h"
|
#include "ConfigCLI.h"
|
||||||
#include "ConfigFile.h"
|
#include "ConfigFile.h"
|
||||||
#include "FileUtils.h"
|
#include "FileUtils.h"
|
||||||
|
#include "FlagData.h"
|
||||||
#include "HFileGen.h"
|
#include "HFileGen.h"
|
||||||
#include "Makefile.h"
|
#include "Makefile.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
@@ -25,22 +26,23 @@ By default it always compiles code with parallell jobs.
|
|||||||
Usage: makegen [options]
|
Usage: makegen [options]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h, --help Displays this information
|
-h, --help Displays this information
|
||||||
-v, --version Displays the version of this program
|
-v, --version Displays the version of this program
|
||||||
-m,-a, make, all Generates a Makefile and runs
|
-m,-a, make, all Generates a Makefile and runs
|
||||||
make all
|
make all
|
||||||
-i, install Generates a Makefile and runs
|
-i, install Generates a Makefile and runs
|
||||||
make all && make install
|
make all && make install
|
||||||
-c, clean Generates a Makefile and runs
|
-c, clean Generates a Makefile and runs
|
||||||
make clean
|
make clean
|
||||||
-r, rebuild Generates a Makefile and runs
|
-r, rebuild Generates a Makefile and runs
|
||||||
make clean && make all
|
make clean && make all
|
||||||
-e, run, execute Generates a Makefile and runs
|
-e, run, execute Generates a Makefile and runs
|
||||||
make all && make run
|
make all && make run
|
||||||
-s, single Runs additional makegen options as single thread
|
-s, single Runs additional makegen options as single thread
|
||||||
(no --jobs=X flag)
|
(no --jobs=X flag)
|
||||||
--simple Creates a simple Makefile without include dependencies
|
--simple Creates a simple Makefile without include dependencies
|
||||||
(no --jobs=X flag)
|
(no --jobs=X flag)
|
||||||
|
--target=<target> Run the makegen.xml file with the specified target
|
||||||
|
|
||||||
If no option is given it will run \"make all\"
|
If no option is given it will run \"make all\"
|
||||||
|
|
||||||
@@ -55,11 +57,11 @@ void GenMakefile(ConfigFile& conf, unsigned int flags)
|
|||||||
Makefile::Save(conf, flags);
|
Makefile::Save(conf, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ReadFlags(int argc, char** argv)
|
FlagData ReadFlags(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if(argc >= 2 && std::string(argv[1]) == "conf")
|
if(argc >= 2 && std::string(argv[1]) == "conf")
|
||||||
return FLAG_CONFIG;
|
return FlagData{FLAG_CONFIG};
|
||||||
unsigned int flags = 0;
|
FlagData flagData{};
|
||||||
bool make = true;
|
bool make = true;
|
||||||
for(int i = 1;i<argc;i++)
|
for(int i = 1;i<argc;i++)
|
||||||
{
|
{
|
||||||
@@ -68,52 +70,63 @@ unsigned int ReadFlags(int argc, char** argv)
|
|||||||
std::string flag(argv[i]);
|
std::string flag(argv[i]);
|
||||||
if(flag == "-h" || flag == "--help")
|
if(flag == "-h" || flag == "--help")
|
||||||
{
|
{
|
||||||
flags |= FLAG_HELP;
|
flagData.flags |= FLAG_HELP;
|
||||||
}
|
}
|
||||||
else if(flag == "-v" || flag == "--version")
|
else if(flag == "-v" || flag == "--version")
|
||||||
{
|
{
|
||||||
flags |= FLAG_VERSION;
|
flagData.flags |= FLAG_VERSION;
|
||||||
}
|
}
|
||||||
else if(flag == "make" || flag == "-m" || flag == "all" || flag == "-a")
|
else if(flag == "make" || flag == "-m" || flag == "all" || flag == "-a")
|
||||||
{
|
{
|
||||||
flags |= FLAG_MAKE;
|
flagData.flags |= FLAG_MAKE;
|
||||||
}
|
}
|
||||||
else if(flag == "clean" || flag == "-c")
|
else if(flag == "clean" || flag == "-c")
|
||||||
{
|
{
|
||||||
make = false;
|
make = false;
|
||||||
flags |= FLAG_CLEAN;
|
flagData.flags |= FLAG_CLEAN;
|
||||||
}
|
}
|
||||||
else if(flag == "run" || flag == "-e" || flag == "execute")
|
else if(flag == "run" || flag == "-e" || flag == "execute")
|
||||||
{
|
{
|
||||||
flags |= FLAG_RUN;
|
flagData.flags |= FLAG_RUN;
|
||||||
}
|
}
|
||||||
else if(flag == "install" || flag == "-i")
|
else if(flag == "install" || flag == "-i")
|
||||||
{
|
{
|
||||||
flags |= FLAG_INSTALL;
|
flagData.flags |= FLAG_INSTALL;
|
||||||
}
|
}
|
||||||
else if(flag == "rebuild" || flag == "-r")
|
else if(flag == "rebuild" || flag == "-r")
|
||||||
{
|
{
|
||||||
flags |= FLAG_CLEAN;
|
flagData.flags |= FLAG_CLEAN;
|
||||||
flags |= FLAG_MAKE;
|
flagData.flags |= FLAG_MAKE;
|
||||||
}
|
}
|
||||||
else if(flag == "single" || flag == "-s")
|
else if(flag == "single" || flag == "-s")
|
||||||
{
|
{
|
||||||
flags |= FLAG_SINGLE_THREAD;
|
flagData.flags |= FLAG_SINGLE_THREAD;
|
||||||
}
|
}
|
||||||
else if(flag == "--simple")
|
else if(flag == "--simple")
|
||||||
{
|
{
|
||||||
flags |= FLAG_SIMPLE;
|
flagData.flags |= FLAG_SIMPLE;
|
||||||
|
}
|
||||||
|
else if(Utils::StartsWith(flag, "--target="))
|
||||||
|
{
|
||||||
|
std::string prefix("--target=");
|
||||||
|
if (flag.size() < prefix.size() + 1)
|
||||||
|
{
|
||||||
|
LOG_ERROR("No target specified in --target=<target>");
|
||||||
|
return FlagData{FLAG_HELP};
|
||||||
|
}
|
||||||
|
flagData.flags |= FLAG_TARGET;
|
||||||
|
flagData.target = flag.substr(std::string("--target=").size());
|
||||||
}
|
}
|
||||||
else if(flag != "")
|
else if(flag != "")
|
||||||
{
|
{
|
||||||
LOG_ERROR("Unknown argument ", flag);
|
LOG_ERROR("Unknown argument ", flag);
|
||||||
return FLAG_HELP;
|
return FlagData{FLAG_HELP};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(make)
|
if(make)
|
||||||
flags |= FLAG_MAKE;
|
flagData.flags |= FLAG_MAKE;
|
||||||
return flags;
|
return flagData;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RunMake(const std::string& filepath, unsigned int flags, ConfigFile& conf)
|
bool RunMake(const std::string& filepath, unsigned int flags, ConfigFile& conf)
|
||||||
@@ -140,7 +153,7 @@ bool RunMake(const std::string& filepath, unsigned int flags, ConfigFile& conf)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MakeGen(const std::string& filepath, unsigned int flags, ConfigFile& conf)
|
bool MakeGen(const std::string& filepath, const FlagData& flagData, ConfigFile& conf)
|
||||||
{
|
{
|
||||||
std::vector<std::string>& dependencies = conf.GetSettingVectorString(ConfigSetting::Dependency);
|
std::vector<std::string>& dependencies = conf.GetSettingVectorString(ConfigSetting::Dependency);
|
||||||
for(size_t i = 0;i<dependencies.size();++i)
|
for(size_t i = 0;i<dependencies.size();++i)
|
||||||
@@ -148,10 +161,10 @@ bool MakeGen(const std::string& filepath, unsigned int flags, ConfigFile& conf)
|
|||||||
std::filesystem::path currentPath = std::filesystem::current_path();
|
std::filesystem::path currentPath = std::filesystem::current_path();
|
||||||
std::filesystem::current_path(dependencies[i]);
|
std::filesystem::current_path(dependencies[i]);
|
||||||
|
|
||||||
auto conf = ConfigFile::GetConfigFile();
|
auto conf = ConfigFile::GetConfigFile("./", flagData);
|
||||||
if(conf)
|
if(conf)
|
||||||
{
|
{
|
||||||
bool success = MakeGen("./", flags, conf.value());
|
bool success = MakeGen("./", flagData, conf.value());
|
||||||
if(!success)
|
if(!success)
|
||||||
{
|
{
|
||||||
std::filesystem::current_path(currentPath);
|
std::filesystem::current_path(currentPath);
|
||||||
@@ -164,7 +177,7 @@ bool MakeGen(const std::string& filepath, unsigned int flags, ConfigFile& conf)
|
|||||||
LOG_INFO("Building ", conf.GetSettingString(ConfigSetting::ProjectName));
|
LOG_INFO("Building ", conf.GetSettingString(ConfigSetting::ProjectName));
|
||||||
LOG_INFO("Generating Makefile...");
|
LOG_INFO("Generating Makefile...");
|
||||||
Timer timer;
|
Timer timer;
|
||||||
GenMakefile(conf, flags);
|
GenMakefile(conf, flagData.flags);
|
||||||
LOG_INFO("Took ", round(timer.Elapsed()*1000.0)/1000.0,"s");
|
LOG_INFO("Took ", round(timer.Elapsed()*1000.0)/1000.0,"s");
|
||||||
LOG_INFO("Running Makefile...");
|
LOG_INFO("Running Makefile...");
|
||||||
|
|
||||||
@@ -176,31 +189,31 @@ bool MakeGen(const std::string& filepath, unsigned int flags, ConfigFile& conf)
|
|||||||
if(!FileUtils::HasPath(intermediatePath ))
|
if(!FileUtils::HasPath(intermediatePath ))
|
||||||
FileUtils::CreateDirectory(intermediatePath );
|
FileUtils::CreateDirectory(intermediatePath );
|
||||||
}
|
}
|
||||||
return RunMake(filepath, flags, conf);
|
return RunMake(filepath, flagData.flags, conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
unsigned int flags = ReadFlags(argc,argv);
|
FlagData flagData = ReadFlags(argc,argv);
|
||||||
if(flags & FLAG_HELP)
|
if(flagData.flags & FLAG_HELP)
|
||||||
{
|
{
|
||||||
PrintHelp();
|
PrintHelp();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(flags & FLAG_VERSION)
|
if(flagData.flags & FLAG_VERSION)
|
||||||
{
|
{
|
||||||
LOG_INFO("MakeGen ", MAKEGEN_VERSION);
|
LOG_INFO("MakeGen ", MAKEGEN_VERSION);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(flags & FLAG_CONFIG)
|
if(flagData.flags & FLAG_CONFIG)
|
||||||
{
|
{
|
||||||
return ConfigCLI::Main(argc-1, &argv[1]);
|
return ConfigCLI::Main(argc-1, &argv[1]);
|
||||||
}
|
}
|
||||||
std::map<std::string, ConfigFile> files{};
|
std::map<std::string, ConfigFile> files{};
|
||||||
auto conf = ConfigFile::GetConfigFile();
|
auto conf = ConfigFile::GetConfigFile("./", flagData);
|
||||||
if(conf)
|
if(conf)
|
||||||
{
|
{
|
||||||
bool success = MakeGen("./", flags, *conf);
|
bool success = MakeGen("./", flagData, *conf);
|
||||||
return success ? 0 : 1;
|
return success ? 0 : 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user