News:

Want to praise Simutrans?
Your feedback is important for us ;D.

CMake build support

Started by ceeac, August 05, 2018, 08:50:34 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ceeac

This patch is a work-in-progress attempt to provide support for building Simutrans with CMake.

Currently this patch only works on Linux, not on Windows or macOS.
What should work:

  • Support for clang and gcc compilers
  • Building Simutrans
  • Building makeobj
  • Building nettool
  • Using CCache to speed up compilation (if available)
  • Automatically selecting a suitable graphics backend based on installed libraries (can be overridden manually)
  • Freetype support
  • MiniUPNP support
  • Automatically pulling revision information from git or svn
  • Profiling information support (-DPROFILE)
There is also a github branch available: https://github.com/ceeac/simutrans/tree/cmake

Instructions for building (with the patch applied):

mkdir build
cd build
cmake ..
make


Instructions for building from git:

git clone https://github.com/ceeac/simutrans.git simutrans
cd simutrans
git checkout cmake
mkdir build
cd build
cmake ..
make


Please test and provide feedback.  :)

Ters

We're having trouble keeping the current Makefile system working on all platforms, and keeping the Makefile and Visual Studio projects synchronized. Yet another build system in parallel is not what we need. If the build system's dependencies are rather small and can generate the Visual Studio project from some cross-platform model, it sounds promising as a complete replacement for what we got.

Personally, I've always had trouble getting cmake to work on mingw.

prissi

There is an autoconf working for mingw and linux (and possibly even MacOS, if someone would give feedback). I have no experience with cmake, and I am not sure how easy this is to install. Currently the MSVC is maintained seperately from the rest, and if thing could get streamlines, it would be really nice. But my past experience made me very cautious on portability promises.

I think Dwachs uses clang, and I think no changes are needed to the makefile. I could also use our makefile for the nightly crosscompilation, so it seems quite robust and tolerates even old-stable debian (what my server runs).

Cmake would need to fulfill all this. But then it could be of great help. I may test it given time later in August.

Mariculous

#3
*digging deep*
Cmake made its way into extended.
Is there any chance to get this integrated into standard as well?
Many IDEs nowdays can use CMake as a project file, so does mine. It can generate buildfiles for many build system, including but not limited to makefiles and vxcproj.

Mariculous

#4
I just backported the CMake support from extended.
See this PR https://github.com/aburch/simutrans/pull/15

Thanks to ceeac for the great job.

prissi

#5
Somehow Cmake is broken. It cannot generate builds for MSYS2 Makefiles, or I am too stupid for this. It does not even generate a MSVC project, as it fails to find zlib (installed by VCPKG).

If anyone can write clear reproducable instructions on how to generate a mingw Makefile or a MSVC project file (or whatever) with CMake, I might consider it. But as it stands now, it just does not work.

EDIT2: It seems to miss also Xaudio support on windows, which does not need the large fluidsynth libraries and still can play multiple sounds at once. Also lots of references to extended in there. Standard does not use git (it is a read only mirror of the SVN). Amended those, but as said I could not test it, since all three cmake (the MSYS2, the CMake gui and the one in MSVC failed to process this patch).

Mariculous

For reference as An-dz requested a patch instead of a PR, there is the patch related to this PR.
https://patch-diff.githubusercontent.com/raw/aburch/simutrans/pull/15.patch

I am not a CMake expert nor do I build simutrans on windows but I might have a look later on.

Roboron

I can't compile using cmake when applying the last patch from prissi.

Without the changes to simdebug.h, compilation will fail:

brueckenbauer.cc:668:2: error: 'DBG_MESSAGE' was not declared in this scope

Compilation will also fail on water_vehicle.cc without the additional includes. So those changes on the patch by Freahk were necessary. I've re-added them on the patch attached, and also removed a last reference to git versioning.

I'm also interested on getting this working for Standard. Let's recap what's missing:

1. :done: ? Strip Extended-related features.
2. Document how to generate MinGW Makefiles from CMake.
3. CMake should be able to locate libraries installed by VCPKG.
4. CMake should be able to locate natively available Xaudio on Windows.

2. How to generate MinGW Makefiles from CMake.

Looking at how Simutrans Extended does it, an additional cmake toolchain configuration file is needed to build on MinGW.

=> https://github.com/jamespetts/simutrans-extended/blob/master/.github/toolchain_mingw.cmake

I've tried it on my mingw linux installation (note that you need to adjust the TARGET_ENVIRONMENT variable to fit your MinGW installation). It worked, until the linking phase, when it failed with undefined references caused by miniupnp (and fluidsynth, but that's not necessary anyway). I don't know if this is reproducible on other mingw installations and in such a case if anyone from Extended know how to solve it. Please confirm this.

Anyway, I tried compiling without those and it worked.

cmake -DCMAKE_TOOLCHAIN_FILE=toolchain_mingw.cmake -DSIMUTRANS_USE_FLUIDSYNTH_MIDI=0 -DSIMUTRANS_USE_UPNP=0 ..
make


I don't have more time now, but I'll leave hints about the other points.

