Cmake experiment...

Discussion of development and patch submission.
Post Reply
shermanp
Posts: 175
Joined: Sat 18 Feb, 2017 2:09 am

Cmake experiment...

Post by shermanp »

So, I may have decided to experiment with cmake a bit, and, um... well.... this is the result. Oops?

For those who don't know what cmake is, it generates build files for a number of different build systems (eg, MAKE, Visual Studio etc.). Think of it like a cross platform alternative to the Unix autotools.

I've created an experimental proof-of-concept cmake configuration for PCem that folks may be interested in trying. If there's any interest, I will try and improve it based on user feedback. If Sarah is interested, I'll submit it as formal patch for inclusion upstream once the kinks have been worked out.

Why cmake? I realized that there are many users here who are using their own custom build system to compile PCem. Some are using MSYS, others MSYS2. Then there's the ones using standalone MinGW and MinGW-w64. And still others who may be using Linux. The current situation means that Sarah is keeping a whole bunch of different makefiles and autotools files in sync with each others.

The idea of using cmake would mean that only one set of files (or for most tasks, the source list file) needs to be altered, and cmake can worry about creating build system specific files.

Also, cmake makes it easy to build out of source.

Usage

I've currently tested this with a standalone/portable version of MinGW-w64, and MSYS2. It should also work fine on Linux.

Standalone MinGW(w-64) is the most difficult to get working, simply due to the fact that finding needed libraries/headers can be a bit of a pain. Here's a suggested example that should hopefully work:

Code: Select all

(make sure gcc and g++ are in your path)
> set PATH=%PATH%;C:\mingw-w64\mingw32\bin

(set root dir of where wxWidgets can be found. In my case, it's installed to my MinGW location)
> set WXWIN=C:/mingw-w64/mingw32

(create a build directory. May be subdirectory of pcem directory. In my case, it's a sibling directory)
> mkdir pcem-build
> cd pcem-build

(run cmake. The option "-DCMAKE_PREFIX_PATH" will help cmake find the appropriate libraries)
pcem-build> cmake -G "MinGW Makefiles" -DCMAKE_PREFIX_PATH=C:/mingw-w64/mingw32 ../pcem

(If it errors out unable to find wxWidgets, run the above again. If it still doesn't work, we will need to figure out how to improve things)
(Once successfully run, we simply run mingw32-make
pcem-build> mingw32-make -j
MSYS2 is considerably easier:

Code: Select all

$ pacman -S mingw-w64-i686-cmake
$ mkdir pcem-build
$ cd pcem-build
$ cmake -G "MSYS Makefiles" ../pcem
$ make -j
Linux should be as simple as:

Code: Select all

$ mkdir pcem-build
$ cd pcem-build
$ cmake -G "Unix Makefiles" ../pcem
$ make -j
To build a release or debug build, add the option -DCMAKE_BUILD_TYPE=Release or -DCMAKE_BUILD_TYPE=Debug to cmake before the path to pcem.

EDIT: If you change a source file, running make (or mingw32-make) again should be sufficient. No need to re-run cmake after source code changes, or even new source files. Also, if you want to start again, it's a simple matter of deleting the contents of your build directory and re-running cmake.

I welcome any feedback. As said earlier, this is an experimental POC, expect it to break :p Have fun!

As an aside, cmake is only slightly less obtuse to figure out than the autotools. I've also never used cmake before today, so there are probably better ways of doing some stuff.
Attachments
cmake-experiment.patch
(16.53 KiB) Downloaded 345 times
User avatar
SarahWalker
Site Admin
Posts: 2054
Joined: Thu 24 Apr, 2014 4:18 pm

Re: Cmake experiment...

Post by SarahWalker »

shermanp wrote: Sat 01 Dec, 2018 9:59 am If Sarah is interested, I'll submit it as formal patch for inclusion upstream once the kinks have been worked out.
Not especially, to be honest. The autotools system should work for almost all setups, with Ming/W being the exception. I'd rather work to fix the existing issues with the autotools setup and remove the non-Ming/W makefiles rather than introduce an entirely different build system.
shermanp
Posts: 175
Joined: Sat 18 Feb, 2017 2:09 am

Re: Cmake experiment...

Post by shermanp »

SarahWalker wrote: Sat 01 Dec, 2018 2:16 pm
shermanp wrote: Sat 01 Dec, 2018 9:59 am If Sarah is interested, I'll submit it as formal patch for inclusion upstream once the kinks have been worked out.
Not especially, to be honest. The autotools system should work for almost all setups, with Ming/W being the exception. I'd rather work to fix the existing issues with the autotools setup and remove the non-Ming/W makefiles rather than introduce an entirely different build system.
Fair enough, and thanks for the quick reply. I kind of suspected this might be the case, but I thought I would throw the idea out there anyway.

Also, it was a good learning experience. For example, I found that make on MSYS2 doesn't have to be dead slow, it all depends on how the makefile is generated.
Post Reply