-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathcreate_project.cpp
More file actions
2802 lines (2376 loc) · 93.1 KB
/
create_project.cpp
File metadata and controls
2802 lines (2376 loc) · 93.1 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
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#define ENABLE_XCODE
#if (defined(_WIN32) || defined(WIN32)) && !defined(__GNUC__)
#define USE_WIN32_API
#endif
#if (defined(_WIN32) || defined(WIN32))
#define _WIN32_WINNT 0x0502
#include <windows.h>
#else
#include <dirent.h>
#include <errno.h>
#include <sstream>
#include <sys/param.h>
#include <sys/stat.h>
#endif
#include "create_project.h"
#include "config.h"
#include "cmake.h"
#include "codeblocks.h"
#include "msbuild.h"
#include "msvc.h"
#include "xcode.h"
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <sstream>
#include <stack>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <ctime>
// We can't use the common/util.h header here, since create_project
// is a standalone tool, and may be built individually from the rest
// of the devtools.
#ifdef ARRAYSIZE
#undef ARRAYSIZE
#endif
#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
namespace {
/**
* Converts the given path to only use slashes as
* delimiters.
* This means that for example the path:
* foo/bar\test.txt
* will be converted to:
* foo/bar/test.txt
*
* @param path Path string.
* @return Converted path.
*/
std::string unifyPath(const std::string &path);
/**
* Removes trailing slash from path if it exists
*
* @param path Path string.
*/
void removeTrailingSlash(std::string& path);
/**
* Display the help text for the program.
*
* @param exe Name of the executable.
*/
void displayHelp(const char *exe);
/**
* Build a list of options to enable or disable GCC warnings
*
* @param globalWarnings Resulting list of warnings
*/
void addGCCWarnings(StringList &globalWarnings);
} // End of anonymous namespace
enum ProjectType {
kProjectNone,
kProjectCMake,
kProjectCodeBlocks,
kProjectMSVC,
kProjectXcode
};
std::map<std::string, bool> isEngineEnabled;
static void fixupFeatures(ProjectType projectType, BuildSetup &setup);
static void fixupComponents(BuildSetup &setup);
int main(int argc, char *argv[]) {
#ifndef USE_WIN32_API
// Initialize random number generator for UUID creation
std::srand((unsigned int)std::time(nullptr));
#endif
if (argc < 2) {
displayHelp(argv[0]);
return -1;
}
const std::string srcDir = argv[1];
BuildSetup setup;
setup.srcDir = unifyPath(srcDir);
removeTrailingSlash(setup.srcDir);
setup.filePrefix = setup.srcDir;
setup.outputDir = '.';
setup.engines = parseEngines(setup.srcDir);
if (setup.engines.empty()) {
std::cout << "WARNING: No engines found in configure file or configure file missing in \"" << setup.srcDir << "\"\n";
return 0;
}
setup.features = getAllFeatures();
setup.components = getAllComponents(setup.srcDir, setup.features);
ProjectType projectType = kProjectNone;
const MSVCVersion *msvc = nullptr;
int msvcVersion = 0;
// Parse command line arguments
using std::cout;
for (int i = 2; i < argc; ++i) {
if (!std::strcmp(argv[i], "--list-engines")) {
cout << " The following enables are available in the " PROJECT_DESCRIPTION " source distribution\n"
<< " located at \"" << srcDir << "\":\n";
cout << " state | name | description\n\n";
cout.setf(std::ios_base::left, std::ios_base::adjustfield);
for (EngineDescList::const_iterator j = setup.engines.begin(); j != setup.engines.end(); ++j)
cout << ' ' << (j->enable ? " enabled" : "disabled") << " | " << std::setw((std::streamsize)15) << j->name << std::setw((std::streamsize)0) << " | " << j->desc << "\n";
cout.setf(std::ios_base::right, std::ios_base::adjustfield);
return 0;
} else if (!std::strcmp(argv[i], "--cmake")) {
if (projectType != kProjectNone) {
std::cerr << "ERROR: You cannot pass more than one project type!\n";
return -1;
}
projectType = kProjectCMake;
} else if (!std::strcmp(argv[i], "--codeblocks")) {
if (projectType != kProjectNone) {
std::cerr << "ERROR: You cannot pass more than one project type!\n";
return -1;
}
projectType = kProjectCodeBlocks;
} else if (!std::strcmp(argv[i], "--msvc")) {
if (projectType != kProjectNone) {
std::cerr << "ERROR: You cannot pass more than one project type!\n";
return -1;
}
projectType = kProjectMSVC;
#ifdef ENABLE_XCODE
} else if (!std::strcmp(argv[i], "--xcode")) {
if (projectType != kProjectNone) {
std::cerr << "ERROR: You cannot pass more than one project type!\n";
return -1;
}
projectType = kProjectXcode;
} else if (!std::strcmp(argv[i], "--ios")) {
setup.appleEmbedded = true;
} else if (!std::strcmp(argv[i], "--tvos")) {
setup.appleEmbedded = true;
#endif
} else if (!std::strcmp(argv[i], "--msvc-version")) {
if (i + 1 >= argc) {
std::cerr << "ERROR: Missing \"version\" parameter for \"--msvc-version\"!\n";
return -1;
}
msvcVersion = atoi(argv[++i]);
} else if (!strncmp(argv[i], "--enable-engine=", 16)) {
const char *names = &argv[i][16];
if (!*names) {
std::cerr << "ERROR: Invalid command \"" << argv[i] << "\"\n";
return -1;
}
TokenList tokens = tokenize(names, ',');
TokenList::const_iterator token = tokens.begin();
while (token != tokens.end()) {
std::string name = *token++;
if (!setEngineBuildState(name, setup.engines, true)) {
std::cerr << "ERROR: \"" << name << "\" is not a known engine!\n";
return -1;
}
}
} else if (!strncmp(argv[i], "--disable-engine=", 17)) {
const char *names = &argv[i][17];
if (!*names) {
std::cerr << "ERROR: Invalid command \"" << argv[i] << "\"\n";
return -1;
}
TokenList tokens = tokenize(names, ',');
TokenList::const_iterator token = tokens.begin();
while (token != tokens.end()) {
std::string name = *token++;
if (!setEngineBuildState(name, setup.engines, false)) {
std::cerr << "ERROR: \"" << name << "\" is not a known engine!\n";
return -1;
}
}
} else if (!strncmp(argv[i], "--enable-", 9)) {
const char *name = &argv[i][9];
if (!*name) {
std::cerr << "ERROR: Invalid command \"" << argv[i] << "\"\n";
return -1;
}
if (!std::strcmp(name, "all-engines")) {
for (EngineDescList::iterator j = setup.engines.begin(); j != setup.engines.end(); ++j)
j->enable = true;
} else if (!setFeatureBuildState(name, setup.features, true)) {
std::cerr << "ERROR: \"" << name << "\" is not a feature!\n";
return -1;
}
} else if (!strncmp(argv[i], "--disable-", 10)) {
const char *name = &argv[i][10];
if (!*name) {
std::cerr << "ERROR: Invalid command \"" << argv[i] << "\"\n";
return -1;
}
if (!std::strcmp(name, "all-engines")) {
for (EngineDescList::iterator j = setup.engines.begin(); j != setup.engines.end(); ++j)
j->enable = false;
} else if (!setFeatureBuildState(name, setup.features, false)) {
std::cerr << "ERROR: \"" << name << "\" is not a feature!\n";
return -1;
}
} else if (!std::strcmp(argv[i], "--file-prefix")) {
if (i + 1 >= argc) {
std::cerr << "ERROR: Missing \"prefix\" parameter for \"--file-prefix\"!\n";
return -1;
}
setup.filePrefix = unifyPath(argv[++i]);
removeTrailingSlash(setup.filePrefix);
} else if (!std::strcmp(argv[i], "--output-dir")) {
if (i + 1 >= argc) {
std::cerr << "ERROR: Missing \"path\" parameter for \"--output-dir\"!\n";
return -1;
}
setup.outputDir = unifyPath(argv[++i]);
removeTrailingSlash(setup.outputDir);
} else if (!std::strcmp(argv[i], "--include-dir")) {
if (i + 1 >= argc) {
std::cerr << "ERROR: Missing \"path\" parameter for \"--include-dir\"!\n";
return -1;
}
std::string includeDir = unifyPath(argv[++i]);
removeTrailingSlash(includeDir);
setup.includeDirs.push_back(includeDir);
} else if (!std::strcmp(argv[i], "--library-dir")) {
if (i + 1 >= argc) {
std::cerr << "ERROR: Missing \"path\" parameter for \"--library-dir\"!\n";
return -1;
}
std::string libraryDir = unifyPath(argv[++i]);
removeTrailingSlash(libraryDir);
setup.libraryDirs.push_back(libraryDir);
} else if (!std::strcmp(argv[i], "--build-events")) {
setup.runBuildEvents = true;
} else if (!std::strcmp(argv[i], "--installer")) {
setup.runBuildEvents = true;
setup.createInstaller = true;
} else if (!std::strcmp(argv[i], "--tools")) {
setup.devTools = true;
} else if (!std::strcmp(argv[i], "--tests")) {
setup.tests = true;
} else if (!std::strcmp(argv[i], "--sdl1")) {
setup.useSDL = kSDLVersion1;
} else if (!std::strcmp(argv[i], "--sdl2")) {
setup.useSDL = kSDLVersion2;
} else if (!std::strcmp(argv[i], "--sdl3")) {
setup.useSDL = kSDLVersion3;
} else if (!std::strcmp(argv[i], "--use-canonical-lib-names")) {
// Deprecated: Kept here so it doesn't error
} else if (!std::strcmp(argv[i], "--use-slnx")) {
setup.useSlnx = true;
} else if (!std::strcmp(argv[i], "--use-windows-unicode")) {
setup.useWindowsUnicode = true;
} else if (!std::strcmp(argv[i], "--use-windows-ansi")) {
setup.useWindowsUnicode = false;
} else if (!std::strcmp(argv[i], "--use-windows-subsystem")) {
setup.useWindowsSubsystem = true;
} else if (!std::strcmp(argv[i], "--use-xcframework")) {
setup.useXCFramework = true;
} else if (!std::strcmp(argv[i], "--vcpkg")) {
setup.useVcpkg = true;
} else if (!std::strcmp(argv[i], "--libs-path")) {
if (i + 1 >= argc) {
std::cerr << "ERROR: Missing \"path\" parameter for \"--libs-path\"!\n";
return -1;
}
std::string libsDir = unifyPath(argv[++i]);
removeTrailingSlash(libsDir);
setup.libsDir = libsDir;
} else if (!std::strcmp(argv[i], "--list-components")) {
for (ComponentList::const_iterator j = setup.components.begin(); j != setup.components.end(); ++j)
cout << ' ' << j->description << "\n";
return 0;
} else {
std::cerr << "ERROR: Unknown parameter \"" << argv[i] << "\"\n";
return -1;
}
}
// When building tests, disable some features and all engines
if (setup.tests) {
setup.useStaticDetection = false;
setFeatureBuildState("mt32emu", setup.features, false);
setFeatureBuildState("eventrecorder", setup.features, false);
for (EngineDescList::iterator j = setup.engines.begin(); j != setup.engines.end(); ++j)
j->enable = false;
} else if (setup.devTools) {
setup.useStaticDetection = false;
}
if (!getFeatureBuildState("detection-static", setup.features)) {
setup.useStaticDetection = false;
}
fixupFeatures(projectType, setup);
// Disable engines for which we are missing dependencies and mark components as needed
for (EngineDescList::const_iterator i = setup.engines.begin(); i != setup.engines.end(); ++i) {
if (!i->enable) {
continue;
}
bool enabled = true;
std::list<FeatureList::iterator> missingFeatures;
for (StringList::const_iterator ef = i->requiredFeatures.begin(); ef != i->requiredFeatures.end(); ++ef) {
FeatureList::iterator feature = std::find(setup.features.begin(), setup.features.end(), *ef);
if (feature == setup.features.end()) {
std::cerr << "ERROR: Missing feature " << *ef << " from engine " << i->name << '\n';
return -1;
} else if (!feature->enable) {
enabled = false;
missingFeatures.push_back(feature);
}
}
isEngineEnabled[i->name] = enabled;
if (!enabled) {
setEngineBuildState(i->name, setup.engines, false);
std::cout << "WARNING: Disabling engine " << i->desc << " because the following dependencies are unmet:";
for (std::list<FeatureList::iterator>::iterator itr = missingFeatures.begin(); itr != missingFeatures.end(); itr++) {
std::cout << " " << (*itr)->description;
}
std::cout << "\n";
continue;
}
// Mark components as needed now the engine is definitely enabled
for (StringList::const_iterator ef = i->requiredFeatures.begin(); ef != i->requiredFeatures.end(); ++ef) {
ComponentList::iterator component = std::find(setup.components.begin(), setup.components.end(), *ef);
if (component == setup.components.end()) {
continue;
}
component->needed = true;
}
for (StringList::const_iterator ef = i->wishedComponents.begin(); ef != i->wishedComponents.end(); ++ef) {
ComponentList::iterator component = std::find(setup.components.begin(), setup.components.end(), *ef);
if (component == setup.components.end()) {
std::cerr << "ERROR: Missing component " << *ef << " from engine " << i->name << '\n';
return -1;
}
component->needed = true;
}
}
// Disable unused features / components
if (!setup.tests)
disableComponents(setup.components);
// Handle hard-coded component logic
fixupComponents(setup);
// Print status
cout << "Enabled engines:\n\n";
for (EngineDescList::const_iterator i = setup.engines.begin(); i != setup.engines.end(); ++i) {
if (i->enable)
cout << " " << i->desc << '\n';
}
cout << "\nDisabled engines:\n\n";
for (EngineDescList::const_iterator i = setup.engines.begin(); i != setup.engines.end(); ++i) {
if (!i->enable)
cout << " " << i->desc << '\n';
}
cout << "\nEnabled features:\n\n";
for (FeatureList::const_iterator i = setup.features.begin(); i != setup.features.end(); ++i) {
if (i->enable)
cout << " " << i->description << '\n';
}
cout << "\nDisabled features:\n\n";
for (FeatureList::const_iterator i = setup.features.begin(); i != setup.features.end(); ++i) {
if (!i->enable)
cout << " " << i->description << '\n';
}
// Check if tools and tests are enabled simultaneously
if (setup.devTools && setup.tests) {
std::cerr << "ERROR: The tools and tests projects cannot be created simultaneously\n";
return -1;
}
// Setup defines and libraries
setup.defines = getEngineDefines(setup.engines);
// Add features
StringList featureDefines = getFeatureDefines(setup.features);
setup.defines.splice(setup.defines.begin(), featureDefines);
if (projectType == kProjectXcode) {
setup.defines.push_back("POSIX");
if (setup.appleEmbedded) {
setup.defines.push_back("IPHONE");
setup.defines.push_back("IPHONE_IOS7");
setup.defines.push_back("SCUMMVM_NEON");
} else {
setup.defines.push_back("MACOSX");
// We have two TTS backends, one that is deprecated in macOS 11 and a newer one
// that requires macOS 10.14 minimum. Use the new one when compiling for ARM, and
// otherwise (PPC, Intel) use the old one. We assume the current arch to compile
// create_project is also the one we will be compiling ScummVM for.
#if !defined(__aarch64__)
if (getFeatureBuildState("tts", setup.features)) {
setup.defines.push_back("USE_NS_SPEECH_SYNTHESIZER");
}
#endif
}
} else if (projectType == kProjectMSVC || projectType == kProjectCodeBlocks) {
setup.defines.push_back("WIN32");
setup.win32 = true;
} else {
// As a last resort, select the backend files to build based on the platform used to build create_project.
// This is broken when cross compiling.
#if defined(_WIN32) || defined(WIN32)
setup.defines.push_back("WIN32");
setup.win32 = true;
#else
setup.defines.push_back("POSIX");
#endif
}
for (FeatureList::const_iterator i = setup.features.begin(); i != setup.features.end(); ++i) {
if (i->enable) {
if (!strcmp(i->name, "updates"))
setup.defines.push_back("USE_SPARKLE");
else if (setup.win32 && !strcmp(i->name, "libcurl"))
setup.defines.push_back("CURL_STATICLIB");
else if (!strcmp(i->name, "fluidlite"))
setup.defines.push_back("USE_FLUIDSYNTH");
}
}
if (projectType != kProjectXcode || !setup.appleEmbedded) {
setup.defines.push_back("SDL_BACKEND");
if (setup.useSDL == kSDLVersion1) {
cout << "\nBuilding against SDL 1.2\n\n";
} else if (setup.useSDL == kSDLVersion2) {
cout << "\nBuilding against SDL 2\n\n";
setup.defines.push_back("USE_SDL2");
} else if (setup.useSDL == kSDLVersion3) {
cout << "\nBuilding against SDL 3\n\n";
setup.defines.push_back("USE_SDL3");
} else {
std::cerr << "ERROR: Unsupported SDL version\n";
return -1;
}
}
if (setup.useStaticDetection) {
setup.defines.push_back("DETECTION_STATIC");
}
if (getFeatureBuildState("opengl", setup.features)) {
setup.defines.push_back("USE_GLAD");
}
// HACK: Add IMGUI SDL Renderer support
if (getFeatureBuildState("imgui", setup.features)) {
// This needs SDL 2.0.18+
if (setup.useSDL == kSDLVersion2) {
setup.defines.push_back("USE_IMGUI_SDLRENDERER2");
} else if (setup.useSDL == kSDLVersion3) {
setup.defines.push_back("USE_IMGUI_SDLRENDERER3");
}
}
// List of global warnings and map of project-specific warnings
// FIXME: As shown below these two structures have different behavior for
// Code::Blocks and MSVC. In Code::Blocks this is used to enable *and*
// disable certain warnings (and some other not warning related flags
// actually...). While in MSVC this is solely for disabling warnings.
// That is really not nice. We should consider a nicer way of doing this.
StringList globalWarnings;
StringList globalErrors;
std::map<std::string, StringList> projectWarnings;
CreateProjectTool::ProjectProvider *provider = nullptr;
switch (projectType) {
default:
case kProjectNone:
std::cerr << "ERROR: No project type has been specified!\n";
return -1;
case kProjectCMake:
if (setup.devTools || setup.tests) {
std::cerr << "ERROR: Building tools or tests is not supported for the CMake project type!\n";
return -1;
}
addGCCWarnings(globalWarnings);
provider = new CreateProjectTool::CMakeProvider(globalWarnings, projectWarnings, globalErrors);
break;
case kProjectCodeBlocks:
if (setup.devTools || setup.tests) {
std::cerr << "ERROR: Building tools or tests is not supported for the CodeBlocks project type!\n";
return -1;
}
addGCCWarnings(globalWarnings);
provider = new CreateProjectTool::CodeBlocksProvider(globalWarnings, projectWarnings, globalErrors);
break;
case kProjectMSVC:
// Auto-detect if no version is specified
if (msvcVersion == 0) {
msvcVersion = getInstalledMSVC();
if (msvcVersion == 0) {
std::cerr << "ERROR: No Visual Studio versions found, please specify one with \"--msvc-version\"\n";
return -1;
} else {
cout << "Visual Studio " << msvcVersion << " detected\n\n";
}
}
msvc = getMSVCVersion(msvcVersion);
if (!msvc) {
std::cerr << "ERROR: Unsupported version: \"" << msvcVersion << "\" passed to \"--msvc-version\"!\n";
return -1;
}
if (setup.useSlnx && msvc->version < 17) {
std::cerr << "ERROR: Using SLNX solution files requires Visual Studio 2022 17.14 or higher\n";
return 1;
}
////////////////////////////////////////////////////////////////////////////
// For Visual Studio, all warnings are on by default in the project files,
// so we pass a list of warnings to disable globally or per-project
//
////////////////////////////////////////////////////////////////////////////
//
// 4068 (unknown pragma)
// only used in scumm engine to mark code sections
//
// 4100 (unreferenced formal parameter)
//
// 4103 (alignment changed after including header, may be due to missing #pragma pack(pop))
// used by pack-start / pack-end
//
// 4127 (conditional expression is constant)
// used in a lot of engines
//
// 4244 ('conversion' conversion from 'type1' to 'type2', possible loss of data)
// throws tons and tons of warnings, most of them false positives
//
// 4250 ('class1' : inherits 'class2::member' via dominance)
// two or more members have the same name. Should be harmless
//
// 4267 ('var' : conversion from 'size_t' to 'type', possible loss of data)
// throws tons and tons of warnings (no immediate plan to fix all usages)
//
// 4310 (cast truncates constant value)
// used in some engines
//
// 4345 (behavior change: an object of POD type constructed with an
// initializer of the form () will be default-initialized)
// used in Common::Array(), and it basically means that newer VS
// versions adhere to the standard in this case. Can be safely
// disabled.
//
// 4351 (new behavior: elements of array 'array' will be default initialized)
// a change in behavior in Visual Studio 2005. We want the new behavior, so it can be disabled
//
// 4505 ('function' : unreferenced local function has been removed)
// libvpx triggers this warning a lot. The compiler eliminates the code and that's expected.
//
// 4512 ('class' : assignment operator could not be generated)
// some classes use const items and the default assignment operator cannot be generated
//
// 4577 ('noexcept' used with no exception handling mode specified)
//
// 4589 (Constructor of abstract class 'type' ignores initializer for virtual base class 'type')
// caused by Common::Stream virtual inheritance, should be harmless
//
// 4702 (unreachable code)
// mostly thrown after error() calls (marked as NORETURN)
//
// 4706 (assignment within conditional expression)
// used in a lot of engines
//
// 4800 ('type' : forcing value to bool 'true' or 'false' (performance warning))
//
// 4996 ('function': was declared deprecated)
// disabling it removes all the non-standard unsafe functions warnings (strcpy_s, etc.)
//
// 6211 (Leaking memory <pointer> due to an exception. Consider using a local catch block to clean up memory)
// we disable exceptions
//
// 6204 (possible buffer overrun in call to <function>: use of unchecked parameter <variable>)
// 6385 (invalid data: accessing <buffer name>, the readable size is <size1> bytes, but <size2> bytes may be read)
// 6386 (buffer overrun: accessing <buffer name>, the writable size is <size1> bytes, but <size2> bytes may be written)
// give way too many false positives
//
////////////////////////////////////////////////////////////////////////////
//
// 4189 (local variable is initialized but not referenced)
// false positive in lure engine
//
// 4355 ('this' : used in base member initializer list)
// only disabled for specific engines where it is used in a safe way
//
// 4373 (previous versions of the compiler did not override when parameters only differed by const/volatile qualifiers)
//
// 4510 ('class' : default constructor could not be generated)
//
// 4511 ('class' : copy constructor could not be generated)
//
// 4610 (object 'class' can never be instantiated - user-defined constructor required)
// "correct" but harmless (as is 4510)
//
// 4324 (structure was padded due to alignment specifier)
//
////////////////////////////////////////////////////////////////////////////
globalWarnings.push_back("4068");
globalWarnings.push_back("4100");
globalWarnings.push_back("4103");
globalWarnings.push_back("4127");
globalWarnings.push_back("4244");
globalWarnings.push_back("4250");
globalWarnings.push_back("4310");
globalWarnings.push_back("4324");
globalWarnings.push_back("4345");
globalWarnings.push_back("4351");
globalWarnings.push_back("4505");
globalWarnings.push_back("4512");
globalWarnings.push_back("4589");
globalWarnings.push_back("4702");
globalWarnings.push_back("4706");
globalWarnings.push_back("4800");
globalWarnings.push_back("4996");
globalWarnings.push_back("6204");
globalWarnings.push_back("6211");
globalWarnings.push_back("6385");
globalWarnings.push_back("6386");
if (msvcVersion >= 14) {
globalWarnings.push_back("4267");
globalWarnings.push_back("4577");
}
globalErrors.push_back("4701"); // potential use of uninitialized local variable
globalErrors.push_back("4703"); // potential use of uninitialized local pointer
globalErrors.push_back("4456"); // declaration hides previous local declaration
globalErrors.push_back("4003"); // not enough arguments for function-like macro invocation
globalErrors.push_back("4840"); // use of non-trivial class as an argument to a variadic function
globalErrors.push_back("4805"); // comparison of bool to non-bool, unsafe mix of bool and int in arithmetic or bitwise operation
globalErrors.push_back("4305"); // truncation of double to float or int to bool
globalErrors.push_back("4366"); // address taken of unaligned field
globalErrors.push_back("4315"); // unaligned field has constructor that expects to be aligned
globalErrors.push_back("4715"); // not all control paths return a value
globalErrors.push_back("4716"); // function must return a value
projectWarnings["agi"].push_back("4510");
projectWarnings["agi"].push_back("4610");
projectWarnings["agos"].push_back("4511");
projectWarnings["dreamweb"].push_back("4355");
projectWarnings["lure"].push_back("4189");
projectWarnings["lure"].push_back("4355");
projectWarnings["kyra"].push_back("4355");
projectWarnings["kyra"].push_back("4510");
projectWarnings["kyra"].push_back("4610");
projectWarnings["m4"].push_back("4355");
projectWarnings["sci"].push_back("4373");
projectWarnings["grim"].push_back("4611");
provider = new CreateProjectTool::MSBuildProvider(globalWarnings, projectWarnings, globalErrors, msvcVersion, *msvc);
break;
case kProjectXcode:
if (setup.devTools || setup.tests) {
std::cerr << "ERROR: Building tools or tests is not supported for the XCode project type!\n";
return -1;
}
addGCCWarnings(globalWarnings);
provider = new CreateProjectTool::XcodeProvider(globalWarnings, projectWarnings, globalErrors);
break;
}
// Setup project name and description
setup.projectName = PROJECT_NAME;
setup.projectDescription = PROJECT_DESCRIPTION;
if (setup.devTools) {
setup.projectName += "-tools";
setup.projectDescription += "Tools";
}
if (setup.tests) {
setup.projectName += "-tests";
setup.projectDescription += "Tests";
}
provider->createProject(setup);
delete provider;
}
namespace {
std::string unifyPath(const std::string &path) {
std::string result = path;
std::replace(result.begin(), result.end(), '\\', '/');
return result;
}
void removeTrailingSlash(std::string& path) {
if (path.size() > 0 && path.at(path.size() - 1) == '/')
path.erase(path.size() - 1);
}
void displayHelp(const char *exe) {
using std::cout;
cout << "Usage:\n"
<< exe << " path\\to\\source [optional options]\n"
<< "\n"
<< " Creates project files for the " PROJECT_DESCRIPTION " source located at \"path\\to\\source\".\n"
" The project files will be created in the directory where tool is run from and\n"
" will include \"path\\to\\source\" for relative file paths, thus be sure that you\n"
" pass a relative file path like \"..\\..\\trunk\".\n"
"\n"
" Additionally there are the following switches for changing various settings:\n"
"\n"
"Project specific settings:\n"
" --cmake build CMake project files\n"
" --codeblocks build Code::Blocks project files\n"
" --msvc build Visual Studio project files\n"
" --xcode build XCode project files\n"
" --file-prefix prefix allow overwriting of relative file prefix in the\n"
" MSVC project files. By default the prefix is the\n"
" \"path\\to\\source\" argument\n"
" --output-dir path overwrite path, where the project files are placed\n"
" By default this is \".\", i.e. the current working\n"
" directory\n"
" --include-dir path add a path to the include search path\n"
" --library-dir path add a path to the library search path\n"
"\n"
"MSVC specific settings:\n"
" --msvc-version version set the targeted MSVC version. Possible values:\n";
const MSVCList msvc = getAllMSVCVersions();
for (MSVCList::const_iterator i = msvc.begin(); i != msvc.end(); ++i)
cout << " " << i->version << " stands for \"" << i->name << "\"\n";
cout << " If no version is set, the latest installed version is used\n"
" --build-events Run custom build events as part of the build\n"
" (default: false)\n"
" --installer Create installer after the build (implies --build-events)\n"
" (default: false)\n"
" --tools Create project files for the devtools\n"
" (ignores --build-events and --installer, as well as engine settings)\n"
" (default: false)\n"
" --tests Create project files for the tests\n"
" (ignores --build-events and --installer, as well as engine settings)\n"
" (default: false)\n"
" --use-slnx Use new XML-based Visual Studio solution format\n"
" (default: false)\n"
" --use-windows-unicode Use Windows Unicode APIs\n"
" (default: true)\n"
" --use-windows-ansi Use Windows ANSI APIs\n"
" (default: false)\n"
" --use-windows-subsystem Use Windows subsystem instead of Console\n"
" (default: false)\n"
" --libs-path path Specify the path of pre-built libraries instead of using the\n"
" " LIBS_DEFINE " environment variable\n "
" --vcpkg Use vcpkg-provided libraries instead of pre-built libraries\n"
" (default: false)\n"
"\n"
"XCode specific settings:\n"
" --ios build for iOS or tvOS\n"
" --tvos build for iOS or tvOS\n"
"\n"
"Engines settings:\n"
" --list-engines list all available engines and their default state\n"
" --enable-engine=<name> enable building of the engine with the name \"name\"\n"
" --disable-engine=<name> disable building of the engine with the name \"name\"\n"
" --enable-all-engines enable building of all engines\n"
" --disable-all-engines disable building of all engines\n"
"\n"
"Optional features settings:\n"
" --enable-<name> enable inclusion of the feature \"name\"\n"
" --disable-<name> disable inclusion of the feature \"name\"\n"
"\n"
"SDL settings:\n"
" --sdl1 link to SDL 1.2\n"
" --sdl2 link to SDL 2 (default)\n"
" --sdl3 link to SDL 3\n"
"\n"
" There are the following features available:\n"
"\n";
cout << " state | name | description\n\n";
const FeatureList features = getAllFeatures();
cout.setf(std::ios_base::left, std::ios_base::adjustfield);
for (FeatureList::const_iterator i = features.begin(); i != features.end(); ++i)
cout << ' ' << (i->enable ? " enabled" : "disabled") << " | " << std::setw((std::streamsize)15) << i->name << std::setw((std::streamsize)0) << " | " << i->description << '\n';
cout.setf(std::ios_base::right, std::ios_base::adjustfield);
}
void addGCCWarnings(StringList &globalWarnings) {
////////////////////////////////////////////////////////////////////////////
//
// -Wall
// enable all warnings
//
// -Wno-long-long -Wno-multichar -Wno-unknown-pragmas -Wno-reorder
// disable annoying and not-so-useful warnings
//
// -Wpointer-arith -Wcast-qual -Wcast-align
// -Wshadow -Wimplicit -Wnon-virtual-dtor -Wwrite-strings
// enable even more warnings...
//
// -fno-exceptions -fcheck-new
// disable exceptions, and enable checking of pointers returned by "new"
//
////////////////////////////////////////////////////////////////////////////
globalWarnings.push_back("-Wall");
globalWarnings.push_back("-Wno-long-long");
globalWarnings.push_back("-Wno-multichar");
globalWarnings.push_back("-Wno-unknown-pragmas");
globalWarnings.push_back("-Wno-reorder");
globalWarnings.push_back("-Wpointer-arith");
globalWarnings.push_back("-Wcast-qual");
globalWarnings.push_back("-Wcast-align");
globalWarnings.push_back("-Wshadow");
globalWarnings.push_back("-Wnon-virtual-dtor");
globalWarnings.push_back("-Wwrite-strings");
// The following are not warnings at all... We should consider adding them to
// a different list of parameters.
#if !NEEDS_RTTI
globalWarnings.push_back("-fno-rtti");
#endif
globalWarnings.push_back("-fno-exceptions");
globalWarnings.push_back("-fcheck-new");
}
/**
* Parse the configure.engine file of a given engine directory and return a
* list of all defined engines.
*
* @param engineDir The directory of the engine.
* @return The list of all defined engines.
*/
EngineDescList parseEngineConfigure(const std::string &engineDir);
/**
* Compares two FSNode entries in a strict-weak fashion based on the name.
*
* @param left The first operand.
* @param right The second operand.
* @return "true" when the name of the left operand is strictly smaller than
* the name of the second operand. "false" otherwise.
*/
bool compareFSNode(const CreateProjectTool::FSNode &left, const CreateProjectTool::FSNode &right);
#ifdef FIRST_ENGINE
/**
* Compares two FSNode entries in a strict-weak fashion based on engine name
* order.
*
* @param left The first operand.
* @param right The second operand.
* @return "true" when the name of the left operand is strictly smaller than
* the name of the second operand. "false" otherwise.
*/
bool compareEngineNames(const CreateProjectTool::FSNode &left, const CreateProjectTool::FSNode &right);
#endif
} // End of anonymous namespace
EngineDescList parseEngines(const std::string &srcDir) {
using CreateProjectTool::FileList;
using CreateProjectTool::listDirectory;
EngineDescList engineList;
FileList engineFiles = listDirectory(srcDir + "/engines/");
#ifdef FIRST_ENGINE
// In case we want to sort an engine to the front of the list we will
// use some manual sorting predicate which assures that.
engineFiles.sort(&compareEngineNames);
#else
// Otherwise, we simply sort the file list alphabetically this allows
// for a nicer order in --list-engines output, for example.
engineFiles.sort(&compareFSNode);
#endif
for (FileList::const_iterator i = engineFiles.begin(), end = engineFiles.end(); i != end; ++i) {
// Each engine requires its own sub directory thus we will skip all
// non directory file nodes here.
if (!i->isDirectory) {
continue;
}
// Retrieve all engines defined in this sub directory and add them to
// the list of all engines.
EngineDescList list = parseEngineConfigure(srcDir + "/engines/" + i->name);
engineList.splice(engineList.end(), list);
}
return engineList;
}
bool isSubEngine(const std::string &name, const EngineDescList &engines) {
for (EngineDescList::const_iterator i = engines.begin(); i != engines.end(); ++i) {
if (std::find(i->subEngines.begin(), i->subEngines.end(), name) != i->subEngines.end())
return true;
}
return false;