Add exclude source and header compilation

This commit is contained in:
Thraix
2020-03-02 21:44:38 +01:00
parent 5f6f605e32
commit f68861367b
6 changed files with 72 additions and 34 deletions
-2
View File
@@ -1,7 +1,6 @@
<makegen>
<configuration name="Release">
<generatehfile>false</generatehfile>
<hfilename>MakeGen.h</hfilename>
<outputdir>bin/</outputdir>
<outputname>makegen</outputname>
<outputtype>executable</outputtype>
@@ -13,7 +12,6 @@
<cflag>-g3</cflag>
<cflag>-w</cflag>
<generatehfile>false</generatehfile>
<hfilename>MakeGen.h</hfilename>
<outputdir>bin/</outputdir>
<outputname>makegen</outputname>
<outputtype>executable</outputtype>
+33 -25
View File
@@ -13,16 +13,16 @@ MakeGen conf is used to create, modify and query the makegen.xml file.
Usage: makegen conf <command> [<args>] [--help]
Generating config files
gen Prompt the user to enter information to create config
gen Prompt the user to enter information to create config
Modifying config settings
add Add values to config settings which support multiple arguments
remove Remove values from config settings which support multiple
arguments
set Set value to config settings which support only one argument
add Add values to config settings which support multiple arguments
remove Remove values from config settings which support multiple
arguments
set Set value to config settings which support only one argument
Querying config settings
get Get value of the config setting)");
get Get value of the config setting)");
}
void ConfigCLI::DisplayGenHelp()
@@ -33,10 +33,10 @@ Generate a config file from prompts
Usage: makegen conf gen <option>
options:
prompt Prompt the user for all needed settings
default Generate a default config file. Source directory is set to
src/, outputdir is set to bin/ and project name is set to
the current directory name.)");
prompt Prompt the user for all needed settings
default Generate a default config file. Source directory is set to
src/, outputdir is set to bin/ and project name is set to
the current directory name.)");
}
void ConfigCLI::DisplayAddHelp()
@@ -47,13 +47,15 @@ Add values to config settings which support multiple arguments
Usage: makegen conf add <setting> <value> [<values>]
Valid settings are:
library Library
librarydir Library directory
includedir Include directory
define Preprocessor define
cflag g++ compiler flag
lflag g++ linking flag
dependency Project which current project depends on)");
library Library
librarydir Library directory
includedir Include directory
define Preprocessor define
cflag g++ compiler flag
lflag g++ linking flag
dependency Project which current project depends on
excludesource Exclude source file from compiling
excludeheader Exclude header file from project h-file)");
}
void ConfigCLI::DisplayRemoveHelp()
@@ -64,13 +66,15 @@ Remove values to config settings which support multiple
Usage: makegen conf remove <setting> <value> [<
Valid settings are
library Library name
librarydir Library directory
includedir Include directory
define Preprocessor define
cflag g++ compiler flag
lflag g++ linking flag
dependency Project which current project depends on)");
library Library name
librarydir Library directory
includedir Include directory
define Preprocessor define
cflag g++ compiler flag
lflag g++ linking flag
dependency Project which current project depends on
excludesource Exclude source file from compiling
excludeheader Exclude header file from project h-file)");
}
void ConfigCLI::DisplaySetHelp()
@@ -108,7 +112,9 @@ Valid settings are:
define Preprocessor define
cflag g++ compiler flag
lflag g++ linking flag
dependency Project which current project depends on
dependency Project which current project depends on
excludesource Exclude source file from compiling
excludeheader Exclude header file from project h-file
outputdir Directory of the compiled output
outputname Name of the output executable/library
outputtype Type of the output, valid values are executable, sharedlibrary
@@ -134,6 +140,8 @@ ConfigSetting ConfigCLI::CLIStringToSetting(const std::string& s)
{"define", ConfigSetting::Define},
{"cflag", ConfigSetting::CFlag},
{"lflag", ConfigSetting::LFlag},
{"excludesource", ConfigSetting::ExcludeSource},
{"excludeheader", ConfigSetting::ExcludeHeader},
{"dependency", ConfigSetting::Dependency},
{"genhfile", ConfigSetting::GenerateHFile},
};
+1 -1
View File
@@ -316,7 +316,7 @@ XMLObject& ConfigFile::GetConfiguration()
const std::string& ConfigFile::GetConfigPath() const
{
return configPath;;
return configPath;
}
ConfigFile& ConfigFile::GetDependencyConfig(size_t i)
+13 -1
View File
@@ -18,7 +18,7 @@ struct ConfigCache
enum class ConfigSetting
{
// vectors
Library = 0, LibraryDir = 1, IncludeDir = 2, Define = 3, Dependency = 4, CFlag = 5, LFlag = 6,
Library = 0, LibraryDir = 1, IncludeDir = 2, Define = 3, Dependency = 4, CFlag = 5, LFlag = 6, ExcludeSource = 7, ExcludeHeader = 8,
// Strings
SourceDir = 32, OutputDir = 33, OutputName = 34, OutputType = 35, ProjectName = 36, HFileName = 37,
// Bools
@@ -59,6 +59,10 @@ struct ConfigUtils
return "cflag";
case ConfigSetting::LFlag:
return "lflag";
case ConfigSetting::ExcludeSource:
return "excludesource";
case ConfigSetting::ExcludeHeader:
return "excludeheader";
case ConfigSetting::GenerateHFile:
return "generatehfile";
case ConfigSetting::Invalid:
@@ -84,6 +88,8 @@ struct ConfigUtils
case ConfigSetting::Define:
case ConfigSetting::CFlag:
case ConfigSetting::LFlag:
case ConfigSetting::ExcludeSource:
case ConfigSetting::ExcludeHeader:
case ConfigSetting::GenerateHFile:
return false;
default:
@@ -110,6 +116,8 @@ struct ConfigUtils
case ConfigSetting::Define:
case ConfigSetting::CFlag:
case ConfigSetting::LFlag:
case ConfigSetting::ExcludeHeader:
case ConfigSetting::ExcludeSource:
case ConfigSetting::GenerateHFile:
case ConfigSetting::Invalid:
return false;
@@ -127,6 +135,8 @@ struct ConfigUtils
case ConfigSetting::Define:
case ConfigSetting::CFlag:
case ConfigSetting::LFlag:
case ConfigSetting::ExcludeHeader:
case ConfigSetting::ExcludeSource:
return true;
case ConfigSetting::SourceDir:
case ConfigSetting::OutputDir:
@@ -158,6 +168,8 @@ struct ConfigUtils
case ConfigSetting::Define:
case ConfigSetting::CFlag:
case ConfigSetting::LFlag:
case ConfigSetting::ExcludeHeader:
case ConfigSetting::ExcludeSource:
case ConfigSetting::Invalid:
return false;
}
+8 -2
View File
@@ -10,7 +10,7 @@ void HFileGen::Create(ConfigFile& conf)
std::string path = conf.GetConfigPath() + conf.GetSettingString(ConfigSetting::SourceDir);
FileUtils::GetAllFiles(path,files);
// include paramenter with the path of the file
// For example src/graphics/Window.h -> graphics/Window.h if src is a src folder
// For example src/graphics/Window.h -> graphics/Window.h if src is a src folder
for(auto it = files.begin(); it!=files.end();++it)
{
size_t extensionPos = it->find_last_of(".");
@@ -25,8 +25,14 @@ void HFileGen::Create(ConfigFile& conf)
}
}
const std::vector<std::string>& excludeHeaders = conf.GetSettingVectorString(ConfigSetting::ExcludeHeader);
std::ofstream os(path + "/" + conf.GetSettingString(ConfigSetting::HFileName));
os << "#pragma once" << std::endl << std::endl;
for(auto&& hFile : hFiles)
os << "#include <" << hFile << ">" << std::endl;
{
std::string headerFile = conf.GetSettingString(ConfigSetting::SourceDir) + hFile;
auto it = std::find(excludeHeaders.begin(), excludeHeaders.end(), headerFile);
if(it == excludeHeaders.end())
os << "#include <" << hFile << ">" << std::endl;
}
}
+17 -3
View File
@@ -22,6 +22,7 @@ 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);
const std::vector<std::string>& excludeSources = conf.GetSettingVectorString(ConfigSetting::ExcludeSource);
for(auto it = files.begin(); it!=files.end();++it)
{
@@ -32,7 +33,12 @@ void Utils::GetCppFiles(ConfigFile& conf, std::set<std::string>& cppFiles)
std::string filename = it->substr(path.length());
if(extension == "cpp" || extension == "c")
{
cppFiles.emplace(filename);
std::string sourceFile =conf.GetSettingString(ConfigSetting::SourceDir) + filename;
auto it = std::find(excludeSources.begin(), excludeSources.end(), sourceFile);
if(it == excludeSources.end())
{
cppFiles.emplace(filename);
}
}
}
}
@@ -43,8 +49,9 @@ void Utils::GetCppAndHFiles(ConfigFile& conf, std::set<HFile>& hFiles, std::set<
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 example src/graphics/Window.h -> graphics/Window.h if src is a src folder
for(auto it = files.begin(); it!=files.end();++it)
{
size_t extensionPos = it->find_last_of(".");
@@ -54,7 +61,14 @@ void Utils::GetCppAndHFiles(ConfigFile& conf, std::set<HFile>& hFiles, std::set<
std::string filename = it->substr(path.length());
if(extension == "cpp" || extension == "c")
{
cppFiles.emplace(filename);
std::string sourceFile =conf.GetSettingString(ConfigSetting::SourceDir) + filename;
auto it = std::find(excludeSources.begin(), excludeSources.end(), sourceFile);
if(it == excludeSources.end())
{
cppFiles.emplace(filename);
}
else
LOG_INFO("Excluding: ", sourceFile);
}
else if(extension == "hpp" || extension == "h")
{