The International Simutrans Forum

 

Author Topic: How to compile Simutrans with MS Visual Studio  (Read 16242 times)

0 Members and 1 Guest are viewing this topic.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2908
  • D'oh
    • by An_dz
  • Languages: pt, en, it, (de)
How to compile Simutrans with MS Visual Studio
« on: July 14, 2019, 10:38:59 PM »
I'm currently trying to improve our Visual Studio solutions as they are pretty messy and outdated. I've both used Visual Studio Community 2019 and manually edited them to make them better.

According to Microsoft [1] these files should be backwards compatible down to ~VS2012. If you are using a VS older than 2019 and newer than 2012 please try to load the attached solutions and let me know how they work for you.

One of the changes I did is to always compile inside the build/ dir just like GCC (it won't conflict with GCC unless you really want to).

Another change for the Simutrans solution is that now it's a single solution file with 4 projects. Simutrans-Main is the project that holds the shared, non back-end specific, files; Simutrans GDI, Simutrans SDL2 and Simutrans Server all use Main to build the specific back-end executables.

And a final difference is that now there are 3 compilation configurations for the main executable. Debug remains the same, meant for developing; Stable is the old Release, meant for compiling stable versions; and Release continues to build optimised code but now using revision data just like debug, this is meant for creating optimised nightly builds for servers.

These project files should also be easier to maintain, when new source files are added to Simutrans you just need to add those files in the Simutrans-Main.vcxitems file in alphabetical order and it will compile correctly just like the Makefile.

Please test as if they have backwards compatibility as promised I'll replace the files in trunk

I also compiled all the latest versions of the libraries required for Simutrans with Visual Studio Community 2019 (MSVC v14.21). The attached solutions expect them, most notably pthread-win32 version 3 which is an upgrade from the current outdated version 2 we are using. All libraries are available as Debug and Release.

Download Dependencies (Compatible with VS 2015+)

Visual StudioOpen ProjectLibs Work
2019 CommunityFlawlessYes
2017 CommunityFlawlessYes
2015 CommunityFlawlessYes
2013 CommunityFlawlessNo
2012 ExpressConverts firstNo
2010 ExpressFailNot tested

  • zlib 1.2.11 (static)
  • bzip2 1.0.8 (static)
  • libpng 1.6.37 (static)
  • pthread 3.0.0 (static)
  • SDL2 2.0.9 (dynamic)
  • freetype 2.10.1 (static)
  • miniupnpc 2.1 (dynamic)

Some information about compiling the dependencies as I ran into trouble compiling them:

All Release libraries were compiled without Whole Program Optimisation /GL to make them portable. If compiling yourself consider turning this flag on for more optimisations.

miniupnpc will simply refuse to work with static linking, and for dynamic you need to download the project file from GitHub (miniupnpc.vcxproj) as the stable release is older than this change and the old vcxproj does not contain a dll setting. And tweaking the old vcxproj is more time consuming than just updating it.
For minupnpc in Librarian add iphlpapi.lib to Additional Dependencies.

zlib debug requires to change the Runtime Library setting to Multi-threaded Debug (/MTd). You also need to remove ZLIB_WINAPI from the Preprocessor of both debug and release or add it to Simutrans. Release can't be used if compiling with assembly because of some security check.

bzip2 debug requires either enabling Function-level Linking or changing Debug Information Format to C7 compatible /Z7. The former is more easily portable as the debug info is inside the lib; it's the option used for this build.

The same above for bzip2 applies to freetype.

libpng needs to remove Treat Warnings as Errors otherwise you get errors when a warning about applying Spectre mitigation occurs. For Release it's also worth removing the Debug Information Format.

Pthread version 3 is available here. It's the same project from Sourceware. [1] [2] [3]
« Last Edit: October 06, 2019, 02:38:54 PM by An_dz »