-
Notifications
You must be signed in to change notification settings - Fork 21
Visual Studio compilation fixes #306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
0c7625d
8522160
a7ba716
9341036
72c9dcc
d2ef6cc
f435761
26d7c78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| #include "getopt.h" | ||
| #include <string.h> | ||
| #include <stdio.h> | ||
|
|
||
| // For Windows MSVC only | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where does this code come from?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ChatGPT. There are tons of versions of this code online. I would credit someone but the amount of copy-paste in there is quite significant.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uhm... originally I was using
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are committing to a multiplatform codebase. We ahould be using the easiest and most reliable code to do that. Because MSVC doesn't have getopt I hacked together something to make it compile. But if instead we use boost I have no problem, the more reliable and the fewer platform-specific splits the better.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did try a switch (back?) from
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have moved to
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quick comment: you still use boost::property_tree in common2 so that would also have to go if we're getting off boost 100% |
||
|
|
||
| char *optarg = NULL; | ||
| int optind = 1, opterr = 1, optopt = '?'; | ||
|
|
||
| static int optpos = 1; | ||
|
|
||
| static int | ||
| _parse_short(int argc, char * const argv[], const char *optstring) | ||
| { | ||
| char c = argv[optind][optpos]; | ||
| const char *cp = strchr(optstring, c); | ||
|
|
||
| if (!cp) { | ||
| if (opterr) | ||
| fprintf(stderr, "unknown option -- %c\n", c); | ||
| if (argv[optind][++optpos] == '\0') { | ||
| optind++; | ||
| optpos = 1; | ||
| } | ||
| optopt = c; | ||
| return '?'; | ||
| } | ||
| if (cp[1] == ':') { | ||
| if (argv[optind][optpos+1] != '\0') { | ||
| optarg = &argv[optind][optpos+1]; | ||
| optind++; | ||
| } else if (++optind < argc) { | ||
| optarg = argv[optind++]; | ||
| } else { | ||
| optopt = c; | ||
| return (optstring[0] == ':') ? ':' : '?'; | ||
| } | ||
| optpos = 1; | ||
| } else { | ||
| if (argv[optind][++optpos] == '\0') { | ||
| optpos = 1; | ||
| optind++; | ||
| } | ||
| optarg = NULL; | ||
| } | ||
| return c; | ||
| } | ||
|
|
||
| int getopt(int argc, char * const argv[], const char *optstring) | ||
| { | ||
| if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') | ||
| return -1; | ||
| if (strcmp(argv[optind], "--") == 0) { | ||
| optind++; | ||
| return -1; | ||
| } | ||
| return _parse_short(argc, argv, optstring); | ||
| } | ||
|
|
||
| int getopt_long(int argc, char * const argv[], const char *optstring, | ||
| const struct option *longopts, int *longindex) | ||
| { | ||
| if (optind >= argc) return -1; | ||
|
|
||
| if (argv[optind][0] == '-' && argv[optind][1] == '-') { | ||
| const char *name = argv[optind] + 2; | ||
| const char *eq = strchr(name, '='); | ||
| size_t len = eq ? (size_t)(eq - name) : strlen(name); | ||
|
|
||
| for (int i = 0; longopts[i].name; i++) { | ||
| if (strncmp(name, longopts[i].name, len) == 0 | ||
| && len == strlen(longopts[i].name)) { | ||
| if (longindex) *longindex = i; | ||
| if (longopts[i].has_arg == no_argument) { | ||
| optarg = NULL; | ||
| } else if (longopts[i].has_arg == required_argument) { | ||
| if (eq) | ||
| optarg = (char*)eq+1; | ||
| else if (optind+1 < argc) | ||
| optarg = argv[++optind]; | ||
| else | ||
| return optopt = longopts[i].val, '?'; | ||
| } else if (longopts[i].has_arg == optional_argument) { | ||
| optarg = eq ? (char*)eq+1 : NULL; | ||
| } | ||
| optind++; | ||
| if (longopts[i].flag) { | ||
| *(longopts[i].flag) = longopts[i].val; | ||
| return 0; | ||
| } else { | ||
| return longopts[i].val; | ||
| } | ||
| } | ||
| } | ||
| /* no match */ | ||
| if (opterr) | ||
| fprintf(stderr, "unrecognized option '--%s'\n", name); | ||
| optind++; | ||
| return '?'; | ||
| } | ||
| /* fallback to short option parsing */ | ||
| return getopt(argc, argv, optstring); | ||
| } | ||
|
|
||
| int getopt_long_only(int argc, char * const argv[], const char *optstring, | ||
| const struct option *longopts, int *longindex) | ||
| { | ||
| return getopt_long(argc, argv, optstring, longopts, longindex); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #ifndef GETOPT_H | ||
| #define GETOPT_H | ||
|
|
||
| // For Windows MSVC only | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /* argument flags */ | ||
| #define no_argument 0 | ||
| #define required_argument 1 | ||
| #define optional_argument 2 | ||
|
|
||
| struct option { | ||
| const char *name; | ||
| int has_arg; | ||
| int *flag; | ||
| int val; | ||
| }; | ||
|
|
||
| /* globals */ | ||
| extern char *optarg; | ||
| extern int optind, opterr, optopt; | ||
|
|
||
| /* functions */ | ||
| int getopt(int argc, char * const argv[], const char *optstring); | ||
|
|
||
| int getopt_long(int argc, char * const argv[], const char *optstring, | ||
| const struct option *longopts, int *longindex); | ||
|
|
||
| int getopt_long_only(int argc, char * const argv[], const char *optstring, | ||
| const struct option *longopts, int *longindex); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* GETOPT_H */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Microsoft VisualStudio support | ||
|
|
||
| ## Why | ||
|
|
||
| The original AppleWin project is built with Visual Studio. We now provide support for Visual Studio when building 'sa2', the SDL version of AppleWin. | ||
|
|
||
| ## Status | ||
|
|
||
| `sa2` compiles under VisualStudio 2022. | ||
|
|
||
| ## Building | ||
|
|
||
| Very **important** to install `vcpkg`. Refer to the Microsoft documentation. | ||
|
|
||
| Install using `vcpkg` the following packages: | ||
| ``` | ||
| vcpkg install sdl2 sdl2-image sdl2-ttf | ||
| vcpkg install zlib | ||
| vcpkg install boost | ||
| ``` | ||
| Then configure: | ||
| ``` | ||
| cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=C:\PATH_TO_VCPKG\scripts\buildsystems\vcpkg.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DVCPKG_TARGET_TRIPLET=x64-windows -DBUILD_SA2=ON | ||
| ``` | ||
| Then open the generated `build\applewin.sln` file in Visual Studio. | ||
|
|
||
| ## Running | ||
|
|
||
| `sa2` should be the startup project that runs when you press F5. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Apple Xcode support | ||
|
|
||
| ## Status | ||
|
|
||
| Compiles cleanly under Xcode. | ||
|
|
||
| ## Building | ||
|
|
||
| Configure: | ||
| Move to the top level directory of AppleWin | ||
| Create a `build` directory and configure (here to build the SDL version): | ||
| ``` | ||
| mkdir build | ||
| cmake -G Xcode -B build -DBUILD_SA2=ON | ||
| ``` | ||
| Then open the generated `build/applewin.xcodeproj` file in Xcode, or just type: | ||
| ``` | ||
| open build/applewin.xcodeproj | ||
| ``` | ||
|
|
||
| ## Running | ||
|
|
||
| `sa2` should be inside build/Debug or build/Release depending on your choice. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally we should fix this code in the upstream repo. can you propose a MR there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me see where it pukes and propose a PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well they use
/utf-8in the upstream repo so here for MSVC I can use:add_compile_options(/utf-8)instead of
/wd4566, which tracks closer to upstream. But your-Wno-multicharis also/wd4566.Thoughts?