forked from SoftwareNetwork/sw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.cpp
377 lines (336 loc) · 16.1 KB
/
sw.cpp
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#pragma sw require header pub.egorpugin.primitives.tools.embedder-master
#pragma sw require header org.sw.demo.google.grpc.cpp.plugin
#pragma sw require header org.sw.demo.lexxmark.winflexbison.bison
#pragma sw require header org.sw.demo.qtproject.qt.base.tools.moc
void build(Solution &s)
{
auto &p = s.addProject("sw.client", "0.4.2");
p += Git("https://github.com/SoftwareNetwork/sw", "", "master");
auto &support = p.addTarget<LibraryTarget>("support");
{
support.ApiName = "SW_SUPPORT_API";
support.ExportIfStatic = true;
support += cpp17;
support += "src/sw/support/.*"_rr;
auto cmddep = "pub.egorpugin.primitives.command-master"_dep;
auto verdep = "pub.egorpugin.primitives.version-master"_dep;
auto srcdep = "pub.egorpugin.primitives.source-master"_dep;
support.Public +=
cmddep, verdep, srcdep,
"pub.egorpugin.primitives.date_time-master"_dep,
"pub.egorpugin.primitives.http-master"_dep,
"pub.egorpugin.primitives.hash-master"_dep,
"pub.egorpugin.primitives.log-master"_dep,
"pub.egorpugin.primitives.executor-master"_dep,
"pub.egorpugin.primitives.symbol-master"_dep,
"org.sw.demo.boost.property_tree"_dep,
"org.sw.demo.boost.stacktrace"_dep;
//cmddep->getSettings()["export-if-static"] = "true";
//cmddep->getSettings()["export-if-static"].setRequired();
verdep->getSettings()["export-if-static"] = "true";
verdep->getSettings()["export-if-static"].setRequired();
srcdep->getSettings()["export-if-static"] = "true";
srcdep->getSettings()["export-if-static"].setRequired();
if (support.getBuildSettings().TargetOS.Type == OSType::Windows)
{
support.Protected += "_CRT_SECURE_NO_WARNINGS"_d;
support.Public += "UNICODE"_d;
}
if (support.getCompilerType() != CompilerType::MSVC &&
support.getCompilerType() != CompilerType::ClangCl)
{
support.Protected.CompileOptions.push_back("-Wall");
support.Protected.CompileOptions.push_back("-Wextra");
}
if (support.getCompilerType() == CompilerType::ClangCl)
{
support.Protected.CompileOptions.push_back("-Wno-macro-redefined");
support.Protected.CompileOptions.push_back("-Wno-microsoft-template");
support.Protected.CompileOptions.push_back("-Wno-deprecated-declarations"); // maybe use STL define instead?
support.Protected.CompileOptions.push_back("-Wno-assume");
}
}
auto &protos = p.addTarget<StaticLibraryTarget>("protos");
{
protos += cpp17;
protos += "src/sw/protocol/.*"_rr;
protos.Public += "pub.egorpugin.primitives.grpc_helpers-master"_dep;
ProtobufData d;
d.public_protobuf = true;
d.addIncludeDirectory(protos.SourceDir / "src");
for (auto &[p, _] : protos["src/sw/protocol/.*\\.proto"_rr])
gen_grpc_cpp("org.sw.demo.google.protobuf"_dep, "org.sw.demo.google.grpc.cpp.plugin"_dep, protos, p, d);
}
auto &manager = p.addTarget<LibraryTarget>("manager");
{
manager.ApiName = "SW_MANAGER_API";
manager.ExportIfStatic = true;
manager += cpp17;
manager.Public += "BOOST_DLL_USE_STD_FS"_def;
manager +=
"pub.egorpugin.primitives.csv-master"_dep;
manager.Public += support, protos,
"pub.egorpugin.primitives.db.sqlite3-master"_dep,
"pub.egorpugin.primitives.lock-master"_dep,
"pub.egorpugin.primitives.pack-master"_dep,
"pub.egorpugin.primitives.sw.settings-master"_dep,
"pub.egorpugin.primitives.yaml-master"_dep,
"org.sw.demo.nlohmann.json"_dep,
"org.sw.demo.boost.variant"_dep,
"org.sw.demo.boost.dll"_dep,
"org.sw.demo.rbock.sqlpp11_connector_sqlite3-master"_dep
;
manager.Public -= "pub.egorpugin.primitives.win32helpers-master"_dep;
if (manager.getBuildSettings().TargetOS.Type == OSType::Windows)
manager.Public += "pub.egorpugin.primitives.win32helpers-master"_dep;
manager += "src/sw/manager/.*"_rr;
manager.Public += "src/sw/manager/manager.natvis";
manager.Public.Definitions["VERSION_MAJOR"] += std::to_string(manager.getPackage().getVersion().getMajor());
manager.Public.Definitions["VERSION_MINOR"] += std::to_string(manager.getPackage().getVersion().getMinor());
manager.Public.Definitions["VERSION_PATCH"] += std::to_string(manager.getPackage().getVersion().getPatch());
embed2("pub.egorpugin.primitives.tools.embedder2-master"_dep, manager, "src/sw/manager/inserts/packages_db_schema.sql");
gen_sqlite2cpp("pub.egorpugin.primitives.tools.sqlpp11.sqlite2cpp-master"_dep,
manager, manager.SourceDir / "src/sw/manager/inserts/packages_db_schema.sql", "db_packages.h", "db::packages");
/*PrecompiledHeader pch;
if (!s.Variables["SW_SELF_BUILD"])
{
pch.header = manager.SourceDir / "src/sw/manager/pch.h";
pch.force_include_pch = true;
//manager.addPrecompiledHeader(pch);
}*/
}
auto &builder = p.addTarget<LibraryTarget>("builder");
{
builder.ApiName = "SW_BUILDER_API";
builder.ExportIfStatic = true;
builder += cpp17;
builder += "src/sw/builder/.*"_rr;
builder.Public += manager,
"org.sw.demo.preshing.junction-master"_dep,
"org.sw.demo.boost.graph"_dep,
"org.sw.demo.boost.serialization"_dep,
"org.sw.demo.microsoft.gsl"_dep,
"pub.egorpugin.primitives.emitter-master"_dep;
//if (!s.Variables["SW_SELF_BUILD"])
{
/*PrecompiledHeader pch;
pch.header = "src/sw/builder/pch.h";
pch.force_include_pch = true;*/
//builder.addPrecompiledHeader(pch);
}
}
auto &core = p.addTarget<LibraryTarget>("core");
{
core.ApiName = "SW_CORE_API";
core.ExportIfStatic = true;
core += cpp17;
core.Public += builder;
core += "src/sw/core/.*"_rr;
core += "org.sw.demo.Neargye.magic_enum"_dep;
embed2("pub.egorpugin.primitives.tools.embedder2-master"_dep, core, "src/sw/core/inserts/input_db_schema.sql");
gen_sqlite2cpp("pub.egorpugin.primitives.tools.sqlpp11.sqlite2cpp-master"_dep,
core, core.SourceDir / "src/sw/core/inserts/input_db_schema.sql", "db_inputs.h", "db::inputs");
}
auto &cpp_driver = p.addTarget<LibraryTarget>("driver.cpp");
{
cpp_driver.ApiName = "SW_DRIVER_CPP_API";
cpp_driver.ExportIfStatic = true;
cpp_driver.PackageDefinitions = true;
cpp_driver.WholeArchive = true;
cpp_driver += cpp17;
cpp_driver.Public += core,
"pub.egorpugin.primitives.patch-master"_dep,
"org.sw.demo.ToruNiina.toml11"_dep,
"org.sw.demo.boost.assign"_dep,
"org.sw.demo.boost.bimap"_dep,
"org.sw.demo.boost.uuid"_dep;
cpp_driver.Public -= "org.sw.demo.giovannidicanio.winreg"_dep;
cpp_driver += "src/sw/driver/.*"_rr;
cpp_driver -= "src/sw/driver/misc/delay_load_helper.cpp";
gen_flex_bison("org.sw.demo.lexxmark.winflexbison"_dep, cpp_driver, "src/sw/driver/bazel/lexer.ll", "src/sw/driver/bazel/grammar.yy");
if (cpp_driver.getCompilerType() == CompilerType::MSVC || cpp_driver.getCompilerType() == CompilerType::ClangCl)
cpp_driver.CompileOptions.push_back("-bigobj");
if (cpp_driver.getBuildSettings().TargetOS.Type == OSType::Windows)
{
cpp_driver.Public += "org.sw.demo.giovannidicanio.winreg"_dep;
cpp_driver += "dbghelp.lib"_slib;
cpp_driver += "OleAut32.lib"_slib;
}
//else if (s.getBuildSettings().Native.CompilerType == CompilerType::GNU)
//cpp_driver.CompileOptions.push_back("-Wa,-mbig-obj");
if (cpp_driver.getBuildSettings().Native.LibrariesType == LibraryType::Shared)
cpp_driver += "SW_DRIVER_SHARED_BUILD"_def;
{
auto &self_builder = cpp_driver.addTarget<ExecutableTarget>("self_builder");
self_builder.PackageDefinitions = true;
self_builder += cpp17;
self_builder += "src/sw/tools/self_builder.cpp";
self_builder +=
core,
"pub.egorpugin.primitives.emitter-master"_dep,
"pub.egorpugin.primitives.sw.main-master"_dep;
auto c = cpp_driver.addCommand();
c << cmd::prog(self_builder)
<< cmd::out("build_self.generated.h")
<< cmd::out("build_self.packages.generated.h")
;
}
{
auto &cl_generator = cpp_driver.addTarget<ExecutableTarget>("cl_generator");
cl_generator.PackageDefinitions = true;
cl_generator += cpp17;
cl_generator += "src/sw/tools/cl_generator.*"_rr;
cl_generator +=
"pub.egorpugin.primitives.emitter-master"_dep,
"pub.egorpugin.primitives.yaml-master"_dep,
"pub.egorpugin.primitives.main-master"_dep;
auto c = cpp_driver.addCommand();
c << cmd::prog(cl_generator)
<< cmd::in("src/sw/driver/options_cl.yml")
<< cmd::out("options_cl.generated.h")
<< cmd::out("options_cl.generated.cpp", cmd::Skip)
;
std::dynamic_pointer_cast<::sw::driver::Command>(c.getCommand())->ignore_deps_generated_commands = true;
// make sure this is exported header, so we depend on it
cpp_driver.Public += "options_cl.generated.h";
}
//if (!s.Variables["SW_SELF_BUILD"])
{
/*PrecompiledHeader pch;
pch.header = "src/sw/driver/pch.h";
pch.force_include_pch = true;*/
//cpp_driver.addPrecompiledHeader(pch);
}
embed2("pub.egorpugin.primitives.tools.embedder2-master"_dep, cpp_driver, "src/sw/driver/sw1.h");
embed2("pub.egorpugin.primitives.tools.embedder2-master"_dep, cpp_driver, "src/sw/driver/sw_check_abi_version.h");
embed2("pub.egorpugin.primitives.tools.embedder2-master"_dep, cpp_driver, "src/sw/driver/misc/delay_load_helper.cpp");
// preprocess sw.h
/*if (!cpp_driver.DryRun)
{
auto pp = cpp_driver.BinaryPrivateDir / "sw.pp";
auto f = cpp_driver["src/sw/driver/misc/sw.cpp"].as<NativeSourceFile *>();
if (!f)
throw SW_RUNTIME_ERROR("cannot cast to NativeSourceFile");
// for cmdline build
f->skip_linking = true;
f->fancy_name = "[preprocess forced include header]";
if (auto c = f->compiler->as<VisualStudioCompiler *>())
{
c->PreprocessToFile = true;
c->PreprocessSupressLineDirectives = true;
c->PreprocessFileName = pp;
File(pp, cpp_driver.getFs()).setGenerated(true);
}
else
SW_UNIMPLEMENTED;
cpp_driver += pp; // mark as generated (to add into vs solution)
embed2("pub.egorpugin.primitives.tools.embedder2-master"_dep, cpp_driver, pp, cpp_driver.BinaryPrivateDir / "sw.pp.emb", 1);
// exclude
cpp_driver.add(sw::CallbackType::EndPrepare, [&cpp_driver, f]()
{
cpp_driver -= "src/sw/driver/misc/sw.cpp";
auto c = f->compiler->getCommand(cpp_driver);
// for ide build
c->inputs.erase(cpp_driver.SourceDir / "src/sw/driver/misc/sw.cpp");
});
}*/
}
auto &client = p.addTarget<ExecutableTarget>("sw", "1.0.0");
auto &client_common = client.addTarget<LibraryTarget>("common");
{
client_common.ApiName = "SW_CLIENT_COMMON_API";
client_common.PackageDefinitions = true;
client_common.SwDefinitions = true;
client_common.StartupProject = true;
client_common += "src/sw/client/common/.*"_rr;
client_common += cpp17;
client_common.Public += core, cpp_driver;
embed2("pub.egorpugin.primitives.tools.embedder2-master"_dep, client_common, "src/sw/client/common/inserts/SWConfig.cmake");
embed2("pub.egorpugin.primitives.tools.embedder2-master"_dep, client_common, "src/sw/client/common/inserts/project_templates.yml");
generate_cl("pub.egorpugin.primitives.tools.cl_generator-master"_dep, client_common,
"src/sw/client/common/cl.yml", "llvm");
}
// client
{
client.PackageDefinitions = true;
client.SwDefinitions = true;
client.StartupProject = true;
client += "src/sw/client/cli/.*"_rr;
client += cpp17;
client += client_common,
//"org.sw.demo.microsoft.mimalloc"_dep,
"pub.egorpugin.primitives.sw.main-master"_dep
;
if (client.getCompilerType() == CompilerType::MSVC)
client.CompileOptions.push_back("-bigobj");
if (client.getBuildSettings().TargetOS.Type != OSType::Windows)
{
//client.getSelectedTool()->LinkOptions.push_back("-static-libstdc++");
//client.getSelectedTool()->LinkOptions.push_back("-static-libgcc");
// needed to export all shared symbols
// so dlopen will work for plugins
//client.LinkOptions.push_back("-Wl,--export-dynamic");
//client.LinkOptions.push_back("-Wl,-export-dynamic");
client.LinkOptions.push_back("-rdynamic");
}
if (client.getCompilerType() == CompilerType::MSVC)
client.CompileOptions.push_back("-wd4275");
create_git_revision("pub.egorpugin.primitives.tools.create_git_rev-master"_dep, client);
}
// tests
{
// at the moment tests cannot run in parallel
auto p = std::make_shared<sw::ResourcePool>(1);
auto add_build_test = [&cpp_driver, &client, &p](const path &dir)
{
auto t = cpp_driver.addTest(client);
t->pool = p;
t->push_back("build");
t->push_back(dir);
return t;
};
auto add_configs = [](auto &c)
{
c->push_back("-static");
c->push_back("-shared");
c->push_back("-config=d,msr,rwdi,r");
};
auto root = client.SourceDir / "test" / "build";
auto add_build_test_with_configs = [&add_build_test, &add_configs, &root](const auto &dir)
{
auto t = add_build_test(root / dir);
t.getCommand()->name = dir;
add_configs(t.getCommand());
return t;
};
add_build_test_with_configs("simple/sw.cpp");
add_build_test_with_configs("c/exe");
add_build_test_with_configs("c/api");
add_build_test_with_configs("cpp/static");
add_build_test_with_configs("cpp/multiconf");
add_build_test_with_configs("cpp/pch");
}
if (s.getExternalVariables()["with-gui"] != "true")
return;
auto &gui = client.addTarget<ExecutableTarget>("gui", "0.4.0");
{
gui.PackageDefinitions = true;
gui.SwDefinitions = true;
gui += "src/sw/client/gui/.*"_rr;
gui += cpp17;
gui += client_common;
gui += "org.sw.demo.qtproject.qt.base.widgets"_dep;
gui += "org.sw.demo.qtproject.qt.base.winmain"_dep;
gui += "org.sw.demo.qtproject.qt.base.plugins.platforms.windows"_dep;
gui += "org.sw.demo.qtproject.qt.base.plugins.styles.windowsvista"_dep;
gui += "org.sw.demo.qtproject.qt.labs.vstools.natvis-dev"_dep;
gui -= "org.sw.demo.qtproject.qt.winextras"_dep;
if (client.getBuildSettings().TargetOS.Type == OSType::Windows)
gui += "org.sw.demo.qtproject.qt.winextras"_dep;
if (auto L = gui.getSelectedTool()->as<VisualStudioLinker*>(); L)
L->Subsystem = vs::Subsystem::Windows;
qt_moc_rcc_uic("org.sw.demo.qtproject.qt"_dep, gui);
qt_tr("org.sw.demo.qtproject.qt"_dep, gui);
create_git_revision("pub.egorpugin.primitives.tools.create_git_rev-master"_dep, gui);
}
}