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) --- cppbuild.cc | 2 ++ libcppbuild.cc | 42 ++++++++++++++++++++++++++++++++---------- libcppbuild.h | 9 +++++++++ 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/cppbuild.cc b/cppbuild.cc index b0f3eae..50c364f 100644 --- a/cppbuild.cc +++ b/cppbuild.cc @@ -7,6 +7,7 @@ BuildConfigurations myConfigs() return { { + .type = TargetType::Executable, .target = "plugingui", .sources = { "drumgizmo/zita-resampler/libs/cresampler.cc", @@ -56,6 +57,7 @@ BuildConfigurations myConfigs2() return { { + .type = TargetType::DynamicLibrary, .target = "libplugingui.so", .sources = { "drumgizmo/plugingui/abouttab.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; diff --git a/libcppbuild.h b/libcppbuild.h index a052ac8..5b442f8 100644 --- a/libcppbuild.h +++ b/libcppbuild.h @@ -5,8 +5,17 @@ #include //#include +enum class TargetType +{ + Auto, // Default - deduce from target name + Executable, + StaticLibrary, + DynamicLibrary, +}; + struct BuildConfiguration { + TargetType type{TargetType::Auto}; std::string target; std::vector sources; std::vector depends; -- cgit v1.2.3