-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAppCMakeGenerator.cpp
More file actions
1583 lines (1284 loc) · 44.5 KB
/
Copy pathAppCMakeGenerator.cpp
File metadata and controls
1583 lines (1284 loc) · 44.5 KB
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
*
* @file AppCMakeGenerator.cpp
* @author Gaspard Kirira
*
* Copyright 2026, Gaspard Kirira. All rights reserved.
* https://github.com/vixcpp/vix
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
* Vix.cpp
*
* CMake generator for simple vix.app projects.
*
*/
#include <vix/cli/app/AppCMakeGenerator.hpp>
#include <vix/cli/modules/ModuleManifest.hpp>
#include <vix/cli/modules/ModuleGraph.hpp>
#include <vix/cli/modules/DependencyOwnership.hpp>
#include <algorithm>
#include <cctype>
#include <fstream>
#include <sstream>
#include <system_error>
namespace vix::cli::app
{
namespace
{
// ---------------------------------------------------------------
// Quoting and path helpers
// ---------------------------------------------------------------
static std::string cmake_quote(const std::string &value)
{
std::string out;
out.reserve(value.size() + 8);
out.push_back('"');
for (char c : value)
{
if (c == '\\')
out += "\\\\";
else if (c == '"')
out += "\\\"";
else
out.push_back(c);
}
out.push_back('"');
return out;
}
static std::string cmake_path(const fs::path &path)
{
return path.lexically_normal().generic_string();
}
static std::string cmake_quoted_path(const fs::path &path)
{
return cmake_quote(cmake_path(path));
}
static fs::path absolute_project_path(
const fs::path &projectDir,
const std::string &relativePath)
{
const fs::path path(relativePath);
if (path.is_absolute())
return path.lexically_normal();
return (projectDir / path).lexically_normal();
}
static std::string lower_copy(std::string value)
{
for (char &c : value)
{
c = static_cast<char>(
std::tolower(static_cast<unsigned char>(c)));
}
return value;
}
static std::string normalize_module_id(std::string name)
{
name.erase(
name.begin(),
std::find_if(
name.begin(),
name.end(),
[](unsigned char c)
{
return std::isspace(c) == 0;
}));
name.erase(
std::find_if(
name.rbegin(),
name.rend(),
[](unsigned char c)
{
return std::isspace(c) == 0;
})
.base(),
name.end());
for (char &c : name)
{
if (c == '-')
c = '_';
}
return name;
}
static fs::path module_manifest_path(
const fs::path &projectDir,
const AppModule &module)
{
const std::string normalized =
normalize_module_id(module.name);
const std::string path =
module.path.empty() ? ("modules/" + normalized) : module.path;
return absolute_project_path(projectDir, path) / "vix.module";
}
static bool app_needs_registry_deps_loader(
const AppManifest &manifest,
const vix::cli::modules::DependencyOwnership &ownership)
{
if (!manifest.deps.empty() || !manifest.gitDependencies.empty())
return true;
return std::any_of(ownership.requirements.begin(), ownership.requirements.end(), [](const auto &item) {
return item.owner.active && (item.source == vix::cli::modules::DependencySource::Registry || item.source == vix::cli::modules::DependencySource::Git);
});
}
static void emit_module_links_for_loader(
std::ostringstream &out,
const vix::cli::modules::DependencyOwnership &ownership)
{
bool wroteHeader = false;
std::string currentModule;
for (const auto &link : ownership.links)
{
if (link.owner.kind != vix::cli::modules::DependencyOwnerKind::Module ||
!link.owner.active ||
(link.source != vix::cli::modules::DependencySource::Registry && link.source != vix::cli::modules::DependencySource::Git))
continue;
const std::string normalized = vix::cli::modules::ModuleGraph::canonical_identity(link.owner.module);
if (!wroteHeader)
{
out << "# Module dependency links declared in vix.module\n";
wroteHeader = true;
}
if (currentModule != normalized)
{
if (!currentModule.empty()) out << ")\n\n";
currentModule = normalized;
out << "set(VIX_MODULE_" << normalized << "_LINKS\n";
}
out << " " << link.target << "\n";
}
if (!currentModule.empty()) out << ")\n\n";
}
static bool supports_generated_app_modules(
const AppManifest &manifest)
{
if (manifest.type != AppTargetType::Executable)
return false;
// The generated module bridge includes and uses the Vix application
// runtime. A plain C++ executable declared in vix.app must remain
// usable with only its own dependencies, so only generate that bridge
// when the application explicitly links the umbrella Vix target.
return std::any_of(
manifest.links.begin(),
manifest.links.end(),
[](const std::string &link)
{
return link == "vix::vix" || link == "Vix::vix";
});
}
static bool is_routed_app_module(
const AppModule &module)
{
if (!module.enabled)
return false;
const std::string kind = lower_copy(module.kind);
return kind == "backend" ||
kind == "service" ||
kind == "app";
}
static bool is_runtime_app_module(
const AppModule &module,
const fs::path &projectDir)
{
if (!module.enabled)
return false;
const fs::path manifestPath =
module_manifest_path(projectDir, module);
const auto loaded = vix::cli::modules::load_module_manifest(manifestPath);
const std::string workflow = loaded.success() ? lower_copy(loaded.manifest.workflow) : "";
if (workflow == "websocket.client")
return false;
const bool runtime = loaded.success() && loaded.manifest.runtime;
if (runtime)
{
return true;
}
return workflow.rfind("websocket.", 0) == 0;
}
static std::vector<AppModule> enabled_runtime_app_modules(
const AppManifest &manifest,
const fs::path &projectDir)
{
std::vector<AppModule> out;
for (const AppModule &module : manifest.appModules)
{
if (is_runtime_app_module(module, projectDir))
out.push_back(module);
}
return out;
}
static std::string module_class_name(const std::string &module)
{
const std::string normalized = normalize_module_id(module);
std::string out;
bool upperNext = true;
for (char c : normalized)
{
if (c == '_' || c == '-')
{
upperNext = true;
continue;
}
if (upperNext)
{
out.push_back(static_cast<char>(
std::toupper(static_cast<unsigned char>(c))));
upperNext = false;
}
else
{
out.push_back(c);
}
}
if (out.empty())
out = "Module";
return out;
}
static fs::path generated_modules_include_dir(
const fs::path &projectDir)
{
return projectDir / ".vix" / "generated" / "app" / "include";
}
static fs::path generated_modules_header_path(
const fs::path &projectDir)
{
return generated_modules_include_dir(projectDir) / "vix_app_modules.hpp";
}
static fs::path generated_modules_cpp_path(
const fs::path &projectDir)
{
return projectDir / ".vix" / "generated" / "app" / "vix_app_modules.cpp";
}
static std::string generate_app_modules_header_content()
{
std::ostringstream out;
out << "#pragma once\n\n";
out << "// Auto-generated by Vix from vix.app.\n";
out << "// Do not edit this file directly.\n\n";
out << "#include <memory>\n\n";
out << "namespace vix\n";
out << "{\n";
out << " class App;\n";
out << "}\n\n";
out << "namespace vix::config\n";
out << "{\n";
out << " class Config;\n";
out << "}\n\n";
out << "namespace vix::executor\n";
out << "{\n";
out << " class RuntimeExecutor;\n";
out << "}\n\n";
out << "namespace vix::app_generated\n";
out << "{\n";
out << " void register_app_modules(vix::App &app);\n\n";
out << " int run_app(\n";
out << " vix::App &app,\n";
out << " const vix::config::Config &cfg,\n";
out << " std::shared_ptr<vix::executor::RuntimeExecutor> executor);\n";
out << "} // namespace vix::app_generated\n";
return out.str();
}
static std::string generate_app_modules_cpp_content(
const AppManifest &manifest,
const fs::path &projectDir)
{
std::ostringstream out;
out << "// Auto-generated by Vix from vix.app.\n";
out << "// Do not edit this file directly.\n\n";
out << "#include <vix_app_modules.hpp>\n\n";
out << "#include <vix/app/App.hpp>\n";
out << "#include <vix/config/Config.hpp>\n";
out << "#include <vix/executor/RuntimeExecutor.hpp>\n\n";
out << "#include <utility>\n\n";
for (const AppModule &module : manifest.appModules)
{
if (!is_routed_app_module(module))
continue;
const std::string normalized =
normalize_module_id(module.name);
const std::string classBase =
module_class_name(normalized);
out << "#include <"
<< normalized
<< "/"
<< classBase
<< "Module.hpp>\n";
}
out << "\n";
out << "namespace vix::app_generated\n";
out << "{\n";
out << " void register_app_modules(vix::App &app)\n";
out << " {\n";
out << " (void)app;\n\n";
for (const AppModule &module : manifest.appModules)
{
if (!is_routed_app_module(module))
continue;
const std::string normalized =
normalize_module_id(module.name);
const std::string classBase =
module_class_name(normalized);
out << " "
<< manifest.name
<< "::"
<< normalized
<< "::"
<< classBase
<< "Module::register_routes(app);\n";
}
out << " }\n";
const std::vector<AppModule> runtimeModules =
enabled_runtime_app_modules(manifest, projectDir);
if (runtimeModules.empty())
{
out << "\n";
out << " int run_app(\n";
out << " vix::App &app,\n";
out << " const vix::config::Config &cfg,\n";
out << " std::shared_ptr<vix::executor::RuntimeExecutor> executor)\n";
out << " {\n";
out << " (void)executor;\n";
out << " app.run(cfg);\n";
out << " return 0;\n";
out << " }\n";
}
else
{
const AppModule &module = runtimeModules.front();
const std::string normalized =
normalize_module_id(module.name);
const std::string classBase =
module_class_name(normalized);
out << "\n";
out << " int run_app(\n";
out << " vix::App &app,\n";
out << " const vix::config::Config &cfg,\n";
out << " std::shared_ptr<vix::executor::RuntimeExecutor> executor)\n";
out << " {\n";
out << " return "
<< manifest.name
<< "::"
<< normalized
<< "::"
<< classBase
<< "Module::run(app, cfg, std::move(executor));\n";
out << " }\n";
}
out << "} // namespace vix::app_generated\n";
return out.str();
}
static bool parse_registry_dep_alias(
const std::string &raw,
std::string &alias)
{
std::string value = raw;
value.erase(
value.begin(),
std::find_if(
value.begin(),
value.end(),
[](unsigned char c)
{
return std::isspace(c) == 0;
}));
value.erase(
std::find_if(
value.rbegin(),
value.rend(),
[](unsigned char c)
{
return std::isspace(c) == 0;
})
.base(),
value.end());
if (value.empty())
return false;
if (value.front() == '@')
value.erase(value.begin());
const std::size_t slash = value.find('/');
if (slash == std::string::npos ||
slash == 0 ||
slash + 1 >= value.size())
{
return false;
}
const std::size_t atVersion = value.find('@', slash + 1);
const std::string ns = value.substr(0, slash);
const std::string name =
atVersion == std::string::npos
? value.substr(slash + 1)
: value.substr(slash + 1, atVersion - slash - 1);
if (ns.empty() || name.empty())
return false;
alias = ns + "::" + name;
return true;
}
// ---------------------------------------------------------------
// Standard normalization
// ---------------------------------------------------------------
static int cpp_standard_number(const std::string &standard)
{
const std::string s = lower_copy(standard);
if (s == "c++11" || s == "cpp11" || s == "11")
return 11;
if (s == "c++14" || s == "cpp14" || s == "14")
return 14;
if (s == "c++17" || s == "cpp17" || s == "17")
return 17;
if (s == "c++20" || s == "cpp20" || s == "20")
return 20;
if (s == "c++23" || s == "cpp23" || s == "23")
return 23;
if (s == "c++26" || s == "cpp26" || s == "26")
return 26;
return 20;
}
// ---------------------------------------------------------------
// Atomic file write
// ---------------------------------------------------------------
static bool write_text_file_atomic(
const fs::path &path,
const std::string &content)
{
const fs::path parent = path.parent_path();
if (!parent.empty())
{
std::error_code ec;
fs::create_directories(parent, ec);
}
const fs::path tmp = path.string() + ".tmp";
{
std::ofstream out(tmp, std::ios::binary | std::ios::trunc);
if (!out)
return false;
out << content;
if (!out)
return false;
}
std::error_code ec;
fs::rename(tmp, path, ec);
if (!ec)
return true;
fs::remove(path, ec);
ec.clear();
fs::rename(tmp, path, ec);
return !ec;
}
static std::string read_text_file_or_empty(const fs::path &path)
{
std::ifstream in(path, std::ios::binary);
if (!in)
return {};
std::ostringstream out;
out << in.rdbuf();
return out.str();
}
static bool write_text_file_if_different(
const fs::path &path,
const std::string &content)
{
std::error_code ec;
if (fs::exists(path, ec) && !ec && read_text_file_or_empty(path) == content)
return true;
return write_text_file_atomic(path, content);
}
// ---------------------------------------------------------------
// Target type helpers
// ---------------------------------------------------------------
static std::string cmake_target_command(AppTargetType type)
{
switch (type)
{
case AppTargetType::Executable:
return "add_executable";
case AppTargetType::StaticLibrary:
return "add_library";
case AppTargetType::SharedLibrary:
return "add_library";
default:
return "add_executable";
}
}
static std::string cmake_library_kind(AppTargetType type)
{
switch (type)
{
case AppTargetType::StaticLibrary:
return " STATIC";
case AppTargetType::SharedLibrary:
return " SHARED";
case AppTargetType::Executable:
default:
return "";
}
}
// ---------------------------------------------------------------
// Generic emit helpers
// ---------------------------------------------------------------
static void emit_quoted_list(
std::ostringstream &out,
const std::string &command,
const std::string &targetName,
const std::vector<std::string> &values)
{
if (values.empty())
return;
out << command << "(" << targetName << " PRIVATE\n";
for (const std::string &value : values)
out << " " << cmake_quote(value) << "\n";
out << ")\n\n";
}
// Emit a list without quoting each entry. Used for CMake items that
// must remain syntactically meaningful — imported targets such as
// Threads::Threads or fmt::fmt, generator expressions, raw compiler
// and linker flags, and compile features like cxx_std_23. Quoting
// these would either cause CMake to treat them as plain strings or
// suppress flag expansion.
static void emit_raw_list(
std::ostringstream &out,
const std::string &command,
const std::string &targetName,
const std::vector<std::string> &values)
{
if (values.empty())
return;
out << command << "(" << targetName << " PRIVATE\n";
for (const std::string &value : values)
out << " " << value << "\n";
out << ")\n\n";
}
static void emit_path_list(
std::ostringstream &out,
const std::string &command,
const std::string &targetName,
const fs::path &projectDir,
const std::vector<std::string> &values)
{
if (values.empty())
return;
out << command << "(" << targetName << " PRIVATE\n";
for (const std::string &value : values)
{
const fs::path resolved = absolute_project_path(projectDir, value);
out << " " << cmake_quoted_path(resolved) << "\n";
}
out << ")\n\n";
}
// ---------------------------------------------------------------
// Section emitters
// ---------------------------------------------------------------
static void emit_header(std::ostringstream &out)
{
out << "# Auto-generated by Vix from vix.app\n";
out << "# Do not edit this file directly.\n\n";
out << "cmake_minimum_required(VERSION 3.24)\n\n";
}
static void emit_project(
std::ostringstream &out,
const std::string &targetName)
{
out << "project(" << targetName << " LANGUAGES CXX)\n\n";
}
static void emit_standard(
std::ostringstream &out,
const std::string &standard)
{
const int number = cpp_standard_number(standard);
out << "set(CMAKE_CXX_STANDARD " << number << ")\n";
out << "set(CMAKE_CXX_STANDARD_REQUIRED ON)\n";
out << "set(CMAKE_CXX_EXTENSIONS OFF)\n\n";
}
static void emit_enabled_modules_for_loader(
std::ostringstream &out,
const AppManifest &manifest)
{
if (manifest.appModules.empty() && manifest.modules.empty())
return;
out << "# Enabled application modules declared in vix.app\n";
out << "set(VIX_APP_NAME " << cmake_quote(manifest.name) << ")\n";
out << "set(VIX_ENABLED_MODULES\n";
for (const std::string &module : manifest.modules)
{
const std::string normalized = normalize_module_id(module);
out << " " << normalized << "\n";
}
out << ")\n";
for (const AppModule &module : manifest.appModules)
{
if (!module.enabled)
continue;
const std::string normalized =
normalize_module_id(module.name);
const std::string path =
module.path.empty()
? ("modules/" + normalized)
: module.path;
out << "set(VIX_MODULE_"
<< normalized
<< "_PATH "
<< cmake_quote(path)
<< ")\n";
}
out << "\n";
}
static void emit_modules_loader(
std::ostringstream &out,
const fs::path &projectDir)
{
const fs::path loader =
projectDir / "cmake" / "vix_modules.cmake";
out << "# Internal application modules declared by `vix modules`\n";
out << "if(EXISTS " << cmake_quoted_path(loader) << ")\n";
out << " include(" << cmake_quoted_path(loader) << ")\n";
out << "endif()\n\n";
}
static void emit_registry_deps_loader(
std::ostringstream &out,
const AppManifest &manifest,
const fs::path &projectDir,
const vix::cli::modules::DependencyOwnership &ownership)
{
if (!app_needs_registry_deps_loader(manifest, ownership))
return;
const fs::path depsFile =
fs::absolute(projectDir / ".vix" / "vix_deps.cmake").lexically_normal();
out << "# Dependencies declared in vix.app or enabled vix.module files\n";
out << "if(EXISTS " << cmake_quoted_path(depsFile) << ")\n";
out << " include(" << cmake_quoted_path(depsFile) << ")\n";
out << "else()\n";
out << " message(FATAL_ERROR \"Dependencies are declared by vix.app or enabled modules, but .vix/vix_deps.cmake was not found. Run: vix install\")\n";
out << "endif()\n\n";
}
static bool is_vix_package(const AppPackage &pkg)
{
const std::string name = lower_copy(pkg.name);
return name == "vix";
}
static bool is_threads_package(const AppPackage &pkg)
{
return lower_copy(pkg.name) == "threads";
}
static void emit_vix_package(std::ostringstream &out)
{
out << "find_package(vix QUIET CONFIG)\n";
out << "if (NOT vix_FOUND)\n";
out << " find_package(Vix CONFIG REQUIRED)\n";
out << "endif()\n";
}
static void emit_packages(
std::ostringstream &out,
const std::vector<AppPackage> &packages)
{
if (packages.empty())
return;
// `packages` only emits find_package() calls. Imported targets
// produced by these packages (e.g. Threads::Threads, fmt::fmt)
// must be added explicitly to `links` in the manifest. Keeping
// discovery and linking separate makes the manifest predictable.
out << "# Packages declared in vix.app\n";
out << "# Imported targets must be listed explicitly under `links`.\n";
for (const AppPackage &pkg : packages)
{
if (is_vix_package(pkg))
{
emit_vix_package(out);
continue;
}
if (is_threads_package(pkg))
{
// Threads is special: this hint must be set before
// find_package(Threads) for the pthread flag to be picked.
out << "set(THREADS_PREFER_PTHREAD_FLAG ON)\n";
}
out << "find_package(" << pkg.name;
if (!pkg.components.empty())
{
out << " COMPONENTS";
for (const std::string &component : pkg.components)
out << " " << component;
}
if (pkg.required)
out << " REQUIRED";
out << ")\n";
}
out << "\n";
}
static void emit_target(
std::ostringstream &out,
const AppManifest &manifest,
const std::string &targetName,
const fs::path &projectDir)
{
out << cmake_target_command(manifest.type)
<< "("
<< targetName
<< cmake_library_kind(manifest.type)
<< "\n";
for (const std::string &source : manifest.sources)
{
const fs::path resolved = absolute_project_path(projectDir, source);
out << " " << cmake_quoted_path(resolved) << "\n";
}
if (supports_generated_app_modules(manifest))
{
out << " "
<< cmake_quoted_path(generated_modules_cpp_path(projectDir))
<< "\n";
}
out << ")\n\n";
}
static void emit_includes_and_defines(
std::ostringstream &out,
const AppManifest &manifest,
const std::string &targetName,
const fs::path &projectDir)
{
emit_path_list(
out,
"target_include_directories",
targetName,
projectDir,
manifest.includeDirs);
if (supports_generated_app_modules(manifest))
{
out << "target_include_directories("
<< targetName
<< " PRIVATE\n";
out << " "
<< cmake_quoted_path(generated_modules_include_dir(projectDir))
<< "\n";
out << ")\n\n";
}
emit_quoted_list(
out,
"target_compile_definitions",
targetName,
manifest.defines);
}
static void emit_options_and_features(
std::ostringstream &out,
const AppManifest &manifest,
const std::string &targetName)
{
emit_raw_list(
out,
"target_compile_options",
targetName,
manifest.compileOptions);
emit_raw_list(
out,
"target_link_options",
targetName,
manifest.linkOptions);
emit_raw_list(
out,
"target_compile_features",
targetName,
manifest.compileFeatures);
}
static void emit_sanitizer_options(
std::ostringstream &out,
const std::string &targetName)
{
out << "# Sanitizer variant selected by vix build\n";
out << "if(DEFINED VIX_SANITIZER_MODE "
<< "AND NOT VIX_SANITIZER_MODE STREQUAL \"\")\n";
/*
* Give the command-line cache entry a stable type while preserving
* the value selected by Vix.
*/
out << " set(VIX_SANITIZER_MODE "
<< "\"${VIX_SANITIZER_MODE}\" "
<< "CACHE STRING "
<< "\"Vix sanitizer mode\" "
<< "FORCE)\n\n";
out << " if(NOT CMAKE_CXX_COMPILER_ID "
<< "MATCHES \"GNU|Clang|AppleClang\")\n";
out << " message(FATAL_ERROR "
<< "\"VIX_SANITIZER_MODE requires GCC or Clang\")\n";
out << " endif()\n\n";
out << " set(_vix_sanitizer_compile_options\n";
out << " -g3\n";
out << " -fno-omit-frame-pointer\n";
out << " -fno-optimize-sibling-calls\n";
out << " )\n";
out << " set(_vix_sanitizer_link_options)\n\n";
out << " if(VIX_SANITIZER_MODE STREQUAL \"address\")\n";
out << " list(APPEND _vix_sanitizer_compile_options\n";
out << " -fsanitize=address\n";
out << " )\n";
out << " list(APPEND _vix_sanitizer_link_options\n";