3. CMake should be able to locate libraries installed by VCPKG.

This seems to be what we are looking for:

=> https://vcpkg.readthedocs.io/en/latest/examples/installing-and-using-packages/#cmake

4. CMake should be able to locate natively available Xaudio on Windows.

First it needs to be added to SimutransDependencies.cmake. If adding findpackage(Xaudio) or similar is not enough, we probably have to manually point CMake to the library location (on a new file cmake/FindXaudio.cmake).

prissi

#8
cmake does not work in a plain vanilla installation in Windows 10 for me. I tried open cmake files in MSVC, using cmake on commandline, or using cmake GUI or cmake that comes with msys2. I tried on two computers. The mingw target in cmake is only for crosscompiling it seems.

MSVC studio does not allow any settings for cmake, and it finds the libaries during compilation even when not defined in the project files. And still it cannot use cmake.

EDIT:

I finally get cmake to do something. However, the commands given in the docs are wrong.

On MSYS2

cmake . -B aaa
[...]
System is unknown to cmake, create:
Platform/MINGW32_NT-10.0-19042 to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
[...]

This version number however changes with each update to the system. As it is now, linking fails since it builds a 64 bit SDL2 even if no SDL is there and on MSYS2-i686. So the cmake file seems very broken to me and not detect the system correctly.

MSVC
Cmake just build x64 targets for MSVC. So this is why it seems to fails with my installation, which just have 32 bit libaries.

So the cmake files seems to need much much more work. This seems much more complicated than autoconf, which is agnostic on bit size or if cross compiling or not (it find that out itself as it should).

Also it seems there is no Xcode mac target?

And why does it force clang instead using system default. That would take care of crosscompilation automatically.

I have to admid that at the moment the advantages of cmake seems low to me.

EDIT2:
I think I worded that too hard. At the moment, there is some help needed from a person more experienced with cMake to have some files that work out of the box on more than one architecture or setup without assuming bit size etc.

Roboron

Ok let's go one issue at a time.

Building on MSYS with cmake

First, you may want to uninstall the cmake version that comes with MSYS, as this doesn't work and will be called instead of mingw's cmake.

pacman -R cmake

Second, make sure you have installed cmake for your mingw architecture

pacman -S mingw-w64-{x86_64,i686}-cmake

