From 94b0690973a460c86e36a7935adbe201e4f66361 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 20 Jun 2021 14:27:31 +0200 Subject: Add explicit target types (with 'auto' being the default) --- libcppbuild.cc | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'libcppbuild.cc') diff --git a/libcppbuild.cc b/libcppbuild.cc index 441ba00..c18d725 100644 --- a/libcppbuild.cc +++ b/libcppbuild.cc @@ -33,6 +33,29 @@ std::list> 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 objects; std::list> tasks; for(const auto& file : config.sources) @@ -42,28 +65,27 @@ std::list> 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(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(config, settings, config.target, objects)); - } - else - { - // executable + break; + + case TargetType::Executable: tasks.emplace_back(std::make_shared(config, settings, config.target, objects)); + break; } return tasks; -- cgit v1.2.3