From 67c0ed8a2f2011237b8a280d5f264c4b38c0f51b Mon Sep 17 00:00:00 2001 From: Ted John Date: Wed, 4 Jan 2017 22:10:16 +0000 Subject: [PATCH 01/13] Add new windows project --- openrct2.sln | 22 +++++ src/openrct2-win/openrct2-win.cpp | 112 ++++++++++++++++++++++++++ src/openrct2-win/openrct2-win.vcxproj | 75 +++++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 src/openrct2-win/openrct2-win.cpp create mode 100644 src/openrct2-win/openrct2-win.vcxproj diff --git a/openrct2.sln b/openrct2.sln index c98f53ac32..c161447964 100644 --- a/openrct2.sln +++ b/openrct2.sln @@ -16,6 +16,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2202A816-377 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{480B577D-4E4A-4757-9A42-28A9AD33E6B0}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openrct2-win", "src\openrct2-win\openrct2-win.vcxproj", "{7A9A57D5-7006-4208-A290-5491BA3C8808}" + ProjectSection(ProjectDependencies) = postProject + {D24D94F6-2A74-480C-B512-629C306CE92F} = {D24D94F6-2A74-480C-B512-629C306CE92F} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -65,6 +70,22 @@ Global {62B020FA-E4FB-4C6E-B32A-DC999470F155}.ReleaseTests|Win32.Build.0 = ReleaseTests|Win32 {62B020FA-E4FB-4C6E-B32A-DC999470F155}.ReleaseTests|x64.ActiveCfg = ReleaseTests|x64 {62B020FA-E4FB-4C6E-B32A-DC999470F155}.ReleaseTests|x64.Build.0 = ReleaseTests|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Debug|Win32.ActiveCfg = Debug|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Debug|Win32.Build.0 = Debug|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Debug|x64.ActiveCfg = Debug|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Debug|x64.Build.0 = Debug|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.DebugTests|Win32.ActiveCfg = DebugTests|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.DebugTests|Win32.Build.0 = DebugTests|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.DebugTests|x64.ActiveCfg = DebugTests|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.DebugTests|x64.Build.0 = DebugTests|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Release|Win32.ActiveCfg = Release|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Release|Win32.Build.0 = Release|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Release|x64.ActiveCfg = Release|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Release|x64.Build.0 = Release|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.ReleaseTests|Win32.ActiveCfg = ReleaseTests|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.ReleaseTests|Win32.Build.0 = ReleaseTests|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.ReleaseTests|x64.ActiveCfg = ReleaseTests|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.ReleaseTests|x64.Build.0 = ReleaseTests|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -73,5 +94,6 @@ Global {D24D94F6-2A74-480C-B512-629C306CE92F} = {2202A816-377D-4FA0-A7AF-7D4105F8A4FB} {57E60BA1-FB76-4316-909E-C1449C142327} = {480B577D-4E4A-4757-9A42-28A9AD33E6B0} {62B020FA-E4FB-4C6E-B32A-DC999470F155} = {480B577D-4E4A-4757-9A42-28A9AD33E6B0} + {7A9A57D5-7006-4208-A290-5491BA3C8808} = {2202A816-377D-4FA0-A7AF-7D4105F8A4FB} EndGlobalSection EndGlobal diff --git a/src/openrct2-win/openrct2-win.cpp b/src/openrct2-win/openrct2-win.cpp new file mode 100644 index 0000000000..433607d313 --- /dev/null +++ b/src/openrct2-win/openrct2-win.cpp @@ -0,0 +1,112 @@ +#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers +/***************************************************************************** + * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. + * + * OpenRCT2 is the work of many authors, a full list can be found in contributors.md + * For more information, visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 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. + * + * A full copy of the GNU General Public License can be found in licence.txt + *****************************************************************************/ +#pragma endregion + +#define WIN32_LEAN_AND_MEAN + +#include +#include +#include +#include + +// Enable visual styles +#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") + +static bool GetCommandLineArgs(int * outargc, char * * * outargv); +static void FreeCommandLineArgs(int argc, char * * argv); +static char * ConvertUTF16toUTF8(const wchar_t * src); + +/** + * Windows entry point to OpenRCT2 with a console window using a traditional C main function. + */ +int main(int argc, char * * argv) +{ + if (!GetCommandLineArgs(&argc, &argv)) + { + puts("Unable to fetch command line arguments."); + return -1; + } + + int exitCode = 0; // RunOpenRCT2 + + FreeCommandLineArgs(argc, argv); + return exitCode; +} + +/** + * Windows entry point to OpenRCT2 without a console window. + */ +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +{ + int argc; + char * * argv; + if (!GetCommandLineArgs(&argc, &argv)) + { + puts("Unable to fetch command line arguments."); + return -1; + } + + int exitCode = 0; // RunOpenRCT2 + + FreeCommandLineArgs(argc, argv); + return exitCode; +} + +static bool GetCommandLineArgs(int * outargc, char * * * outargv) +{ + // Get UTF-16 command line arguments + int argc; + LPWSTR cmdLine = GetCommandLineW(); + LPWSTR * argvW = CommandLineToArgvW(cmdLine, &argc); + + // Allocate UTF-8 strings + char * * argv = (char * *)malloc(argc * sizeof(char *)); + if (argv == nullptr) + { + return false; + } + + // Convert to UTF-8 + for (int i = 0; i < argc; i++) + { + argv[i] = ConvertUTF16toUTF8(argvW[i]); + } + + // Free UTF-16 strings + LocalFree(argvW); + + *outargc = argc; + *outargv = argv; + return true; +} + +static void FreeCommandLineArgs(int argc, char * * argv) +{ + // Free argv + for (int i = 0; i < argc; i++) + { + free(argv[i]); + } + free(argv); +} + +static char * ConvertUTF16toUTF8(const wchar_t * src) +{ + int srcLen = lstrlenW(src); + int sizeReq = WideCharToMultiByte(CP_UTF8, 0, src, srcLen, nullptr, 0, nullptr, nullptr); + char * result = (char *)calloc(1, sizeReq + 1); + WideCharToMultiByte(CP_UTF8, 0, src, srcLen, result, sizeReq, nullptr, nullptr); + return result; +} diff --git a/src/openrct2-win/openrct2-win.vcxproj b/src/openrct2-win/openrct2-win.vcxproj new file mode 100644 index 0000000000..33c89c907c --- /dev/null +++ b/src/openrct2-win/openrct2-win.vcxproj @@ -0,0 +1,75 @@ + + + + ..\..\ + + + + Debug + Win32 + + + Debug + x64 + + + DebugTests + Win32 + + + DebugTests + x64 + + + Release + Win32 + + + Release + x64 + + + ReleaseTests + Win32 + + + ReleaseTests + x64 + + + + {7A9A57D5-7006-4208-A290-5491BA3C8808} + openrct2-win + openrct2-win + + + Application + + + + + __NOENTRYPOINT__;%(PreprocessorDefinitions) + + + + + $(IntDir)\%(RelativeDir) + $(OPENRCT2_CL_ADDITIONALOPTIONS) %(AdditionalOptions) + + + Console + Windows + + + MachineX86 + MachineX64 + + + + + + + + + + \ No newline at end of file From 73b21b5880f5087242737eb91ef0fe3c23b132c8 Mon Sep 17 00:00:00 2001 From: Ted John Date: Wed, 4 Jan 2017 22:50:35 +0000 Subject: [PATCH 02/13] Convert openrct2 to static library --- openrct2.sln | 46 ++++--------------- src/openrct2-win/openrct2-win.cpp | 5 +- src/openrct2-win/openrct2-win.vcxproj | 21 ++------- src/openrct2/OpenRCT2.h | 4 ++ ...{openrct2.vcxproj => openrct2-lib.vcxproj} | 30 ++---------- src/openrct2/platform/windows.c | 32 +------------ test/tests/tests.vcxproj | 20 ++++---- 7 files changed, 36 insertions(+), 122 deletions(-) rename src/openrct2/{openrct2.vcxproj => openrct2-lib.vcxproj} (95%) diff --git a/openrct2.sln b/openrct2.sln index c161447964..7933d2540c 100644 --- a/openrct2.sln +++ b/openrct2.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openrct2", "src\openrct2\openrct2.vcxproj", "{D24D94F6-2A74-480C-B512-629C306CE92F}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openrct2-lib", "src\openrct2\openrct2-lib.vcxproj", "{D24D94F6-2A74-480C-B512-629C306CE92F}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testpaint", "test\testpaint\testpaint.vcxproj", "{57E60BA1-FB76-4316-909E-C1449C142327}" EndProject @@ -25,67 +25,39 @@ Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 Debug|x64 = Debug|x64 - DebugTests|Win32 = DebugTests|Win32 - DebugTests|x64 = DebugTests|x64 Release|Win32 = Release|Win32 Release|x64 = Release|x64 - ReleaseTests|Win32 = ReleaseTests|Win32 - ReleaseTests|x64 = ReleaseTests|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {D24D94F6-2A74-480C-B512-629C306CE92F}.Debug|Win32.ActiveCfg = Debug|Win32 {D24D94F6-2A74-480C-B512-629C306CE92F}.Debug|Win32.Build.0 = Debug|Win32 {D24D94F6-2A74-480C-B512-629C306CE92F}.Debug|x64.ActiveCfg = Debug|x64 {D24D94F6-2A74-480C-B512-629C306CE92F}.Debug|x64.Build.0 = Debug|x64 - {D24D94F6-2A74-480C-B512-629C306CE92F}.DebugTests|Win32.ActiveCfg = DebugTests|Win32 - {D24D94F6-2A74-480C-B512-629C306CE92F}.DebugTests|Win32.Build.0 = DebugTests|Win32 - {D24D94F6-2A74-480C-B512-629C306CE92F}.DebugTests|x64.ActiveCfg = DebugTests|x64 - {D24D94F6-2A74-480C-B512-629C306CE92F}.DebugTests|x64.Build.0 = DebugTests|x64 {D24D94F6-2A74-480C-B512-629C306CE92F}.Release|Win32.ActiveCfg = Release|Win32 {D24D94F6-2A74-480C-B512-629C306CE92F}.Release|Win32.Build.0 = Release|Win32 {D24D94F6-2A74-480C-B512-629C306CE92F}.Release|x64.ActiveCfg = Release|x64 {D24D94F6-2A74-480C-B512-629C306CE92F}.Release|x64.Build.0 = Release|x64 - {D24D94F6-2A74-480C-B512-629C306CE92F}.ReleaseTests|Win32.ActiveCfg = ReleaseTests|Win32 - {D24D94F6-2A74-480C-B512-629C306CE92F}.ReleaseTests|Win32.Build.0 = ReleaseTests|Win32 - {D24D94F6-2A74-480C-B512-629C306CE92F}.ReleaseTests|x64.ActiveCfg = ReleaseTests|x64 - {D24D94F6-2A74-480C-B512-629C306CE92F}.ReleaseTests|x64.Build.0 = ReleaseTests|x64 {57E60BA1-FB76-4316-909E-C1449C142327}.Debug|Win32.ActiveCfg = Debug|Win32 {57E60BA1-FB76-4316-909E-C1449C142327}.Debug|Win32.Build.0 = Debug|Win32 {57E60BA1-FB76-4316-909E-C1449C142327}.Debug|x64.ActiveCfg = Debug|Win32 - {57E60BA1-FB76-4316-909E-C1449C142327}.DebugTests|Win32.ActiveCfg = Debug|Win32 - {57E60BA1-FB76-4316-909E-C1449C142327}.DebugTests|x64.ActiveCfg = Debug|Win32 {57E60BA1-FB76-4316-909E-C1449C142327}.Release|Win32.ActiveCfg = Release|Win32 {57E60BA1-FB76-4316-909E-C1449C142327}.Release|x64.ActiveCfg = Release|Win32 - {57E60BA1-FB76-4316-909E-C1449C142327}.ReleaseTests|Win32.ActiveCfg = Release|Win32 - {57E60BA1-FB76-4316-909E-C1449C142327}.ReleaseTests|x64.ActiveCfg = Release|Win32 - {62B020FA-E4FB-4C6E-B32A-DC999470F155}.Debug|Win32.ActiveCfg = DebugTests|Win32 - {62B020FA-E4FB-4C6E-B32A-DC999470F155}.Debug|x64.ActiveCfg = DebugTests|x64 - {62B020FA-E4FB-4C6E-B32A-DC999470F155}.DebugTests|Win32.ActiveCfg = DebugTests|Win32 - {62B020FA-E4FB-4C6E-B32A-DC999470F155}.DebugTests|Win32.Build.0 = DebugTests|Win32 - {62B020FA-E4FB-4C6E-B32A-DC999470F155}.DebugTests|x64.ActiveCfg = DebugTests|x64 - {62B020FA-E4FB-4C6E-B32A-DC999470F155}.DebugTests|x64.Build.0 = DebugTests|x64 - {62B020FA-E4FB-4C6E-B32A-DC999470F155}.Release|Win32.ActiveCfg = ReleaseTests|Win32 - {62B020FA-E4FB-4C6E-B32A-DC999470F155}.Release|x64.ActiveCfg = ReleaseTests|x64 - {62B020FA-E4FB-4C6E-B32A-DC999470F155}.ReleaseTests|Win32.ActiveCfg = ReleaseTests|Win32 - {62B020FA-E4FB-4C6E-B32A-DC999470F155}.ReleaseTests|Win32.Build.0 = ReleaseTests|Win32 - {62B020FA-E4FB-4C6E-B32A-DC999470F155}.ReleaseTests|x64.ActiveCfg = ReleaseTests|x64 - {62B020FA-E4FB-4C6E-B32A-DC999470F155}.ReleaseTests|x64.Build.0 = ReleaseTests|x64 + {62B020FA-E4FB-4C6E-B32A-DC999470F155}.Debug|Win32.ActiveCfg = Debug|Win32 + {62B020FA-E4FB-4C6E-B32A-DC999470F155}.Debug|Win32.Build.0 = Debug|Win32 + {62B020FA-E4FB-4C6E-B32A-DC999470F155}.Debug|x64.ActiveCfg = Debug|x64 + {62B020FA-E4FB-4C6E-B32A-DC999470F155}.Debug|x64.Build.0 = Debug|x64 + {62B020FA-E4FB-4C6E-B32A-DC999470F155}.Release|Win32.ActiveCfg = Release|Win32 + {62B020FA-E4FB-4C6E-B32A-DC999470F155}.Release|Win32.Build.0 = Release|Win32 + {62B020FA-E4FB-4C6E-B32A-DC999470F155}.Release|x64.ActiveCfg = Release|x64 + {62B020FA-E4FB-4C6E-B32A-DC999470F155}.Release|x64.Build.0 = Release|x64 {7A9A57D5-7006-4208-A290-5491BA3C8808}.Debug|Win32.ActiveCfg = Debug|Win32 {7A9A57D5-7006-4208-A290-5491BA3C8808}.Debug|Win32.Build.0 = Debug|Win32 {7A9A57D5-7006-4208-A290-5491BA3C8808}.Debug|x64.ActiveCfg = Debug|x64 {7A9A57D5-7006-4208-A290-5491BA3C8808}.Debug|x64.Build.0 = Debug|x64 - {7A9A57D5-7006-4208-A290-5491BA3C8808}.DebugTests|Win32.ActiveCfg = DebugTests|Win32 - {7A9A57D5-7006-4208-A290-5491BA3C8808}.DebugTests|Win32.Build.0 = DebugTests|Win32 - {7A9A57D5-7006-4208-A290-5491BA3C8808}.DebugTests|x64.ActiveCfg = DebugTests|x64 - {7A9A57D5-7006-4208-A290-5491BA3C8808}.DebugTests|x64.Build.0 = DebugTests|x64 {7A9A57D5-7006-4208-A290-5491BA3C8808}.Release|Win32.ActiveCfg = Release|Win32 {7A9A57D5-7006-4208-A290-5491BA3C8808}.Release|Win32.Build.0 = Release|Win32 {7A9A57D5-7006-4208-A290-5491BA3C8808}.Release|x64.ActiveCfg = Release|x64 {7A9A57D5-7006-4208-A290-5491BA3C8808}.Release|x64.Build.0 = Release|x64 - {7A9A57D5-7006-4208-A290-5491BA3C8808}.ReleaseTests|Win32.ActiveCfg = ReleaseTests|Win32 - {7A9A57D5-7006-4208-A290-5491BA3C8808}.ReleaseTests|Win32.Build.0 = ReleaseTests|Win32 - {7A9A57D5-7006-4208-A290-5491BA3C8808}.ReleaseTests|x64.ActiveCfg = ReleaseTests|x64 - {7A9A57D5-7006-4208-A290-5491BA3C8808}.ReleaseTests|x64.Build.0 = ReleaseTests|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/openrct2-win/openrct2-win.cpp b/src/openrct2-win/openrct2-win.cpp index 433607d313..29736969cf 100644 --- a/src/openrct2-win/openrct2-win.cpp +++ b/src/openrct2-win/openrct2-win.cpp @@ -20,6 +20,7 @@ #include #include #include +#include // Enable visual styles #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") @@ -39,7 +40,7 @@ int main(int argc, char * * argv) return -1; } - int exitCode = 0; // RunOpenRCT2 + int exitCode = RunOpenRCT2(argc, argv); FreeCommandLineArgs(argc, argv); return exitCode; @@ -58,7 +59,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine return -1; } - int exitCode = 0; // RunOpenRCT2 + int exitCode = RunOpenRCT2(argc, argv); FreeCommandLineArgs(argc, argv); return exitCode; diff --git a/src/openrct2-win/openrct2-win.vcxproj b/src/openrct2-win/openrct2-win.vcxproj index 33c89c907c..67c40a3a0d 100644 --- a/src/openrct2-win/openrct2-win.vcxproj +++ b/src/openrct2-win/openrct2-win.vcxproj @@ -12,14 +12,6 @@ Debug x64 - - DebugTests - Win32 - - - DebugTests - x64 - Release Win32 @@ -28,14 +20,6 @@ Release x64 - - ReleaseTests - Win32 - - - ReleaseTests - x64 - {7A9A57D5-7006-4208-A290-5491BA3C8808} @@ -46,6 +30,10 @@ Application + + openrct2 + $(SolutionDir)bin;$(LibraryPath) + __NOENTRYPOINT__;%(PreprocessorDefinitions) @@ -57,6 +45,7 @@ $(OPENRCT2_CL_ADDITIONALOPTIONS) %(AdditionalOptions) + openrct2-lib.lib;%(AdditionalDependencies) Console Windows diff --git a/src/openrct2/OpenRCT2.h b/src/openrct2/OpenRCT2.h index a601dd6798..e7d814f1d1 100644 --- a/src/openrct2/OpenRCT2.h +++ b/src/openrct2/OpenRCT2.h @@ -87,6 +87,10 @@ extern "C" int cmdline_run(const char * * argv, int argc); +#ifdef _MSC_VER + int RunOpenRCT2(int argc, char * *); +#endif + #ifdef __cplusplus } #endif diff --git a/src/openrct2/openrct2.vcxproj b/src/openrct2/openrct2-lib.vcxproj similarity index 95% rename from src/openrct2/openrct2.vcxproj rename to src/openrct2/openrct2-lib.vcxproj index 2cd5814180..4a50422ff2 100644 --- a/src/openrct2/openrct2.vcxproj +++ b/src/openrct2/openrct2-lib.vcxproj @@ -12,14 +12,6 @@ Debug x64 - - DebugTests - Win32 - - - DebugTests - x64 - Release Win32 @@ -28,35 +20,23 @@ Release x64 - - ReleaseTests - Win32 - - - ReleaseTests - x64 - {D24D94F6-2A74-480C-B512-629C306CE92F} - openrct2 - openrct2 + openrct2-lib + openrct2-lib - Application + StaticLibrary DynamicLibrary - - StaticLibrary - USE_BREAKPAD;%(PreprocessorDefinitions) - __NOENTRYPOINT__;%(PreprocessorDefinitions) @@ -64,10 +44,6 @@ $(IntDir)\%(RelativeDir) $(OPENRCT2_CL_ADDITIONALOPTIONS) %(AdditionalOptions) - - Console - Windows - MachineX86 MachineX64 diff --git a/src/openrct2/platform/windows.c b/src/openrct2/platform/windows.c index 4c90cb9b64..bf4a85b5bc 100644 --- a/src/openrct2/platform/windows.c +++ b/src/openrct2/platform/windows.c @@ -55,38 +55,10 @@ utf8 **windows_get_command_line_args(int *outNumArgs); static HMODULE _dllModule = NULL; -#if defined(NO_RCT2) && !defined(__NOENTRYPOINT__) - -/** - * Windows entry point to OpenRCT2 without a console window. - */ -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) -{ - _dllModule = hInstance; - - core_init(); - - int argc; - char ** argv = (char**)windows_get_command_line_args(&argc); - int runGame = cmdline_run((const char **)argv, argc); - - // Free argv - for (int i = 0; i < argc; i++) { - free(argv[i]); - } - free(argv); - - if (runGame == 1) { - openrct2_launch(); - } - - return gExitCode; -} - /** * Windows entry point to OpenRCT2 with a console window using a traditional C main function. */ -int main(int argc, char *argv[]) +int RunOpenRCT2(int argc, char * * argv) { HINSTANCE hInstance = GetModuleHandle(NULL); _dllModule = hInstance; @@ -101,7 +73,7 @@ int main(int argc, char *argv[]) return gExitCode; } -#else +#ifndef NO_RCT2 /* DllMain is already defined in one of static libraries we implicitly depend * on (libcrypto), which is their bug really, but since we don't do anything in diff --git a/test/tests/tests.vcxproj b/test/tests/tests.vcxproj index d10bc48bf3..8b7bca2f9f 100644 --- a/test/tests/tests.vcxproj +++ b/test/tests/tests.vcxproj @@ -5,20 +5,20 @@ $(SolutionDir)lib\googletest\googletest - - DebugTests + + Debug Win32 - - ReleaseTests + + Release Win32 - - DebugTests + + Debug x64 - - ReleaseTests + + Release x64 @@ -33,7 +33,7 @@ $(SolutionDir)bin\tests\ - $(GtestDir);$(GtestDir)\include;$(SolutionDir)src\openrct2;$(IncludePath) + $(GtestDir);$(GtestDir)\include;$(IncludePath) $(SolutionDir)bin;$(LibraryPath) @@ -41,7 +41,7 @@ GTEST_LANG_CXX11;%(PreprocessorDefinitions) - openrct2.lib;%(AdditionalDependencies) + openrct2-lib.lib;%(AdditionalDependencies) Console From 7d6ea1f5cdbf317c475286f8701fd815fb2d6f62 Mon Sep 17 00:00:00 2001 From: Ted John Date: Wed, 4 Jan 2017 23:36:36 +0000 Subject: [PATCH 03/13] Create DLL for openrct2 with win as a wrapper --- openrct2.sln | 15 +++++ src/openrct2-dll/openrct2-dll.cpp | 80 ++++++++++++++++++++++++ src/openrct2-dll/openrct2-dll.vcxproj | 62 +++++++++++++++++++ src/openrct2-win/openrct2-win.cpp | 88 ++------------------------- src/openrct2-win/openrct2-win.vcxproj | 5 +- src/openrct2/OpenRCT2.h | 2 +- 6 files changed, 164 insertions(+), 88 deletions(-) create mode 100644 src/openrct2-dll/openrct2-dll.cpp create mode 100644 src/openrct2-dll/openrct2-dll.vcxproj diff --git a/openrct2.sln b/openrct2.sln index 7933d2540c..3998763de4 100644 --- a/openrct2.sln +++ b/openrct2.sln @@ -17,6 +17,12 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{480B577D-4E4A-4757-9A42-28A9AD33E6B0}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openrct2-win", "src\openrct2-win\openrct2-win.vcxproj", "{7A9A57D5-7006-4208-A290-5491BA3C8808}" + ProjectSection(ProjectDependencies) = postProject + {7B8DB129-79EF-417E-B372-8A18E009D261} = {7B8DB129-79EF-417E-B372-8A18E009D261} + {D24D94F6-2A74-480C-B512-629C306CE92F} = {D24D94F6-2A74-480C-B512-629C306CE92F} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openrct2-dll", "src\openrct2-dll\openrct2-dll.vcxproj", "{7B8DB129-79EF-417E-B372-8A18E009D261}" ProjectSection(ProjectDependencies) = postProject {D24D94F6-2A74-480C-B512-629C306CE92F} = {D24D94F6-2A74-480C-B512-629C306CE92F} EndProjectSection @@ -58,6 +64,14 @@ Global {7A9A57D5-7006-4208-A290-5491BA3C8808}.Release|Win32.Build.0 = Release|Win32 {7A9A57D5-7006-4208-A290-5491BA3C8808}.Release|x64.ActiveCfg = Release|x64 {7A9A57D5-7006-4208-A290-5491BA3C8808}.Release|x64.Build.0 = Release|x64 + {7B8DB129-79EF-417E-B372-8A18E009D261}.Debug|Win32.ActiveCfg = Debug|Win32 + {7B8DB129-79EF-417E-B372-8A18E009D261}.Debug|Win32.Build.0 = Debug|Win32 + {7B8DB129-79EF-417E-B372-8A18E009D261}.Debug|x64.ActiveCfg = Debug|x64 + {7B8DB129-79EF-417E-B372-8A18E009D261}.Debug|x64.Build.0 = Debug|x64 + {7B8DB129-79EF-417E-B372-8A18E009D261}.Release|Win32.ActiveCfg = Release|Win32 + {7B8DB129-79EF-417E-B372-8A18E009D261}.Release|Win32.Build.0 = Release|Win32 + {7B8DB129-79EF-417E-B372-8A18E009D261}.Release|x64.ActiveCfg = Release|x64 + {7B8DB129-79EF-417E-B372-8A18E009D261}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -67,5 +81,6 @@ Global {57E60BA1-FB76-4316-909E-C1449C142327} = {480B577D-4E4A-4757-9A42-28A9AD33E6B0} {62B020FA-E4FB-4C6E-B32A-DC999470F155} = {480B577D-4E4A-4757-9A42-28A9AD33E6B0} {7A9A57D5-7006-4208-A290-5491BA3C8808} = {2202A816-377D-4FA0-A7AF-7D4105F8A4FB} + {7B8DB129-79EF-417E-B372-8A18E009D261} = {2202A816-377D-4FA0-A7AF-7D4105F8A4FB} EndGlobalSection EndGlobal diff --git a/src/openrct2-dll/openrct2-dll.cpp b/src/openrct2-dll/openrct2-dll.cpp new file mode 100644 index 0000000000..622160bb42 --- /dev/null +++ b/src/openrct2-dll/openrct2-dll.cpp @@ -0,0 +1,80 @@ +#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers +/***************************************************************************** + * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. + * + * OpenRCT2 is the work of many authors, a full list can be found in contributors.md + * For more information, visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 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. + * + * A full copy of the GNU General Public License can be found in licence.txt + *****************************************************************************/ +#pragma endregion + +#define WIN32_LEAN_AND_MEAN + +#include +#include +#include +#include +#include + +#define DLLEXPORT extern "C" __declspec(dllexport) + +static char * * GetCommandLineArgs(int argc, wchar_t * * argvW); +static void FreeCommandLineArgs(int argc, char * * argv); +static char * ConvertUTF16toUTF8(const wchar_t * src); + +DLLEXPORT int LaunchOpenRCT2(int argc, wchar_t * * argvW) +{ + char * * argv = GetCommandLineArgs(argc, argvW); + if (argv == nullptr) + { + puts("Unable to fetch command line arguments."); + return -1; + } + + int exitCode = RunOpenRCT2(argc, argv); + FreeCommandLineArgs(argc, argv); + return exitCode; +} + +static char * * GetCommandLineArgs(int argc, wchar_t * * argvW) +{ + // Allocate UTF-8 strings + char * * argv = (char * *)malloc(argc * sizeof(char *)); + if (argv == nullptr) + { + return false; + } + + // Convert to UTF-8 + for (int i = 0; i < argc; i++) + { + argv[i] = ConvertUTF16toUTF8(argvW[i]); + } + + return argv; +} + +static void FreeCommandLineArgs(int argc, char * * argv) +{ + // Free argv + for (int i = 0; i < argc; i++) + { + free(argv[i]); + } + free(argv); +} + +static char * ConvertUTF16toUTF8(const wchar_t * src) +{ + int srcLen = lstrlenW(src); + int sizeReq = WideCharToMultiByte(CP_UTF8, 0, src, srcLen, nullptr, 0, nullptr, nullptr); + char * result = (char *)calloc(1, sizeReq + 1); + WideCharToMultiByte(CP_UTF8, 0, src, srcLen, result, sizeReq, nullptr, nullptr); + return result; +} diff --git a/src/openrct2-dll/openrct2-dll.vcxproj b/src/openrct2-dll/openrct2-dll.vcxproj new file mode 100644 index 0000000000..3cb9c34dfe --- /dev/null +++ b/src/openrct2-dll/openrct2-dll.vcxproj @@ -0,0 +1,62 @@ + + + + ..\..\ + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {7B8DB129-79EF-417E-B372-8A18E009D261} + openrct2-dll + openrct2-dll + + + DynamicLibrary + + + + openrct2 + $(SolutionDir)bin;$(LibraryPath) + + + + __NOENTRYPOINT__;%(PreprocessorDefinitions) + + + + + $(IntDir)\%(RelativeDir) + $(OPENRCT2_CL_ADDITIONALOPTIONS) %(AdditionalOptions) + + + openrct2-lib.lib;%(AdditionalDependencies) + + + MachineX86 + MachineX64 + + + + + + + + + + \ No newline at end of file diff --git a/src/openrct2-win/openrct2-win.cpp b/src/openrct2-win/openrct2-win.cpp index 29736969cf..24084a6c27 100644 --- a/src/openrct2-win/openrct2-win.cpp +++ b/src/openrct2-win/openrct2-win.cpp @@ -16,98 +16,18 @@ #define WIN32_LEAN_AND_MEAN -#include -#include #include -#include -#include // Enable visual styles #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") -static bool GetCommandLineArgs(int * outargc, char * * * outargv); -static void FreeCommandLineArgs(int argc, char * * argv); -static char * ConvertUTF16toUTF8(const wchar_t * src); +#define DLLIMPORT extern "C" +DLLIMPORT int LaunchOpenRCT2(int argc, wchar_t * * argv); /** * Windows entry point to OpenRCT2 with a console window using a traditional C main function. */ -int main(int argc, char * * argv) +int wmain(int argc, wchar_t * * argvW, wchar_t * envp) { - if (!GetCommandLineArgs(&argc, &argv)) - { - puts("Unable to fetch command line arguments."); - return -1; - } - - int exitCode = RunOpenRCT2(argc, argv); - - FreeCommandLineArgs(argc, argv); - return exitCode; -} - -/** - * Windows entry point to OpenRCT2 without a console window. - */ -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) -{ - int argc; - char * * argv; - if (!GetCommandLineArgs(&argc, &argv)) - { - puts("Unable to fetch command line arguments."); - return -1; - } - - int exitCode = RunOpenRCT2(argc, argv); - - FreeCommandLineArgs(argc, argv); - return exitCode; -} - -static bool GetCommandLineArgs(int * outargc, char * * * outargv) -{ - // Get UTF-16 command line arguments - int argc; - LPWSTR cmdLine = GetCommandLineW(); - LPWSTR * argvW = CommandLineToArgvW(cmdLine, &argc); - - // Allocate UTF-8 strings - char * * argv = (char * *)malloc(argc * sizeof(char *)); - if (argv == nullptr) - { - return false; - } - - // Convert to UTF-8 - for (int i = 0; i < argc; i++) - { - argv[i] = ConvertUTF16toUTF8(argvW[i]); - } - - // Free UTF-16 strings - LocalFree(argvW); - - *outargc = argc; - *outargv = argv; - return true; -} - -static void FreeCommandLineArgs(int argc, char * * argv) -{ - // Free argv - for (int i = 0; i < argc; i++) - { - free(argv[i]); - } - free(argv); -} - -static char * ConvertUTF16toUTF8(const wchar_t * src) -{ - int srcLen = lstrlenW(src); - int sizeReq = WideCharToMultiByte(CP_UTF8, 0, src, srcLen, nullptr, 0, nullptr, nullptr); - char * result = (char *)calloc(1, sizeReq + 1); - WideCharToMultiByte(CP_UTF8, 0, src, srcLen, result, sizeReq, nullptr, nullptr); - return result; + return LaunchOpenRCT2(argc, argvW); } diff --git a/src/openrct2-win/openrct2-win.vcxproj b/src/openrct2-win/openrct2-win.vcxproj index 67c40a3a0d..fd3c828888 100644 --- a/src/openrct2-win/openrct2-win.vcxproj +++ b/src/openrct2-win/openrct2-win.vcxproj @@ -45,9 +45,8 @@ $(OPENRCT2_CL_ADDITIONALOPTIONS) %(AdditionalOptions) - openrct2-lib.lib;%(AdditionalDependencies) - Console - Windows + openrct2.lib;%(AdditionalDependencies) + Console MachineX86 diff --git a/src/openrct2/OpenRCT2.h b/src/openrct2/OpenRCT2.h index e7d814f1d1..72c97060b7 100644 --- a/src/openrct2/OpenRCT2.h +++ b/src/openrct2/OpenRCT2.h @@ -88,7 +88,7 @@ extern "C" int cmdline_run(const char * * argv, int argc); #ifdef _MSC_VER - int RunOpenRCT2(int argc, char * *); + int RunOpenRCT2(int argc, char * * argv); #endif #ifdef __cplusplus From b7b58817bb4f9571351726d2380bd3a92b9afa8d Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 9 Jan 2017 19:57:26 +0000 Subject: [PATCH 04/13] Rename openrct2-lib to libopenrct2 --- openrct2.sln | 2 +- src/openrct2-dll/openrct2-dll.vcxproj | 2 +- src/openrct2/{openrct2-lib.vcxproj => libopenrct2.vcxproj} | 2 +- test/tests/tests.vcxproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename src/openrct2/{openrct2-lib.vcxproj => libopenrct2.vcxproj} (99%) diff --git a/openrct2.sln b/openrct2.sln index 3998763de4..beefaf1616 100644 --- a/openrct2.sln +++ b/openrct2.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openrct2-lib", "src\openrct2\openrct2-lib.vcxproj", "{D24D94F6-2A74-480C-B512-629C306CE92F}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libopenrct2", "src\openrct2\libopenrct2.vcxproj", "{D24D94F6-2A74-480C-B512-629C306CE92F}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testpaint", "test\testpaint\testpaint.vcxproj", "{57E60BA1-FB76-4316-909E-C1449C142327}" EndProject diff --git a/src/openrct2-dll/openrct2-dll.vcxproj b/src/openrct2-dll/openrct2-dll.vcxproj index 3cb9c34dfe..605489b76c 100644 --- a/src/openrct2-dll/openrct2-dll.vcxproj +++ b/src/openrct2-dll/openrct2-dll.vcxproj @@ -45,7 +45,7 @@ $(OPENRCT2_CL_ADDITIONALOPTIONS) %(AdditionalOptions) - openrct2-lib.lib;%(AdditionalDependencies) + libopenrct2.lib;%(AdditionalDependencies) MachineX86 diff --git a/src/openrct2/openrct2-lib.vcxproj b/src/openrct2/libopenrct2.vcxproj similarity index 99% rename from src/openrct2/openrct2-lib.vcxproj rename to src/openrct2/libopenrct2.vcxproj index 4a50422ff2..e585fe0d34 100644 --- a/src/openrct2/openrct2-lib.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -24,7 +24,7 @@ {D24D94F6-2A74-480C-B512-629C306CE92F} openrct2-lib - openrct2-lib + libopenrct2 StaticLibrary diff --git a/test/tests/tests.vcxproj b/test/tests/tests.vcxproj index 8b7bca2f9f..5b866801fb 100644 --- a/test/tests/tests.vcxproj +++ b/test/tests/tests.vcxproj @@ -41,7 +41,7 @@ GTEST_LANG_CXX11;%(PreprocessorDefinitions) - openrct2-lib.lib;%(AdditionalDependencies) + libopenrct2.lib;%(AdditionalDependencies) Console From 4d8779957f0529bcf9dbcab281738326f31cc19f Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 9 Jan 2017 20:25:30 +0000 Subject: [PATCH 05/13] Create openrct2.com and add to installer --- distribution/windows/install.nsi | 4 ++++ openrct2.proj | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/distribution/windows/install.nsi b/distribution/windows/install.nsi index 0607e5c3d6..92a919333f 100644 --- a/distribution/windows/install.nsi +++ b/distribution/windows/install.nsi @@ -152,6 +152,8 @@ Section "!OpenRCT2" Section1 ; Copy executable File /oname=${OPENRCT2_EXE} ${BINARY_DIR}\${OPENRCT2_EXE} + File /oname=openrct2.com ${BINARY_DIR}\openrct2.com + File /oname=openrct2.dll ${BINARY_DIR}\openrct2.dll ; Create the Registry Entries WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenRCT2" "Comments" "Visit ${APPURLLINK}" @@ -218,6 +220,8 @@ Section "Uninstall" Delete "$INSTDIR\readme.txt" Delete "$INSTDIR\contributors.md" Delete "$INSTDIR\${OPENRCT2_EXE}" + Delete "$INSTDIR\openrct2.com" + Delete "$INSTDIR\openrct2.dll" Delete "$INSTDIR\INSTALL.LOG" ; Data files diff --git a/openrct2.proj b/openrct2.proj index 17be4373d3..d676a7a86a 100644 --- a/openrct2.proj +++ b/openrct2.proj @@ -40,6 +40,8 @@ $(DistDir)windows\install.nsi $(TargetDir)openrct2.exe + $(TargetDir)openrct2.com + $(TargetDir)openrct2.dll $(TargetDir)data\g2.dat $(DistDir)windows\code-sign-key-openrct2.org.pfx @@ -75,15 +77,21 @@ + + + + + + @@ -137,6 +145,7 @@ + @@ -204,6 +213,14 @@ StandardOutputImportance="low" /> + + + + + + Date: Mon, 9 Jan 2017 21:02:06 +0000 Subject: [PATCH 06/13] Remove BuildTests task --- openrct2.proj | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/openrct2.proj b/openrct2.proj index d676a7a86a..f82fa92ddd 100644 --- a/openrct2.proj +++ b/openrct2.proj @@ -188,17 +188,8 @@ - - - DebugTests - ReleaseTests - $(SlnProperties);Configuration=$(Configuration) - - - - - + From 1b21a308cdfd5866733d9b657c52fae725440048 Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 9 Jan 2017 22:06:47 +0000 Subject: [PATCH 07/13] Fix debugging by using unique named PDBs --- openrct2.proj | 3 ++- src/openrct2-dll/openrct2-dll.vcxproj | 1 + src/openrct2-win/openrct2-win.vcxproj | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/openrct2.proj b/openrct2.proj index f82fa92ddd..b70b3beee7 100644 --- a/openrct2.proj +++ b/openrct2.proj @@ -85,7 +85,8 @@ - + + diff --git a/src/openrct2-dll/openrct2-dll.vcxproj b/src/openrct2-dll/openrct2-dll.vcxproj index 605489b76c..79367987c9 100644 --- a/src/openrct2-dll/openrct2-dll.vcxproj +++ b/src/openrct2-dll/openrct2-dll.vcxproj @@ -46,6 +46,7 @@ libopenrct2.lib;%(AdditionalDependencies) + $(OutDir)openrct2-dll.pdb MachineX86 diff --git a/src/openrct2-win/openrct2-win.vcxproj b/src/openrct2-win/openrct2-win.vcxproj index fd3c828888..dcc0fade85 100644 --- a/src/openrct2-win/openrct2-win.vcxproj +++ b/src/openrct2-win/openrct2-win.vcxproj @@ -46,6 +46,7 @@ openrct2.lib;%(AdditionalDependencies) + $(OutDir)openrct2-win.pdb Console From d535e290d31d6229c51c7c27766f2bb87b93e149 Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 9 Jan 2017 22:28:28 +0000 Subject: [PATCH 08/13] Remove --console CLI switch --- src/openrct2/cmdline/RootCommands.cpp | 18 ------------------ src/openrct2/platform/platform.h | 2 -- src/openrct2/platform/shared.c | 4 ---- src/openrct2/platform/windows.c | 23 ----------------------- 4 files changed, 47 deletions(-) diff --git a/src/openrct2/cmdline/RootCommands.cpp b/src/openrct2/cmdline/RootCommands.cpp index fefd5c8869..0fe7173b17 100644 --- a/src/openrct2/cmdline/RootCommands.cpp +++ b/src/openrct2/cmdline/RootCommands.cpp @@ -39,10 +39,6 @@ extern "C" #define IMPLIES_SILENT_BREAKPAD #endif // USE_BREAKPAD -#if defined(__WINDOWS__) && !defined(DEBUG) - #define __PROVIDE_CONSOLE__ 1 -#endif // defined(__WINDOWS__) && !defined(DEBUG) - #ifndef DISABLE_NETWORK int gNetworkStart = NETWORK_MODE_NONE; char gNetworkStartHost[128]; @@ -51,10 +47,6 @@ int gNetworkStartPort = NETWORK_DEFAULT_PORT; static uint32 _port = 0; #endif -#ifdef __PROVIDE_CONSOLE__ - static bool _provideConsole; -#endif - static bool _help = false; static bool _version = false; static bool _noInstall = false; @@ -77,9 +69,6 @@ static const CommandLineOptionDefinition StandardOptions[] { CMDLINE_TYPE_SWITCH, &_about, NAC, "about", "show information about " OPENRCT2_NAME }, { CMDLINE_TYPE_SWITCH, &_verbose, NAC, "verbose", "log verbose messages" }, { CMDLINE_TYPE_SWITCH, &_headless, NAC, "headless", "run " OPENRCT2_NAME " headless" IMPLIES_SILENT_BREAKPAD }, -#ifdef __PROVIDE_CONSOLE__ - { CMDLINE_TYPE_SWITCH, &_provideConsole, NAC, "console", "creates a new or attaches to an existing console window for standard output" }, -#endif #ifndef DISABLE_NETWORK { CMDLINE_TYPE_INTEGER, &_port, NAC, "port", "port to use for hosting or joining a server" }, #endif @@ -166,13 +155,6 @@ exitcode_t CommandLine::HandleCommandDefault() { exitcode_t result = EXITCODE_CONTINUE; -#ifdef __PROVIDE_CONSOLE__ - if (_provideConsole) - { - platform_windows_open_console(); - } -#endif - if (_about) { PrintAbout(); diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h index 27cc648cfb..32652a44fb 100644 --- a/src/openrct2/platform/platform.h +++ b/src/openrct2/platform/platform.h @@ -220,8 +220,6 @@ void core_init(); #include #undef GetMessage - void platform_windows_open_console(); - void platform_windows_close_console(); int windows_get_registry_install_info(rct2_install_info *installInfo, char *source, char *font, uint8 charset); HWND windows_get_window_handle(); void platform_setup_file_associations(); diff --git a/src/openrct2/platform/shared.c b/src/openrct2/platform/shared.c index 6ee2e3ac89..d4673430ab 100644 --- a/src/openrct2/platform/shared.c +++ b/src/openrct2/platform/shared.c @@ -643,10 +643,6 @@ void platform_free() platform_close_window(); SDL_Quit(); - -#ifdef __WINDOWS__ - platform_windows_close_console(); -#endif } void platform_start_text_input(utf8* buffer, int max_length) diff --git a/src/openrct2/platform/windows.c b/src/openrct2/platform/windows.c index bf4a85b5bc..2cbcb1fbc8 100644 --- a/src/openrct2/platform/windows.c +++ b/src/openrct2/platform/windows.c @@ -47,7 +47,6 @@ static utf8 _userDataDirectoryPath[MAX_PATH] = { 0 }; static utf8 _openrctDataDirectoryPath[MAX_PATH] = { 0 }; -static bool _consoleIsAttached = false; utf8 **windows_get_command_line_args(int *outNumArgs); @@ -125,28 +124,6 @@ __declspec(dllexport) int StartOpenRCT(HINSTANCE hInstance, HINSTANCE hPrevInsta #endif // NO_RCT2 -void platform_windows_open_console() -{ - if (!AttachConsole(ATTACH_PARENT_PROCESS)) { - if (!AllocConsole()) { - return; - } - } - - freopen("CONIN$", "r", stdin); - freopen("CONOUT$", "w", stdout); - freopen("CONOUT$", "w", stderr); - _consoleIsAttached = true; -} - -void platform_windows_close_console() -{ - if (_consoleIsAttached) { - _consoleIsAttached = false; - FreeConsole(); - } -} - utf8 **windows_get_command_line_args(int *outNumArgs) { int argc; From 21bb7b9da6ca309a254513073639ea0235b7188b Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 9 Jan 2017 22:28:39 +0000 Subject: [PATCH 09/13] Add back main entry point for mingw --- src/openrct2/platform/windows.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/openrct2/platform/windows.c b/src/openrct2/platform/windows.c index 2cbcb1fbc8..b0ad47b655 100644 --- a/src/openrct2/platform/windows.c +++ b/src/openrct2/platform/windows.c @@ -72,7 +72,18 @@ int RunOpenRCT2(int argc, char * * argv) return gExitCode; } -#ifndef NO_RCT2 +#ifdef NO_RCT2 + +#ifdef __MINGW32__ + +int main(int argc, const char **argv) +{ + return RunOpenRCT2(argc, argv); +} + +#endif + +#else /* DllMain is already defined in one of static libraries we implicitly depend * on (libcrypto), which is their bug really, but since we don't do anything in From bbac8b86de8b6a3ad6bd17b8c4844fd3674b7da6 Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 9 Jan 2017 23:10:34 +0000 Subject: [PATCH 10/13] Use editbin instead to change subsystem --- appveyor.yml | 2 +- openrct2.proj | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 0f85f297d4..707866e324 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,7 +14,7 @@ environment: OPENRCT2_ORG_TOKEN: secure: leQX3xCQpmBLGuMqrxjFlzexDt96ypNRMM5TTRVHbGE8PwVg9crgeykLc2BIZU6HDHveJCHqh2cGMdHtHYJYcw== BUILD_SERVER: AppVeyor - PATH: $(PATH);C:\Program Files (x86)\Windows Kits\10\bin\x86 + PATH: $(PATH);C:\Program Files (x86)\Windows Kits\10\bin\x86;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin install: - ps: >- .\scripts\ps\appveyor_install.ps1 diff --git a/openrct2.proj b/openrct2.proj index b70b3beee7..a2bbc5c1ec 100644 --- a/openrct2.proj +++ b/openrct2.proj @@ -208,9 +208,7 @@ - + From 9387891ad39f0da0849a91c99a4926daa924904a Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 10 Jan 2017 12:09:48 +0000 Subject: [PATCH 11/13] Convert tabs to spaces --- CMakeLists.txt | 316 ++++++++++++++++++++++++------------------------- 1 file changed, 158 insertions(+), 158 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae13bd80be..148e265168 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ set (ORCT2_RESOURCE_DIR ${CMAKE_INSTALL_PREFIX}/share/${PROJECT}/) project(${PROJECT}) if (CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR) - message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt") + message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt") endif() add_definitions(-DORCT2_RESOURCE_DIR="${ORCT2_RESOURCE_DIR}") add_definitions(-DHAVE_CONFIG_H) @@ -32,31 +32,31 @@ add_definitions(-DCURL_STATICLIB) # Define current git branch. execute_process( - COMMAND git rev-parse --abbrev-ref HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE OPENRCT2_BRANCH - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE OPENRCT2_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET ) add_definitions(-DOPENRCT2_BRANCH="${OPENRCT2_BRANCH}") # Define commit hash. execute_process( - COMMAND git rev-parse HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE OPENRCT2_COMMIT_SHA1 - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET + COMMAND git rev-parse HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE OPENRCT2_COMMIT_SHA1 + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET ) add_definitions(-DOPENRCT2_COMMIT_SHA1="${OPENRCT2_COMMIT_SHA1}") # Define short commit hash. execute_process( - COMMAND git rev-parse --short HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE OPENRCT2_COMMIT_SHA1_SHORT - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET + COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE OPENRCT2_COMMIT_SHA1_SHORT + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET ) add_definitions(-DOPENRCT2_COMMIT_SHA1_SHORT="${OPENRCT2_COMMIT_SHA1_SHORT}") @@ -99,7 +99,7 @@ INCLUDE(FindPkgConfig) # Needed for linking with non-broken OpenSSL on Apple platforms if (APPLE) - set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/opt/openssl/lib/pkgconfig") + set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/opt/openssl/lib/pkgconfig") endif (APPLE) # Options @@ -118,20 +118,20 @@ set(COMMON_COMPILE_OPTIONS "${COMMON_COMPILE_OPTIONS} -fstrict-aliasing -Werror # On mingw all code is already PIC, this will avoid compiler error on redefining this option if(NOT MINGW) - set(COMMON_COMPILE_OPTIONS "${COMMON_COMPILE_OPTIONS} -fPIC") + set(COMMON_COMPILE_OPTIONS "${COMMON_COMPILE_OPTIONS} -fPIC") endif() if (NOT DISABLE_RCT2) - set (FORCE32 ON) - message("DISABLE_RCT2 implies FORCE32") + set (FORCE32 ON) + message("DISABLE_RCT2 implies FORCE32") endif() if (DISABLE_HTTP_TWITCH) - add_definitions(-DDISABLE_HTTP -DDISABLE_TWITCH) + add_definitions(-DDISABLE_HTTP -DDISABLE_TWITCH) endif (DISABLE_HTTP_TWITCH) if (DISABLE_TTF) - add_definitions(-DNO_TTF) + add_definitions(-DNO_TTF) endif (DISABLE_TTF) # Launchpad turns on -Wdate-time for compilers that support it, this shouldn't break our build @@ -139,51 +139,51 @@ ADD_CHECK_C_COMPILER_FLAG(CMAKE_C_FLAGS C_WARN_WRITE_STRINGS -Wno-error=date-tim ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS CXX_WARN_WRITE_STRINGS -Wno-error=date-time) if (FORCE32) - set(TARGET_M "-m32") + set(TARGET_M "-m32") endif() if (FORCE32) - set(OBJ_FORMAT "elf32-i386") - set(LINKER_SCRIPT "ld_script_i386.xc") + set(OBJ_FORMAT "elf32-i386") + set(LINKER_SCRIPT "ld_script_i386.xc") endif () if (DISABLE_OPENGL) - add_definitions(-DDISABLE_OPENGL) + add_definitions(-DDISABLE_OPENGL) else (DISABLE_OPENGL) - # Makes OpenGL function get queried in run-time rather than linked-in - add_definitions(-DOPENGL_NO_LINK) + # Makes OpenGL function get queried in run-time rather than linked-in + add_definitions(-DOPENGL_NO_LINK) endif (DISABLE_OPENGL) if (USE_MMAP) - add_definitions(-DUSE_MMAP) + add_definitions(-DUSE_MMAP) endif (USE_MMAP) if (DISABLE_NETWORK) - add_definitions(-DDISABLE_NETWORK) + add_definitions(-DDISABLE_NETWORK) else (DISABLE_NETWORK) - if (WIN32) - SET(NETWORKLIBS ${NETWORKLIBS} ws2_32) - endif (WIN32) - # If you are on macOS, CMake might try using system-provided OpenSSL. - # This is too old and will not work. - PKG_CHECK_MODULES(SSL REQUIRED openssl>=1.0.0) + if (WIN32) + SET(NETWORKLIBS ${NETWORKLIBS} ws2_32) + endif (WIN32) + # If you are on macOS, CMake might try using system-provided OpenSSL. + # This is too old and will not work. + PKG_CHECK_MODULES(SSL REQUIRED openssl>=1.0.0) endif (DISABLE_NETWORK) if (DISABLE_RCT2) - add_definitions(-DNO_RCT2) + add_definitions(-DNO_RCT2) endif (DISABLE_RCT2) # Start of library checks PKG_CHECK_MODULES(PNG libpng>=1.6) if (NOT PNG_FOUND) - PKG_CHECK_MODULES(PNG libpng16) + PKG_CHECK_MODULES(PNG libpng16) endif (NOT PNG_FOUND) if (NOT PNG_FOUND) - PKG_CHECK_MODULES(PNG libpng>=1.2) + PKG_CHECK_MODULES(PNG libpng>=1.2) endif (NOT PNG_FOUND) if (NOT PNG_FOUND) - PKG_CHECK_MODULES(PNG REQUIRED libpng12) + PKG_CHECK_MODULES(PNG REQUIRED libpng12) endif (NOT PNG_FOUND) PKG_CHECK_MODULES(ZLIB REQUIRED zlib) @@ -206,40 +206,40 @@ if ((NOT DISABLE_RCT2) AND UNIX) DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/openrct2.exe ) add_custom_target(segfiles DEPENDS openrct2_text openrct2_data) - if (NOT USE_MMAP) - if (APPLE) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sectcreate rct2_text __text ${CMAKE_CURRENT_SOURCE_DIR}/build/openrct2_text -sectcreate rct2_data __data ${CMAKE_CURRENT_SOURCE_DIR}/build/openrct2_data -segaddr rct2_data 0x8a4000 -segprot rct2_data rwx rwx -segaddr rct2_text 0x401000 -segprot rct2_text rwx rwx -segaddr __TEXT 0x2000000 -read_only_relocs suppress") - else (APPLE) - # For Linux we have to use objcopy to wrap regular binaries into a linkable - # format. We use specific section names which are then referenced in a - # bespoke linker script so they can be placed at predefined VMAs. - add_custom_command( - OUTPUT openrct2_text_section.o - COMMAND objcopy --input binary --output ${OBJ_FORMAT} --binary-architecture i386 openrct2_text openrct2_text_section.o --rename-section .data=.rct2_text,contents,alloc,load,readonly,code - DEPENDS segfiles - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - ) - add_custom_command( - OUTPUT openrct2_data_section.o - COMMAND objcopy --input binary --output ${OBJ_FORMAT} --binary-architecture i386 openrct2_data openrct2_data_section.o --rename-section .data=.rct2_data,contents,alloc,load,readonly,data - DEPENDS segfiles - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - ) - add_custom_target(linkable_sections DEPENDS openrct2_text_section.o openrct2_data_section.o) - SET_SOURCE_FILES_PROPERTIES( - openrct2_text_section.o openrct2_data_section.o - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - # can't use GLOB here, as the files don't exist yet at cmake-time - set(RCT2_SECTIONS "${CMAKE_BINARY_DIR}/openrct2_data_section.o" "${CMAKE_BINARY_DIR}/openrct2_text_section.o") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-T,\"${CMAKE_CURRENT_SOURCE_DIR}/distribution/linux/${LINKER_SCRIPT}\"") - endif (APPLE) - endif (NOT USE_MMAP) + if (NOT USE_MMAP) + if (APPLE) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sectcreate rct2_text __text ${CMAKE_CURRENT_SOURCE_DIR}/build/openrct2_text -sectcreate rct2_data __data ${CMAKE_CURRENT_SOURCE_DIR}/build/openrct2_data -segaddr rct2_data 0x8a4000 -segprot rct2_data rwx rwx -segaddr rct2_text 0x401000 -segprot rct2_text rwx rwx -segaddr __TEXT 0x2000000 -read_only_relocs suppress") + else (APPLE) + # For Linux we have to use objcopy to wrap regular binaries into a linkable + # format. We use specific section names which are then referenced in a + # bespoke linker script so they can be placed at predefined VMAs. + add_custom_command( + OUTPUT openrct2_text_section.o + COMMAND objcopy --input binary --output ${OBJ_FORMAT} --binary-architecture i386 openrct2_text openrct2_text_section.o --rename-section .data=.rct2_text,contents,alloc,load,readonly,code + DEPENDS segfiles + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + add_custom_command( + OUTPUT openrct2_data_section.o + COMMAND objcopy --input binary --output ${OBJ_FORMAT} --binary-architecture i386 openrct2_data openrct2_data_section.o --rename-section .data=.rct2_data,contents,alloc,load,readonly,data + DEPENDS segfiles + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + add_custom_target(linkable_sections DEPENDS openrct2_text_section.o openrct2_data_section.o) + SET_SOURCE_FILES_PROPERTIES( + openrct2_text_section.o openrct2_data_section.o + PROPERTIES + EXTERNAL_OBJECT true + GENERATED true + ) + # can't use GLOB here, as the files don't exist yet at cmake-time + set(RCT2_SECTIONS "${CMAKE_BINARY_DIR}/openrct2_data_section.o" "${CMAKE_BINARY_DIR}/openrct2_text_section.o") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-T,\"${CMAKE_CURRENT_SOURCE_DIR}/distribution/linux/${LINKER_SCRIPT}\"") + endif (APPLE) + endif (NOT USE_MMAP) elseif (USE_MMAP) - # No dd here, can't extract data segment - message(WARNING "Sorry, your platform is not supported, you have to extract data segment manually") + # No dd here, can't extract data segment + message(WARNING "Sorry, your platform is not supported, you have to extract data segment manually") endif ((NOT DISABLE_RCT2) AND UNIX) set(DEBUG_LEVEL 0 CACHE STRING "Select debug level for compilation. Use value in range 0–3.") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDEBUG=${DEBUG_LEVEL}") @@ -250,15 +250,15 @@ include_directories("lib/") # add source files file(GLOB_RECURSE ORCT2_SOURCES "src/*.c" "src/*.cpp" "src/*.h" "src/*.hpp") if (APPLE) - file(GLOB_RECURSE ORCT2_MM_SOURCES "src/*.m") - set_source_files_properties(${ORCT2_MM_SOURCES} PROPERTIES COMPILE_FLAGS "-x objective-c -fmodules") + file(GLOB_RECURSE ORCT2_MM_SOURCES "src/*.m") + set_source_files_properties(${ORCT2_MM_SOURCES} PROPERTIES COMPILE_FLAGS "-x objective-c -fmodules") endif (APPLE) if (APPLE AND NOT USE_MMAP) - set(PIE_FLAG "-fno-pie") + set(PIE_FLAG "-fno-pie") else () - set(PIE_FLAG "-fpie") + set(PIE_FLAG "-fpie") endif () # set necessary flags to compile code as is @@ -268,78 +268,78 @@ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${TARGET_M}") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS} ${PIE_FLAG}") if (MINGW) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++") endif () option(WITH_BREAKPAD "Enable breakpad") if (WITH_BREAKPAD) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_BREAKPAD") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BREAKPAD") - set(BREAKPAD_DIR "/home/janisozaur/workspace/breakpad/src") - set(BREAKPAD_INCLUDE_DIR "${BREAKPAD_DIR}/src") - set(BREAKPAD_LIBRARY_DIR "${BREAKPAD_DIR}/src/client/linux") - set(BREAKPAD_LIBS breakpad_client pthread) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_BREAKPAD") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BREAKPAD") + set(BREAKPAD_DIR "/home/janisozaur/workspace/breakpad/src") + set(BREAKPAD_INCLUDE_DIR "${BREAKPAD_DIR}/src") + set(BREAKPAD_LIBRARY_DIR "${BREAKPAD_DIR}/src/client/linux") + set(BREAKPAD_LIBS breakpad_client pthread) endif (WITH_BREAKPAD) PKG_CHECK_MODULES(LIBZIP REQUIRED libzip>=1.0) # find and include SDL2 PKG_CHECK_MODULES(SDL2 REQUIRED sdl2) if (NOT DISABLE_TTF) - PKG_CHECK_MODULES(SDL2_TTF REQUIRED SDL2_ttf) + PKG_CHECK_MODULES(SDL2_TTF REQUIRED SDL2_ttf) endif (NOT DISABLE_TTF) if (STATIC) - if (NOT DISABLE_TTF) - # FreeType is required by SDL2_ttf, but not wired up properly in package - PKG_CHECK_MODULES(FREETYPE REQUIRED freetype2) - endif (NOT DISABLE_TTF) - SET(SDL2LIBS ${SDL2_STATIC_LIBRARIES} ${SDL2_TTF_STATIC_LIBRARIES} ${FREETYPE_STATIC_LIBRARIES}) + if (NOT DISABLE_TTF) + # FreeType is required by SDL2_ttf, but not wired up properly in package + PKG_CHECK_MODULES(FREETYPE REQUIRED freetype2) + endif (NOT DISABLE_TTF) + SET(SDL2LIBS ${SDL2_STATIC_LIBRARIES} ${SDL2_TTF_STATIC_LIBRARIES} ${FREETYPE_STATIC_LIBRARIES}) else (STATIC) - SET(SDL2LIBS ${SDL2_LIBRARIES} ${SDL2_TTF_LIBRARIES}) + SET(SDL2LIBS ${SDL2_LIBRARIES} ${SDL2_TTF_LIBRARIES}) endif (STATIC) if (STATIC) - set(STATIC_START "-static") - SET(REQUIREDLIBS ${PNG_STATIC_LIBRARIES} ${JANSSON_STATIC_LIBRARIES} ${ZLIB_STATIC_LIBRARIES} ${SSL_STATIC_LIBRARIES} ${LIBZIP_STATIC_LIBRARIES}) + set(STATIC_START "-static") + SET(REQUIREDLIBS ${PNG_STATIC_LIBRARIES} ${JANSSON_STATIC_LIBRARIES} ${ZLIB_STATIC_LIBRARIES} ${SSL_STATIC_LIBRARIES} ${LIBZIP_STATIC_LIBRARIES}) else (STATIC) - SET(REQUIREDLIBS ${PNG_LIBRARIES} ${JANSSON_LIBRARIES} ${ZLIB_LIBRARIES} ${SSL_LIBRARIES} ${LIBZIP_LIBRARIES}) + SET(REQUIREDLIBS ${PNG_LIBRARIES} ${JANSSON_LIBRARIES} ${ZLIB_LIBRARIES} ${SSL_LIBRARIES} ${LIBZIP_LIBRARIES}) endif (STATIC) if (NOT DISABLE_OPENGL) - if (WIN32) - # Curl depends on openssl and ws2 in mingw builds, but is not wired up in pkg-config - set(GLLIBS opengl32) - # mingw complains about "%zu" not being a valid format specifier for printf, unless we - # tell it that it is - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__USE_MINGW_ANSI_STDIO=1") - elseif (APPLE) - # GL doesn't work nicely with macOS, while find_package doesn't work with multiarch on Ubuntu. - find_package(OpenGL REQUIRED) - set(GLLIBS ${OPENGL_LIBRARY}) - else (WIN32) - PKG_CHECK_MODULES(GL REQUIRED gl) - set(GLLIBS ${GL_LIBRARIES}) - endif (WIN32) + if (WIN32) + # Curl depends on openssl and ws2 in mingw builds, but is not wired up in pkg-config + set(GLLIBS opengl32) + # mingw complains about "%zu" not being a valid format specifier for printf, unless we + # tell it that it is + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__USE_MINGW_ANSI_STDIO=1") + elseif (APPLE) + # GL doesn't work nicely with macOS, while find_package doesn't work with multiarch on Ubuntu. + find_package(OpenGL REQUIRED) + set(GLLIBS ${OPENGL_LIBRARY}) + else (WIN32) + PKG_CHECK_MODULES(GL REQUIRED gl) + set(GLLIBS ${GL_LIBRARIES}) + endif (WIN32) endif (NOT DISABLE_OPENGL) if (NOT DISABLE_HTTP_TWITCH) - PKG_CHECK_MODULES(LIBCURL REQUIRED libcurl) - if (WIN32) - # Curl depends on openssl and ws2 in mingw builds, but is not wired up in pkg-config - set(WSLIBS ws2_32) - endif (WIN32) - if (STATIC) - SET(HTTPLIBS ${LIBCURL_STATIC_LIBRARIES} ${WSLIBS}) - else (STATIC) - SET(HTTPLIBS ${LIBCURL_LIBRARIES} ${WSLIBS}) - endif (STATIC) + PKG_CHECK_MODULES(LIBCURL REQUIRED libcurl) + if (WIN32) + # Curl depends on openssl and ws2 in mingw builds, but is not wired up in pkg-config + set(WSLIBS ws2_32) + endif (WIN32) + if (STATIC) + SET(HTTPLIBS ${LIBCURL_STATIC_LIBRARIES} ${WSLIBS}) + else (STATIC) + SET(HTTPLIBS ${LIBCURL_LIBRARIES} ${WSLIBS}) + endif (STATIC) endif (NOT DISABLE_HTTP_TWITCH) PKG_CHECK_MODULES(SPEEX REQUIRED speexdsp) if (UNIX AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "BSD") - # Include libdl for dlopen - set(DLLIB dl) + # Include libdl for dlopen + set(DLLIB dl) endif () INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS} ${LIBCURL_INCLUDE_DIRS} ${JANSSON_INCLUDE_DIRS} ${SPEEX_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${BREAKPAD_INCLUDE_DIR} ${SSL_INCLUDE_DIRS} ${LIBZIP_INCLUDE_DIRS}) @@ -347,39 +347,39 @@ INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS} ${LIBCURL_INCLUDE_DIRS} ${JANSSON_INCLU LINK_DIRECTORIES(${SDL2_LIBRARY_DIRS} ${JANSSON_LIBRARY_DIRS} ${LIBCURL_LIBRARY_DIRS} ${PNG_LIBRARY_DIRS} ${ZLIB_LIBRARY_DIRS} ${BREAKPAD_LIBRARY_DIR} ${SSL_LIBRARY_DIRS} ${LIBZIP_LIBRARY_DIRS}) if (NOT DISABLE_RCT2) - # Disable optimizations for addresses.c for all compilers, to allow optimized - # builds without need for -fno-omit-frame-pointer - set_source_files_properties(src/addresses.c PROPERTIES COMPILE_FLAGS -O0) + # Disable optimizations for addresses.c for all compilers, to allow optimized + # builds without need for -fno-omit-frame-pointer + set_source_files_properties(src/addresses.c PROPERTIES COMPILE_FLAGS -O0) endif (NOT DISABLE_RCT2) if (WIN32) - # build as library for now, replace with add_executable - if (USE_MMAP OR DISABLE_RCT2) - add_executable(${PROJECT} ${ORCT2_SOURCES} ${SPEEX_SOURCES}) - else () - add_library(${PROJECT} SHARED ${ORCT2_SOURCES} ${SPEEX_SOURCES}) - endif () + # build as library for now, replace with add_executable + if (USE_MMAP OR DISABLE_RCT2) + add_executable(${PROJECT} ${ORCT2_SOURCES} ${SPEEX_SOURCES}) + else () + add_library(${PROJECT} SHARED ${ORCT2_SOURCES} ${SPEEX_SOURCES}) + endif () else (WIN32) - add_executable(${PROJECT} ${ORCT2_SOURCES} ${ORCT2_MM_SOURCES} ${RCT2_SECTIONS}) - if (NOT DISABLE_RCT2) - add_dependencies(${PROJECT} segfiles) - if (NOT APPLE AND NOT USE_MMAP) - add_dependencies(${PROJECT} linkable_sections) - endif () - endif (NOT DISABLE_RCT2) - add_custom_command( - OUTPUT g2.dat - COMMAND ./openrct2 sprite build ${CMAKE_BINARY_DIR}/g2.dat ${CMAKE_CURRENT_SOURCE_DIR}/resources/g2/ - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - ) - add_custom_target(g2 DEPENDS ${PROJECT} g2.dat) + add_executable(${PROJECT} ${ORCT2_SOURCES} ${ORCT2_MM_SOURCES} ${RCT2_SECTIONS}) + if (NOT DISABLE_RCT2) + add_dependencies(${PROJECT} segfiles) + if (NOT APPLE AND NOT USE_MMAP) + add_dependencies(${PROJECT} linkable_sections) + endif () + endif (NOT DISABLE_RCT2) + add_custom_command( + OUTPUT g2.dat + COMMAND ./openrct2 sprite build ${CMAKE_BINARY_DIR}/g2.dat ${CMAKE_CURRENT_SOURCE_DIR}/resources/g2/ + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + add_custom_target(g2 DEPENDS ${PROJECT} g2.dat) endif (WIN32) if (UNIX AND NOT APPLE AND NOT DISABLE_TTF) - # FontConfig for TrueType fonts. - PKG_CHECK_MODULES(FONTCONFIG REQUIRED fontconfig) - INCLUDE_DIRECTORIES(${FONTCONFIG_INCLUDE_DIRS}) - TARGET_LINK_LIBRARIES(${PROJECT} ${FONTCONFIG_LIBRARIES}) + # FontConfig for TrueType fonts. + PKG_CHECK_MODULES(FONTCONFIG REQUIRED fontconfig) + INCLUDE_DIRECTORIES(${FONTCONFIG_INCLUDE_DIRS}) + TARGET_LINK_LIBRARIES(${PROJECT} ${FONTCONFIG_LIBRARIES}) endif (UNIX AND NOT APPLE AND NOT DISABLE_TTF) @@ -396,8 +396,8 @@ TARGET_LINK_LIBRARIES(${PROJECT} ${GLLIBS}) TARGET_LINK_LIBRARIES(${PROJECT} ${STATIC_START} ${SDL2LIBS} ${HTTPLIBS} ${NETWORKLIBS} ${SPEEX_LIBRARIES} ${DLLIB} ${REQUIREDLIBS} ${BREAKPAD_LIBS}) if (APPLE OR STATIC OR ${CMAKE_SYSTEM_NAME} MATCHES "BSD") - FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2 c) - TARGET_LINK_LIBRARIES(${PROJECT} ${ICONV_LIBRARIES}) + FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2 c) + TARGET_LINK_LIBRARIES(${PROJECT} ${ICONV_LIBRARIES}) endif () # Don't recurse, grab all *.txt and *.md files @@ -424,20 +424,20 @@ install(FILES resources/logo/icon_flag.svg DESTINATION share/icons/hicolor/scala install(FILES distribution/linux/openrct2.desktop DESTINATION share/applications) if (WITH_TESTS) - enable_testing() - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/tests/) + enable_testing() + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/tests/) endif () if (UNIX AND (NOT USE_MMAP) AND (NOT DISABLE_RCT2) AND (FORCE32)) - set(OPENRCT2_SRCPATH "src/openrct2") - file(GLOB_RECURSE ORCT2_RIDE_SOURCES "${OPENRCT2_SRCPATH}/ride/*/*.c") - file(GLOB_RECURSE ORCT2_RIDE_DEP_SOURCES "${OPENRCT2_SRCPATH}/ride/ride_data.c" "${OPENRCT2_SRCPATH}/ride/track_data.c" "${OPENRCT2_SRCPATH}/ride/track_data_old.c" "${OPENRCT2_SRCPATH}/ride/track_paint.c" "${OPENRCT2_SRCPATH}/rct2/addresses.c" "${OPENRCT2_SRCPATH}/diagnostic.c" "${OPENRCT2_SRCPATH}/rct2/hook.c" "${OPENRCT2_SRCPATH}/paint/map_element/map_element.c" "${OPENRCT2_SRCPATH}/paint/paint_helpers.c") - file(GLOB_RECURSE ORCT2_TESTPAINT_SOURCES "test/testpaint/*.c" "test/testpaint/*.cpp" "test/testpaint/*.h") + set(OPENRCT2_SRCPATH "src/openrct2") + file(GLOB_RECURSE ORCT2_RIDE_SOURCES "${OPENRCT2_SRCPATH}/ride/*/*.c") + file(GLOB_RECURSE ORCT2_RIDE_DEP_SOURCES "${OPENRCT2_SRCPATH}/ride/ride_data.c" "${OPENRCT2_SRCPATH}/ride/track_data.c" "${OPENRCT2_SRCPATH}/ride/track_data_old.c" "${OPENRCT2_SRCPATH}/ride/track_paint.c" "${OPENRCT2_SRCPATH}/rct2/addresses.c" "${OPENRCT2_SRCPATH}/diagnostic.c" "${OPENRCT2_SRCPATH}/rct2/hook.c" "${OPENRCT2_SRCPATH}/paint/map_element/map_element.c" "${OPENRCT2_SRCPATH}/paint/paint_helpers.c") + file(GLOB_RECURSE ORCT2_TESTPAINT_SOURCES "test/testpaint/*.c" "test/testpaint/*.cpp" "test/testpaint/*.h") - add_executable(testpaint EXCLUDE_FROM_ALL ${ORCT2_RIDE_SOURCES} ${ORCT2_RIDE_DEP_SOURCES} ${ORCT2_TESTPAINT_SOURCES} ${RCT2_SECTIONS}) - target_include_directories(testpaint PRIVATE "src/") - set_target_properties(testpaint PROPERTIES COMPILE_FLAGS "-DNO_VEHICLES -D__TESTPAINT__ -Wno-unused") - add_dependencies(testpaint segfiles) + add_executable(testpaint EXCLUDE_FROM_ALL ${ORCT2_RIDE_SOURCES} ${ORCT2_RIDE_DEP_SOURCES} ${ORCT2_TESTPAINT_SOURCES} ${RCT2_SECTIONS}) + target_include_directories(testpaint PRIVATE "src/") + set_target_properties(testpaint PROPERTIES COMPILE_FLAGS "-DNO_VEHICLES -D__TESTPAINT__ -Wno-unused") + add_dependencies(testpaint segfiles) endif () set(CPACK_PACKAGE_VERSION_MAJOR 0) From 7ca58573075cecc0364162c5b1c5712c4f94acf3 Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 10 Jan 2017 12:14:32 +0000 Subject: [PATCH 12/13] Isolate cmake sources to openrct2 --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 148e265168..8ea4b959b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,7 +190,7 @@ PKG_CHECK_MODULES(ZLIB REQUIRED zlib) PKG_CHECK_MODULES(JANSSON REQUIRED jansson>=2.3) # Handle creating the rct2 text and data files on macOS and Linux -# See details in src/openrct2.c:openrct2_setup_rct2_segment for how the values +# See details in src/openrct2/rct2/interop.c:rct2_interop_setup_segment for how the values # were derived. if ((NOT DISABLE_RCT2) AND UNIX) add_custom_command( @@ -248,9 +248,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG=${DEBUG_LEVEL}") # include lib include_directories("lib/") # add source files -file(GLOB_RECURSE ORCT2_SOURCES "src/*.c" "src/*.cpp" "src/*.h" "src/*.hpp") +file(GLOB_RECURSE ORCT2_SOURCES "src/openrct2/*.c" "src/openrct2/*.cpp" "src/openrct2/*.h" "src/openrct2/*.hpp") if (APPLE) - file(GLOB_RECURSE ORCT2_MM_SOURCES "src/*.m") + file(GLOB_RECURSE ORCT2_MM_SOURCES "src/openrct2/*.m") set_source_files_properties(${ORCT2_MM_SOURCES} PROPERTIES COMPILE_FLAGS "-x objective-c -fmodules") endif (APPLE) @@ -349,7 +349,7 @@ LINK_DIRECTORIES(${SDL2_LIBRARY_DIRS} ${JANSSON_LIBRARY_DIRS} ${LIBCURL_LIBRARY_ if (NOT DISABLE_RCT2) # Disable optimizations for addresses.c for all compilers, to allow optimized # builds without need for -fno-omit-frame-pointer - set_source_files_properties(src/addresses.c PROPERTIES COMPILE_FLAGS -O0) + set_source_files_properties(src/openrct2/addresses.c PROPERTIES COMPILE_FLAGS -O0) endif (NOT DISABLE_RCT2) if (WIN32) From 191c4ab9982c5d81aa3a81b3bac267d035431b01 Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 10 Jan 2017 17:37:08 +0000 Subject: [PATCH 13/13] Fix mingw build --- src/openrct2/OpenRCT2.h | 2 +- src/openrct2/platform/windows.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openrct2/OpenRCT2.h b/src/openrct2/OpenRCT2.h index 72c97060b7..b52494aeb3 100644 --- a/src/openrct2/OpenRCT2.h +++ b/src/openrct2/OpenRCT2.h @@ -87,7 +87,7 @@ extern "C" int cmdline_run(const char * * argv, int argc); -#ifdef _MSC_VER +#ifdef __WINDOWS__ int RunOpenRCT2(int argc, char * * argv); #endif diff --git a/src/openrct2/platform/windows.c b/src/openrct2/platform/windows.c index b0ad47b655..517f827aa5 100644 --- a/src/openrct2/platform/windows.c +++ b/src/openrct2/platform/windows.c @@ -76,7 +76,7 @@ int RunOpenRCT2(int argc, char * * argv) #ifdef __MINGW32__ -int main(int argc, const char **argv) +int main(int argc, char **argv) { return RunOpenRCT2(argc, argv); }