diff options
Diffstat (limited to 'libcppbuild.cc')
-rw-r--r-- | libcppbuild.cc | 42 |
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; |