summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cppbuild.cc2
-rw-r--r--libcppbuild.cc42
-rw-r--r--libcppbuild.h9
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<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;
diff --git a/libcppbuild.h b/libcppbuild.h
index a052ac8..5b442f8 100644
--- a/libcppbuild.h
+++ b/libcppbuild.h
@@ -5,8 +5,17 @@
#include <vector>
//#include <source_location>
+enum class TargetType
+{
+ Auto, // Default - deduce from target name
+ Executable,
+ StaticLibrary,
+ DynamicLibrary,
+};
+
struct BuildConfiguration
{
+ TargetType type{TargetType::Auto};
std::string target;
std::vector<std::string> sources;
std::vector<std::string> depends;