Now when you call cmake the right cmake binary will be called (you can also call it explictly with /mingw64/bin/cmake if you don't want to uninstall the MSYS one). And you should be able to build simutrans with:

cmake -G "MSYS Makefiles" ..

=> https://cmake.org/cmake/help/latest/generator/MSYS%20Makefiles.html

I've tried it and it works, so please try it.

On the attached patch I've added (forced) static linking when building with mingw (for some reason Extended lack this?). Previously mentioned linking issues were fixed.

prissi


cmake -G "MSYS Makefiles" -B aaa

or so is the correct command it seems to build. Ok, thank it works at least.

But it builds SDL2 and not Xaudio GDI, and builds makeobj and nettol, which is not needed very time. Also how to make debug/release builds, server builds and set all the other flags in the code now?

Also a lot of strange warning flags seems activated, giving many useless errors (like when the format string is not explicitely given).

Also the building seems to fail to generate the resouces. See the detailed setting for release and for this build:

And I still cannot use this cmake with MSVC studio, even in the 2019 latest version. It just offers x64-debug as target, no choice for SDL2 or not, not the other exe.

So there is certainly progress, but still not there yet.

Mariculous

#11
See cmake -L[A][H] for a list of available variables.
The optional A will also list so called "advanced" configuration variables.
The optional H will add a short description of these variables to the output.
To set these variables, use the -D<var>=<value>

for example, to build simutrans headless, call cmake -DSIMUTRANS_BACKEND=none

Roboron

Let's continue with MSYS compilation, I think we are close.

QuoteBut it builds SDL2 and not Xaudio GDI

If SDL2 is found, then it builds with SDL2, yes. However, you can specify gdi backend with -DSIMUTRANS_BACKEND=gdi option. For usingh Xaudio2 with GDI, the attached patch add support for that.

Quotebuilds makeobj and nettol, which is not needed very time

I've found that if you only want to compile one target you can do so running cmake instead of make like this:

cmake --build . --target simutrans

QuoteAlso how to make debug/release builds, server builds and set all the other flags in the code now?

The type of build can also be configured when calling cmake. To sum up, using MSYS to make a Release build with GDI backend and only compiling the simutrans executable:

cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release -DSIMUTRANS_BACKEND=gdi ..
cmake --build . --target simutrans


Similarly other backends (sdl2, sdl2mixer) and builds (Release, Debug) can be given.

QuoteAlso the building seems to fail to generate the resouces.

What do you mean with resouces¿

Mariculous

cmake --build . --target simutrans
You can, and I'd recommend this as it will (or at least should) work with any supported build system but you don't have to.
You can simply use
make simutrans
instead.

prissi

Thanks. The resources is a file simres.rc containing copyright, version, and icons, and the manifest, which states high resolution aware

Roboron

Ah, yes. It was never included in the source list. Now it is.

This patch also removes the config/ files as that is not related to cmake. I have also included some minor fixes I needed for cross-compilation.

QuoteYou can, and I'd recommend this as it will (or at least should) work with any supported build system but you don't have to.

Ah, that's great to know. Thank you.

Roboron

Quote from: prissi on April 23, 2021, 01:39:59 AMAnd I still cannot use this cmake with MSVC studio, even in the 2019 latest version. It just offers x64-debug as target

It seems that you need to specify the target architecture when generating the MSVC project, cmake can't generate both at the same time. Quoting ceeac on the Extended thread:

Quotecmake.exe .. -G "Visual Studio 16 2019" -A x64 -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake

In this call you need to replace "-A x64" with "-A Win32" to generate a 32 bit MSVC project. I've tried and succedeed.

Does that work for you? If so, I think that's all. I can work next on documenting all of this on the wiki (and maybe later updating the README).

Attached patch has no new changes, I only re-added some files that were not added on the previous one for some reason.

prissi

Ok, MSVC delibrately hid the options. I could load the cmake file, and compile simutrans then after some clicking in some cmake options.. But I cannot debug it, since there is no window to enter the debug options (like start in D:/Simjtrans with -use_workdir ..." ALso I have no idea what binary (GDI or SDL2) was actually built. Somehow cmake let me feel like a Mac user, (or living in Japan): Everything great until you want something non-standard and then everything falls apart ...



Roboron

Quote from: prissi on May 11, 2021, 12:52:18 PMBut I cannot debug it, since there is no window to enter the debug options (like start in D:/Simjtrans with -use_workdir ...

Have you considered opening a shell in the executable directory and call it from there? There may be a way to do it directly from MSVC, but I don't know barely anything about MSVC.

Quote from: prissi on May 11, 2021, 12:52:18 PMALso I have no idea what binary (GDI or SDL2) was actually built.

Well, you should know it since you called cmake, and you can call it with -DSIMUTRANS_BACKEND=gdi to specify the backend. If you didn't specify any backend, SDL2 will be choosed if SDL2 is found, otherwise GDI.

I also noticed you didn't even need to open MSVC to compile. Calling cmake with the previously mentioned cmake command:

cmake --build . --target simutrans --config Release

Will build simutrans on the shell using the MSVC compiler. Sweet!

prissi

For building on the commandline, one does not need cmake. The only advantage would be if cmake can build on the shell and inside MSVC, i.e. that one only has to support one building system instead two (as it is now). For building on the command line, it is hard to beat the autotools, since they run on anything that has bash and a c-compiler ...

(But then maybe cmake versus autotools is like svn versus git, both have their good and bad points, and both can do the job and it is down to personal preference)

Having said that, I still would like to avoid to support two building systems or getting Android running. If cmake can help with that, it would be great.

(Also I a pretty sure there is somewhere an option to set debug commands also when using cmake with MSVC.)

Mariculous

#20
Quote from: prissi on May 11, 2021, 12:52:18 PMsince there is no window to enter the debug options (like start in D:/Simjtrans with -use_workdir ..."
I don't know anything about MSVC, but generally, it's a run/launch option, not a compile option, so I'd expect even in MSVC this has nothing to do with how the program was compiled (Cmake or not) but only to how it is launched, so there should be a MSVC setting hidden somewhere in the depth of the UI.

Edit: I just found this one.
Launch.vs.json and "args": ["-use_workdir"] might be what you are looking for, but again, I have no idea of MSVC.
https://docs.microsoft.com/de-de/cpp/build/configure-cmake-debugging-sessions?view=msvc-160#reference-keys-in-cmakesettingsjson

Roboron

Quote from: prissi on May 11, 2021, 02:09:08 PMHaving said that, I still would like to avoid to support two building systems or getting Android running. If cmake can help with that, it would be great.

According to the documentation about using C++ code with Android, yes, CMake will be needed to build an Android version of Simutrans.

QuoteAndroid Studio's default build tool to compile native libraries is CMake. Android Studio also supports ndk-build due to the large number of existing projects that use the build toolkit. However, if you are creating a new native library, you should use CMake.

=> https://developer.android.com/ndk/guides

Probably some minor changes to the CMakeLists.txt will be needed for Android, but let's focus on having CMake ready for current supported systems before going on that hole.

prissi

Some Progress: During compile it fails for nettool. It seems nettool ignores the x86 setting and is compiled as 64bit app by default?!?

But we are getting closer. The libraries are not static linked (which should be the default, at least for windows and likely for MacOS too) And because there is not dynamic version of zstd installed on my system starting simutrans fails (but linking works, looks like a bug in vcpkg to still have the linking stub there). Still static libaries should be the preferred way. (That way a release only contains the needed code instead everything and the binary works on any computer regardsless of the OS version.)

Also the message level is 0 by default instead 3. I try some things for force it to three when not given, but not much success with it.

Byt the way: Has cMake building tested for MacOS?

Mariculous

Quote from: prissi on May 12, 2021, 01:39:29 AMByt the way: Has cMake building tested for MacOS?
Extended builds without any issues on MacOS using Cmake.
At least that's a feedback I got from the pak192.comic community.

prissi

#24
It does not work with MSVC. Nettool never finds zstd.h while all the other are built.

Moreover, after and error or a warning, the program is not rebuilt. delete the out folder and start with cache generation again. Most annoying.

Debugging with a different startup directory is very difficult. One has to click in the clock in the projet view window the solution explorer icon select cmake solutions, selectct simutrans and then there one can edit a json with startup options as below
https://stackoverflow.com/questions/41864259/how-to-set-working-directory-for-visual-studio-2017-rc-cmake-project

However, it did not work for me. Is there no one using MSVC with cMake?

EDIT:
I could finally generate a project file using the commandline which compiled and linked simutrans (but not nettool, that is definitely broken, does not find zlib.h!" I looked into the cMakefile but I am not sure how to fix this.)

Furthermore, the cmake generation fails when not specifying the vcpgk.cmake full path, despite being in the MSVC developer prompt (where it otherwise compiles normally without spoecify anything.). And this is needed each time I test a SDL2 ot normal build and so on. Honestly, this is very uncorfortable as developer and wastes a lot of time and resets all customisation each time as well. (Not to mention that on each of my developer computers the github location is different due to different user names and primary partition size.)

I found a lot of wrong space/tabs in the files, and some other stuff like static linking. Also the endianness support is gone, which might be required for some architectures on Linux.

EDIT2:
So until the inbuilt cMake support from MSVC is fixed, the MSVC proj needed to be still supported. Unfortunately this removes any gain of switching to cmake, since it would require redoing all nightly builds etc. Also I can fix Makefiles (and thus autoconf) but I fail a cMake (yet).

That all would change if MSVC cmake support become useable for development and not only for single use compiling. Or there is an android port which requires cmake, and thus a third build system to support. So this is considered, I would say, but the gain is not very high compared to the troubles it brings short term for changing all build systems, deployment etc.

ceeac

Quote from: prissi on May 13, 2021, 01:18:52 AM(but not nettool, that is definitely broken, does not find zlib.h!"
The error was also present in trunk, but masked by the fact that zlib is required for the main program. Should be fixed now (r9772).

prissi

Thanks. I will try with cMake later this week, hopefully.

Roboron

Quote from: prissi on May 13, 2021, 01:18:52 AMFurthermore, the cmake generation fails when not specifying the vcpgk.cmake full path

It says in the vcpkg documentation you have to set it in MSVC:

=> https://github.com/Microsoft/vcpkg#vcpkg-with-visual-studio-cmake-projects

After that it also says we can set a default vcpkg directory it in the CMakeLists.txt, so I did (it is set to the build directory). So if you bootstrap vcpkg in the build directory (as recommended), you won't need to call CMake with -DCMAKE_TOOLCHAIN_FILE.

I have also try to improve the static libs. I've found that calling CMake with -DVCPKG_TARGET_TRIPLET=x64-windows-static linked against the static libraries built by vcpkg, so we can set this to usefor static libs by default.

if (WIN32)
# Windows uses vcpkg (installed to the build dir) to link against static libraries by default
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_BINARY_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file")
if(NOT ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "x64")) # 32 bit Windows
set(VCPKG_TARGET_TRIPLET x86-windows-static CACHE STRING "Vcpkg target libraries")
else( NOT ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "x86") ) # 64 bit Windows
set(VCPKG_TARGET_TRIPLET x64-windows-static CACHE STRING "Vcpkg target libraries")
endif()
endif ()


For linking dynamically one would need now to call cmake with -DVCPKG_TARGET_TRIPLET=x64-windows instead (that is, the situation is the reverse now, but I guess that's ok since static linking is preferred). Maybe doing this an option would be better for the user, feel free to improve.

Quote from: prissi on May 13, 2021, 01:18:52 AMAlso the endianness support is gone, which might be required for some architectures on Linux.

There's a test for endianness that set the SIM_BIG_ENDIAN flag. Isn't that what you are refering to?

if (SIMUTRANS_BIG_ENDIAN)
target_compile_definitions(simutrans PRIVATE SIM_BIG_ENDIAN=1)
endif ()


Attached patch include the vcpkg static libs code and some files (nettool and makeobj CMakeList.txt) that were not in your previous patch for some reason.

prissi

#28
Thanks, I will test it.

Can you give also a list of options, please. Since there is no template any more, there is absolutely no way to find out what flags on may want to set and what not. cmake -LAH never works for me, and is of no use if used with MSVC, since it cannot be accessed there.

EDIT:
At least miniunpnc does not link with this, seems to be still linking to the DLL. And it does not find zstd, even though it is installed the same way then freetype etc.

EDIT 2:
I cannot use cmake even any more with MSYS2. I had to remove the whole if (WIN32) part

EDIT 3:
freetype does not link libbrotli and thus I cannot build MSYS2. Seems like a problem with freetype?

EDIT 4:
I think it does not make sense to set the vcpkg triplet. I have anyway to edit json files to build and debug on MSVC, so specifying this is no further issue. It can be even set graphically inside MSVC. (However, the standard user will have no idea that this is there.)

EDIT 5:
I could finally build and debug something with MSVC, so there may be a light at the horizon. It requires editing hidden json file and clicking on obscure images never needed otherwise, but it is possible to use the cmake file now in MSVC. I have to test this on my other computer, to seem how reproducible this is.
The find miniu... needs at least this to build.

if (MSVC)
    set_property(TARGET MiniUPNP::MiniUPNP PROPERTY INTERFACE_LINK_LIBRARIES "iphlpapi.lib")
endif (MSVC)
endif (MiniUPNP_FOUND)


Mariculous

#29
Quote from: Freahk on April 23, 2021, 12:21:31 PMSee cmake -L[A][H] for a list of available variables.
The optional A will also list so called "advanced" configuration variables.
The optional H will add a short description of these variables to the output.
To set these variables, use the -D<var>=<value>

for example, to build simutrans headless, call cmake -DSIMUTRANS_BACKEND=none

This should work, I'll post the output here.
However, how does it fail? What's the reported error?
Usually you want to run CMake in a subdirectory as I did below.
If the error message is something like
QuoteCMake Error at CMakeLists.txt:10 (message):
  Building Simutrans in-source is not supported.  Please delete
  /path/to/simutrans/source/CMakeCache.txt and configure in a
  different (preferrably empty) directory.
then you should delete /path/to/simutrans/source/CMakeCache.txt, create a build subdirectory, for example build-standard and run Cmake -LAH .. from that directory.

I didn't run te latest state of this, so a few variables might have changed in the meantime..

The short list, which is roughly the default.config equivalent.
QuoteDome@linux-9uud:~/projects/simutrans-extended/build-standard> cmake -L ..
-- Could NOT find CCache (missing: CCache_EXECUTABLE)
-- Configuring Simutrans-Extended (commit 4e94f3f on standard-cmake-support) ...
-- Configuring done
-- Generating done
-- Build files have been written to: /home/Dome/projects/simutrans-extended/build-standard
-- Cache values
CMAKE_BUILD_TYPE:STRING=RelWithDebInfo
CMAKE_INSTALL_PREFIX:PATH=/usr/local
SIMUTRANS_BACKEND:STRING=sdl2
SIMUTRANS_BUILD_32BIT:BOOL=OFF
SIMUTRANS_DEBUG_SIMRAND:BOOL=OFF
SIMUTRANS_ENABLE_IPV6:BOOL=ON
SIMUTRANS_ENABLE_PROFILING:BOOL=OFF
SIMUTRANS_ENABLE_RANDOMNESS:BOOL=ON
SIMUTRANS_MSG_LEVEL:STRING=0
SIMUTRANS_MULTI_THREAD:BOOL=ON
SIMUTRANS_USE_FLUIDSYNTH_MIDI:BOOL=ON
SIMUTRANS_USE_FREETYPE:BOOL=OFF
SIMUTRANS_USE_SYSLOG:BOOL=OFF
SIMUTRANS_USE_UPNP:BOOL=ON
SIMUTRANS_USE_ZSTD:BOOL=ON
SIMUTRANS_VALGRIND_SUPPORT:BOOL=OFF
SIMUTRANS_WITH_REVISION:BOOL=ON


And here is the full list with all advanced variables
QuoteDome@linux-9uud:~/projects/simutrans-extended/build-standard> cmake -LAH ..
-- Could NOT find CCache (missing: CCache_EXECUTABLE)
-- Configuring Simutrans-Extended (commit 4e94f3f on standard-cmake-support) ...
-- Configuring done
-- Generating done
-- Build files have been written to: /home/Dome/projects/simutrans-extended/build-standard
-- Cache values
// Path to a file.
BZIP2_INCLUDE_DIR:PATH=/usr/include

// Path to a library.
BZIP2_LIBRARY_DEBUG:FILEPATH=BZIP2_LIBRARY_DEBUG-NOTFOUND

// Path to a library.
BZIP2_LIBRARY_RELEASE:FILEPATH=/usr/lib64/libbz2.so

// Path to a program.
CCache_EXECUTABLE:FILEPATH=CCache_EXECUTABLE-NOTFOUND

// Path to a program.
CMAKE_ADDR2LINE:FILEPATH=/usr/bin/addr2line

// Path to a program.
CMAKE_AR:FILEPATH=/usr/bin/ar

// Build type. Valid values are Debug Release MinSizeRel RelWithDebInfo
CMAKE_BUILD_TYPE:STRING=RelWithDebInfo

// Enable/Disable color output during build.
CMAKE_COLOR_MAKEFILE:BOOL=ON

// CXX compiler
CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++

// A wrapper around 'ar' adding the appropriate '--plugin' option for the GCC compiler
CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-7

// A wrapper around 'ranlib' adding the appropriate '--plugin' option for the GCC compiler
CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-7

// Flags used by the CXX compiler during all build types.
CMAKE_CXX_FLAGS:STRING=

// Flags used by the CXX compiler during DEBUG builds.
CMAKE_CXX_FLAGS_DEBUG:STRING=-g

// Flags used by the CXX compiler during MINSIZEREL builds.
CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG

// Flags used by the CXX compiler during RELEASE builds.
CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG

// Flags used by the CXX compiler during RELWITHDEBINFO builds.
CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG

// C compiler
CMAKE_C_COMPILER:FILEPATH=/usr/bin/cc

// A wrapper around 'ar' adding the appropriate '--plugin' option for the GCC compiler
CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-7

// A wrapper around 'ranlib' adding the appropriate '--plugin' option for the GCC compiler
CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-7

// Flags used by the C compiler during all build types.
CMAKE_C_FLAGS:STRING=

// Flags used by the C compiler during DEBUG builds.
CMAKE_C_FLAGS_DEBUG:STRING=-g

// Flags used by the C compiler during MINSIZEREL builds.
CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG

// Flags used by the C compiler during RELEASE builds.
CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG

// Flags used by the C compiler during RELWITHDEBINFO builds.
CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG

// Path to a program.
CMAKE_DLLTOOL:FILEPATH=CMAKE_DLLTOOL-NOTFOUND

// Flags used by the linker during all build types.
CMAKE_EXE_LINKER_FLAGS:STRING=

// Flags used by the linker during DEBUG builds.
CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING=

// Flags used by the linker during MINSIZEREL builds.
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING=

// Flags used by the linker during RELEASE builds.
CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING=

// Flags used by the linker during RELWITHDEBINFO builds.
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING=

// Enable/Disable output of compile commands during generation.
CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=

// Install path prefix, prepended onto install directories.
CMAKE_INSTALL_PREFIX:PATH=/usr/local

// Path to a program.
CMAKE_LINKER:FILEPATH=/usr/bin/ld

// Path to a program.
CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/gmake

// Flags used by the linker during the creation of modules during all build types.
CMAKE_MODULE_LINKER_FLAGS:STRING=

// Flags used by the linker during the creation of modules during DEBUG builds.
CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING=

// Flags used by the linker during the creation of modules during MINSIZEREL builds.
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING=

// Flags used by the linker during the creation of modules during RELEASE builds.
CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING=

// Flags used by the linker during the creation of modules during RELWITHDEBINFO builds.
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING=

// Path to a program.
CMAKE_NM:FILEPATH=/usr/bin/nm

// Path to a program.
CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy

// Path to a program.
CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump

// Path to a program.
CMAKE_RANLIB:FILEPATH=/usr/bin/ranlib

// Path to a program.
CMAKE_READELF:FILEPATH=/usr/bin/readelf

// Flags used by the linker during the creation of shared libraries during all build types.
CMAKE_SHARED_LINKER_FLAGS:STRING=

// Flags used by the linker during the creation of shared libraries during DEBUG builds.
CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING=

// Flags used by the linker during the creation of shared libraries during MINSIZEREL builds.
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING=

// Flags used by the linker during the creation of shared libraries during RELEASE builds.
CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING=

// Flags used by the linker during the creation of shared libraries during RELWITHDEBINFO builds.
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING=

// If set, runtime paths are not added when installing shared libraries, but are added when building.
CMAKE_SKIP_INSTALL_RPATH:BOOL=NO

// If set, runtime paths are not added when using shared libraries.
CMAKE_SKIP_RPATH:BOOL=NO

// Flags used by the linker during the creation of static libraries during all build types.
CMAKE_STATIC_LINKER_FLAGS:STRING=

// Flags used by the linker during the creation of static libraries during DEBUG builds.
CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING=

// Flags used by the linker during the creation of static libraries during MINSIZEREL builds.
CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING=

// Flags used by the linker during the creation of static libraries during RELEASE builds.
CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING=

// Flags used by the linker during the creation of static libraries during RELWITHDEBINFO builds.
CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING=

// Path to a program.
CMAKE_STRIP:FILEPATH=/usr/bin/strip

// If this value is on, makefiles will be generated without the .SILENT directive, and all commands will be echoed to the console during the make.  This is useful for debugging only. With Visual Studio IDE projects all commands are done without /nologo.
CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE

// Enable to build RPM source packages
CPACK_SOURCE_RPM:BOOL=OFF

// Enable to build TBZ2 source packages
CPACK_SOURCE_TBZ2:BOOL=ON

// Enable to build TGZ source packages
CPACK_SOURCE_TGZ:BOOL=ON

// Enable to build TXZ source packages
CPACK_SOURCE_TXZ:BOOL=ON

// Enable to build TZ source packages
CPACK_SOURCE_TZ:BOOL=ON

// Enable to build ZIP source packages
CPACK_SOURCE_ZIP:BOOL=OFF

// Path to a file.
FREETYPE_INCLUDE_DIR_freetype2:PATH=/usr/include/freetype2

// Path to a file.
FREETYPE_INCLUDE_DIR_ft2build:PATH=/usr/include/freetype2

// Path to a library.
FREETYPE_LIBRARY_DEBUG:FILEPATH=FREETYPE_LIBRARY_DEBUG-NOTFOUND

// Path to a library.
FREETYPE_LIBRARY_RELEASE:FILEPATH=/usr/lib64/libfreetype.so

// Path to a file.
FluidSynth_INCLUDE_DIR:PATH=/usr/include

// Path to a library.
FluidSynth_LIBRARY:FILEPATH=/usr/lib64/libfluidsynth.so

// Git command line client
GIT_EXECUTABLE:FILEPATH=/usr/bin/git

// Path to a file.
MiniUPNP_INCLUDE_DIR:PATH=/usr/include/miniupnpc

// Path to a library.
MiniUPNP_LIBRARY:FILEPATH=/usr/lib64/libminiupnpc.so

// Path to a library.
MiniUPNP_STATIC_LIBRARY:FILEPATH=MiniUPNP_STATIC_LIBRARY-NOTFOUND

// Path to a library.
PNG_LIBRARY_DEBUG:FILEPATH=PNG_LIBRARY_DEBUG-NOTFOUND

// Path to a library.
PNG_LIBRARY_RELEASE:FILEPATH=/usr/lib64/libpng.so

// Path to a file.
PNG_PNG_INCLUDE_DIR:PATH=/usr/include

// Where the SDL2 headers can be found
SDL2_INCLUDE_DIR:PATH=/usr/include/SDL2

// Where the SDL2 Library can be found
SDL2_LIBRARY:FILEPATH=/usr/lib64/libSDL2.so

// Where the SDL2_mixer headers can be found
SDL2_MIXER_INCLUDE_DIR:PATH=/usr/include/SDL2

// Where the SDL2_mixer Library can be found
SDL2_MIXER_LIBRARY:FILEPATH=/usr/lib64/libSDL2_mixer.so

// Disable search SDL2_mixer Library in default path
SDL2_MIXER_NO_DEFAULT_PATH:BOOL=OFF

// Custom SDL2_mixer Library path
SDL2_MIXER_PATH:STRING=

// Disable search SDL2 Library in default path
SDL2_NO_DEFAULT_PATH:BOOL=OFF

// Custom SDL2 Library path
SDL2_PATH:STRING=

// Graphics backend
SIMUTRANS_BACKEND:STRING=sdl2

// Build 32 or 64 bit executable
SIMUTRANS_BUILD_32BIT:BOOL=OFF

// Debug the random number generator
SIMUTRANS_DEBUG_SIMRAND:BOOL=OFF

// Enable connections using IPv6 in addition to IPv4
SIMUTRANS_ENABLE_IPV6:BOOL=ON

// Enable profiling code
SIMUTRANS_ENABLE_PROFILING:BOOL=OFF

// Disable to make get_random_seed() always return the same number
SIMUTRANS_ENABLE_RANDOMNESS:BOOL=ON

// Message verbosity level
SIMUTRANS_MSG_LEVEL:STRING=0

// Use multiple threads for drawing
SIMUTRANS_MULTI_THREAD:BOOL=ON

// Enable FluidSynth for MIDI playback
SIMUTRANS_USE_FLUIDSYNTH_MIDI:BOOL=ON

// Enable TrueType font support using freetype library
SIMUTRANS_USE_FREETYPE:BOOL=OFF

// Enable logging to syslog
SIMUTRANS_USE_SYSLOG:BOOL=OFF

// Use MiniUPNP for easier server setup
SIMUTRANS_USE_UPNP:BOOL=ON

// Enable support for zstd save file compression (larger save files than bzip2, but faster)
SIMUTRANS_USE_ZSTD:BOOL=ON

// Add support for valgrind "memcheck" tool
SIMUTRANS_VALGRIND_SUPPORT:BOOL=OFF

// Build executable with git commit information
SIMUTRANS_WITH_REVISION:BOOL=ON

// Path to a file.
ZLIB_INCLUDE_DIR:PATH=/usr/include

// Path to a library.
ZLIB_LIBRARY_DEBUG:FILEPATH=ZLIB_LIBRARY_DEBUG-NOTFOUND

// Path to a library.
ZLIB_LIBRARY_RELEASE:FILEPATH=/usr/lib64/libz.so

// Path to a file.
ZSTD_INCLUDE_DIR:PATH=/usr/include

// Path to a library.
ZSTD_LIBRARY:FILEPATH=/usr/lib64/libzstd.so

prissi

#30
mingw just cannot built a working executable. After removing msys64 totally and reinstalling, I was able to build, but it failed at linking; essentially all stuff to harfbuzz (from freetype) was missing. (The latter is anywhere a 9 MB unneccessary monster.) MVSC requires editing the .json configuration files to add the correct triplet for static linking.

Compared to a config file, this listing of parameters is of limited use. For instance, there are no valid parameters given for backend or value range for debug parameters (or are there other command line switches). Also the optimised profiling build option seems to have vanished.

One can probably end up with a single build system in the end; however, the windows build process (which was hailed a the biggest avantage of cmake) is not so straightforward. And debugging the cmake Makefiles to find out why harfbuzz is not included, is not very easy. Especially comparing to "./configure make" on almost any other system.

EDIT:
No success with msys2 though. But here are the file which would build at least with a correct revision.

Roboron

#31
Quote from: prissi on June 01, 2021, 03:19:42 AMI cannot use cmake even any more with MSYS2. I had to remove the whole if (WIN32) part

I don't have such a problem but we can also replace WIN32 with MSVC (this checks for the compiler, not the OS).

Quote from: prissi on June 01, 2021, 12:21:00 PMI was able to build, but it failed at linking; essentially all stuff to harfbuzz (from freetype) was missing.

I see. When adding the necessary linking flags for MinGW, I didn't check for every combination of libraries. I was able to build without problems because another library (fluidsynth) was linking to harfbuzz, but it indeed fail if I try to compile with FreeType only. This should fix it; try again.

Quoteif (SIMUTRANS_USE_FREETYPE)
   target_compile_definitions(simutrans PRIVATE USE_FREETYPE=1)
   target_include_directories(simutrans PRIVATE ${FREETYPE_INCLUDE_DIRS})
   target_link_libraries(simutrans PRIVATE ${FREETYPE_LIBRARIES})
   if (MINGW)
       # MinGW needs additional link flags
       target_link_libraries(simutrans PRIVATE  -lpng16 -lharfbuzz -lrpcrt4 -lgraphite2 -lglib-2.0 -lbrotlidec -lbrotlicommon -lfreetype)
   endif (MINGW)
endif (SIMUTRANS_USE_FREETYPE)

EDIT. Using MSVC to check for the compiler does not work on my system. But searching for Visual Studio in CMAKE_GENERATOR seems to do the trick

if (${CMAKE_GENERATOR} MATCHES "Visual Studio*") ...

prissi

I have a serious problem with cmake. While it should be platform-independent, yet I have to tell with which libraries to link SDL2 or freetype? This may work for one year or two, and then break again.

This is not good for something that long around as simutrans. Why not using pkg-config? The installed library should know best with what options it was compiled! Instead some SDL2 module from some time ago was used for SDL2. I highly doubt this will work when compiling for arm ...

Also strange why the msys build freetype would ask for libharfbuzz, since I built (and linked) mine without for the classic make. Maybe it tries to make a 64 build on a 32 bit shell? Unfortunately I failed to see the actual commandline passed to the compiler to clear this up.

Anyway, cmake would be very broken, if it only support cmake. In the internet I found "PkgConfig" which according to the logfiles produces the right includes/libs/etc. But then it says some error has been produced and no makefile is generated. But the log file has no error.

if (SIMUTRANS_USE_FREETYPE)
find_package(PkgConfig REQUIRED)
pkg_check_modules(Freetype REQUIRED freetype2)
target_compile_options(simutrans PUBLIC ${FREETYPE_CFLAGS_OTHER})
target_include_directories(simutrans PUBLIC ${FREETYPE_INCLUDE_DIRS})
target_link_libraries(simutrans PRIVATE ${FREETYPE_LIBRARIES})
target_compile_definitions(simutrans PRIVATE USE_FREETYPE=1)
endif (SIMUTRANS_USE_FREETYPE)

In the internet I found

Roboron

This worked for me:

if (SIMUTRANS_USE_FREETYPE)
target_compile_definitions(simutrans PRIVATE USE_FREETYPE=1)
target_include_directories(simutrans PRIVATE ${FREETYPE_INCLUDE_DIRS})
if(MINGW)
find_package(PkgConfig REQUIRED)
pkg_check_modules(FREETYPE REQUIRED freetype2)
target_link_libraries(simutrans PRIVATE ${FREETYPE_STATIC_LDFLAGS} )
else ()
target_link_libraries(simutrans PRIVATE ${FREETYPE_LIBRARIES})
endif (MINGW)
endif (SIMUTRANS_USE_FREETYPE)


It is indeed an improvement to be able to use pkg-config inside cmake. Note that this still needs some improvements (we should check for PkgConfig (and the modules) in SimutransDependencies.cmake, and should be applied to other libraries as well. But test it before going forward :-)

prissi

#34
How does the neccessary freetype libaries are found in linux (or whatever your build system uses?) without a configure script?

AFTERTHOUGHT:
Also there is a long findsdl2 script from somewhere (origin unknown) under a different li\cense than simutrans artistic license.. And yet we have to give all libaries by hand for linking Mingw. This is broken by design.

I the net I read that cmake should be great for windows. If you are not using windows, do not bother, use autotools. Well, I am using windows and spent a weel trying to get a perfectly well working environment to compile und windows. What is the point. It seems less work to have a handcrafted makefile for each architekture than using the convoluted cmake syntax, which just hides the fact that there is a script for each architekture.

I am really fed up. For me cmake generates tons of problems and it solves exactly nothing. Unless there comes an architecture which requires cmake, there is no point for me trying to get this broken piece of **** engineering "cmake" to work. Sorry for the harsh words. I will take a break here, this is too frustrating. I have so little time in the next weeks, I will rather spend them constructively than trying project maintenance.