Add sourcefile as makegen.xml option
- sourcefile will add additional individual files. Useful for when the user needs to manually specify files from existing repositories. If those repositories contain multiple files for different platforms - Rework IncludeDeps to support sourcefiles
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# This Makefile was generated using MakeGen v1.3.1 made by Tim Håkansson
|
||||
# This Makefile was generated using MakeGen v1.3.2 made by Tim Håkansson
|
||||
# and is licensed under MIT. Full source of the project can be found at
|
||||
# https://github.com/Thraix/MakeGen
|
||||
CC=@g++
|
||||
@@ -33,33 +33,33 @@ $(OUTPUT): $(OBJECTS)
|
||||
install: all
|
||||
$(info Installing MakeGen to /usr/bin/)
|
||||
@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/xml/XMLObject.h
|
||||
$(info -[10%]- $<)
|
||||
$(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/xml/XMLObject.h src/compatibility/ConfigFileConf.h src/xml/XML.h
|
||||
$(info -[20%]- $<)
|
||||
$(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/xml/XMLObject.h
|
||||
$(info -[30%]- $<)
|
||||
$(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/xml/XMLObject.h
|
||||
$(info -[40%]- $<)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
$(OBJPATH)/Makefile.o : src/Makefile.cpp src/IncludeDeps.h src/ConfigFile.h src/ConfigUtils.h src/Common.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/xml/XMLObject.h src/Makefile.h
|
||||
$(info -[50%]- $<)
|
||||
$(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/xml/XMLObject.h
|
||||
$(info -[60%]- $<)
|
||||
$(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/xml/XMLObject.h src/compatibility/ConfigFileConf.h
|
||||
$(info -[70%]- $<)
|
||||
$(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/xml/XMLObject.h src/HFileGen.h src/Makefile.h src/Timer.h
|
||||
$(info -[80%]- $<)
|
||||
$(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
|
||||
$(info -[90%]- $<)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
$(OBJPATH)/XMLObject.o : src/xml/XMLObject.cpp src/Common.h src/Utils.h src/xml/XMLException.h src/xml/XMLObject.h
|
||||
$(OBJPATH)/XMLObject.o : src/xml/XMLObject.cpp src/Common.h src/Utils.h src/xml/XMLException.h src/xml/XMLObject.h
|
||||
$(info -[100%]- $<)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
+1
-1
@@ -19,5 +19,5 @@
|
||||
<srcdir>src/</srcdir>
|
||||
</configuration>
|
||||
<target>Release</target>
|
||||
<version>v1.3.0</version>
|
||||
<version>v1.3.2</version>
|
||||
</makegen>
|
||||
|
||||
+33
-1
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
#define BIT(x) (1<<x)
|
||||
|
||||
@@ -12,7 +14,7 @@
|
||||
// Release, should be backwards compatible with any minor version
|
||||
#define MAKEGEN_VERSION_RELEASE 3
|
||||
// Minor changes, generally bug fixes
|
||||
#define MAKEGEN_VERSION_MINOR 1
|
||||
#define MAKEGEN_VERSION_MINOR 2
|
||||
|
||||
#define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR))
|
||||
|
||||
@@ -60,3 +62,33 @@ void LogHelper(const T& var, const Ts& ...vars)
|
||||
Log(vars...);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::ostream& operator<<(std::ostream& ostream, const std::vector<T>& vec)
|
||||
{
|
||||
ostream << "[" << std::endl;
|
||||
for (size_t i = 0; i < vec.size(); i++)
|
||||
{
|
||||
if (i != 0)
|
||||
ostream << ", " << std::endl;
|
||||
ostream << vec[i];
|
||||
}
|
||||
ostream << std::endl << "]";
|
||||
return ostream;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::ostream& operator<<(std::ostream& ostream, const std::set<T>& set)
|
||||
{
|
||||
ostream << "[" << std::endl;
|
||||
int i = 0;
|
||||
for (const auto& elem : set)
|
||||
{
|
||||
if (i != 0)
|
||||
ostream << ", " << std::endl;
|
||||
ostream << " " << elem;
|
||||
i++;
|
||||
}
|
||||
ostream << std::endl << "]";
|
||||
return ostream;
|
||||
}
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ std::string& ConfigFile::GetSettingString(ConfigSetting setting)
|
||||
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] != '/')
|
||||
if(ConfigUtils::IsDirectory(setting) && !s.empty() && s[s.size()-1] != '/')
|
||||
s += '/';
|
||||
return cache.strings.emplace(sSetting, s).first->second;
|
||||
}
|
||||
|
||||
+7
-1
@@ -18,7 +18,7 @@ struct ConfigCache
|
||||
enum class ConfigSetting
|
||||
{
|
||||
// vectors
|
||||
Library = 0, LibraryDir = 1, IncludeDir = 2, Define = 3, Dependency = 4, CFlag = 5, LFlag = 6, ExcludeSource = 7, ExcludeHeader = 8, ExecPreArgument = 9, ExecArgument = 10,
|
||||
Library = 0, LibraryDir = 1, IncludeDir = 2, Define = 3, Dependency = 4, CFlag = 5, LFlag = 6, ExcludeSource = 7, ExcludeHeader = 8, ExecPreArgument = 9, ExecArgument = 10, SourceFile = 11,
|
||||
// Strings
|
||||
SourceDir = 32, OutputDir = 33, OutputName = 34, OutputType = 35, ProjectName = 36, HFileName = 37,
|
||||
// Bools
|
||||
@@ -69,6 +69,8 @@ struct ConfigUtils
|
||||
return "argument";
|
||||
case ConfigSetting::GenerateHFile:
|
||||
return "generatehfile";
|
||||
case ConfigSetting::SourceFile:
|
||||
return "sourcefile";
|
||||
case ConfigSetting::Invalid:
|
||||
return "invalid";
|
||||
}
|
||||
@@ -98,6 +100,7 @@ struct ConfigUtils
|
||||
case ConfigSetting::ExecPreArgument:
|
||||
case ConfigSetting::ExecArgument:
|
||||
case ConfigSetting::GenerateHFile:
|
||||
case ConfigSetting::SourceFile:
|
||||
case ConfigSetting::Invalid:
|
||||
return false;
|
||||
}
|
||||
@@ -127,6 +130,7 @@ struct ConfigUtils
|
||||
case ConfigSetting::ExecPreArgument:
|
||||
case ConfigSetting::ExecArgument:
|
||||
case ConfigSetting::GenerateHFile:
|
||||
case ConfigSetting::SourceFile:
|
||||
case ConfigSetting::Invalid:
|
||||
return false;
|
||||
}
|
||||
@@ -148,6 +152,7 @@ struct ConfigUtils
|
||||
case ConfigSetting::ExcludeSource:
|
||||
case ConfigSetting::ExecPreArgument:
|
||||
case ConfigSetting::ExecArgument:
|
||||
case ConfigSetting::SourceFile:
|
||||
return true;
|
||||
case ConfigSetting::SourceDir:
|
||||
case ConfigSetting::OutputDir:
|
||||
@@ -184,6 +189,7 @@ struct ConfigUtils
|
||||
case ConfigSetting::ExcludeSource:
|
||||
case ConfigSetting::ExecPreArgument:
|
||||
case ConfigSetting::ExecArgument:
|
||||
case ConfigSetting::SourceFile:
|
||||
case ConfigSetting::Invalid:
|
||||
return false;
|
||||
}
|
||||
|
||||
+9
-35
@@ -12,6 +12,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unistd.h>
|
||||
#include <filesystem>
|
||||
|
||||
struct FileUtils
|
||||
{
|
||||
@@ -37,40 +38,6 @@ struct FileUtils
|
||||
return GetTopDirectory(path);
|
||||
}
|
||||
|
||||
// Collapsed "..", ie "example/../file.h" -> "file.h"
|
||||
static std::string CollapseDirectory(const std::string& dir)
|
||||
{
|
||||
std::string ret = dir;
|
||||
size_t pos2 = dir.find_last_of("/");
|
||||
size_t pos1 = dir.find_last_of("/", pos2-1);
|
||||
size_t collapse = 0;
|
||||
size_t collapsePos = 0;
|
||||
while(pos2 != std::string::npos)
|
||||
{
|
||||
if(pos1 == std::string::npos)
|
||||
pos1 = 0;
|
||||
|
||||
if(std::string_view(dir.c_str()+pos1, pos2 - pos1 + 1) == "/../")
|
||||
{
|
||||
if(collapse == 0)
|
||||
collapsePos = pos2;
|
||||
collapse++;
|
||||
}
|
||||
else if(collapse > 0)
|
||||
{
|
||||
collapse--;
|
||||
ret = ret.substr(0, pos1) + ret.substr(pos2 + 3);
|
||||
}
|
||||
if(pos1 == 0)
|
||||
break;
|
||||
pos2 = pos1;
|
||||
pos1 = dir.find_last_of("/", pos1-1);
|
||||
}
|
||||
if(ret[0] == '/' && dir[0] != '/')
|
||||
ret = ret.substr(1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static std::string GetTopDirectory(const std::string& dir)
|
||||
{
|
||||
if(dir.size() == 0)
|
||||
@@ -146,6 +113,8 @@ struct FileUtils
|
||||
{
|
||||
// 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();
|
||||
@@ -170,7 +139,7 @@ struct FileUtils
|
||||
DIR* dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir(folder.c_str())) == NULL){
|
||||
LOG_ERROR(errno);
|
||||
LOG_ERROR("Failed to open directory: ", folder);
|
||||
return;
|
||||
}
|
||||
while((dirp = readdir(dp)) != NULL)
|
||||
@@ -190,4 +159,9 @@ struct FileUtils
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
|
||||
static bool FileExists(const std::string& filename)
|
||||
{
|
||||
return std::filesystem::exists(filename) && !std::filesystem::is_directory(filename);
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "ConfigFile.h"
|
||||
|
||||
class HFileGen
|
||||
class HFileGen
|
||||
{
|
||||
public:
|
||||
static void Create(ConfigFile& conf);
|
||||
|
||||
+39
-21
@@ -1,17 +1,19 @@
|
||||
#include "IncludeDeps.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include <sstream>
|
||||
|
||||
std::set<std::string> IncludeDeps::printSet;
|
||||
int IncludeDeps::printCounter = 0;
|
||||
|
||||
IncludeDeps::IncludeDeps(const std::string& filename, const std::string& dir, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps)
|
||||
: IncludeDeps{filename, dir, false, files, allDeps}
|
||||
IncludeDeps::IncludeDeps(const std::string& filename, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps)
|
||||
: IncludeDeps{filename, false, files, allDeps}
|
||||
{}
|
||||
|
||||
IncludeDeps::IncludeDeps(const std::string& filename, const std::string& dir, bool projectHFile, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps)
|
||||
: filepath(dir+filename), projectHFile{projectHFile}
|
||||
IncludeDeps::IncludeDeps(const std::string& filename, bool projectHFile, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps)
|
||||
: filepath(filename), projectHFile{projectHFile}
|
||||
{
|
||||
std::filesystem::path path{filepath};
|
||||
if(Utils::IsHeaderFile(filename))
|
||||
{
|
||||
allDeps.emplace(filepath, this);
|
||||
@@ -20,42 +22,58 @@ IncludeDeps::IncludeDeps(const std::string& filename, const std::string& dir, bo
|
||||
std::string line;
|
||||
while(std::getline(file,line))
|
||||
{
|
||||
size_t pos = line.find("#include");
|
||||
if(pos != std::string::npos)
|
||||
std::string start;
|
||||
std::stringstream ss{line};
|
||||
ss >> start;
|
||||
if(start == "#include")
|
||||
{
|
||||
std::string include = FileUtils::CollapseDirectory(GetIncludeFile(line, pos, filename));
|
||||
auto it = files.find({include, "", false});
|
||||
if(it != files.end())
|
||||
std::string include = GetIncludeFile(line);
|
||||
|
||||
// Check if file can be found relative to current file:
|
||||
std::filesystem::path includeFileRelativeToSource = std::filesystem::relative(path.parent_path(), ".").string() + "/" + include;
|
||||
if (FileUtils::FileExists(includeFileRelativeToSource.string()))
|
||||
{
|
||||
auto itD = allDeps.find(it->filepath);
|
||||
auto itD = allDeps.find(includeFileRelativeToSource.string());
|
||||
if(itD == allDeps.end())
|
||||
{
|
||||
IncludeDeps* inc = new IncludeDeps(it->filename,it->directory, it->isProjectHFile, files,allDeps);
|
||||
dependencies.emplace(it->filepath, inc);
|
||||
}else{
|
||||
IncludeDeps* inc = new IncludeDeps(includeFileRelativeToSource.string(), false, files, allDeps);
|
||||
dependencies.emplace(includeFileRelativeToSource, inc);
|
||||
} else {
|
||||
dependencies.emplace(itD->first, itD->second);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto it = files.find({include, "", false});
|
||||
if(it != files.end())
|
||||
{
|
||||
auto itD = allDeps.find(it->filepath);
|
||||
if(itD == allDeps.end())
|
||||
{
|
||||
IncludeDeps* inc = new IncludeDeps(it->filepath, it->isProjectHFile, files, allDeps);
|
||||
dependencies.emplace(it->filepath, inc);
|
||||
}else{
|
||||
dependencies.emplace(itD->first, itD->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string IncludeDeps::GetIncludeFile(const std::string& line, size_t pos, const std::string& filename)
|
||||
std::string IncludeDeps::GetIncludeFile(const std::string& line)
|
||||
{
|
||||
size_t bracket = line.find('<',pos);
|
||||
size_t bracket = line.find('<');
|
||||
if(bracket == std::string::npos)
|
||||
{
|
||||
bracket = line.find('\"',pos);
|
||||
bracket = line.find('\"');
|
||||
if(bracket == std::string::npos)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
size_t slash = filename.find_last_of("/");
|
||||
|
||||
std::string include = line.substr(bracket+1, line.find('\"',bracket+1)-bracket-1);
|
||||
if(slash == std::string::npos)
|
||||
slash = -1;
|
||||
return filename.substr(0,slash+1)+include;
|
||||
std::string include = line.substr(bracket + 1, line.find('\"',bracket+1)-bracket-1);
|
||||
return include;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+11
-8
@@ -4,6 +4,7 @@
|
||||
#include "FileUtils.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
@@ -19,23 +20,25 @@ class IncludeDeps
|
||||
static std::set<std::string> printSet;
|
||||
static int printCounter;
|
||||
|
||||
IncludeDeps(const std::string& filename, const std::string& dir, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps);
|
||||
IncludeDeps(const std::string& filename, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps);
|
||||
|
||||
IncludeDeps(const std::string& filename, const std::string& dir, bool projectHFile, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps);
|
||||
IncludeDeps(const std::string& filename, bool projectHFile, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps);
|
||||
|
||||
std::string GetIncludeFile(const std::string& line, size_t pos, const std::string& filename);
|
||||
std::string GetIncludeFile(const std::string& line);
|
||||
|
||||
std::ostream& Output(std::ostream& stream, const ConfigFile& conf)
|
||||
{
|
||||
if(printSet.find(filepath) != printSet.end())
|
||||
std::string filePathRelativeToConfig = std::filesystem::relative(conf.GetConfigPath() + "/" + filepath, "./").string();
|
||||
if(printSet.find(filePathRelativeToConfig) != printSet.end())
|
||||
return stream;
|
||||
printSet.emplace(filePathRelativeToConfig);
|
||||
printCounter++;
|
||||
printSet.emplace(filepath);
|
||||
if(!projectHFile)
|
||||
stream << FileUtils::GetRelativePath(conf.GetConfigPath(), filepath);
|
||||
for(auto it = dependencies.begin();it!=dependencies.end();++it)
|
||||
{
|
||||
stream << " ";
|
||||
stream << " " << filePathRelativeToConfig;
|
||||
}
|
||||
for(auto it = dependencies.begin(); it != dependencies.end(); ++it)
|
||||
{
|
||||
(it->second)->Output(stream, conf);
|
||||
}
|
||||
printCounter--;
|
||||
|
||||
+4
-4
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "IncludeDeps.h"
|
||||
#include "Utils.h"
|
||||
#include "Common.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
@@ -166,16 +167,15 @@ void Makefile::Save(ConfigFile& conf, unsigned int flags)
|
||||
for(auto it = cppFiles.begin(); it != cppFiles.end();++it)
|
||||
{
|
||||
i++;
|
||||
std::string& srcdir = conf.GetSettingString(ConfigSetting::SourceDir);
|
||||
auto itD = dependencies.find(srcdir + *it);
|
||||
auto itD = dependencies.find(*it);
|
||||
if(itD == dependencies.end())
|
||||
{
|
||||
IncludeDeps* deps = new IncludeDeps(*it, conf.GetConfigPath() + srcdir,hFiles,dependencies);
|
||||
IncludeDeps* deps = new IncludeDeps(*it, hFiles, dependencies);
|
||||
size_t extensionPos = it->find_last_of(".");
|
||||
size_t slash = it->find_last_of("/")+1;
|
||||
std::string oFile = it->substr(slash, extensionPos - slash)+".o ";
|
||||
|
||||
outputFile << "$(OBJPATH)/" << oFile << ": ";
|
||||
outputFile << "$(OBJPATH)/" << oFile << ":";
|
||||
deps->Output(outputFile, conf);
|
||||
outputFile << std::endl;
|
||||
outputFile << "\t$(info -[" << (int)(i / (float)cppFiles.size() * 100) << "%]- $<)" << std::endl;
|
||||
|
||||
+64
-15
@@ -3,6 +3,8 @@
|
||||
#include "ConfigFile.h"
|
||||
#include "FileUtils.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
bool Utils::IsSourceFile(const std::string& filepath)
|
||||
{
|
||||
std::string_view extension(filepath);
|
||||
@@ -24,7 +26,6 @@ bool Utils::IsHeaderFile(const std::string& filepath)
|
||||
size_t pDot = filepath.find_last_of('.');
|
||||
if(pDot == std::string::npos || (pSlash != std::string::npos && pSlash > pDot))
|
||||
{
|
||||
LOG_ERROR("No file extension for file: ", filepath);
|
||||
return false;
|
||||
}
|
||||
extension.remove_prefix(pDot + 1);
|
||||
@@ -48,16 +49,28 @@ std::string Utils::CommonPrefix(const std::string& s1, const std::string& s2)
|
||||
void Utils::GetCppFiles(ConfigFile& conf, std::set<std::string>& cppFiles)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
std::string path = conf.GetConfigPath() + conf.GetSettingString(ConfigSetting::SourceDir);
|
||||
FileUtils::GetAllFiles(path, files);
|
||||
std::string sourceDir = conf.GetSettingString(ConfigSetting::SourceDir);
|
||||
std::string path = conf.GetConfigPath() + sourceDir;
|
||||
if (!sourceDir.empty())
|
||||
{
|
||||
FileUtils::GetAllFiles(path, files);
|
||||
}
|
||||
const std::vector<std::string>& excludeSources = conf.GetSettingVectorString(ConfigSetting::ExcludeSource);
|
||||
|
||||
for(const auto& sourceFile : conf.GetSettingVectorString(ConfigSetting::SourceFile))
|
||||
{
|
||||
if(FileUtils::FileExists(conf.GetConfigPath() + sourceFile))
|
||||
cppFiles.emplace(conf.GetConfigPath() + sourceFile);
|
||||
else
|
||||
LOG_WARNING("Source file doesn't exist: ", sourceFile);
|
||||
}
|
||||
|
||||
for(auto it = files.begin(); it!=files.end();++it)
|
||||
{
|
||||
std::string filename = it->substr(path.length());
|
||||
if(IsSourceFile(filename))
|
||||
{
|
||||
std::string sourceFile =conf.GetSettingString(ConfigSetting::SourceDir) + filename;
|
||||
std::string sourceFile = conf.GetSettingString(ConfigSetting::SourceDir) + filename;
|
||||
auto it = std::find(excludeSources.begin(), excludeSources.end(), sourceFile);
|
||||
if(it == excludeSources.end())
|
||||
{
|
||||
@@ -70,18 +83,25 @@ void Utils::GetCppFiles(ConfigFile& conf, std::set<std::string>& cppFiles)
|
||||
void Utils::GetCppAndHFiles(ConfigFile& conf, std::set<HFile>& hFiles, std::set<std::string>& cppFiles)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
std::string path = conf.GetConfigPath() + conf.GetSettingString(ConfigSetting::SourceDir);
|
||||
FileUtils::GetAllFiles(path,files);
|
||||
const std::vector<std::string>& excludeSources = conf.GetSettingVectorString(ConfigSetting::ExcludeSource);
|
||||
// include paramenter with the path of the file
|
||||
// For example src/graphics/Window.h -> graphics/Window.h if src is a src folder
|
||||
for(auto it = files.begin(); it!=files.end();++it)
|
||||
std::string sourceDir = conf.GetSettingString(ConfigSetting::SourceDir);
|
||||
std::string path = conf.GetConfigPath() + sourceDir;
|
||||
if (!sourceDir.empty())
|
||||
{
|
||||
FileUtils::GetAllFiles(path, files);
|
||||
}
|
||||
const std::vector<std::string>& excludeSources = conf.GetSettingVectorString(ConfigSetting::ExcludeSource);
|
||||
for(const auto& sourceFile : conf.GetSettingVectorString(ConfigSetting::SourceFile))
|
||||
{
|
||||
if(FileUtils::FileExists(conf.GetConfigPath() + sourceFile))
|
||||
cppFiles.emplace(conf.GetConfigPath() + sourceFile);
|
||||
else
|
||||
LOG_WARNING("Source file doesn't exist: ", sourceFile);
|
||||
}
|
||||
for(const auto& filename : files)
|
||||
{
|
||||
std::string filename = it->substr(path.length());
|
||||
if(IsSourceFile(filename))
|
||||
{
|
||||
std::string sourceFile =conf.GetSettingString(ConfigSetting::SourceDir) + filename;
|
||||
auto it = std::find(excludeSources.begin(), excludeSources.end(), sourceFile);
|
||||
auto it = std::find(excludeSources.begin(), excludeSources.end(), filename);
|
||||
if(it == excludeSources.end())
|
||||
{
|
||||
cppFiles.emplace(filename);
|
||||
@@ -89,7 +109,22 @@ void Utils::GetCppAndHFiles(ConfigFile& conf, std::set<HFile>& hFiles, std::set<
|
||||
}
|
||||
else if(IsHeaderFile(filename))
|
||||
{
|
||||
hFiles.emplace(HFile{filename,path,false});
|
||||
std::filesystem::path path = std::filesystem::relative(filename, sourceDir);
|
||||
hFiles.emplace(HFile{path.string(), sourceDir, false});
|
||||
}
|
||||
}
|
||||
|
||||
for(const auto& includePath : conf.GetSettingVectorString(ConfigSetting::IncludeDir))
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
FileUtils::GetAllFiles(includePath, files);
|
||||
for(const auto& file : files)
|
||||
{
|
||||
std::filesystem::path path = std::filesystem::relative(file, includePath);
|
||||
if(IsHeaderFile(path.string()))
|
||||
{
|
||||
hFiles.emplace(HFile{path.string(), includePath, false});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +154,21 @@ void Utils::GetHFiles(const std::string& dependencyDir, ConfigFile& conf, std::s
|
||||
if(IsHeaderFile(*it))
|
||||
{
|
||||
std::string filename = it->substr(depSrcDir.length());
|
||||
hFiles.emplace(HFile{filename, depSrcDir, conf.GetSettingBool(ConfigSetting::GenerateHFile) && filename == conf.GetSettingString(ConfigSetting::HFileName)});
|
||||
auto it = hFiles.find({filename, "", false});
|
||||
if(it != hFiles.end())
|
||||
{
|
||||
if(filename == conf.GetSettingString(ConfigSetting::HFileName) && !it->isProjectHFile)
|
||||
{
|
||||
HFile hfile = *it;
|
||||
hfile.isProjectHFile = true;
|
||||
hFiles.erase(it);
|
||||
hFiles.emplace(hfile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hFiles.emplace(HFile{filename, depSrcDir, conf.GetSettingBool(ConfigSetting::GenerateHFile) && filename == conf.GetSettingString(ConfigSetting::HFileName)});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -2,18 +2,18 @@
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
struct HFile
|
||||
{
|
||||
std::string filename;
|
||||
std::string directory;
|
||||
bool isProjectHFile;
|
||||
|
||||
std::string filepath;
|
||||
|
||||
HFile(const std::string& filename, const std::string& directory, bool isProjectHFile)
|
||||
: filename{filename}, directory{directory}, isProjectHFile{isProjectHFile}, filepath{directory+filename}
|
||||
: filename{filename}, isProjectHFile{isProjectHFile}, filepath{directory+filename}
|
||||
{}
|
||||
|
||||
friend bool operator<(const HFile& h1, const HFile& h2)
|
||||
|
||||
@@ -25,18 +25,18 @@ ConfigFileConf::ConfigFileConf()
|
||||
[](unsigned char c)
|
||||
{
|
||||
if(c == ' ')
|
||||
return '_';
|
||||
return '_';
|
||||
return (char)std::tolower(c);
|
||||
});
|
||||
|
||||
// Removes all other characters
|
||||
std::remove_if(
|
||||
outputdir.erase(std::remove_if(
|
||||
outputdir.begin(),
|
||||
outputdir.end(),
|
||||
[](unsigned char c)
|
||||
{
|
||||
return (c < 'a' || c > 'z') && c != '_';
|
||||
});
|
||||
}));
|
||||
|
||||
// Add suffix
|
||||
outputname += ".out";
|
||||
@@ -78,6 +78,7 @@ void ConfigFileConf::CreateXMLFile(const std::string& filepath)
|
||||
{"#compileflags", {&conf.flags, false}},
|
||||
{"#defines", {&conf.defines, false}},
|
||||
{"#dependencies", {&conf.dependencies, true}},
|
||||
{"#sourcefiles", {&conf.sourceFiles, false}},
|
||||
};
|
||||
|
||||
std::map<std::string, bool*> booleans =
|
||||
@@ -161,7 +162,7 @@ void ConfigFileConf::CreateXMLFile(const std::string& filepath)
|
||||
XMLObject makegen("makegen", {}, std::map<std::string, std::vector<XMLObject>>{});
|
||||
|
||||
// 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.2"));
|
||||
makegen.AddXMLObject(XMLObject("target", {}, "Release"));
|
||||
|
||||
XMLObject configuration("configuration", {{"name", "Release"}}, std::map<std::string, std::vector<XMLObject>>{});
|
||||
@@ -170,7 +171,7 @@ void ConfigFileConf::CreateXMLFile(const std::string& filepath)
|
||||
configuration.AddXMLObject(XMLObject("srcdir", {}, conf.srcdir));
|
||||
configuration.AddXMLObject(XMLObject("outputdir", {}, conf.outputdir));
|
||||
configuration.AddXMLObject(XMLObject("hfilename", {}, conf.hFile));
|
||||
configuration.AddXMLObject(XMLObject("outputtype", {},
|
||||
configuration.AddXMLObject(XMLObject("outputtype", {},
|
||||
conf.executable ? "executable" : (conf.shared ? "sharedlibrary" : "staticlibrary")));
|
||||
configuration.AddXMLObject(XMLObject("generatehfile", {}, conf.generateHFile ? "true" : "false"));
|
||||
|
||||
@@ -186,6 +187,8 @@ void ConfigFileConf::CreateXMLFile(const std::string& filepath)
|
||||
configuration.AddXMLObject({"cflag",{},*it});
|
||||
for(auto it = conf.dependencies.begin();it != conf.dependencies.end(); ++it)
|
||||
configuration.AddXMLObject({"dependency",{},*it});
|
||||
for(auto it = conf.sourceFiles.begin();it != conf.sourceFiles.end(); ++it)
|
||||
configuration.AddXMLObject({"sourcefile",{},*it});
|
||||
|
||||
makegen.AddXMLObject(configuration);
|
||||
std::ofstream xmlFile(conf.configPath + "makegen.xml");
|
||||
|
||||
@@ -17,6 +17,7 @@ class ConfigFileConf
|
||||
std::vector<std::string> defines;
|
||||
std::vector<std::string> flags;
|
||||
std::vector<std::string> dependencies;
|
||||
std::vector<std::string> sourceFiles;
|
||||
|
||||
std::string outputdir;
|
||||
std::string srcdir;
|
||||
|
||||
+16
-4
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <cmath>
|
||||
#include <thread>
|
||||
#include <filesystem>
|
||||
|
||||
#define RETURN_IF(x, b) \
|
||||
if(x)\
|
||||
@@ -144,9 +145,20 @@ bool MakeGen(const std::string& filepath, unsigned int flags, ConfigFile& conf)
|
||||
std::vector<std::string>& dependencies = conf.GetSettingVectorString(ConfigSetting::Dependency);
|
||||
for(size_t i = 0;i<dependencies.size();++i)
|
||||
{
|
||||
bool success = MakeGen(dependencies[i], flags, conf.GetDependencyConfig(i));
|
||||
if(!success)
|
||||
return success;
|
||||
std::filesystem::path currentPath = std::filesystem::current_path();
|
||||
std::filesystem::current_path(dependencies[i]);
|
||||
|
||||
auto conf = ConfigFile::GetConfigFile();
|
||||
if(conf)
|
||||
{
|
||||
bool success = MakeGen("./", flags, conf.value());
|
||||
if(!success)
|
||||
{
|
||||
std::filesystem::current_path(currentPath);
|
||||
return success;
|
||||
}
|
||||
}
|
||||
std::filesystem::current_path(currentPath);
|
||||
}
|
||||
LOG_INFO("-----------------------------------");
|
||||
LOG_INFO("Building ", conf.GetSettingString(ConfigSetting::ProjectName));
|
||||
@@ -177,7 +189,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
if(flags & FLAG_VERSION)
|
||||
{
|
||||
LOG_INFO("MakeGen ",MAKEGEN_VERSION);
|
||||
LOG_INFO("MakeGen ", MAKEGEN_VERSION);
|
||||
return 0;
|
||||
}
|
||||
if(flags & FLAG_CONFIG)
|
||||
|
||||
Reference in New Issue
Block a user