summaryrefslogtreecommitdiff
path: root/libcppbuild.h
blob: 9ea3fb194fe64cdb6909cb32c8f8367c5d84db32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
{
	Target, // Output for the target system
	BuildHost, // Internal tool during cross-compilation
};

struct BuildConfiguration
{
	TargetType type{TargetType::Auto};
	Language language{Language::Auto};
	OutputSystem system{OutputSystem::Target};
	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 target_cc = "target-cc";
constexpr auto target_cpp = "target-cpp";
constexpr auto target_ar = "target-ar";
constexpr auto target_ld = "target-ld";

constexpr auto host_cc = "host-cc";
constexpr auto host_cpp = "host-cpp";
constexpr auto host_ar = "host-ar";
constexpr auto host_ld = "host-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 = {});