summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2023-01-13 19:56:35 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2023-01-13 22:32:09 +0100
commit916060cb53fddb94f64b20d3616e7360c5e91f64 (patch)
tree4a2bcef4672b5e04b106f88cca3bec631b214c00
parentc093758b4688fb5bae2cc7727b6c9b52b824043e (diff)
Capture flags in a class instead of a string and add conversion functions between them.
-rw-r--r--src/configure.cc44
-rw-r--r--src/ctor.h86
-rw-r--r--src/externals_manual.cc8
-rw-r--r--src/rebuild.cc20
-rw-r--r--src/task_ar.cc13
-rw-r--r--src/task_cc.cc116
-rw-r--r--src/task_ld.cc24
-rw-r--r--src/task_so.cc25
-rw-r--r--src/tools.cc560
-rw-r--r--src/tools.h83
-rw-r--r--src/util.h5
-rw-r--r--test/tools_test.cc778
12 files changed, 1550 insertions, 212 deletions
diff --git a/src/configure.cc b/src/configure.cc
index deeb6a6..34812fa 100644
--- a/src/configure.cc
+++ b/src/configure.cc
@@ -191,6 +191,42 @@ std::ostream& operator<<(std::ostream& stream, const ctor::toolchain& toolchain)
}
return stream;
}
+
+std::ostream& operator<<(std::ostream& ostr, const ctor::c_flag& flag)
+{
+ for(const auto& s : to_strings(ctor::toolchain::any, flag))
+ {
+ ostr << s;
+ }
+ return ostr;
+}
+
+std::ostream& operator<<(std::ostream& ostr, const ctor::cxx_flag& flag)
+{
+ for(const auto& s : to_strings(ctor::toolchain::any, flag))
+ {
+ ostr << s;
+ }
+ return ostr;
+}
+
+std::ostream& operator<<(std::ostream& ostr, const ctor::ld_flag& flag)
+{
+ for(const auto& s : to_strings(ctor::toolchain::any, flag))
+ {
+ ostr << s;
+ }
+ return ostr;
+}
+
+std::ostream& operator<<(std::ostream& ostr, const ctor::asm_flag& flag)
+{
+ for(const auto& s : to_strings(ctor::toolchain::any, flag))
+ {
+ ostr << s;
+ }
+ return ostr;
+}
}
// helper constant for the visitor
@@ -521,7 +557,7 @@ int regenerateCache(ctor::settings& settings,
istr << " .cxxflags = {";
for(const auto& flag : resolved_flags.cxxflags)
{
- istr << "\"" << flag << "\",";
+ istr << flag << ",";
}
istr << "},\n";
}
@@ -531,7 +567,7 @@ int regenerateCache(ctor::settings& settings,
istr << " .cflags = {";
for(const auto& flag : resolved_flags.cflags)
{
- istr << "\"" << flag << "\",";
+ istr << flag << ",";
}
istr << "},\n";
}
@@ -541,7 +577,7 @@ int regenerateCache(ctor::settings& settings,
istr << " .ldflags = {";
for(const auto& flag : resolved_flags.ldflags)
{
- istr << "\"" << flag << "\",";
+ istr << flag << ",";
}
istr << "},\n";
}
@@ -551,7 +587,7 @@ int regenerateCache(ctor::settings& settings,
istr << " .asmflags = {";
for(const auto& flag : resolved_flags.asmflags)
{
- istr << "\"" << flag << "\",";
+ istr << flag << ",";
}
istr << "},\n";
}
diff --git a/src/ctor.h b/src/ctor.h
index 388ec1b..36aa46a 100644
--- a/src/ctor.h
+++ b/src/ctor.h
@@ -66,34 +66,106 @@ enum class toolchain
clang,
};
-enum class opt
+enum class cxx_opt
{
// gcc/clang
output, // -o
debug, // -g
- strip, // -s
warn_all, // -Wall
warnings_as_errors, // -Werror
generate_dep_tree, // -MMD
no_link, // -c
include_path, // -I<arg>
+ cpp_std, // -std=<arg>
+ optimization, // -O<arg>
+ position_independent_code, // -fPIC
+ position_independent_executable, // -fPIE
+ custom, // entire option taken verbatim from <arg>
+};
+
+enum class c_opt
+{
+ // gcc/clang
+ output, // -o
+ debug, // -g
+ warn_all, // -Wall
+ warnings_as_errors, // -Werror
+ generate_dep_tree, // -MMD
+ no_link, // -c
+ include_path, // -I<arg>
+ c_std, // -std=<arg>
+ optimization, // -O<arg>
+ position_independent_code, // -fPIC
+ position_independent_executable, // -fPIE
+ custom, // entire option taken verbatim from <arg>
+};
+
+enum class ld_opt
+{
+ // gcc/clang
+ output, // -o
+ strip, // -s
+ warn_all, // -Wall
+ warnings_as_errors, // -Werror
library_path, // -L<arg>
link, // -l<arg>
cpp_std, // -std=<arg>
build_shared, // -shared
threads, // -pthread
- optimization, // -O<arg>
position_independent_code, // -fPIC
position_independent_executable, // -fPIE
custom, // entire option taken verbatim from <arg>
};
+enum class ar_opt
+{
+ // gcc/clang
+ custom, // entire option taken verbatim from <arg>
+};
+
+enum class asm_opt
+{
+ // gcc/clang
+ custom, // entire option taken verbatim from <arg>
+};
+
+template<typename T>
+class flag
+{
+public:
+ flag(const std::string& str);
+ flag(const char* str);
+ flag(T opt) : opt(opt) {}
+ flag(T opt, const std::string& arg) : opt(opt), arg(arg) {}
+ flag(T opt, const char* arg) : opt(opt), arg(arg) {}
+ flag(ctor::toolchain toolchain, T opt) : toolchain(toolchain), opt(opt) {}
+ flag(ctor::toolchain toolchain, T opt, const char* arg) : toolchain(toolchain), opt(opt), arg(arg) {}
+ flag(ctor::toolchain toolchain, T opt, const std::string& arg) : toolchain(toolchain), opt(opt), arg(arg) {}
+
+ ctor::toolchain toolchain{ctor::toolchain::any};
+ T opt;
+ std::string arg;
+};
+
+using c_flag = ctor::flag<ctor::c_opt>;
+using cxx_flag = ctor::flag<ctor::cxx_opt>;
+using ld_flag = ctor::flag<ctor::ld_opt>;
+using ar_flag = ctor::flag<ctor::ar_opt>;
+using asm_flag = ctor::flag<ctor::asm_opt>;
+
+using c_flags = std::vector<ctor::c_flag>;
+using cxx_flags = std::vector<ctor::cxx_flag>;
+using ld_flags= std::vector<ctor::ld_flag>;
+using ar_flags = std::vector<ctor::ar_flag>;
+using asm_flags = std::vector<ctor::asm_flag>;
+
struct flags
{
- std::vector<std::string> cxxflags; // flags for c++ compiler
- std::vector<std::string> cflags; // flags for c compiler
- std::vector<std::string> ldflags; // flags for linker
- std::vector<std::string> asmflags; // flags for asm translator
+ ctor::c_flags cflags; // flags for c compiler
+ ctor::cxx_flags cxxflags; // flags for c++ compiler
+ ctor::ld_flags ldflags; // flags for linker
+ ctor::ar_flags arflags; // flags for archiver
+ ctor::asm_flags asmflags; // flags for asm translator
};
struct settings
diff --git a/src/externals_manual.cc b/src/externals_manual.cc
index bc8e9d0..3b96263 100644
--- a/src/externals_manual.cc
+++ b/src/externals_manual.cc
@@ -16,21 +16,19 @@ extern std::map<std::string, std::string> external_libdir;
int resolv(const ctor::settings& settings, const ctor::external_configuration& config,
const ctor::external_manual& ext, ctor::flags& flags)
{
- auto toolchain = getToolChain(config.system);
-
flags = ext.flags;
auto inc = external_includedir.find(config.name);
if(inc != external_includedir.end())
{
- append(flags.cflags, getOption(toolchain, ctor::opt::include_path, inc->second));
- append(flags.cxxflags, getOption(toolchain, ctor::opt::include_path, inc->second));
+ flags.cflags.push_back({ctor::c_opt::include_path, inc->second});
+ flags.cxxflags.push_back({ctor::cxx_opt::include_path, inc->second});
}
auto lib = external_libdir.find(config.name);
if(lib != external_libdir.end())
{
- append(flags.ldflags, getOption(toolchain, ctor::opt::library_path, lib->second));
+ flags.ldflags.push_back({ctor::ld_opt::library_path, lib->second});
}
return 0;
diff --git a/src/rebuild.cc b/src/rebuild.cc
index dec7119..c97452d 100644
--- a/src/rebuild.cc
+++ b/src/rebuild.cc
@@ -162,27 +162,21 @@ bool recompileCheck(const ctor::settings& global_settings, int argc, char* argv[
config.name = "ctor";
config.system = ctor::output_system::build;
- auto toolchain = getToolChain(config.system);
+ config.flags.cxxflags.push_back({ctor::cxx_opt::optimization, "3"});
+ config.flags.cxxflags.push_back({ctor::cxx_opt::cpp_std, "c++20"});
- append(config.flags.cxxflags,
- getOption(toolchain, ctor::opt::optimization, "3"));
- append(config.flags.cxxflags,
- getOption(toolchain, ctor::opt::cpp_std, "c++20"));
const auto& c = ctor::get_configuration();
if(c.has(ctor::cfg::ctor_includedir))
{
- append(config.flags.cxxflags,
- getOption(toolchain, ctor::opt::include_path,
- c.get(ctor::cfg::ctor_includedir)));
+ config.flags.cxxflags.push_back({ctor::cxx_opt::include_path,
+ c.get(ctor::cfg::ctor_includedir)});
}
if(c.has(ctor::cfg::ctor_libdir))
{
- append(config.flags.ldflags,
- getOption(toolchain, ctor::opt::library_path,
- c.get(ctor::cfg::ctor_libdir)));
+ config.flags.ldflags.push_back({ctor::ld_opt::library_path, c.get(ctor::cfg::ctor_libdir)});
}
- append(config.flags.ldflags, getOption(toolchain, ctor::opt::link, "ctor"));
- append(config.flags.ldflags, getOption(toolchain, ctor::opt::threads));
+ config.flags.ldflags.push_back({ctor::ld_opt::link, "ctor"});
+ config.flags.ldflags.push_back({ctor::ld_opt::threads});
ctor::settings settings{global_settings};
settings.verbose = -1; // Make check completely silent.
diff --git a/src/task_ar.cc b/src/task_ar.cc
index edd60ae..81ced0f 100644
--- a/src/task_ar.cc
+++ b/src/task_ar.cc
@@ -9,6 +9,7 @@
#include "ctor.h"
#include "execute.h"
#include "util.h"
+#include "tools.h"
TaskAR::TaskAR(const ctor::build_configuration& config,
const ctor::settings& settings,
@@ -160,14 +161,20 @@ bool TaskAR::derived() const
std::string TaskAR::flagsString() const
{
+ auto toolchain = getToolChain(config.system);
std::string flagsStr;
+ bool first{true};
for(const auto& flag : config.flags.ldflags)
{
- if(flag != config.flags.ldflags[0])
+ for(const auto& str : to_strings(toolchain, flag))
{
- flagsStr += " ";
+ if(first)
+ {
+ flagsStr += " ";
+ first = false;
+ }
+ flagsStr += str;
}
- flagsStr += flag;
}
flagsStr += "\n";
diff --git a/src/task_cc.cc b/src/task_cc.cc
index c15bd6a..56915f5 100644
--- a/src/task_cc.cc
+++ b/src/task_cc.cc
@@ -256,12 +256,23 @@ std::string TaskCC::source() const
std::vector<std::string> TaskCC::flags() const
{
+ std::vector<std::string> flags;
+ auto toolchain = getToolChain(config.system);
+
switch(sourceLanguage())
{
case ctor::language::c:
- return config.flags.cflags;
+ for(const auto& flag : config.flags.cflags)
+ {
+ append(flags, to_strings(toolchain, flag));
+ }
+ return flags;
case ctor::language::cpp:
- return config.flags.cxxflags;
+ for(const auto& flag : config.flags.cxxflags)
+ {
+ append(flags, to_strings(toolchain, flag));
+ }
+ return flags;
default:
std::cerr << "Unknown CC target type\n";
exit(1);
@@ -285,39 +296,96 @@ std::vector<std::string> TaskCC::getCompilerArgs() const
auto compiler_flags = flags();
std::vector<std::string> args;
- append(args, getOption(toolchain, ctor::opt::generate_dep_tree));
- if(std::filesystem::path(config.target).extension() == ".so")
+ switch(sourceLanguage())
{
- // Add -fPIC arg to all contained object files
- append(args, getOption(toolchain, ctor::opt::position_independent_code));
- }
+ case ctor::language::c:
+ {
+ append(args, c_option(toolchain, ctor::c_opt::generate_dep_tree));
- append(args, getOption(toolchain, ctor::opt::no_link));
- args.push_back(sourceFile.string());
- append(args, getOption(toolchain, ctor::opt::output, targetFile().string()));
+ if(std::filesystem::path(config.target).extension() == ".so")
+ {
+ // Add -fPIC arg to all contained object files
+ append(args, c_option(toolchain,
+ ctor::c_opt::position_independent_code));
+ }
- for(const auto& flag : compiler_flags)
- {
- auto option = getOption(flag);
- switch(option.first)
+ append(args, c_option(toolchain, ctor::c_opt::no_link));
+ args.push_back(sourceFile.string());
+ append(args, c_option(toolchain,
+ ctor::c_opt::output, targetFile().string()));
+
+ // Relative include paths has to be altered to be relative to sourceDir
+ for(const auto& flag : compiler_flags)
+ {
+ auto option = c_option(flag, toolchain);
+ switch(option.opt)
+ {
+ case ctor::c_opt::include_path:
+ {
+ std::filesystem::path path(option.arg);
+ if(path.is_relative())
+ {
+ path = (sourceDir / path).lexically_normal();
+ append(args, c_option(toolchain,
+ ctor::c_opt::include_path, path.string()));
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
+ args.push_back(flag);
+ }
+ }
+ break;
+
+ case ctor::language::cpp:
{
- // Relative include paths has to be altered to be relative to sourceDir
- case ctor::opt::include_path:
+ append(args, cxx_option(toolchain, ctor::cxx_opt::generate_dep_tree));
+
+ if(std::filesystem::path(config.target).extension() == ".so")
{
- std::filesystem::path path(option.second);
- if(path.is_relative())
+ // Add -fPIC arg to all contained object files
+ append(args, cxx_option(toolchain,
+ ctor::cxx_opt::position_independent_code));
+ }
+
+ append(args, cxx_option(toolchain, ctor::cxx_opt::no_link));
+ args.push_back(sourceFile.string());
+ append(args, cxx_option(toolchain,
+ ctor::cxx_opt::output, targetFile().string()));
+
+ // Relative include paths has to be altered to be relative to sourceDir
+ for(const auto& flag : compiler_flags)
+ {
+ auto option = cxx_option(flag, toolchain);
+ switch(option.opt)
{
- path = (sourceDir / path).lexically_normal();
- append(args, getOption(toolchain, ctor::opt::include_path, path.string()));
+ case ctor::cxx_opt::include_path:
+ {
+ std::filesystem::path path(option.arg);
+ if(path.is_relative())
+ {
+ path = (sourceDir / path).lexically_normal();
+ append(args, cxx_option(toolchain,
+ ctor::cxx_opt::include_path, path.string()));
+ }
+ }
+ break;
+ default:
+ break;
}
+
+ args.push_back(flag);
}
- continue;
- default:
- break;
+
}
+ break;
- args.push_back(flag);
+ default:
+ break;
}
return args;
diff --git a/src/task_ld.cc b/src/task_ld.cc
index 4915de9..3d917e4 100644
--- a/src/task_ld.cc
+++ b/src/task_ld.cc
@@ -90,10 +90,10 @@ int TaskLD::runInner()
auto depFile = dep->targetFile();
if(depFile.extension() == ".so")
{
- append(args, getOption(toolchain, ctor::opt::library_path,
+ append(args, ld_option(toolchain, ctor::ld_opt::library_path,
targetFile().parent_path().string()));
auto lib = depFile.stem().string().substr(3); // strip 'lib' prefix
- append(args, getOption(toolchain, ctor::opt::link, lib));
+ append(args, ld_option(toolchain, ctor::ld_opt::link, lib));
}
else if(depFile.extension() == ".a" || depFile.extension() == ".o")
{
@@ -101,8 +101,12 @@ int TaskLD::runInner()
}
}
- append(args, config.flags.ldflags);
- append(args, getOption(toolchain, ctor::opt::output, targetFile().string()));
+ for(const auto& flag : config.flags.ldflags)
+ {
+ append(args, to_strings(toolchain, flag));
+ }
+
+ append(args, ld_option(toolchain, ctor::ld_opt::output, targetFile().string()));
{ // Write flags to file.
std::ofstream flagsStream(flagsFile);
@@ -168,14 +172,20 @@ bool TaskLD::derived() const
std::string TaskLD::flagsString() const
{
+ auto toolchain = getToolChain(config.system);
std::string flagsStr;
+ bool first{true};
for(const auto& flag : config.flags.ldflags)
{
- if(flag != config.flags.ldflags[0])
+ for(const auto& str : to_strings(toolchain, flag))
{
- flagsStr += " ";
+ if(first)
+ {
+ flagsStr += " ";
+ first = false;
+ }
+ flagsStr += str;
}
- flagsStr += flag;
}
flagsStr += "\n";
diff --git a/src/task_so.cc b/src/task_so.cc
index 93a5ddb..9061591 100644
--- a/src/task_so.cc
+++ b/src/task_so.cc
@@ -83,17 +83,20 @@ int TaskSO::runInner()
std::vector<std::string> args;
- append(args, getOption(toolchain, ctor::opt::position_independent_code));
- append(args, getOption(toolchain, ctor::opt::build_shared));
+ append(args, ld_option(toolchain, ctor::ld_opt::position_independent_code));
+ append(args, ld_option(toolchain, ctor::ld_opt::build_shared));
- append(args, getOption(toolchain, ctor::opt::output, targetFile().string()));
+ append(args, ld_option(toolchain, ctor::ld_opt::output, targetFile().string()));
for(const auto& task : getDependsTasks())
{
args.push_back(task->targetFile().string());
}
- append(args, config.flags.ldflags);
+ for(const auto& flag : config.flags.ldflags)
+ {
+ append(args, to_strings(toolchain, flag));
+ }
{ // Write flags to file.
std::ofstream flagsStream(flagsFile);
@@ -159,10 +162,20 @@ bool TaskSO::derived() const
std::string TaskSO::flagsString() const
{
- std::string flagsStr = compiler();
+ auto toolchain = getToolChain(config.system);
+ std::string flagsStr;
+ bool first{true};
for(const auto& flag : config.flags.ldflags)
{
- flagsStr += " " + flag;
+ for(const auto& str : to_strings(toolchain, flag))
+ {
+ if(first)
+ {
+ flagsStr += " ";
+ first = false;
+ }
+ flagsStr += str;
+ }
}
flagsStr += "\n";
diff --git a/src/tools.cc b/src/tools.cc
index 610a550..476386b 100644
--- a/src/tools.cc
+++ b/src/tools.cc
@@ -5,9 +5,98 @@
#include <filesystem>
#include <iostream>
+#include <sstream>
#include <cassert>
+std::ostream& operator<<(std::ostream& stream, const ctor::c_opt& opt)
+{
+ // Adding to this enum should also imply adding to the unit-tests below
+ switch(opt)
+ {
+ case ctor::c_opt::output: stream << "ctor::c_opt::output"; break;
+ case ctor::c_opt::debug: stream << "ctor::c_opt::debug"; break;
+ case ctor::c_opt::warn_all: stream << "ctor::c_opt::warn_all"; break;
+ case ctor::c_opt::warnings_as_errors: stream << "ctor::c_opt::warnings_as_errors"; break;
+ case ctor::c_opt::generate_dep_tree: stream << "ctor::c_opt::generate_dep_tree"; break;
+ case ctor::c_opt::no_link: stream << "ctor::c_opt::no_link"; break;
+ case ctor::c_opt::include_path: stream << "ctor::c_opt::include_path"; break;
+ case ctor::c_opt::c_std: stream << "ctor::c_opt::c_std"; break;
+ case ctor::c_opt::optimization: stream << "ctor::c_opt::optimization"; break;
+ case ctor::c_opt::position_independent_code: stream << "ctor::c_opt::position_independent_code"; break;
+ case ctor::c_opt::position_independent_executable: stream << "ctor::c_opt::position_independent_executable"; break;
+ case ctor::c_opt::custom: stream << "ctor::c_opt::custom"; break;
+ }
+
+ return stream;
+}
+
+std::ostream& operator<<(std::ostream& stream, const ctor::cxx_opt& opt)
+{
+ // Adding to this enum should also imply adding to the unit-tests below
+ switch(opt)
+ {
+ case ctor::cxx_opt::output: stream << "ctor::cxx_opt::output"; break;
+ case ctor::cxx_opt::debug: stream << "ctor::cxx_opt::debug"; break;
+ case ctor::cxx_opt::warn_all: stream << "ctor::cxx_opt::warn_all"; break;
+ case ctor::cxx_opt::warnings_as_errors: stream << "ctor::cxx_opt::warnings_as_errors"; break;
+ case ctor::cxx_opt::generate_dep_tree: stream << "ctor::cxx_opt::generate_dep_tree"; break;
+ case ctor::cxx_opt::no_link: stream << "ctor::cxx_opt::no_link"; break;
+ case ctor::cxx_opt::include_path: stream << "ctor::cxx_opt::include_path"; break;
+ case ctor::cxx_opt::cpp_std: stream << "ctor::cxx_opt::cpp_std"; break;
+ case ctor::cxx_opt::optimization: stream << "ctor::cxx_opt::optimization"; break;
+ case ctor::cxx_opt::position_independent_code: stream << "ctor::cxx_opt::position_independent_code"; break;
+ case ctor::cxx_opt::position_independent_executable: stream << "ctor::cxx_opt::position_independent_executable"; break;
+ case ctor::cxx_opt::custom: stream << "ctor::cxx_opt::custom"; break;
+ }
+
+ return stream;
+}
+
+std::ostream& operator<<(std::ostream& stream, const ctor::ld_opt& opt)
+{
+ // Adding to this enum should also imply adding to the unit-tests below
+ switch(opt)
+ {
+ case ctor::ld_opt::output: stream << "ctor::ld_opt::output"; break;
+ case ctor::ld_opt::strip: stream << "ctor::ld_opt::strip"; break;
+ case ctor::ld_opt::warn_all: stream << "ctor::ld_opt::warn_all"; break;
+ case ctor::ld_opt::warnings_as_errors: stream << "ctor::ld_opt::warnings_as_errors"; break;
+ case ctor::ld_opt::library_path: stream << "ctor::ld_opt::library_path"; break;
+ case ctor::ld_opt::link: stream << "ctor::ld_opt::link"; break;
+ case ctor::ld_opt::cpp_std: stream << "ctor::ld_opt::cpp_std"; break;
+ case ctor::ld_opt::build_shared: stream << "ctor::ld_opt::build_shared"; break;
+ case ctor::ld_opt::threads: stream << "ctor::ld_opt::threads"; break;
+ case ctor::ld_opt::position_independent_code: stream << "ctor::ld_opt::position_independent_code"; break;
+ case ctor::ld_opt::position_independent_executable: stream << "ctor::ld_opt::position_independent_executable"; break;
+ case ctor::ld_opt::custom: stream << "ctor::ld_opt::custom"; break;
+ }
+
+ return stream;
+}
+
+std::ostream& operator<<(std::ostream& stream, const ctor::ar_opt& opt)
+{
+ // Adding to this enum should also imply adding to the unit-tests below
+ switch(opt)
+ {
+ case ctor::ar_opt::custom: stream << "ctor::ar_opt::custom"; break;
+ }
+
+ return stream;
+}
+
+std::ostream& operator<<(std::ostream& stream, const ctor::asm_opt& opt)
+{
+ // Adding to this enum should also imply adding to the unit-tests below
+ switch(opt)
+ {
+ case ctor::asm_opt::custom: stream << "ctor::asm_opt::custom"; break;
+ }
+
+ return stream;
+}
+
ctor::toolchain getToolChain(const std::string& compiler)
{
std::filesystem::path cc(compiler);
@@ -48,63 +137,191 @@ ctor::toolchain getToolChain(ctor::output_system system)
}
}
-namespace
+namespace gcc {
+ctor::c_flag c_option(const std::string& flag)
{
-std::vector<std::string> getOptionGcc(ctor::opt option, const std::string& arg)
+ if(flag.substr(0, 2) == "-I")
+ {
+ std::string path = flag.substr(2);
+ path.erase(0, path.find_first_not_of(' '));
+ return { ctor::c_opt::include_path, path };
+ }
+
+ return { ctor::c_opt::custom, flag };
+}
+
+ctor::cxx_flag cxx_option(const std::string& flag)
+{
+ if(flag.substr(0, 2) == "-I")
+ {
+ std::string path = flag.substr(2);
+ path.erase(0, path.find_first_not_of(' '));
+ return { ctor::cxx_opt::include_path, path };
+ }
+
+ return { ctor::cxx_opt::custom, flag };
+}
+
+ctor::ld_flag ld_option(const std::string& flag)
+{
+ if(flag.substr(0, 2) == "-L")
+ {
+ std::string path = flag.substr(2);
+ path.erase(0, path.find_first_not_of(' '));
+ return { ctor::ld_opt::library_path, path };
+ }
+
+ return { ctor::ld_opt::custom, flag };
+}
+
+std::vector<std::string> cxx_option(ctor::cxx_opt opt, const std::string& arg)
{
- switch(option)
+ switch(opt)
{
- case ctor::opt::output:
+ case ctor::cxx_opt::output:
return {"-o", arg};
- case ctor::opt::debug:
+ case ctor::cxx_opt::debug:
return {"-g"};
- case ctor::opt::strip:
- return {"-s"};
- case ctor::opt::warn_all:
+ case ctor::cxx_opt::warn_all:
return {"-Wall"};
- case ctor::opt::warnings_as_errors:
+ case ctor::cxx_opt::warnings_as_errors:
return {"-Werror"};
- case ctor::opt::generate_dep_tree:
+ case ctor::cxx_opt::generate_dep_tree:
return {"-MMD"};
- case ctor::opt::no_link:
+ case ctor::cxx_opt::no_link:
return {"-c"};
- case ctor::opt::include_path:
+ case ctor::cxx_opt::include_path:
return {"-I" + arg};
- case ctor::opt::library_path:
+ case ctor::cxx_opt::cpp_std:
+ return {"-std=" + arg};
+ case ctor::cxx_opt::optimization:
+ return {"-O" + arg};
+ case ctor::cxx_opt::position_independent_code:
+ return {"-fPIC"};
+ case ctor::cxx_opt::position_independent_executable:
+ return {"-fPIE"};
+ case ctor::cxx_opt::custom:
+ return {arg};
+ }
+
+ std::cerr << "Unsupported compiler option.\n";
+ return {};
+}
+
+std::vector<std::string> c_option(ctor::c_opt opt, const std::string& arg)
+{
+ switch(opt)
+ {
+ case ctor::c_opt::output:
+ return {"-o", arg};
+ case ctor::c_opt::debug:
+ return {"-g"};
+ case ctor::c_opt::warn_all:
+ return {"-Wall"};
+ case ctor::c_opt::warnings_as_errors:
+ return {"-Werror"};
+ case ctor::c_opt::generate_dep_tree:
+ return {"-MMD"};
+ case ctor::c_opt::no_link:
+ return {"-c"};
+ case ctor::c_opt::include_path:
+ return {"-I" + arg};
+ case ctor::c_opt::c_std:
+ return {"-std=" + arg};
+ case ctor::c_opt::optimization:
+ return {"-O" + arg};
+ case ctor::c_opt::position_independent_code:
+ return {"-fPIC"};
+ case ctor::c_opt::position_independent_executable:
+ return {"-fPIE"};
+ case ctor::c_opt::custom:
+ return {arg};
+ }
+
+ std::cerr << "Unsupported compiler option.\n";
+ return {};
+}
+
+std::vector<std::string> ld_option(ctor::ld_opt opt, const std::string& arg)
+{
+ switch(opt)
+ {
+ case ctor::ld_opt::output:
+ return {"-o", arg};
+ case ctor::ld_opt::strip:
+ return {"-s"};
+ case ctor::ld_opt::warn_all:
+ return {"-Wall"};
+ case ctor::ld_opt::warnings_as_errors:
+ return {"-Werror"};
+ case ctor::ld_opt::library_path:
return {"-L" + arg};
- case ctor::opt::link:
+ case ctor::ld_opt::link:
return {"-l" + arg};
- case ctor::opt::cpp_std:
+ case ctor::ld_opt::cpp_std:
return {"-std=" + arg};
- case ctor::opt::build_shared:
+ case ctor::ld_opt::build_shared:
return {"-shared"};
- case ctor::opt::threads:
+ case ctor::ld_opt::threads:
return {"-pthread"};
- case ctor::opt::optimization:
- return {"-O" + arg};
- case ctor::opt::position_independent_code:
+ case ctor::ld_opt::position_independent_code:
return {"-fPIC"};
- case ctor::opt::position_independent_executable:
+ case ctor::ld_opt::position_independent_executable:
return {"-fPIE"};
- case ctor::opt::custom:
+ case ctor::ld_opt::custom:
return {arg};
}
std::cerr << "Unsupported compiler option.\n";
return {};
}
+
+std::vector<std::string> ar_option(ctor::ar_opt opt, const std::string& arg)
+{
+ switch(opt)
+ {
+ case ctor::ar_opt::custom:
+ return {arg};
+ }
+
+ std::cerr << "Unsupported compiler option.\n";
+ return {};
}
-std::vector<std::string> getOption(ctor::toolchain toolchain,
- ctor::opt option,
- const std::string& arg)
+std::vector<std::string> asm_option(ctor::asm_opt opt, const std::string& arg)
+{
+ switch(opt)
+ {
+ case ctor::asm_opt::custom:
+ return {arg};
+ }
+
+ std::cerr << "Unsupported compiler option.\n";
+ return {};
+}
+} // gcc::
+
+
+std::vector<std::string> c_option(ctor::toolchain toolchain,
+ ctor::c_opt opt,
+ const std::string& arg)
{
switch(toolchain)
{
case ctor::toolchain::gcc:
case ctor::toolchain::clang:
- return getOptionGcc(option, arg);
+ return gcc::c_option(opt, arg);
case ctor::toolchain::any:
+ {
+ std::ostringstream ss;
+ ss << "{" << opt;
+ if(!arg.empty())
+ {
+ ss << ", \"" << arg << "\"";
+ }
+ ss << "}";
+ return { ss.str() };
+ }
case ctor::toolchain::none:
break;
}
@@ -113,40 +330,301 @@ std::vector<std::string> getOption(ctor::toolchain toolchain,
return {};
}
-namespace {
-std::pair<ctor::opt, std::string> getOptionGcc(const std::string& flag)
+std::vector<std::string> cxx_option(ctor::toolchain toolchain,
+ ctor::cxx_opt opt,
+ const std::string& arg)
{
- if(flag.substr(0, 2) == "-I")
+ switch(toolchain)
{
- std::string path = flag.substr(2);
- path.erase(0, path.find_first_not_of(' '));
- return { ctor::opt::include_path, path };
+ case ctor::toolchain::gcc:
+ case ctor::toolchain::clang:
+ return gcc::cxx_option(opt, arg);
+ case ctor::toolchain::any:
+ {
+ std::ostringstream ss;
+ ss << "{" << opt;
+ if(!arg.empty())
+ {
+ ss << ", \"" << arg << "\"";
+ }
+ ss << "}";
+ return { ss.str() };
+ }
+ case ctor::toolchain::none:
+ break;
}
- if(flag.substr(0, 2) == "-L")
+ std::cerr << "Unsupported tool-chain.\n";
+ return {};
+}
+
+std::vector<std::string> ld_option(ctor::toolchain toolchain,
+ ctor::ld_opt opt,
+ const std::string& arg)
+{
+ switch(toolchain)
{
- std::string path = flag.substr(2);
- path.erase(0, path.find_first_not_of(' '));
- return { ctor::opt::library_path, path };
+ case ctor::toolchain::gcc:
+ case ctor::toolchain::clang:
+ return gcc::ld_option(opt, arg);
+ case ctor::toolchain::any:
+ {
+ std::ostringstream ss;
+ ss << "{" << opt;
+ if(!arg.empty())
+ {
+ ss << ", \"" << arg << "\"";
+ }
+ ss << "}";
+ return { ss.str() };
+ }
+ case ctor::toolchain::none:
+ break;
}
- return { ctor::opt::custom, flag };
+ std::cerr << "Unsupported tool-chain.\n";
+ return {};
}
+
+std::vector<std::string> ar_option(ctor::toolchain toolchain,
+ ctor::ar_opt opt,
+ const std::string& arg)
+{
+ switch(toolchain)
+ {
+ case ctor::toolchain::gcc:
+ case ctor::toolchain::clang:
+ return gcc::ar_option(opt, arg);
+ case ctor::toolchain::any:
+ {
+ std::ostringstream ss;
+ ss << "{" << opt;
+ if(!arg.empty())
+ {
+ ss << ", \"" << arg << "\"";
+ }
+ ss << "}";
+ return { ss.str() };
+ }
+ case ctor::toolchain::none:
+ break;
+ }
+
+ std::cerr << "Unsupported tool-chain.\n";
+ return {};
}
-std::pair<ctor::opt, std::string> getOption(const std::string& flag,
- ctor::toolchain toolchain)
+std::vector<std::string> asm_option(ctor::toolchain toolchain,
+ ctor::asm_opt opt,
+ const std::string& arg)
{
switch(toolchain)
{
case ctor::toolchain::gcc:
case ctor::toolchain::clang:
- return getOptionGcc(flag);
+ return gcc::asm_option(opt, arg);
case ctor::toolchain::any:
+ {
+ std::ostringstream ss;
+ ss << "{" << opt;
+ if(!arg.empty())
+ {
+ ss << ", \"" << arg << "\"";
+ }
+ ss << "}";
+ return { ss.str() };
+ }
case ctor::toolchain::none:
break;
}
std::cerr << "Unsupported tool-chain.\n";
- return { ctor::opt::custom, flag };
+ return {};
+}
+
+
+ctor::c_flag c_option(const std::string& flag, ctor::toolchain toolchain)
+{
+ switch(toolchain)
+ {
+ case ctor::toolchain::gcc:
+ case ctor::toolchain::clang:
+ return gcc::c_option(flag);
+ case ctor::toolchain::any:
+ case ctor::toolchain::none:
+ break;
+ }
+
+ return { ctor::c_opt::custom, flag };
+}
+
+ctor::cxx_flag cxx_option(const std::string& flag, ctor::toolchain toolchain)
+{
+ switch(toolchain)
+ {
+ case ctor::toolchain::gcc:
+ case ctor::toolchain::clang:
+ return gcc::cxx_option(flag);
+ case ctor::toolchain::any:
+ case ctor::toolchain::none:
+ break;
+ }
+
+ return { ctor::cxx_opt::custom, flag };
+}
+
+ctor::ld_flag ld_option(const std::string& flag, ctor::toolchain toolchain)
+{
+ switch(toolchain)
+ {
+ case ctor::toolchain::gcc:
+ case ctor::toolchain::clang:
+ return gcc::ld_option(flag);
+ case ctor::toolchain::any:
+ case ctor::toolchain::none:
+ break;
+ }
+
+ return { ctor::ld_opt::custom, flag };
+}
+
+ctor::ar_flag ar_option(const std::string& flag, ctor::toolchain toolchain)
+{
+ switch(toolchain)
+ {
+ case ctor::toolchain::gcc:
+ case ctor::toolchain::clang:
+ case ctor::toolchain::any:
+ case ctor::toolchain::none:
+ break;
+ }
+
+ return { ctor::ar_opt::custom, flag };
+}
+
+ctor::asm_flag asm_option(const std::string& flag, ctor::toolchain toolchain)
+{
+ switch(toolchain)
+ {
+ case ctor::toolchain::gcc:
+ case ctor::toolchain::clang:
+ case ctor::toolchain::any:
+ case ctor::toolchain::none:
+ break;
+ }
+
+ return { ctor::asm_opt::custom, flag };
+}
+
+// Flag to string coversions
+
+std::vector<std::string> to_strings(ctor::toolchain toolchain,
+ const ctor::c_flag& flag)
+{
+ if(flag.toolchain == ctor::toolchain::any ||
+ flag.toolchain == toolchain)
+ {
+ return c_option(toolchain, flag.opt, flag.arg);
+ }
+
+ return {};
+}
+
+std::vector<std::string> to_strings(ctor::toolchain toolchain,
+ const ctor::cxx_flag& flag)
+{
+ if(flag.toolchain == ctor::toolchain::any ||
+ flag.toolchain == toolchain)
+ {
+ return cxx_option(toolchain, flag.opt, flag.arg);
+ }
+
+ return {};
+}
+
+std::vector<std::string> to_strings(ctor::toolchain toolchain,
+ const ctor::ld_flag& flag)
+{
+ if(flag.toolchain == ctor::toolchain::any ||
+ flag.toolchain == toolchain)
+ {
+ return ld_option(toolchain, flag.opt, flag.arg);
+ }
+
+ return {};
+}
+
+std::vector<std::string> to_strings(ctor::toolchain toolchain,
+ const ctor::ar_flag& flag)
+{
+ if(flag.toolchain == ctor::toolchain::any ||
+ flag.toolchain == toolchain)
+ {
+ return ar_option(toolchain, flag.opt, flag.arg);
+ }
+
+ return {};
+}
+
+std::vector<std::string> to_strings(ctor::toolchain toolchain,
+ const ctor::asm_flag& flag)
+{
+ if(flag.toolchain == ctor::toolchain::any ||
+ flag.toolchain == toolchain)
+ {
+ return asm_option(toolchain, flag.opt, flag.arg);
+ }
+
+ return {};
+}
+
+namespace {
+ctor::toolchain guess_toolchain(const std::string& opt)
+{
+ if(opt.empty())
+ {
+ return ctor::toolchain::any;
+ }
+
+ if(opt[0] == '-')
+ {
+ return ctor::toolchain::gcc;
+ }
+
+ //if(opt[0] == '/')
+ //{
+ // return ctor::toolchain::msvc;
+ //}
+ return ctor::toolchain::any;
+}
+}
+
+template<>
+ctor::flag<ctor::c_opt>::flag(const char* str)
+{
+ *this = c_option(str, guess_toolchain(str));
+}
+
+template<>
+ctor::flag<ctor::cxx_opt>::flag(const char* str)
+{
+ *this = cxx_option(str, guess_toolchain(str));
+}
+
+template<>
+ctor::flag<ctor::ld_opt>::flag(const char* str)
+{
+ *this = ld_option(str, guess_toolchain(str));
+}
+
+template<>
+ctor::flag<ctor::ar_opt>::flag(const char* str)
+{
+ *this = ar_option(str, guess_toolchain(str));
+}
+
+template<>
+ctor::flag<ctor::asm_opt>::flag(const char* str)
+{
+ *this = asm_option(str, guess_toolchain(str));
}
diff --git a/src/tools.h b/src/tools.h
index e6c2264..b1285ec 100644
--- a/src/tools.h
+++ b/src/tools.h
@@ -5,23 +5,92 @@
#include <vector>
#include <string>
+#include <ostream>
#include "ctor.h"
+
+std::ostream& operator<<(std::ostream& stream, const ctor::c_opt& opt);
+std::ostream& operator<<(std::ostream& stream, const ctor::cxx_opt& opt);
+std::ostream& operator<<(std::ostream& stream, const ctor::ld_opt& opt);
+std::ostream& operator<<(std::ostream& stream, const ctor::ar_opt& opt);
+std::ostream& operator<<(std::ostream& stream, const ctor::asm_opt& opt);
+
+
//! Get tool-chain type from compiler path string
ctor::toolchain getToolChain(const std::string& compiler);
//! Get tool-chain type from output system (via configuration)
ctor::toolchain getToolChain(ctor::output_system system);
+
+
+//! Get tool argument(s) for specific option type matching the supplied
+//! tool-chain
+std::vector<std::string> c_option(ctor::toolchain toolchain,
+ ctor::c_opt option,
+ const std::string& arg = {});
+
+//! Get tool argument(s) for specific option type matching the supplied
+//! tool-chain
+std::vector<std::string> cxx_option(ctor::toolchain toolchain,
+ ctor::cxx_opt option,
+ const std::string& arg = {});
+
//! Get tool argument(s) for specific option type matching the supplied
//! tool-chain
-std::vector<std::string> getOption(ctor::toolchain toolchain,
- ctor::opt option,
+std::vector<std::string> ld_option(ctor::toolchain toolchain,
+ ctor::ld_opt option,
const std::string& arg = {});
-//! Get opt enum value and argument from string,
-//! ie. { opt::InludePath, "foo/bar" } from "-Ifoo/bar"
-//! Returns { opt::Custom, flag } if unknown.
-std::pair<ctor::opt, std::string> getOption(const std::string& flag,
- ctor::toolchain toolchain = ctor::toolchain::gcc);
+//! Get tool argument(s) for specific option type matching the supplied
+//! tool-chain
+std::vector<std::string> ar_option(ctor::toolchain toolchain,
+ ctor::ar_opt option,
+ const std::string& arg = {});
+
+//! Get tool argument(s) for specific option type matching the supplied
+//! tool-chain
+std::vector<std::string> asm_option(ctor::toolchain toolchain,
+ ctor::asm_opt option,
+ const std::string& arg = {});
+
+
+
+//! Get ctor::c_opt enum value and argument from string,
+//! ie. { ctor::c_opt::inlude_path, "foo/bar" } from "-Ifoo/bar"
+//! Returns { ctor::c_opt::custom, flag } if unknown.
+ctor::c_flag c_option(const std::string& flag, ctor::toolchain toolchain);
+
+//! Get ctor::cxx_opt enum value and argument from string,
+//! ie. { ctor::cxx_opt::inlude_path, "foo/bar" } from "-Ifoo/bar"
+//! Returns { ctor::cxx_opt::custom, flag } if unknown.
+ctor::cxx_flag cxx_option(const std::string& flag, ctor::toolchain toolchain);
+
+//! Get ctor::ld_opt enum value and argument from string,
+//! ie. { ctor::ld_opt::inlude_path, "foo/bar" } from "-Ifoo/bar"
+//! Returns { ctor::ld_opt::custom, flag } if unknown.
+ctor::ld_flag ld_option(const std::string& flag, ctor::toolchain toolchain);
+
+//! Get ctor::ar_opt enum value and argument from string,
+//! ie. { ctor::ar_opt::inlude_path, "foo/bar" } from "-Ifoo/bar"
+//! Returns { ctor::ar_opt::custom, flag } if unknown.
+ctor::ar_flag ar_option(const std::string& flag, ctor::toolchain toolchain);
+
+//! Get ctor::asm_opt enum value and argument from string,
+//! ie. { ctor::asm_opt::inlude_path, "foo/bar" } from "-Ifoo/bar"
+//! Returns { ctor::asm_opt::custom, flag } if unknown.
+ctor::asm_flag asm_option(const std::string& flag, ctor::toolchain toolchain);
+
+
+
+std::vector<std::string> to_strings(ctor::toolchain toolchain,
+ const ctor::cxx_flag& flag);
+std::vector<std::string> to_strings(ctor::toolchain toolchain,
+ const ctor::c_flag& flag);
+std::vector<std::string> to_strings(ctor::toolchain toolchain,
+ const ctor::ld_flag& flag);
+std::vector<std::string> to_strings(ctor::toolchain toolchain,
+ const ctor::ar_flag& flag);
+std::vector<std::string> to_strings(ctor::toolchain toolchain,
+ const ctor::asm_flag& flag);
diff --git a/src/util.h b/src/util.h
index d5fccc8..c7318aa 100644
--- a/src/util.h
+++ b/src/util.h
@@ -18,3 +18,8 @@ void append(T& a, const T& b)
{
a.insert(a.end(), b.begin(), b.end());
}
+
+//using cxx_flags = std::vector<ctor::cxx_flag>;
+//using c_flags = std::vector<std::string>;
+//using ld_flags= std::vector<std::string>;
+//using asm_flags = std::vector<std::string>;
diff --git a/test/tools_test.cc b/test/tools_test.cc
index 118490f..1d377b7 100644
--- a/test/tools_test.cc
+++ b/test/tools_test.cc
@@ -1,20 +1,10 @@
#include <vector>
#include <string>
#include <ostream>
-
-#include <tools.h>
-
-std::ostream& operator<<(std::ostream& stream, const std::vector<std::string>& vs);
-std::ostream& operator<<(std::ostream& stream, const ctor::toolchain& toolchain);
-std::ostream& operator<<(std::ostream& stream, const ctor::opt& opt);
-std::ostream& operator<<(std::ostream& stream, const std::pair<ctor::opt, std::string>& vs);
-
-#include <uunit.h>
-
#include <initializer_list>
#include <cassert>
-using namespace std::string_literals;
+#include <tools.h>
std::ostream& operator<<(std::ostream& stream, const ctor::toolchain& toolchain)
{
@@ -54,40 +44,76 @@ std::ostream& operator<<(std::ostream& stream, const std::vector<std::string>& v
return stream;
}
-std::ostream& operator<<(std::ostream& stream, const ctor::opt& opt)
+std::ostream& operator<<(std::ostream& stream, const ctor::c_flag& flag)
{
- // Adding to this enum should also imply adding to the unit-tests below
- switch(opt)
- {
- case ctor::opt::output: stream << "ctor::opt::output"; break;
- case ctor::opt::debug: stream << "ctor::opt::debug"; break;
- case ctor::opt::strip: stream << "ctor::opt::strip"; break;
- case ctor::opt::warn_all: stream << "ctor::opt::warn_all"; break;
- case ctor::opt::warnings_as_errors: stream << "ctor::opt::warnings_as_errors"; break;
- case ctor::opt::generate_dep_tree: stream << "ctor::opt::generate_dep_tree"; break;
- case ctor::opt::no_link: stream << "ctor::opt::no_link"; break;
- case ctor::opt::include_path: stream << "ctor::opt::include_path"; break;
- case ctor::opt::library_path: stream << "ctor::opt::library_path"; break;
- case ctor::opt::link: stream << "ctor::opt::link"; break;
- case ctor::opt::cpp_std: stream << "ctor::opt::cpp_std"; break;
- case ctor::opt::build_shared: stream << "ctor::opt::build_shared"; break;
- case ctor::opt::threads: stream << "ctor::opt::threads"; break;
- case ctor::opt::optimization: stream << "ctor::opt::optimization"; break;
- case ctor::opt::position_independent_code: stream << "ctor::opt::position_independent_code"; break;
- case ctor::opt::position_independent_executable: stream << "ctor::opt::position_independent_executable"; break;
- case ctor::opt::custom: stream << "ctor::opt::custom"; break;
- }
+ stream << "{" << flag.opt << ", \"" << flag.arg << "\", " << flag.toolchain << "}";
+ return stream;
+}
+std::ostream& operator<<(std::ostream& stream, const ctor::cxx_flag& flag)
+{
+ stream << "{" << flag.opt << ", \"" << flag.arg << "\", " << flag.toolchain << "}";
return stream;
}
-std::ostream& operator<<(std::ostream& stream, const std::pair<ctor::opt, std::string>& vs)
+std::ostream& operator<<(std::ostream& stream, const ctor::ld_flag& flag)
{
- stream << "{ " << vs.first << ", " << vs.second << " }";
+ stream << "{" << flag.opt << ", \"" << flag.arg << "\", " << flag.toolchain << "}";
+ return stream;
+}
+std::ostream& operator<<(std::ostream& stream, const ctor::ar_flag& flag)
+{
+ stream << "{" << flag.opt << ", \"" << flag.arg << "\", " << flag.toolchain << "}";
return stream;
}
+std::ostream& operator<<(std::ostream& stream, const ctor::asm_flag& flag)
+{
+ stream << "{" << flag.opt << ", \"" << flag.arg << "\", " << flag.toolchain << "}";
+ return stream;
+}
+
+bool operator!=(const ctor::c_flag& a, const ctor::c_flag& b)
+{
+ return
+ a.opt != b.opt ||
+ a.arg != b.arg ||
+ a.toolchain != b.toolchain;
+}
+
+bool operator!=(const ctor::cxx_flag& a, const ctor::cxx_flag& b)
+{
+ return
+ a.opt != b.opt ||
+ a.arg != b.arg ||
+ a.toolchain != b.toolchain;
+}
+bool operator!=(const ctor::ld_flag& a, const ctor::ld_flag& b)
+{
+ return
+ a.opt != b.opt ||
+ a.arg != b.arg ||
+ a.toolchain != b.toolchain;
+}
+
+bool operator!=(const ctor::ar_flag& a, const ctor::ar_flag& b)
+{
+ return
+ a.opt != b.opt ||
+ a.arg != b.arg ||
+ a.toolchain != b.toolchain;
+}
+bool operator!=(const ctor::asm_flag& a, const ctor::asm_flag& b)
+{
+ return
+ a.opt != b.opt ||
+ a.arg != b.arg ||
+ a.toolchain != b.toolchain;
+}
+
+#include <uunit.h>
+
namespace {
std::string conf_host_cxx{};
std::string conf_build_cxx{};
@@ -124,8 +150,24 @@ public:
ToolsTest()
{
uTEST(ToolsTest::getToolChain_test);
- uTEST(ToolsTest::getOption_toolchain_test);
- uTEST(ToolsTest::getOption_str_test);
+
+ uTEST(ToolsTest::getOption_toolchain_c_test);
+ uTEST(ToolsTest::getOption_toolchain_cxx_test);
+ uTEST(ToolsTest::getOption_toolchain_ld_test);
+ uTEST(ToolsTest::getOption_toolchain_ar_test);
+ uTEST(ToolsTest::getOption_toolchain_asm_test);
+
+ uTEST(ToolsTest::getOption_str_c_test);
+ uTEST(ToolsTest::getOption_str_cxx_test);
+ uTEST(ToolsTest::getOption_str_ld_test);
+ uTEST(ToolsTest::getOption_str_ar_test);
+ uTEST(ToolsTest::getOption_str_asm_test);
+
+ uTEST(ToolsTest::to_strings_c_test);
+ uTEST(ToolsTest::to_strings_cxx_test);
+ uTEST(ToolsTest::to_strings_ld_test);
+ uTEST(ToolsTest::to_strings_ar_test);
+ uTEST(ToolsTest::to_strings_asm_test);
}
void getToolChain_test()
@@ -134,176 +176,722 @@ public:
uASSERT_EQUAL(ctor::toolchain::gcc, getToolChain("/usr/bin/g++-10"));
uASSERT_EQUAL(ctor::toolchain::gcc, getToolChain("/usr/bin/x86_64-pc-linux-gnu-g++-9.3.0"));
uASSERT_EQUAL(ctor::toolchain::clang, getToolChain("/usr/bin/clang++"));
- uASSERT_EQUAL(ctor::toolchain::clang, getToolChain("/usr/bin/clang++-10"));
- uASSERT_EQUAL(ctor::toolchain::clang, getToolChain("/usr/lib/llvm/12/bin/i686-pc-linux-gnu-clang++-12"));
+ uASSERT_EQUAL(ctor::toolchain::clang, getToolChain("/usr/bin/clang++-16"));
+ uASSERT_EQUAL(ctor::toolchain::clang, getToolChain("/usr/lib/llvm/16/bin/i686-pc-linux-gnu-clang++-16"));
}
- void getOption_toolchain_test()
+
+ void getOption_toolchain_c_test()
{
std::vector<std::string> exp;
std::vector<std::string> act;
+ //
+ // gcc
+ //
exp = { "-o", "foo" };
- act = getOption(ctor::toolchain::clang, ctor::opt::output, "foo");
+ act = c_option(ctor::toolchain::gcc, ctor::c_opt::output, "foo");
uASSERT_EQUAL(exp, act);
exp = { "-g" };
- act = getOption(ctor::toolchain::clang, ctor::opt::debug);
- uASSERT_EQUAL(exp, act);
-
- exp = { "-s" };
- act = getOption(ctor::toolchain::clang, ctor::opt::strip);
+ act = c_option(ctor::toolchain::gcc, ctor::c_opt::debug);
uASSERT_EQUAL(exp, act);
exp = { "-Wall" };
- act = getOption(ctor::toolchain::clang, ctor::opt::warn_all);
+ act = c_option(ctor::toolchain::gcc, ctor::c_opt::warn_all);
uASSERT_EQUAL(exp, act);
exp = { "-Werror" };
- act = getOption(ctor::toolchain::clang, ctor::opt::warnings_as_errors);
+ act = c_option(ctor::toolchain::gcc, ctor::c_opt::warnings_as_errors);
uASSERT_EQUAL(exp, act);
exp = { "-MMD" };
- act = getOption(ctor::toolchain::clang, ctor::opt::generate_dep_tree);
+ act = c_option(ctor::toolchain::gcc, ctor::c_opt::generate_dep_tree);
uASSERT_EQUAL(exp, act);
exp = { "-c" };
- act = getOption(ctor::toolchain::clang, ctor::opt::no_link);
+ act = c_option(ctor::toolchain::gcc, ctor::c_opt::no_link);
uASSERT_EQUAL(exp, act);
exp = { "-Ifoo" };
- act = getOption(ctor::toolchain::clang, ctor::opt::include_path, "foo");
+ act = c_option(ctor::toolchain::gcc, ctor::c_opt::include_path, "foo");
uASSERT_EQUAL(exp, act);
- exp = { "-Lfoo" };
- act = getOption(ctor::toolchain::clang, ctor::opt::library_path, "foo");
+ exp = { "-std=foo" };
+ act = c_option(ctor::toolchain::gcc, ctor::c_opt::c_std, "foo");
uASSERT_EQUAL(exp, act);
- exp = { "-lfoo" };
- act = getOption(ctor::toolchain::clang, ctor::opt::link, "foo");
+ exp = { "-Ofoo" };
+ act = c_option(ctor::toolchain::gcc, ctor::c_opt::optimization, "foo");
uASSERT_EQUAL(exp, act);
- exp = { "-std=foo" };
- act = getOption(ctor::toolchain::clang, ctor::opt::cpp_std, "foo");
+ exp = { "-fPIC" };
+ act = c_option(ctor::toolchain::gcc, ctor::c_opt::position_independent_code);
uASSERT_EQUAL(exp, act);
- exp = { "-shared" };
- act = getOption(ctor::toolchain::clang, ctor::opt::build_shared);
+ exp = { "-fPIE" };
+ act = c_option(ctor::toolchain::gcc, ctor::c_opt::position_independent_executable);
uASSERT_EQUAL(exp, act);
- exp = { "-pthread" };
- act = getOption(ctor::toolchain::clang, ctor::opt::threads);
+ exp = { "-foo" };
+ act = c_option(ctor::toolchain::gcc, ctor::c_opt::custom, "-foo");
+ uASSERT_EQUAL(exp, act);
+
+ //
+ // clang
+ //
+ exp = { "-o", "foo" };
+ act = c_option(ctor::toolchain::clang, ctor::c_opt::output, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-g" };
+ act = c_option(ctor::toolchain::clang, ctor::c_opt::debug);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-Wall" };
+ act = c_option(ctor::toolchain::clang, ctor::c_opt::warn_all);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-Werror" };
+ act = c_option(ctor::toolchain::clang, ctor::c_opt::warnings_as_errors);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-MMD" };
+ act = c_option(ctor::toolchain::clang, ctor::c_opt::generate_dep_tree);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-c" };
+ act = c_option(ctor::toolchain::clang, ctor::c_opt::no_link);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-Ifoo" };
+ act = c_option(ctor::toolchain::clang, ctor::c_opt::include_path, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-std=foo" };
+ act = c_option(ctor::toolchain::clang, ctor::c_opt::c_std, "foo");
uASSERT_EQUAL(exp, act);
exp = { "-Ofoo" };
- act = getOption(ctor::toolchain::clang, ctor::opt::optimization, "foo");
+ act = c_option(ctor::toolchain::clang, ctor::c_opt::optimization, "foo");
uASSERT_EQUAL(exp, act);
exp = { "-fPIC" };
- act = getOption(ctor::toolchain::clang, ctor::opt::position_independent_code);
+ act = c_option(ctor::toolchain::clang, ctor::c_opt::position_independent_code);
uASSERT_EQUAL(exp, act);
exp = { "-fPIE" };
- act = getOption(ctor::toolchain::clang, ctor::opt::position_independent_executable);
+ act = c_option(ctor::toolchain::clang, ctor::c_opt::position_independent_executable);
uASSERT_EQUAL(exp, act);
exp = { "-foo" };
- act = getOption(ctor::toolchain::clang, ctor::opt::custom, "-foo");
+ act = c_option(ctor::toolchain::clang, ctor::c_opt::custom, "-foo");
+ uASSERT_EQUAL(exp, act);
+
+ //
+ // any
+ //
+ exp = { "{ctor::c_opt::output, \"foo\"}" };
+ act = c_option(ctor::toolchain::any, ctor::c_opt::output, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::c_opt::debug}" };
+ act = c_option(ctor::toolchain::any, ctor::c_opt::debug);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::c_opt::warn_all}" };
+ act = c_option(ctor::toolchain::any, ctor::c_opt::warn_all);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::c_opt::warnings_as_errors}" };
+ act = c_option(ctor::toolchain::any, ctor::c_opt::warnings_as_errors);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::c_opt::generate_dep_tree}" };
+ act = c_option(ctor::toolchain::any, ctor::c_opt::generate_dep_tree);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::c_opt::no_link}" };
+ act = c_option(ctor::toolchain::any, ctor::c_opt::no_link);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::c_opt::include_path, \"foo\"}" };
+ act = c_option(ctor::toolchain::any, ctor::c_opt::include_path, "foo");
uASSERT_EQUAL(exp, act);
+ exp = { "{ctor::c_opt::c_std, \"foo\"}" };
+ act = c_option(ctor::toolchain::any, ctor::c_opt::c_std, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::c_opt::optimization, \"foo\"}" };
+ act = c_option(ctor::toolchain::any, ctor::c_opt::optimization, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::c_opt::position_independent_code}" };
+ act = c_option(ctor::toolchain::any, ctor::c_opt::position_independent_code);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::c_opt::position_independent_executable}" };
+ act = c_option(ctor::toolchain::any, ctor::c_opt::position_independent_executable);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::c_opt::custom, \"-foo\"}" };
+ act = c_option(ctor::toolchain::any, ctor::c_opt::custom, "-foo");
+ uASSERT_EQUAL(exp, act);
+ }
+
+ void getOption_toolchain_cxx_test()
+ {
+ std::vector<std::string> exp;
+ std::vector<std::string> act;
+
+ //
+ // gcc
+ //
exp = { "-o", "foo" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::output, "foo");
+ act = cxx_option(ctor::toolchain::gcc, ctor::cxx_opt::output, "foo");
uASSERT_EQUAL(exp, act);
exp = { "-g" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::debug);
+ act = cxx_option(ctor::toolchain::gcc, ctor::cxx_opt::debug);
uASSERT_EQUAL(exp, act);
- exp = { "-s" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::strip);
+ exp = { "-Wall" };
+ act = cxx_option(ctor::toolchain::gcc, ctor::cxx_opt::warn_all);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-Werror" };
+ act = cxx_option(ctor::toolchain::gcc, ctor::cxx_opt::warnings_as_errors);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-MMD" };
+ act = cxx_option(ctor::toolchain::gcc, ctor::cxx_opt::generate_dep_tree);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-c" };
+ act = cxx_option(ctor::toolchain::gcc, ctor::cxx_opt::no_link);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-Ifoo" };
+ act = cxx_option(ctor::toolchain::gcc, ctor::cxx_opt::include_path, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-std=foo" };
+ act = cxx_option(ctor::toolchain::gcc, ctor::cxx_opt::cpp_std, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-Ofoo" };
+ act = cxx_option(ctor::toolchain::gcc, ctor::cxx_opt::optimization, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-fPIC" };
+ act = cxx_option(ctor::toolchain::gcc, ctor::cxx_opt::position_independent_code);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-fPIE" };
+ act = cxx_option(ctor::toolchain::gcc, ctor::cxx_opt::position_independent_executable);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-foo" };
+ act = cxx_option(ctor::toolchain::gcc, ctor::cxx_opt::custom, "-foo");
+ uASSERT_EQUAL(exp, act);
+
+ //
+ // clang
+ //
+ exp = { "-o", "foo" };
+ act = cxx_option(ctor::toolchain::clang, ctor::cxx_opt::output, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-g" };
+ act = cxx_option(ctor::toolchain::clang, ctor::cxx_opt::debug);
uASSERT_EQUAL(exp, act);
exp = { "-Wall" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::warn_all);
+ act = cxx_option(ctor::toolchain::clang, ctor::cxx_opt::warn_all);
uASSERT_EQUAL(exp, act);
exp = { "-Werror" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::warnings_as_errors);
+ act = cxx_option(ctor::toolchain::clang, ctor::cxx_opt::warnings_as_errors);
uASSERT_EQUAL(exp, act);
exp = { "-MMD" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::generate_dep_tree);
+ act = cxx_option(ctor::toolchain::clang, ctor::cxx_opt::generate_dep_tree);
uASSERT_EQUAL(exp, act);
exp = { "-c" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::no_link);
+ act = cxx_option(ctor::toolchain::clang, ctor::cxx_opt::no_link);
uASSERT_EQUAL(exp, act);
exp = { "-Ifoo" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::include_path, "foo");
+ act = cxx_option(ctor::toolchain::clang, ctor::cxx_opt::include_path, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-std=foo" };
+ act = cxx_option(ctor::toolchain::clang, ctor::cxx_opt::cpp_std, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-Ofoo" };
+ act = cxx_option(ctor::toolchain::clang, ctor::cxx_opt::optimization, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-fPIC" };
+ act = cxx_option(ctor::toolchain::clang, ctor::cxx_opt::position_independent_code);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-fPIE" };
+ act = cxx_option(ctor::toolchain::clang, ctor::cxx_opt::position_independent_executable);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-foo" };
+ act = cxx_option(ctor::toolchain::clang, ctor::cxx_opt::custom, "-foo");
+ uASSERT_EQUAL(exp, act);
+
+ //
+ // any
+ //
+ exp = { "{ctor::cxx_opt::output, \"foo\"}" };
+ act = cxx_option(ctor::toolchain::any, ctor::cxx_opt::output, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::cxx_opt::debug}" };
+ act = cxx_option(ctor::toolchain::any, ctor::cxx_opt::debug);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::cxx_opt::warn_all}" };
+ act = cxx_option(ctor::toolchain::any, ctor::cxx_opt::warn_all);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::cxx_opt::warnings_as_errors}" };
+ act = cxx_option(ctor::toolchain::any, ctor::cxx_opt::warnings_as_errors);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::cxx_opt::generate_dep_tree}" };
+ act = cxx_option(ctor::toolchain::any, ctor::cxx_opt::generate_dep_tree);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::cxx_opt::no_link}" };
+ act = cxx_option(ctor::toolchain::any, ctor::cxx_opt::no_link);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::cxx_opt::include_path, \"foo\"}" };
+ act = cxx_option(ctor::toolchain::any, ctor::cxx_opt::include_path, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::cxx_opt::cpp_std, \"foo\"}" };
+ act = cxx_option(ctor::toolchain::any, ctor::cxx_opt::cpp_std, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::cxx_opt::optimization, \"foo\"}" };
+ act = cxx_option(ctor::toolchain::any, ctor::cxx_opt::optimization, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::cxx_opt::position_independent_code}" };
+ act = cxx_option(ctor::toolchain::any, ctor::cxx_opt::position_independent_code);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::cxx_opt::position_independent_executable}" };
+ act = cxx_option(ctor::toolchain::any, ctor::cxx_opt::position_independent_executable);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::cxx_opt::custom, \"-foo\"}" };
+ act = cxx_option(ctor::toolchain::any, ctor::cxx_opt::custom, "-foo");
+ uASSERT_EQUAL(exp, act);
+ }
+
+ void getOption_toolchain_ld_test()
+ {
+ std::vector<std::string> exp;
+ std::vector<std::string> act;
+
+ //
+ // gcc
+ //
+ exp = { "-o", "foo" };
+ act = ld_option(ctor::toolchain::gcc, ctor::ld_opt::output, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-s" };
+ act = ld_option(ctor::toolchain::gcc, ctor::ld_opt::strip);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-Wall" };
+ act = ld_option(ctor::toolchain::gcc, ctor::ld_opt::warn_all);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-Werror" };
+ act = ld_option(ctor::toolchain::gcc, ctor::ld_opt::warnings_as_errors);
uASSERT_EQUAL(exp, act);
exp = { "-Lfoo" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::library_path, "foo");
+ act = ld_option(ctor::toolchain::gcc, ctor::ld_opt::library_path, "foo");
uASSERT_EQUAL(exp, act);
exp = { "-lfoo" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::link, "foo");
+ act = ld_option(ctor::toolchain::gcc, ctor::ld_opt::link, "foo");
uASSERT_EQUAL(exp, act);
exp = { "-std=foo" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::cpp_std, "foo");
+ act = ld_option(ctor::toolchain::gcc, ctor::ld_opt::cpp_std, "foo");
uASSERT_EQUAL(exp, act);
exp = { "-shared" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::build_shared);
+ act = ld_option(ctor::toolchain::gcc, ctor::ld_opt::build_shared);
uASSERT_EQUAL(exp, act);
exp = { "-pthread" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::threads);
+ act = ld_option(ctor::toolchain::gcc, ctor::ld_opt::threads);
uASSERT_EQUAL(exp, act);
- exp = { "-Ofoo" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::optimization, "foo");
+ exp = { "-fPIC" };
+ act = ld_option(ctor::toolchain::gcc, ctor::ld_opt::position_independent_code);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-fPIE" };
+ act = ld_option(ctor::toolchain::gcc, ctor::ld_opt::position_independent_executable);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-foo" };
+ act = ld_option(ctor::toolchain::gcc, ctor::ld_opt::custom, "-foo");
+ uASSERT_EQUAL(exp, act);
+
+ //
+ // clang
+ //
+ exp = { "-o", "foo" };
+ act = ld_option(ctor::toolchain::clang, ctor::ld_opt::output, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-s" };
+ act = ld_option(ctor::toolchain::clang, ctor::ld_opt::strip);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-Wall" };
+ act = ld_option(ctor::toolchain::clang, ctor::ld_opt::warn_all);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-Werror" };
+ act = ld_option(ctor::toolchain::clang, ctor::ld_opt::warnings_as_errors);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-Lfoo" };
+ act = ld_option(ctor::toolchain::clang, ctor::ld_opt::library_path, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-lfoo" };
+ act = ld_option(ctor::toolchain::clang, ctor::ld_opt::link, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-std=foo" };
+ act = ld_option(ctor::toolchain::clang, ctor::ld_opt::cpp_std, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-shared" };
+ act = ld_option(ctor::toolchain::clang, ctor::ld_opt::build_shared);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-pthread" };
+ act = ld_option(ctor::toolchain::clang, ctor::ld_opt::threads);
uASSERT_EQUAL(exp, act);
exp = { "-fPIC" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::position_independent_code);
+ act = ld_option(ctor::toolchain::clang, ctor::ld_opt::position_independent_code);
uASSERT_EQUAL(exp, act);
exp = { "-fPIE" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::position_independent_executable);
+ act = ld_option(ctor::toolchain::clang, ctor::ld_opt::position_independent_executable);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "-foo" };
+ act = ld_option(ctor::toolchain::clang, ctor::ld_opt::custom, "-foo");
+ uASSERT_EQUAL(exp, act);
+
+ //
+ // any
+ //
+ exp = { "{ctor::ld_opt::output, \"foo\"}" };
+ act = ld_option(ctor::toolchain::any, ctor::ld_opt::output, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::ld_opt::strip}" };
+ act = ld_option(ctor::toolchain::any, ctor::ld_opt::strip);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::ld_opt::warn_all}" };
+ act = ld_option(ctor::toolchain::any, ctor::ld_opt::warn_all);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::ld_opt::warnings_as_errors}" };
+ act = ld_option(ctor::toolchain::any, ctor::ld_opt::warnings_as_errors);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::ld_opt::library_path, \"foo\"}" };
+ act = ld_option(ctor::toolchain::any, ctor::ld_opt::library_path, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::ld_opt::link, \"foo\"}" };
+ act = ld_option(ctor::toolchain::any, ctor::ld_opt::link, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::ld_opt::cpp_std, \"foo\"}" };
+ act = ld_option(ctor::toolchain::any, ctor::ld_opt::cpp_std, "foo");
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::ld_opt::build_shared}" };
+ act = ld_option(ctor::toolchain::any, ctor::ld_opt::build_shared);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::ld_opt::threads}" };
+ act = ld_option(ctor::toolchain::any, ctor::ld_opt::threads);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::ld_opt::position_independent_code}" };
+ act = ld_option(ctor::toolchain::any, ctor::ld_opt::position_independent_code);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::ld_opt::position_independent_executable}" };
+ act = ld_option(ctor::toolchain::any, ctor::ld_opt::position_independent_executable);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { "{ctor::ld_opt::custom, \"-foo\"}" };
+ act = ld_option(ctor::toolchain::any, ctor::ld_opt::custom, "-foo");
+ uASSERT_EQUAL(exp, act);
+ }
+
+ void getOption_toolchain_ar_test()
+ {
+ std::vector<std::string> exp;
+ std::vector<std::string> act;
+
+ //
+ // gcc
+ //
+ exp = { "-foo" };
+ act = asm_option(ctor::toolchain::gcc, ctor::asm_opt::custom, "-foo");
+ uASSERT_EQUAL(exp, act);
+
+ //
+ // clang
+ //
+ exp = { "-foo" };
+ act = asm_option(ctor::toolchain::clang, ctor::asm_opt::custom, "-foo");
+ uASSERT_EQUAL(exp, act);
+
+ //
+ // any
+ //
+ exp = { "{ctor::asm_opt::custom, \"-foo\"}" };
+ act = asm_option(ctor::toolchain::any, ctor::asm_opt::custom, "-foo");
+ uASSERT_EQUAL(exp, act);
+}
+
+ void getOption_toolchain_asm_test()
+ {
+ std::vector<std::string> exp;
+ std::vector<std::string> act;
+
+ //
+ // gcc
+ //
+ exp = { "-foo" };
+ act = asm_option(ctor::toolchain::gcc, ctor::asm_opt::custom, "-foo");
uASSERT_EQUAL(exp, act);
+ //
+ // clang
+ //
exp = { "-foo" };
- act = getOption(ctor::toolchain::gcc, ctor::opt::custom, "-foo");
+ act = asm_option(ctor::toolchain::clang, ctor::asm_opt::custom, "-foo");
+ uASSERT_EQUAL(exp, act);
+
+ //
+ // any
+ //
+ exp = { "{ctor::asm_opt::custom, \"-foo\"}" };
+ act = asm_option(ctor::toolchain::any, ctor::asm_opt::custom, "-foo");
+ uASSERT_EQUAL(exp, act);
+ }
+
+
+ void getOption_str_c_test()
+ {
+ ctor::c_flag exp("");
+ ctor::c_flag act("");
+
+ //
+ // gcc
+ //
+ exp = { ctor::c_opt::include_path, "foo" };
+ act = c_option("-Ifoo", ctor::toolchain::gcc);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { ctor::c_opt::custom, "foo" };
+ act = c_option("foo", ctor::toolchain::gcc);
+ uASSERT_EQUAL(exp, act);
+
+ //
+ // clang
+ //
+ exp = { ctor::c_opt::include_path, "foo" };
+ act = c_option("-Ifoo", ctor::toolchain::clang);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { ctor::c_opt::custom, "foo" };
+ act = c_option("foo", ctor::toolchain::clang);
+ uASSERT_EQUAL(exp, act);
+ }
+
+ void getOption_str_cxx_test()
+ {
+ ctor::cxx_flag exp("");
+ ctor::cxx_flag act("");
+
+ //
+ // gcc
+ //
+ exp = { ctor::cxx_opt::include_path, "foo" };
+ act = cxx_option("-Ifoo", ctor::toolchain::gcc);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { ctor::cxx_opt::custom, "foo" };
+ act = cxx_option("foo", ctor::toolchain::gcc);
+ uASSERT_EQUAL(exp, act);
+
+ //
+ // clang
+ //
+ exp = { ctor::cxx_opt::include_path, "foo" };
+ act = cxx_option("-Ifoo", ctor::toolchain::clang);
+ uASSERT_EQUAL(exp, act);
+
+ exp = { ctor::cxx_opt::custom, "foo" };
+ act = cxx_option("foo", ctor::toolchain::clang);
uASSERT_EQUAL(exp, act);
}
- void getOption_str_test()
+ void getOption_str_ld_test()
{
- std::pair<ctor::opt, std::string> exp;
- std::pair<ctor::opt, std::string> act;
+ ctor::ld_flag exp("");
+ ctor::ld_flag act("");
- exp = { ctor::opt::include_path, "foo" };
- act = getOption("-Ifoo", ctor::toolchain::gcc);
+ //
+ // gcc
+ //
+ exp = { ctor::ld_opt::library_path, "foo" };
+ act = ld_option("-Lfoo", ctor::toolchain::gcc);
uASSERT_EQUAL(exp, act);
- exp = { ctor::opt::library_path, "foo" };
- act = getOption("-Lfoo", ctor::toolchain::gcc);
+ exp = { ctor::ld_opt::custom, "foo" };
+ act = ld_option("foo", ctor::toolchain::gcc);
uASSERT_EQUAL(exp, act);
- exp = { ctor::opt::include_path, "foo" };
- act = getOption("-Ifoo", ctor::toolchain::clang);
+ //
+ // clang
+ //
+ exp = { ctor::ld_opt::library_path, "foo" };
+ act = ld_option("-Lfoo", ctor::toolchain::clang);
uASSERT_EQUAL(exp, act);
- exp = { ctor::opt::library_path, "foo" };
- act = getOption("-Lfoo", ctor::toolchain::clang);
+ exp = { ctor::ld_opt::custom, "foo" };
+ act = ld_option("foo", ctor::toolchain::clang);
uASSERT_EQUAL(exp, act);
}
+ void getOption_str_ar_test()
+ {
+ ctor::ar_flag exp("");
+ ctor::ar_flag act("");
+ //
+ // gcc
+ //
+ exp = { ctor::ar_opt::custom, "foo" };
+ act = ar_option("foo", ctor::toolchain::gcc);
+ uASSERT_EQUAL(exp, act);
+ //
+ // clang
+ //
+ exp = { ctor::ar_opt::custom, "foo" };
+ act = ar_option("foo", ctor::toolchain::clang);
+ uASSERT_EQUAL(exp, act);
+ }
+
+ void getOption_str_asm_test()
+ {
+ ctor::asm_flag exp("");
+ ctor::asm_flag act("");
+
+ //
+ // gcc
+ //
+ exp = { ctor::asm_opt::custom, "foo" };
+ act = asm_option("foo", ctor::toolchain::gcc);
+ uASSERT_EQUAL(exp, act);
+
+ //
+ // clang
+ //
+ exp = { ctor::asm_opt::custom, "foo" };
+ act = asm_option("foo", ctor::toolchain::clang);
+ uASSERT_EQUAL(exp, act);
+ }
+
+
+ void to_strings_c_test()
+ {
+ std::vector<std::string> exp;
+ std::vector<std::string> act;
+
+ // Mismatching toolchain (required vs actual) results in no output
+ // otherwise to_strings is just a proxy for c_option
+ act = to_strings(ctor::toolchain::gcc, {ctor::toolchain::clang, ctor::c_opt::no_link});
+ uASSERT_EQUAL(exp, act);
+ }
+
+ void to_strings_cxx_test()
+ {
+ std::vector<std::string> exp;
+ std::vector<std::string> act;
+
+ // Mismatching toolchain (required vs actual) results in no output
+ // otherwise to_strings is just a proxy for cxx_option
+ act = to_strings(ctor::toolchain::gcc, {ctor::toolchain::clang, ctor::cxx_opt::no_link});
+ uASSERT_EQUAL(exp, act);
+ }
+
+ void to_strings_ld_test()
+ {
+ std::vector<std::string> exp;
+ std::vector<std::string> act;
+
+ // Mismatching toolchain (required vs actual) results in no output
+ // otherwise to_strings is just a proxy for ld_option
+ act = to_strings(ctor::toolchain::gcc, {ctor::toolchain::clang, ctor::ld_opt::strip});
+ uASSERT_EQUAL(exp, act);
+ }
+
+ void to_strings_ar_test()
+ {
+ std::vector<std::string> exp;
+ std::vector<std::string> act;
+
+ // Mismatching toolchain (required vs actual) results in no output
+ // otherwise to_strings is just a proxy for ar_option
+ act = to_strings(ctor::toolchain::gcc, {ctor::toolchain::clang, ctor::ar_opt::custom, "foo"});
+ uASSERT_EQUAL(exp, act);
+ }
+
+ void to_strings_asm_test()
+ {
+ std::vector<std::string> exp;
+ std::vector<std::string> act;
+
+ // Mismatching toolchain (required vs actual) results in no output
+ // otherwise to_strings is just a proxy for asm_option
+ act = to_strings(ctor::toolchain::gcc, {ctor::toolchain::clang, ctor::asm_opt::custom, "foo"});
+ uASSERT_EQUAL(exp, act);
+ }
};
// Registers the fixture into the 'registry'