Add cppversion as makegen config parameter
- Add cppversion as makegen config parameter, making it possible to specify which cpp version to use - General cleanup of unused code
This commit is contained in:
@@ -34,28 +34,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)/src/ConfigCLI.o: src/ConfigCLI.cpp src/Common.h src/AssertException.h src/ConfigCLI.h src/ConfigFile.h src/ConfigUtils.h src/FileUtils.h src/Utils.h src/Dependency.h src/FlagData.h src/xml/XMLObject.h
|
$(OBJPATH)/src/ConfigCLI.o: src/ConfigCLI.cpp src/Common.h src/AssertException.h src/ConfigCLI.h src/ConfigFile.h src/ConfigUtils.h src/Dependency.h src/FlagData.h src/xml/XMLObject.h src/FileUtils.h src/Utils.h
|
||||||
$(info -[10%]- $<)
|
$(info -[10%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/src/ConfigFile.o: src/ConfigFile.cpp src/ConfigFile.h src/ConfigUtils.h src/Common.h src/AssertException.h src/FileUtils.h src/Utils.h src/Dependency.h src/FlagData.h src/xml/XMLObject.h src/compatibility/ConfigFileConf.h src/xml/XML.h
|
$(OBJPATH)/src/ConfigFile.o: src/ConfigFile.cpp src/ConfigFile.h src/ConfigUtils.h src/Common.h src/AssertException.h src/Dependency.h src/FlagData.h src/xml/XMLObject.h src/FileUtils.h src/Utils.h src/compatibility/ConfigFileConf.h src/xml/XML.h
|
||||||
$(info -[20%]- $<)
|
$(info -[20%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/src/HFileGen.o: src/HFileGen.cpp src/FileUtils.h src/Common.h src/AssertException.h src/Utils.h src/HFileGen.h src/ConfigFile.h src/ConfigUtils.h src/Dependency.h src/FlagData.h src/xml/XMLObject.h
|
$(OBJPATH)/src/HFileGen.o: src/HFileGen.cpp src/FileUtils.h src/Common.h src/AssertException.h src/Utils.h src/HFileGen.h src/ConfigFile.h src/ConfigUtils.h src/Dependency.h src/FlagData.h src/xml/XMLObject.h
|
||||||
$(info -[30%]- $<)
|
$(info -[30%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/src/IncludeDeps.o: src/IncludeDeps.cpp src/Common.h src/AssertException.h src/IncludeDeps.h src/ConfigFile.h src/ConfigUtils.h src/FileUtils.h src/Utils.h src/Dependency.h src/FlagData.h src/xml/XMLObject.h
|
$(OBJPATH)/src/IncludeDeps.o: src/IncludeDeps.cpp src/Common.h src/AssertException.h src/IncludeDeps.h src/ConfigFile.h src/ConfigUtils.h src/Dependency.h src/FlagData.h src/xml/XMLObject.h src/FileUtils.h src/Utils.h
|
||||||
$(info -[40%]- $<)
|
$(info -[40%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/src/Makefile.o: src/Makefile.cpp src/Common.h src/AssertException.h src/IncludeDeps.h src/ConfigFile.h src/ConfigUtils.h src/FileUtils.h src/Utils.h src/Dependency.h src/FlagData.h src/xml/XMLObject.h src/Makefile.h
|
$(OBJPATH)/src/Makefile.o: src/Makefile.cpp src/Common.h src/AssertException.h src/IncludeDeps.h src/ConfigFile.h src/ConfigUtils.h src/Dependency.h src/FlagData.h src/xml/XMLObject.h src/FileUtils.h src/Utils.h src/Makefile.h
|
||||||
$(info -[50%]- $<)
|
$(info -[50%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/src/Utils.o: src/Utils.cpp src/ConfigFile.h src/ConfigUtils.h src/Common.h src/AssertException.h src/FileUtils.h src/Utils.h src/Dependency.h src/FlagData.h src/xml/XMLObject.h
|
$(OBJPATH)/src/Utils.o: src/Utils.cpp src/ConfigFile.h src/ConfigUtils.h src/Common.h src/AssertException.h src/Dependency.h src/FlagData.h src/xml/XMLObject.h src/FileUtils.h src/Utils.h
|
||||||
$(info -[60%]- $<)
|
$(info -[60%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/src/compatibility/ConfigFileConf.o: src/compatibility/ConfigFileConf.cpp src/ConfigFile.h src/ConfigUtils.h src/Common.h src/AssertException.h src/FileUtils.h src/Utils.h src/Dependency.h src/FlagData.h src/xml/XMLObject.h src/compatibility/ConfigFileConf.h
|
$(OBJPATH)/src/compatibility/ConfigFileConf.o: src/compatibility/ConfigFileConf.cpp src/Common.h src/AssertException.h src/xml/XMLObject.h src/compatibility/ConfigFileConf.h
|
||||||
$(info -[70%]- $<)
|
$(info -[70%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/src/main.o: src/main.cpp src/Common.h src/AssertException.h src/ConfigCLI.h src/ConfigFile.h src/ConfigUtils.h src/FileUtils.h src/Utils.h src/Dependency.h src/FlagData.h src/xml/XMLObject.h src/HFileGen.h src/Makefile.h src/Timer.h
|
$(OBJPATH)/src/main.o: src/main.cpp src/Common.h src/AssertException.h src/ConfigCLI.h src/ConfigFile.h src/ConfigUtils.h src/Dependency.h src/FlagData.h src/xml/XMLObject.h src/HFileGen.h src/Makefile.h src/Timer.h src/Utils.h
|
||||||
$(info -[80%]- $<)
|
$(info -[80%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/src/xml/XML.o: src/xml/XML.cpp src/xml/XML.h src/xml/XMLObject.h src/xml/XMLException.h
|
$(OBJPATH)/src/xml/XML.o: src/xml/XML.cpp src/xml/XML.h src/xml/XMLObject.h src/xml/XMLException.h
|
||||||
|
|||||||
+3
-1
@@ -1,5 +1,6 @@
|
|||||||
<makegen>
|
<makegen>
|
||||||
<configuration name="Release">
|
<configuration name="Release">
|
||||||
|
<cppversion>c++17</cppversion>
|
||||||
<outputdir>bin/Release/</outputdir>
|
<outputdir>bin/Release/</outputdir>
|
||||||
<outputname>makegen</outputname>
|
<outputname>makegen</outputname>
|
||||||
<outputtype>executable</outputtype>
|
<outputtype>executable</outputtype>
|
||||||
@@ -9,6 +10,7 @@
|
|||||||
<configuration name="Debug">
|
<configuration name="Debug">
|
||||||
<cflag>-g3</cflag>
|
<cflag>-g3</cflag>
|
||||||
<cflag>-w</cflag>
|
<cflag>-w</cflag>
|
||||||
|
<cppversion>c++17</cppversion>
|
||||||
<define>_DEBUG</define>
|
<define>_DEBUG</define>
|
||||||
<outputdir>bin/Debug/</outputdir>
|
<outputdir>bin/Debug/</outputdir>
|
||||||
<outputname>makegen</outputname>
|
<outputname>makegen</outputname>
|
||||||
@@ -17,5 +19,5 @@
|
|||||||
<srcdir>src/</srcdir>
|
<srcdir>src/</srcdir>
|
||||||
</configuration>
|
</configuration>
|
||||||
<target>Release</target>
|
<target>Release</target>
|
||||||
<version>v1.3.10</version>
|
<version>v1.3.11</version>
|
||||||
</makegen>
|
</makegen>
|
||||||
|
|||||||
+3
-5
@@ -16,7 +16,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 10
|
#define MAKEGEN_VERSION_MINOR 11
|
||||||
|
|
||||||
#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))
|
||||||
|
|
||||||
@@ -42,15 +42,13 @@ const static unsigned int FLAG_TARGET = BIT(11);
|
|||||||
LOG_ERROR(__VA_ARGS__); \
|
LOG_ERROR(__VA_ARGS__); \
|
||||||
throw AssertException{}; \
|
throw AssertException{}; \
|
||||||
} \
|
} \
|
||||||
{ \
|
false
|
||||||
} \
|
|
||||||
while (false)
|
|
||||||
#define ABORT(...) \
|
#define ABORT(...) \
|
||||||
{ \
|
{ \
|
||||||
LOG_ERROR(__VA_ARGS__); \
|
LOG_ERROR(__VA_ARGS__); \
|
||||||
throw AssertException{}; \
|
throw AssertException{}; \
|
||||||
} \
|
} \
|
||||||
while (false)
|
false
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Log(const T& var)
|
void Log(const T& var)
|
||||||
|
|||||||
+8
-3
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "ConfigFile.h"
|
#include "ConfigFile.h"
|
||||||
|
#include "FileUtils.h"
|
||||||
|
|
||||||
void ConfigCLI::DisplayCLIHelp()
|
void ConfigCLI::DisplayCLIHelp()
|
||||||
{
|
{
|
||||||
@@ -93,6 +94,7 @@ Valid string settings are:
|
|||||||
outputtype Type of the output, valid values are executable, sharedlibrary
|
outputtype Type of the output, valid values are executable, sharedlibrary
|
||||||
and staticlibrary
|
and staticlibrary
|
||||||
hfile Name of the generated project h-file
|
hfile Name of the generated project h-file
|
||||||
|
cppversion Version of the c++ to use
|
||||||
|
|
||||||
Valid boolean settings are:
|
Valid boolean settings are:
|
||||||
genhfile Specifies if MakeGen should generate a project h-file
|
genhfile Specifies if MakeGen should generate a project h-file
|
||||||
@@ -125,7 +127,9 @@ Valid settings are:
|
|||||||
and staticlibrary
|
and staticlibrary
|
||||||
projectname Name of the project
|
projectname Name of the project
|
||||||
hfile Name of the generated project h-file
|
hfile Name of the generated project h-file
|
||||||
genhfile Specifies if MakeGen should generate a project h-file)");
|
genhfile Specifies if MakeGen should generate a project h-file
|
||||||
|
cppversion Specifies the version of c++ to use (default=c++17)
|
||||||
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigSetting ConfigCLI::CLIStringToSetting(const std::string& s)
|
ConfigSetting ConfigCLI::CLIStringToSetting(const std::string& s)
|
||||||
@@ -149,9 +153,10 @@ ConfigSetting ConfigCLI::CLIStringToSetting(const std::string& s)
|
|||||||
{"argument", ConfigSetting::ExecArgument},
|
{"argument", ConfigSetting::ExecArgument},
|
||||||
{"dependency", ConfigSetting::Dependency},
|
{"dependency", ConfigSetting::Dependency},
|
||||||
{"genhfile", ConfigSetting::GenerateHFile},
|
{"genhfile", ConfigSetting::GenerateHFile},
|
||||||
|
{"cppversion", ConfigSetting::CppVersion},
|
||||||
};
|
};
|
||||||
auto it = map.find(s);
|
auto it = map.find(s);
|
||||||
ASSERT(it != map.end(), "Invalid config setting: ", s)
|
ASSERT(it != map.end(), "Invalid config setting: ", s);
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +180,7 @@ int ConfigCLI::Gen(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
if (option == "default")
|
if (option == "default")
|
||||||
{
|
{
|
||||||
ConfigFile{FileUtils::GetRealPath("."), FlagData{}, 0}.Save();
|
ConfigFile{std::filesystem::current_path(), FlagData{}, 0}.Save();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
+34
-4
@@ -6,6 +6,8 @@
|
|||||||
#include "compatibility/ConfigFileConf.h"
|
#include "compatibility/ConfigFileConf.h"
|
||||||
#include "xml/XML.h"
|
#include "xml/XML.h"
|
||||||
|
|
||||||
|
const std::string DEFAULT_CPP_VERSION = "c++17";
|
||||||
|
|
||||||
ConfigFile::ConfigFile(const std::string& path, const FlagData& flagData, int)
|
ConfigFile::ConfigFile(const std::string& path, const FlagData& flagData, int)
|
||||||
: makegen{"makegen", {}, std::map<std::string, std::vector<XMLObject>>{}},
|
: makegen{"makegen", {}, std::map<std::string, std::vector<XMLObject>>{}},
|
||||||
configPath{std::filesystem::canonical(path)}
|
configPath{std::filesystem::canonical(path)}
|
||||||
@@ -24,10 +26,9 @@ ConfigFile::ConfigFile(const std::string& path, const FlagData& flagData, int)
|
|||||||
configuration.AddXMLObject(XMLObject("projectname", {}, ConfigUtils::GetDefaultProjectName(configPath)));
|
configuration.AddXMLObject(XMLObject("projectname", {}, ConfigUtils::GetDefaultProjectName(configPath)));
|
||||||
configuration.AddXMLObject(XMLObject("outputname", {}, ConfigUtils::GetDefaultOutputName(configPath)));
|
configuration.AddXMLObject(XMLObject("outputname", {}, ConfigUtils::GetDefaultOutputName(configPath)));
|
||||||
configuration.AddXMLObject(XMLObject("srcdir", {}, "src/"));
|
configuration.AddXMLObject(XMLObject("srcdir", {}, "src/"));
|
||||||
configuration.AddXMLObject(XMLObject("outputdir", {}, "bin/"));
|
configuration.AddXMLObject(XMLObject("outputdir", {}, "bin/" + target + "/"));
|
||||||
configuration.AddXMLObject(XMLObject("hfilename", {}, ConfigUtils::GetDefaultHFileName(configPath)));
|
|
||||||
configuration.AddXMLObject(XMLObject("outputtype", {}, "executable"));
|
configuration.AddXMLObject(XMLObject("outputtype", {}, "executable"));
|
||||||
configuration.AddXMLObject(XMLObject("generatehfile", {}, "false"));
|
configuration.AddXMLObject(XMLObject("cppversion", {}, DEFAULT_CPP_VERSION));
|
||||||
|
|
||||||
makegen.AddXMLObject(configuration);
|
makegen.AddXMLObject(configuration);
|
||||||
Init(flagData);
|
Init(flagData);
|
||||||
@@ -56,6 +57,7 @@ void ConfigFile::Init(const FlagData& flagData)
|
|||||||
InitStringSetting("outputtype", &outputType);
|
InitStringSetting("outputtype", &outputType);
|
||||||
InitStringSetting("outputdir", &outputDir);
|
InitStringSetting("outputdir", &outputDir);
|
||||||
InitStringSetting("projectname", &projectName);
|
InitStringSetting("projectname", &projectName);
|
||||||
|
InitStringSetting("cppversion", DEFAULT_CPP_VERSION, &cppVersion);
|
||||||
InitOptionalStringSetting("srcdir", &sourceDir);
|
InitOptionalStringSetting("srcdir", &sourceDir);
|
||||||
InitOptionalStringSetting("hfilename", &hFileName);
|
InitOptionalStringSetting("hfilename", &hFileName);
|
||||||
InitStringListSetting("librarydir", &libraryDirs);
|
InitStringListSetting("librarydir", &libraryDirs);
|
||||||
@@ -144,7 +146,25 @@ void ConfigFile::InitDependencies()
|
|||||||
void ConfigFile::InitStringSetting(const std::string& name, std::string* output)
|
void ConfigFile::InitStringSetting(const std::string& name, std::string* output)
|
||||||
{
|
{
|
||||||
const std::vector<XMLObject>& values = config.GetObjects(name);
|
const std::vector<XMLObject>& values = config.GetObjects(name);
|
||||||
ASSERT(!values.empty(), "No ", name, " defined in makegen.xml")
|
ASSERT(!values.empty(), "No ", name, " defined in makegen.xml");
|
||||||
|
|
||||||
|
if (values.size() > 1)
|
||||||
|
{
|
||||||
|
LOG_ERROR("Only one instance of ", name, " allowed using ", values.front().GetText());
|
||||||
|
}
|
||||||
|
|
||||||
|
*output = values.front().GetText();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigFile::InitStringSetting(const std::string& name, const std::string& defaultVal, std::string* output)
|
||||||
|
{
|
||||||
|
const std::vector<XMLObject>& values = config.GetObjects(name);
|
||||||
|
if (values.empty())
|
||||||
|
{
|
||||||
|
*output = defaultVal;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ASSERT(!values.empty(), "No ", name, " defined in makegen.xml");
|
||||||
|
|
||||||
if (values.size() > 1)
|
if (values.size() > 1)
|
||||||
{
|
{
|
||||||
@@ -251,6 +271,11 @@ const std::string& ConfigFile::GetOutputType() const
|
|||||||
return outputType;
|
return outputType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& ConfigFile::GetCppVersion() const
|
||||||
|
{
|
||||||
|
return cppVersion;
|
||||||
|
}
|
||||||
|
|
||||||
const std::optional<std::string>& ConfigFile::GetSourceDir() const
|
const std::optional<std::string>& ConfigFile::GetSourceDir() const
|
||||||
{
|
{
|
||||||
return sourceDir;
|
return sourceDir;
|
||||||
@@ -349,6 +374,8 @@ std::vector<std::string> ConfigFile::GetSetting(ConfigSetting setting) const
|
|||||||
return {outputType};
|
return {outputType};
|
||||||
case ConfigSetting::ProjectName:
|
case ConfigSetting::ProjectName:
|
||||||
return {projectName};
|
return {projectName};
|
||||||
|
case ConfigSetting::CppVersion:
|
||||||
|
return {cppVersion};
|
||||||
case ConfigSetting::HFileName:
|
case ConfigSetting::HFileName:
|
||||||
{
|
{
|
||||||
if (hFileName.has_value())
|
if (hFileName.has_value())
|
||||||
@@ -443,6 +470,9 @@ bool ConfigFile::SetSettingString(ConfigSetting setting, std::string value)
|
|||||||
case ConfigSetting::GenerateHFile:
|
case ConfigSetting::GenerateHFile:
|
||||||
generateHFile = value == "true";
|
generateHFile = value == "true";
|
||||||
break;
|
break;
|
||||||
|
case ConfigSetting::CppVersion:
|
||||||
|
cppVersion = value;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
LOG_ERROR("Not a string setting");
|
LOG_ERROR("Not a string setting");
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public:
|
|||||||
const std::string& GetOutputName() const;
|
const std::string& GetOutputName() const;
|
||||||
const std::string& GetProjectName() const;
|
const std::string& GetProjectName() const;
|
||||||
const std::string& GetOutputType() const;
|
const std::string& GetOutputType() const;
|
||||||
|
const std::string& GetCppVersion() const;
|
||||||
const std::optional<std::string>& GetSourceDir() const;
|
const std::optional<std::string>& GetSourceDir() const;
|
||||||
const std::optional<std::string>& GetHFileName() const;
|
const std::optional<std::string>& GetHFileName() const;
|
||||||
const std::vector<std::string>& GetLibraryDirs() const;
|
const std::vector<std::string>& GetLibraryDirs() const;
|
||||||
@@ -69,6 +70,7 @@ private:
|
|||||||
std::string outputDir;
|
std::string outputDir;
|
||||||
std::string projectName;
|
std::string projectName;
|
||||||
std::string outputType;
|
std::string outputType;
|
||||||
|
std::string cppVersion;
|
||||||
std::optional<std::string> sourceDir;
|
std::optional<std::string> sourceDir;
|
||||||
std::optional<std::string> hFileName;
|
std::optional<std::string> hFileName;
|
||||||
std::vector<std::string> libraryDirs;
|
std::vector<std::string> libraryDirs;
|
||||||
@@ -92,6 +94,7 @@ private:
|
|||||||
XMLObject& GetTargetConfig();
|
XMLObject& GetTargetConfig();
|
||||||
void InitDependencies();
|
void InitDependencies();
|
||||||
void InitStringSetting(const std::string& name, std::string* output);
|
void InitStringSetting(const std::string& name, std::string* output);
|
||||||
|
void InitStringSetting(const std::string& name, const std::string& defaultVal, std::string* output);
|
||||||
void InitOptionalStringSetting(const std::string& name, std::optional<std::string>* output);
|
void InitOptionalStringSetting(const std::string& name, std::optional<std::string>* output);
|
||||||
void InitStringListSetting(const std::string& name, std::vector<std::string>* output);
|
void InitStringListSetting(const std::string& name, std::vector<std::string>* output);
|
||||||
void InitBoolSetting(const std::string& name, bool* output);
|
void InitBoolSetting(const std::string& name, bool* output);
|
||||||
|
|||||||
+30
-53
@@ -1,44 +1,39 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <filesystem>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "FileUtils.h"
|
|
||||||
|
|
||||||
struct ConfigCache
|
|
||||||
{
|
|
||||||
std::map<std::string, std::string> strings;
|
|
||||||
std::map<std::string, std::vector<std::string>> vecStrings;
|
|
||||||
std::map<std::string, bool> bools;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class ConfigSetting
|
enum class ConfigSetting
|
||||||
{
|
{
|
||||||
// vectors
|
// vectors
|
||||||
Library = 0,
|
Library,
|
||||||
LibraryDir = 1,
|
LibraryDir,
|
||||||
IncludeDir = 2,
|
IncludeDir,
|
||||||
Define = 3,
|
Define,
|
||||||
Dependency = 4,
|
Dependency,
|
||||||
CFlag = 5,
|
CFlag,
|
||||||
LFlag = 6,
|
LFlag,
|
||||||
ExcludeSource = 7,
|
ExcludeSource,
|
||||||
ExcludeHeader = 8,
|
ExcludeHeader,
|
||||||
ExecPreArgument = 9,
|
ExecPreArgument,
|
||||||
ExecArgument = 10,
|
ExecArgument,
|
||||||
SourceFile = 11,
|
SourceFile,
|
||||||
IncludeDirExclDep = 12,
|
IncludeDirExclDep,
|
||||||
// Strings
|
// Strings
|
||||||
SourceDir = 32,
|
SourceDir,
|
||||||
OutputDir = 33,
|
OutputDir,
|
||||||
OutputName = 34,
|
OutputName,
|
||||||
OutputType = 35,
|
OutputType,
|
||||||
ProjectName = 36,
|
ProjectName,
|
||||||
HFileName = 37,
|
HFileName,
|
||||||
|
CppVersion,
|
||||||
// Bools
|
// Bools
|
||||||
GenerateHFile = 64,
|
GenerateHFile,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ConfigUtils
|
struct ConfigUtils
|
||||||
@@ -87,6 +82,8 @@ struct ConfigUtils
|
|||||||
return "sourcefile";
|
return "sourcefile";
|
||||||
case ConfigSetting::IncludeDirExclDep:
|
case ConfigSetting::IncludeDirExclDep:
|
||||||
return "includedirexcldep";
|
return "includedirexcldep";
|
||||||
|
case ConfigSetting::CppVersion:
|
||||||
|
return "cppversion";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -116,6 +113,7 @@ struct ConfigUtils
|
|||||||
case ConfigSetting::ExecArgument:
|
case ConfigSetting::ExecArgument:
|
||||||
case ConfigSetting::GenerateHFile:
|
case ConfigSetting::GenerateHFile:
|
||||||
case ConfigSetting::SourceFile:
|
case ConfigSetting::SourceFile:
|
||||||
|
case ConfigSetting::CppVersion:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -131,6 +129,7 @@ struct ConfigUtils
|
|||||||
case ConfigSetting::OutputType:
|
case ConfigSetting::OutputType:
|
||||||
case ConfigSetting::ProjectName:
|
case ConfigSetting::ProjectName:
|
||||||
case ConfigSetting::HFileName:
|
case ConfigSetting::HFileName:
|
||||||
|
case ConfigSetting::CppVersion:
|
||||||
return true;
|
return true;
|
||||||
case ConfigSetting::LibraryDir:
|
case ConfigSetting::LibraryDir:
|
||||||
case ConfigSetting::IncludeDir:
|
case ConfigSetting::IncludeDir:
|
||||||
@@ -176,6 +175,7 @@ struct ConfigUtils
|
|||||||
case ConfigSetting::ProjectName:
|
case ConfigSetting::ProjectName:
|
||||||
case ConfigSetting::HFileName:
|
case ConfigSetting::HFileName:
|
||||||
case ConfigSetting::GenerateHFile:
|
case ConfigSetting::GenerateHFile:
|
||||||
|
case ConfigSetting::CppVersion:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -206,35 +206,12 @@ struct ConfigUtils
|
|||||||
case ConfigSetting::ExecArgument:
|
case ConfigSetting::ExecArgument:
|
||||||
case ConfigSetting::SourceFile:
|
case ConfigSetting::SourceFile:
|
||||||
case ConfigSetting::IncludeDirExclDep:
|
case ConfigSetting::IncludeDirExclDep:
|
||||||
|
case ConfigSetting::CppVersion:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string GetDefaultSettingString(ConfigSetting setting, const std::string& path)
|
|
||||||
{
|
|
||||||
switch (setting)
|
|
||||||
{
|
|
||||||
case ConfigSetting::SourceDir:
|
|
||||||
return "src/";
|
|
||||||
case ConfigSetting::OutputDir:
|
|
||||||
return "bin/";
|
|
||||||
case ConfigSetting::OutputName:
|
|
||||||
return GetDefaultOutputName(path);
|
|
||||||
case ConfigSetting::OutputType:
|
|
||||||
return "executable";
|
|
||||||
case ConfigSetting::ProjectName:
|
|
||||||
return GetDefaultProjectName(path);
|
|
||||||
case ConfigSetting::HFileName:
|
|
||||||
return GetDefaultHFileName(path);
|
|
||||||
case ConfigSetting::GenerateHFile:
|
|
||||||
return GetDefaultSettingBool(setting) ? "true" : "false";
|
|
||||||
default:
|
|
||||||
ASSERT(false, "INVALID STRING ENUM: ", (int)setting);
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool GetDefaultSettingBool(ConfigSetting setting)
|
static bool GetDefaultSettingBool(ConfigSetting setting)
|
||||||
{
|
{
|
||||||
switch (setting)
|
switch (setting)
|
||||||
@@ -248,7 +225,7 @@ struct ConfigUtils
|
|||||||
|
|
||||||
static std::string GetDefaultProjectName(const std::string& path)
|
static std::string GetDefaultProjectName(const std::string& path)
|
||||||
{
|
{
|
||||||
return FileUtils::GetTopDirectory(path);
|
return std::filesystem::canonical(path).filename();
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string GetDefaultOutputName(const std::string& path)
|
static std::string GetDefaultOutputName(const std::string& path)
|
||||||
|
|||||||
@@ -17,100 +17,11 @@
|
|||||||
|
|
||||||
struct FileUtils
|
struct FileUtils
|
||||||
{
|
{
|
||||||
static bool HasPath(const std::string& path)
|
|
||||||
{
|
|
||||||
struct stat info;
|
|
||||||
|
|
||||||
if (stat(path.c_str(), &info) != 0)
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool CreateDirectory(const std::string& path)
|
|
||||||
{
|
|
||||||
return mkdir(path.c_str(), 0777);
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string GetCurrentDirectory()
|
|
||||||
{
|
|
||||||
static char path[256]; // Usual maximum filename
|
|
||||||
getcwd(path, sizeof(path));
|
|
||||||
return GetTopDirectory(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string GetTopDirectory(const std::string& dir)
|
|
||||||
{
|
|
||||||
ASSERT(!dir.empty(), "Cannot send empty string to FileUtils::GetTopDirectory()");
|
|
||||||
|
|
||||||
size_t dirEnd = std::string::npos;
|
|
||||||
if (dir[dir.size() - 1] == '/')
|
|
||||||
dirEnd = dir.size() - 2;
|
|
||||||
size_t pos = dir.find_last_of("/", dirEnd);
|
|
||||||
ASSERT(pos != std::string::npos, "Couldn't find / (slash) in directory. This shouldn't occur.");
|
|
||||||
return dir.substr(pos + 1, dirEnd - pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string GetRealPath(const std::string& filename)
|
static std::string GetRealPath(const std::string& filename)
|
||||||
{
|
{
|
||||||
return std::filesystem::canonical(filename).string();
|
return std::filesystem::canonical(filename).string();
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string GetRelativePath(std::string from, std::string to)
|
|
||||||
{
|
|
||||||
std::string result;
|
|
||||||
if (to[to.size() - 1] == '/')
|
|
||||||
to.pop_back();
|
|
||||||
if (from[from.size() - 1] == '/')
|
|
||||||
from.pop_back();
|
|
||||||
|
|
||||||
// Check if the directory is inside 'from'
|
|
||||||
if (strncmp(to.c_str(), from.c_str(), from.size()) == 0)
|
|
||||||
{
|
|
||||||
// Same directory
|
|
||||||
if (to.size() == from.size())
|
|
||||||
return "";
|
|
||||||
// Remove the 'from' path
|
|
||||||
return to.substr(from.size() + 1);
|
|
||||||
}
|
|
||||||
// Check if the directory is a child of from
|
|
||||||
else if (strncmp(from.c_str(), to.c_str(), to.size()) == 0)
|
|
||||||
{
|
|
||||||
std::string sub = from.substr(to.size());
|
|
||||||
size_t n = std::count(sub.begin(), sub.end(), '/');
|
|
||||||
for (int i = 0; i < n; i++)
|
|
||||||
{
|
|
||||||
result += "..";
|
|
||||||
if (i != n - 1)
|
|
||||||
result += "/";
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
// Otherwise it's a path in another directory
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Find the most common directory
|
|
||||||
std::string commonPath = Utils::CommonPrefix(from, to);
|
|
||||||
if (commonPath.empty())
|
|
||||||
return "";
|
|
||||||
while (commonPath.back() != '/') commonPath.pop_back();
|
|
||||||
commonPath.pop_back();
|
|
||||||
|
|
||||||
// Go back to the common directory
|
|
||||||
std::string sub = from.substr(commonPath.size());
|
|
||||||
size_t n = std::count(sub.begin(), sub.end(), '/');
|
|
||||||
for (int i = 0; i < n; i++)
|
|
||||||
{
|
|
||||||
result += "..";
|
|
||||||
if (i != n - 1)
|
|
||||||
result += "/";
|
|
||||||
}
|
|
||||||
// Add the path which diverges
|
|
||||||
result += to.substr(commonPath.size());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void GetAllFiles(const std::string& folder, std::vector<std::string>& files)
|
static void GetAllFiles(const std::string& folder, std::vector<std::string>& files)
|
||||||
{
|
{
|
||||||
DIR* dp;
|
DIR* dp;
|
||||||
|
|||||||
+2
-2
@@ -61,11 +61,11 @@ void Makefile::Save(ConfigFile& conf, unsigned int flags)
|
|||||||
outputFile << std::endl;
|
outputFile << std::endl;
|
||||||
if (outputtype == "executable" || outputtype != "sharedlibrary")
|
if (outputtype == "executable" || outputtype != "sharedlibrary")
|
||||||
{
|
{
|
||||||
outputFile << "CFLAGS=$(INCLUDES) -std=c++17 -c ";
|
outputFile << "CFLAGS=$(INCLUDES) -std=" + conf.GetCppVersion() + " -c ";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
outputFile << "CFLAGS=$(INCLUDES) -fPIC -std=c++17 -c ";
|
outputFile << "CFLAGS=$(INCLUDES) -fPIC -std=" + conf.GetCppVersion() + " -c ";
|
||||||
}
|
}
|
||||||
const std::vector<std::string>& defines = conf.GetDefines();
|
const std::vector<std::string>& defines = conf.GetDefines();
|
||||||
for (const auto& define : defines)
|
for (const auto& define : defines)
|
||||||
|
|||||||
@@ -3,10 +3,11 @@
|
|||||||
const std::string CONFIG_FILENAME_CONF = "makegen.conf";
|
const std::string CONFIG_FILENAME_CONF = "makegen.conf";
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "../ConfigFile.h"
|
#include "../Common.h"
|
||||||
#include "../FileUtils.h"
|
#include "../xml/XMLObject.h"
|
||||||
|
|
||||||
#define FLAG_NONE 0
|
#define FLAG_NONE 0
|
||||||
#define FLAG_VECTOR 1
|
#define FLAG_VECTOR 1
|
||||||
@@ -14,10 +15,10 @@ const std::string CONFIG_FILENAME_CONF = "makegen.conf";
|
|||||||
#define FLAG_BOOL 3
|
#define FLAG_BOOL 3
|
||||||
|
|
||||||
ConfigFileConf::ConfigFileConf()
|
ConfigFileConf::ConfigFileConf()
|
||||||
: outputdir("bin/"),
|
: outputdir("bin/Release"),
|
||||||
srcdir("src/"),
|
srcdir("src/"),
|
||||||
outputname(""),
|
outputname(""),
|
||||||
projectname(FileUtils::GetCurrentDirectory()),
|
projectname(std::filesystem::current_path().filename()),
|
||||||
hFile(""),
|
hFile(""),
|
||||||
executable(true),
|
executable(true),
|
||||||
shared(true),
|
shared(true),
|
||||||
@@ -161,7 +162,7 @@ void ConfigFileConf::CreateXMLFile(const std::string& filepath)
|
|||||||
XMLObject makegen("makegen", {}, std::map<std::string, std::vector<XMLObject>>{});
|
XMLObject makegen("makegen", {}, std::map<std::string, std::vector<XMLObject>>{});
|
||||||
|
|
||||||
// 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.2"));
|
makegen.AddXMLObject(XMLObject("version", {}, MAKEGEN_VERSION));
|
||||||
makegen.AddXMLObject(XMLObject("target", {}, "Release"));
|
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>>{});
|
||||||
|
|||||||
+3
-11
@@ -1,3 +1,5 @@
|
|||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -5,11 +7,11 @@
|
|||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "ConfigCLI.h"
|
#include "ConfigCLI.h"
|
||||||
#include "ConfigFile.h"
|
#include "ConfigFile.h"
|
||||||
#include "FileUtils.h"
|
|
||||||
#include "FlagData.h"
|
#include "FlagData.h"
|
||||||
#include "HFileGen.h"
|
#include "HFileGen.h"
|
||||||
#include "Makefile.h"
|
#include "Makefile.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
#define RETURN_IF(x, b) \
|
#define RETURN_IF(x, b) \
|
||||||
if (x) \
|
if (x) \
|
||||||
@@ -182,14 +184,6 @@ bool MakeGen(const std::string& filepath, const FlagData& flagData, ConfigFile&
|
|||||||
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...");
|
||||||
|
|
||||||
std::string outputPath = conf.GetConfigPath() / conf.GetOutputDir();
|
|
||||||
if (!FileUtils::HasPath(outputPath))
|
|
||||||
{
|
|
||||||
FileUtils::CreateDirectory(outputPath);
|
|
||||||
std::string intermediatePath = outputPath + "intermediates";
|
|
||||||
if (!FileUtils::HasPath(intermediatePath))
|
|
||||||
FileUtils::CreateDirectory(intermediatePath);
|
|
||||||
}
|
|
||||||
return RunMake(filepath, flagData.flags, conf);
|
return RunMake(filepath, flagData.flags, conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,8 +218,6 @@ int Run(int argc, char** argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user