summaryrefslogtreecommitdiff
path: root/ctor.cc
blob: 2f4cb141f75b0aba1082345a9300af3104df10c0 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// -*- c++ -*-
#include <libctor.h>
#include <filesystem>
#include <iostream>

namespace
{
std::vector<Source> eval_mocs(const std::string& path,
                              const std::vector<std::pair<std::string, std::string>>& moc_list)
{
	std::vector<Source> sources;
	for(const auto& moc : moc_list)
	{
		std::filesystem::path input(moc.first);
		std::filesystem::path output(moc.second);

		std::filesystem::path fspath(path);

		if(!std::filesystem::exists(fspath / input))
		{
			std::cerr << "Missing moc input file: " << input.string() << '\n';
			exit(1);
		}

		if(!std::filesystem::exists(path / output) ||
		   std::filesystem::last_write_time(path / input) >
		   std::filesystem::last_write_time(path / output))
		{
			std::string cmd = "cd \"" + path + "\"; moc ";
			cmd += "-o \"" + output.string() + "\" \"" + input.string() + "\"";
			std::cerr << cmd << "\n";
			auto ret = system(cmd.data());
			if(ret != 0)
			{
				std::cerr << "moc generation failed: " << cmd << '\n';
				exit(ret);
			}
		}
		sources.push_back((path / output).string());
	}

	return sources;
}

BuildConfigurations myConfigs()
{
	//
	// Qookie-cast client
	//
	BuildConfiguration qookie =
		{
			.target = "qookie",  // output filename
			.sources = {
				"src/qookie.cc",
				"src/database.cc",
				"src/database_gourmet.cc",
				"src/database_krecipes.cc",
				"src/mainwindow.cc",
				"src/viewer.cc",
				"src/client.cc",
			},
			.flags = {
				.cxxflags = {
					"-fPIC",
					"-Wall", "-Werror", "-Wextra",// "-Wconversion",
					"-Wno-deprecated-copy",
					"-g",
				},
			},
			.externals = { "qt", "sqlite" },
		};
	std::vector<Source> qookie_mocs =
		eval_mocs("src",
		          {
		           { "mainwindow.h", "moc_mainwindow.cc"},
		           { "viewer.h",     "moc_viewer.cc"},
		           { "client.h",     "moc_client.cc"},
		          });
	for(const auto& moc : qookie_mocs)
	{
		qookie.sources.push_back(moc);
	}

	//
	// Qookie-cast client
	//
	BuildConfiguration qookie_cast_client =
		{
			.target = "qookie-cast-client",  // output filename
			.sources = {
				"src/qookie-cast-client.cc",
			},
			.flags = {
				.cxxflags = {
					"-fPIC",
					"-Wall", "-Werror", "-Wextra",// "-Wconversion",
					"-Wno-deprecated-copy",
					"-g",
				},
			},
			.externals = {"qt"},
		};

	std::vector<Source> qookie_cast_client_mocs =
		eval_mocs("src",
		          {
		           { "qookie-cast-client.h", "moc_qookie-cast-client.cc"},
		          });
	for(const auto& moc : qookie_cast_client_mocs)
	{
		qookie_cast_client.sources.push_back(moc);
	}

	return {qookie, qookie_cast_client};
}

ExternalConfigurations ctorExtConfigs()
{
	return
	{
		{
			.name = "qt",
			.external = ExternalManual{
				.flags = {
					.cxxflags = {
						"-I/usr/include/qt5",
					},
					.ldflags = {
						"-lQt5Core",
						"-lQt5Network",
						"-lQt5Gui",
						"-lQt5Widgets",
					},
				},
			},
		},
		{
			.name = "sqlite",
			.external = ExternalManual{
				.flags = {
					.ldflags = {
						"-lsqlite3",
					},
				},
			},
		},
	};
}
}

// Register callbacks
REG(myConfigs);
REG(ctorExtConfigs);