summaryrefslogtreecommitdiff
path: root/src/libcppbuild.h
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-08-28 18:59:29 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-08-28 18:59:29 +0200
commit5da56616cccf4e595ec6a556cf1aef40b37746e3 (patch)
tree8142e294a251ca2ab1697f7541fe67dfd31622e0 /src/libcppbuild.h
parent0597cb9854d66d918762ff167148516b69c02e9a (diff)
Move sources to ... well, src ;)
Diffstat (limited to 'src/libcppbuild.h')
-rw-r--r--src/libcppbuild.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/libcppbuild.h b/src/libcppbuild.h
new file mode 100644
index 0000000..d0a0080
--- /dev/null
+++ b/src/libcppbuild.h
@@ -0,0 +1,76 @@
+// -*- c++ -*-
+#pragma once
+
+#include <string>
+#include <vector>
+#include <map>
+
+enum class TargetType
+{
+ Auto, // Default - deduce from target name and sources extensions
+
+ Executable,
+ StaticLibrary,
+ DynamicLibrary,
+ Object,
+};
+
+enum class Language
+{
+ Auto, // Default - deduce language from source extensions
+
+ C,
+ Cpp,
+ Asm,
+};
+
+enum class OutputSystem
+{
+ Host, // Output for the target system
+ Build, // Internal tool during cross-compilation
+};
+
+struct BuildConfiguration
+{
+ TargetType type{TargetType::Auto};
+ Language language{Language::Auto};
+ OutputSystem system{OutputSystem::Host};
+ std::string target;
+ std::vector<std::string> sources; // source list
+ std::vector<std::string> depends; // internal dependencies
+ std::vector<std::string> cxxflags; // flags for c++ compiler
+ std::vector<std::string> cflags; // flags for c compiler
+ std::vector<std::string> ldflags; // flags for linker
+ std::vector<std::string> asmflags; // flags for asm translator
+};
+
+using BuildConfigurations = std::vector<BuildConfiguration>;
+
+int reg(const char* location, BuildConfigurations (*cb)());
+
+// Convenience macro - ugly but keeps things simple(r)
+#define CONCAT(a, b) CONCAT_INNER(a, b)
+#define CONCAT_INNER(a, b) a ## b
+#define UNIQUE_NAME(base) CONCAT(base, __LINE__)
+#define REG(cb) namespace { int UNIQUE_NAME(unique) = reg(__FILE__, cb); }
+
+// Predefined configuration keys
+namespace cfg
+{
+constexpr auto builddir = "builddir";
+
+constexpr auto host_cc = "host-cc";
+constexpr auto host_cxx = "host-cpp";
+constexpr auto host_ar = "host-ar";
+constexpr auto host_ld = "host-ld";
+
+constexpr auto build_cc = "build-cc";
+constexpr auto build_cxx = "build-cpp";
+constexpr auto build_ar = "build-ar";
+constexpr auto build_ld = "build-ld";
+}
+
+const std::map<std::string, std::string>& configuration();
+bool hasConfiguration(const std::string& key);
+const std::string& getConfiguration(const std::string& key,
+ const std::string& defaultValue = {});