summaryrefslogtreecommitdiff
path: root/libcppbuild.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-06-20 14:27:31 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-06-20 14:27:31 +0200
commit94b0690973a460c86e36a7935adbe201e4f66361 (patch)
tree5aff5bc33e92d356dd8c4b4bd7a69a472f5c8e3a /libcppbuild.cc
parente43c5e6f856ad583579384e1f9509f66e3e0537e (diff)
Add explicit target types (with 'auto' being the default)
Diffstat (limited to 'libcppbuild.cc')
-rw-r--r--libcppbuild.cc42
1 files changed, 32 insertions, 10 deletions
diff --git a/libcppbuild.cc b/libcppbuild.cc
index 441ba00..c18d725 100644
--- a/libcppbuild.cc
+++ b/libcppbuild.cc
@@ -33,6 +33,29 @@ std::list<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config,
{
std::filesystem::path targetFile(config.target);
+ TargetType target_type{config.type};
+ if(target_type == TargetType::Auto)
+ {
+ if(targetFile.extension() == ".a")
+ {
+ target_type = TargetType::StaticLibrary;
+ }
+ else if(targetFile.extension() == ".so")
+ {
+ target_type = TargetType::DynamicLibrary;
+ }
+ else if(targetFile.extension() == "")
+ {
+ target_type = TargetType::Executable;
+ }
+ else
+ {
+ std::cerr << "Could not deduce target type from target " <<
+ targetFile.string() << " please specify.\n";
+ exit(1);
+ }
+ }
+
std::vector<std::string> objects;
std::list<std::shared_ptr<Task>> tasks;
for(const auto& file : config.sources)
@@ -42,28 +65,27 @@ std::list<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config,
objects.push_back(tasks.back()->target());
}
- if(targetFile.extension() == ".a")
+ switch(target_type)
{
- // static lib
+ case TargetType::StaticLibrary:
tasks.emplace_back(std::make_shared<TaskAR>(config, settings, config.target,
objects));
- }
- else if(targetFile.extension() == ".so")
- {
+ break;
+
+ case TargetType::DynamicLibrary:
if(targetFile.stem().string().substr(0, 3) != "lib")
{
std::cerr << "Dynamic library target must have 'lib' prefix\n";
exit(1);
}
- // dynamic lib
tasks.emplace_back(std::make_shared<TaskSO>(config, settings, config.target,
objects));
- }
- else
- {
- // executable
+ break;
+
+ case TargetType::Executable:
tasks.emplace_back(std::make_shared<TaskLD>(config, settings, config.target,
objects));
+ break;
}
return tasks;