aboutsummaryrefslogtreecommitdiff
path: root/cmake/setup.cmake (follow)
Commit message (Collapse)AuthorAge
* Windows: leave puzzles.rc out of auxiliary GUI tools.Simon Tatham2023-11-19
| | | | | | | | | | | | | | | | | | | | | | | | | There's no reason to put the .rc file into developer tools like galaxieseditor at all. Its current job is to add an icon, and those tools don't have any. I'm about to add version information, and they won't have that either (in particular, no description string like the games do). The CLI developer tools already don't include puzzles.rc, and GUI dev tools are more like those than they are like puzzles. puzzles.rc was being added to an aux GUI tool's source file list by get_platform_puzzle_extra_source_files(), which is called for aux GUI tools as well as for puzzles proper. However, it's not as simple as just eliminating that call, because on Unix, we _do_ need to add the same extra source files to GUI dev tools that we do for puzzles, because gtk.c contains external references to either an array of the puzzle's icons or an empty array indicating that there aren't any, so _something_ has to provide that. So instead, get_platform_puzzle_extra_source_files now takes an extra argument saying whether the program is a real puzzle or an aux tool; windows.cmake leaves out puzzles.rc in the latter case, but unix.cmake puts the icon array in unconditionally.
* Add a 'core' library alongside 'common'.Simon Tatham2023-06-16
| | | | | | | | | | | | | | | | | The 'core' library contains almost all the same objects as 'common', but leaves out hat.c. And the auxiliary program 'hatgen' now links against that slightly reduced core library instead of 'common'. This avoids a dependency loop: one of hatgen's jobs is to generate hat-tables.h, but hat-tables.h is a dependency of it. Of course, the generated hat-tables.h is already committed, so this doesn't present a bootstrapping problem in a normal build. But if someone modifies hatgen.c in order to regenerate hat-tables.h, and does so in a way that makes it uncompilable, they can't rebuild hatgen and try again! Of course you can always revert changes with git, but it's annoying to have to. Better to keep the dependencies non-cyclic in the first place.
* Fall back to <math.h> if <tgmath.h> doesn't work.Simon Tatham2023-04-06
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a build failure introduced by commit 2e48ce132e011e8 yesterday. When I saw that commit I expected the most likely problem would be in the NestedVM build, which is currently the thing with the most most out-of-date C implementation. And indeed the NestedVM toolchain doesn't have <tgmath.h> - but much more surprisingly, our _Windows_ builds failed too, with a compile error inside <tgmath.h> itself! I haven't looked closely into the problem yet. Our Windows builds are done with clang, which comes with its own <tgmath.h> superseding the standard Windows one. So you'd _hope_ that clang could make sense of its own header! But perhaps the problem is that this is an unusual compile mode and hasn't been tested. My fix is to simply add a cmake check for <tgmath.h> - which doesn't just check the file's existence, it actually tries compiling a file that #includes it, so it will detect 'file exists but is mysteriously broken' just as easily as 'not there at all'. So this makes the builds start working again, precisely on Ben's theory of opportunistically using <tgmath.h> where possible and falling back to <math.h> otherwise. It looks ugly, though! I'm half tempted to make a new header file whose job is to include a standard set of system headers, just so that that nasty #ifdef doesn't have to sit at the top of almost all the source files. But for the moment this at least gets the build working again.
* Normalise pathnames in assert statements where possible.Simon Tatham2023-02-22
| | | | | | | | | | | | | | | | After commit 1470c9530b1cff3 enabled assertions, I found that my build scripts were complaining that the Windows binaries built from the same source twice were not generating the same output, and it turned out to be because the use of __FILE__ in every assert was baking in a pathname from my build setup containing a mkstemp()-randomised path component. I've found the '-fmacro-prefix-map' option, available in both gcc and clang (except the archaic gcc used by my NestedVM build, alas), which lets you remap pathnames for purpose of what __FILE__ expands to. So now our assertion statements should look as if the puzzle source just lived in /puzzles, and (just in case a pathname in a generated header ever becomes relevant) the cmake build directory is /build.
* Support multiple COMPILE_DEFINITIONS for a programBen Harris2023-02-20
| | | | | | | | Despite the name, COMPILE_DEFINITIONS was only ever used to set a single definition, and as far as I can tell that's all it could do even when I tried to put them in a single word separated by semicolons. Turning COMPILE_DEFINITIONS into a multi-valued argument seems to make it work much better.
* Try to stop CMake disabling assertions in release buildsBen Harris2023-02-19
| | | | | | | | | | Assertion failures are ugly, but they're better than the alternative. Defensive coding is a general principle throughout Puzzles and I don't think it's sensible to selectively turn that off. The mechanism by which we re-enable assertions is stolen from PuTTY (with an enhancement to cover MinSizeRel builds as well) and is pretty ugly because CMake doesn't seem to have a good way to do it.
* Avoid unnecessary timestamp bumps on generated-games.h.Simon Tatham2023-01-17
| | | | | | | | | | | | | | | | | | | | | If I re-run cmake in a Unix build directory, it unconditionally rewrites generated-games.h, which causes fuzzpuzz to be rebuilt. This is a waste of effort in the extremely common case where the rewritten generated-games.h is identical to the old one. Now we write the data to a temporary file first, and use cmake's 'configure_file' command to copy that to generated-games.h, because it so happens that configure_file checks if the two files are identical and avoids updating the timestamp on the destination file if so. (This will presumably also be a beneficial change on any other platform that uses generated_games.h in the build, such as OS X. I just hadn't noticed until it hit the build I most often re-run in an existing build directory.) cmake 3.21 has a more intuitively spelled command I could have used, called 'file(COPY_FILE src dst ONLY_IF_DIFFERENT)'. But we currently permit cmake all the way back to 3.5, so I can't use that.
* Don't use Null Game's extra source files for all GUI programsBen Harris2022-12-31
| | | | | | | | | | | | | All the not-quite-puzzle GUI programs (only galaxieseditor at this point) were using the extra source files from Null Game, presumably as a convenient way of asking not to have an icon on platforms where icons are provided as extra source files. Unfortunately, this all went wrong if Null Game did have a save file for an icon, causing CMake to complain about multiple definitions of a target. Now these programs look for extra files under their own names, which will work just as well since those have no save files to generate icons from either.
* malloc.c: check allocation sizes against PTRDIFF_MAX.Simon Tatham2021-12-11
| | | | | | | | | | | | | | | | | | | | | | | I don't expect this to actually come up in any circumstance, but it prevents a warning in some versions of gcc that would otherwise arise from the use of 'int' to compute the input size: if gcc isn't confident that the int is positive, then it complains that possible inputs to malloc might be in the region of 2^64 - (small multiple of a negative 32-bit int). I would hope malloc would fail in any case on such an input, so failing a couple of lines earlier makes no important difference. Annoyingly, stdint.h is missing in my NestedVM build setup (though it has stdbool.h - it's not _totally_ C90). So I have to check that at cmake time. Also, removed the #defines for smalloc and friends from the tree234 test mode. These were needed in the old build system, when tree234-test was built ad-hoc without being linked against malloc.c. But now tree234-test links against the same utils library as everything else, and can use the real smalloc - and doing so prevents another of these warnings when compiling with -flto.
* Fix benchmark.sh for the new cmake world.Simon Tatham2021-09-06
| | | | | | | | | It relied on reading gamedesc.txt to find a list of puzzle binaries to run. But gamedesc.txt is now specific to the Windows build (since it contains Windows executable names), and isn't available in the Unix cmake build directory. Fixed by making a simpler gamelist.txt available on all platforms.
* Permit building GUI helper tools.Simon Tatham2021-05-25
| | | | | | | | | These look like puzzles, in that they link against a frontend and provide the usual 'struct game', but they don't count as a puzzle for purposes of shipping, or even having to have descriptions and icons. There's one of these buried in the code already under an ifdef, which I'll re-enable in the next commit.
* Advertise user-configurable cmake-time config options.Simon Tatham2021-04-04
| | | | | | | | | | | | | | | | | | Various cmake variables that I was informally expecting users to set on the cmake command line (e.g. cmake -DSTRICT=ON, or cmake -DPUZZLES_GTK_VERSION=2) are now labelled explicitly with the CACHE tag, and provided with a documentation string indicating what they're for. One effect of this is that GUI-like interfaces to your cmake build directory, such as ccmake or cmake-gui, will show those variables explicitly to give you a hint that you might want to change them. Another is that when you do change them, cmake will recognise that it needs to redo the rest of its configuration. Previously, if you sat in an existing cmake build directory and did 'cmake -DSTRICT=ON .' followed by 'cmake -DSTRICT=OFF .', nothing would happen, even though you obviously meant it to.
* Install desktop files and pixmaps from CMakeDmitry Marakasov2021-04-03
|
* Migrate to a CMake-based build system.Simon Tatham2021-03-29
This completely removes the old system of mkfiles.pl + Recipe + .R files that I used to manage the various per-platform makefiles and other build scripts in this code base. In its place is a CMakeLists.txt setup, which is still able to compile for Linux, Windows, MacOS, NestedVM and Emscripten. The main reason for doing this is because mkfiles.pl was a horrible pile of unmaintainable cruft. It was hard to keep up to date (e.g. didn't reliably support the latest Visual Studio project files); it was so specific to me that nobody else could maintain it (or was even interested in trying, and who can blame them?), and it wasn't even easy to _use_ if you weren't me. And it didn't even produce very good makefiles. In fact I've been wanting to hurl mkfiles.pl in the bin for years, but was blocked by CMake not quite being able to support my clang-cl based system for cross-compiling for Windows on Linux. But CMake 3.20 was released this month and fixes the last bug in that area (it had to do with preprocessing of .rc files), so now I'm unblocked! CMake is not perfect, but it's better at mkfiles.pl's job than mkfiles.pl was, and it has the great advantage that lots of other people already know about it. Other advantages of the CMake system: - Easier to build with. At least for the big three platforms, it's possible to write down a list of build commands that's actually the same everywhere ("cmake ." followed by "cmake --build ."). There's endless scope for making your end-user cmake commands more fancy than that, for various advantages, but very few people _have_ to. - Less effort required to add a new puzzle. You just add a puzzle() statement to the top-level CMakeLists.txt, instead of needing to remember eight separate fiddly things to put in the .R file. (Look at the reduction in CHECKLST.txt!) - The 'unfinished' subdirectory is now _built_ unconditionally, even if the things in it don't go into the 'make install' target. So they won't bit-rot in future. - Unix build: unified the old icons makefile with the main build, so that each puzzle builds without an icon, runs to build its icon, then relinks with it. - Windows build: far easier to switch back and forth between debug and release than with the old makefiles. - MacOS build: CMake has its own .dmg generator, which is surely better thought out than my ten-line bodge. - net reduction in the number of lines of code in the code base. In fact, that's still true _even_ if you don't count the deletion of mkfiles.pl itself - that script didn't even have the virtue of allowing everything else to be done exceptionally concisely.