summaryrefslogtreecommitdiff
path: root/src/task_cc.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/task_cc.cc')
-rw-r--r--src/task_cc.cc116
1 files changed, 92 insertions, 24 deletions
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;