mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-22 16:32:13 -07:00
Migrate to a CMake-based build system.
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.
This commit is contained in:
237
icons/icons.cmake
Normal file
237
icons/icons.cmake
Normal file
@ -0,0 +1,237 @@
|
||||
if(NOT build_icons)
|
||||
# This entire subdirectory does nothing on platforms where we can't
|
||||
# build the icons in any case.
|
||||
return()
|
||||
endif()
|
||||
|
||||
find_program(CONVERT convert REQUIRED)
|
||||
find_program(IDENTIFY identify REQUIRED)
|
||||
|
||||
# For puzzles which have animated moves, it's nice to show the sample
|
||||
# image part way through the animation of a move. This setting will
|
||||
# cause a 'redo' action immediately after loading the save file,
|
||||
# causing the first undone move in the undo chain to be redone, and
|
||||
# then it will stop this far through the move animation to take the
|
||||
# screenshot.
|
||||
set(fifteen_redo 0.3)
|
||||
set(flip_redo 0.3)
|
||||
set(netslide_redo 0.3)
|
||||
set(sixteen_redo 0.3)
|
||||
set(twiddle_redo 0.3)
|
||||
|
||||
# For many puzzles, we'd prefer that the icon zooms in on a couple of
|
||||
# squares of the playing area rather than trying to show the whole of
|
||||
# a game. These settings configure that. Each one indicates the
|
||||
# expected full size of the screenshot image, followed by the area we
|
||||
# want to crop to.
|
||||
#
|
||||
# (The expected full size is a safety precaution: if a puzzle changes
|
||||
# its default display size, then that won't match, and we'll get a
|
||||
# build error here rather than silently continuing to take the wrong
|
||||
# subrectangle of the resized puzzle display.)
|
||||
set(blackbox_crop 352x352 144x144+0+208)
|
||||
set(bridges_crop 264x264 107x107+157+157)
|
||||
set(dominosa_crop 304x272 152x152+152+0)
|
||||
set(fifteen_crop 240x240 120x120+0+120)
|
||||
set(filling_crop 256x256 133x133+14+78)
|
||||
set(flip_crop 288x288 145x145+120+72)
|
||||
set(galaxies_crop 288x288 165x165+0+0)
|
||||
set(guess_crop 263x420 178x178+75+17)
|
||||
set(inertia_crop 321x321 128x128+193+0)
|
||||
set(keen_crop 288x288 96x96+24+120)
|
||||
set(lightup_crop 256x256 112x112+144+0)
|
||||
set(loopy_crop 257x257 113x113+0+0)
|
||||
set(magnets_crop 264x232 96x96+36+100)
|
||||
set(mines_crop 240x240 110x110+130+130)
|
||||
set(net_crop 193x193 113x113+0+80)
|
||||
set(netslide_crop 289x289 144x144+0+0)
|
||||
set(palisade_crop 288x288 192x192+0+0)
|
||||
set(pattern_crop 384x384 223x223+0+0)
|
||||
set(pearl_crop 216x216 94x94+108+15)
|
||||
set(pegs_crop 263x263 147x147+116+0)
|
||||
set(range_crop 256x256 98x98+111+15)
|
||||
set(rect_crop 205x205 115x115+90+0)
|
||||
set(signpost_crop 240x240 98x98+23+23)
|
||||
set(singles_crop 224x224 98x98+15+15)
|
||||
set(sixteen_crop 288x288 144x144+144+144)
|
||||
set(slant_crop 321x321 160x160+160+160)
|
||||
set(solo_crop 481x481 145x145+24+24)
|
||||
set(tents_crop 320x320 165x165+142+0)
|
||||
set(towers_crop 300x300 102x102+151+6)
|
||||
set(tracks_crop 246x246 118x118+6+6)
|
||||
set(twiddle_crop 192x192 102x102+69+21)
|
||||
set(undead_crop 416x480 192x192+16+80)
|
||||
set(unequal_crop 208x208 104x104+104+104)
|
||||
set(untangle_crop 320x320 164x164+3+116)
|
||||
|
||||
add_custom_target(icons)
|
||||
|
||||
# All sizes of icon we make for any purpose.
|
||||
set(all_icon_sizes 96 48 32 16)
|
||||
|
||||
# Sizes of icon we put into the Windows .ico files.
|
||||
set(win_icon_sizes 48 32 16)
|
||||
|
||||
# Border thickness for each icon size.
|
||||
set(border_96 4)
|
||||
set(border_48 4)
|
||||
set(border_32 2)
|
||||
set(border_16 1)
|
||||
|
||||
set(icon_srcdir ${CMAKE_SOURCE_DIR}/icons)
|
||||
set(icon_bindir ${CMAKE_BINARY_DIR}/icons)
|
||||
|
||||
function(build_icon name)
|
||||
set(output_icon_files)
|
||||
|
||||
# Compile the GTK puzzle binary without an icon, so that we can run
|
||||
# it to generate a screenshot to make the icon out of.
|
||||
add_executable(${NAME}-icon-maker ${NAME}.c
|
||||
${CMAKE_SOURCE_DIR}/no-icon.c)
|
||||
target_link_libraries(${NAME}-icon-maker
|
||||
common ${platform_gui_libs} ${platform_libs})
|
||||
set_target_properties(${NAME}-icon-maker PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${icon_bindir})
|
||||
|
||||
# Now run that binary to generate a screenshot of the puzzle in
|
||||
# play, which will be the base image we make everything else out
|
||||
# out.
|
||||
if(DEFINED ${name}_redo)
|
||||
set(redo_arg --redo ${name}_redo)
|
||||
else()
|
||||
set(redo_arg)
|
||||
endif()
|
||||
add_custom_command(OUTPUT ${icon_bindir}/${name}-base.png
|
||||
COMMAND ${icon_bindir}/${name}-icon-maker
|
||||
${redo_arg}
|
||||
--screenshot ${icon_bindir}/${name}-base.png
|
||||
--load ${icon_srcdir}/${name}.sav
|
||||
DEPENDS
|
||||
${name}-icon-maker)
|
||||
|
||||
# Shrink it to a fixed-size square image for the web page,
|
||||
# trimming boring border parts of the original image in the
|
||||
# process. Done by square.pl.
|
||||
add_custom_command(OUTPUT ${icon_bindir}/${name}-web.png
|
||||
COMMAND ${icon_srcdir}/square.pl
|
||||
${CONVERT} 150 5
|
||||
${icon_bindir}/${name}-base.png
|
||||
${icon_bindir}/${name}-web.png
|
||||
DEPENDS
|
||||
${icon_srcdir}/square.pl
|
||||
${icon_bindir}/${name}-base.png)
|
||||
list(APPEND output_icon_files ${icon_bindir}/${name}-web.png)
|
||||
|
||||
# Make the base image for all the icons, by cropping out the most
|
||||
# interesting part of the whole screenshot.
|
||||
add_custom_command(OUTPUT ${icon_bindir}/${name}-ibase.png
|
||||
COMMAND ${icon_srcdir}/crop.sh
|
||||
${IDENTIFY} ${CONVERT}
|
||||
${icon_bindir}/${name}-base.png
|
||||
${icon_bindir}/${name}-ibase.png
|
||||
${${name}_crop}
|
||||
DEPENDS
|
||||
${icon_srcdir}/crop.sh
|
||||
${icon_bindir}/${name}-base.png)
|
||||
|
||||
# Coerce that base image down to colour depth of 4 bits, using the
|
||||
# fixed 16-colour Windows palette. We do this before shrinking the
|
||||
# image, because I've found that gives better results than just
|
||||
# doing it after.
|
||||
add_custom_command(OUTPUT ${icon_bindir}/${name}-ibase4.png
|
||||
COMMAND ${CONVERT}
|
||||
-colors 16
|
||||
+dither
|
||||
-set colorspace RGB
|
||||
-map ${icon_srcdir}/win16pal.xpm
|
||||
${icon_bindir}/${name}-ibase.png
|
||||
${icon_bindir}/${name}-ibase4.png
|
||||
DEPENDS
|
||||
${icon_srcdir}/win16pal.xpm
|
||||
${icon_bindir}/${name}-ibase.png)
|
||||
|
||||
foreach(size ${all_icon_sizes})
|
||||
# Make a 24-bit icon image at each size, by shrinking the base
|
||||
# icon image.
|
||||
add_custom_command(OUTPUT ${icon_bindir}/${name}-${size}d24.png
|
||||
COMMAND ${icon_srcdir}/square.pl
|
||||
${CONVERT} ${size} ${border_${size}}
|
||||
${icon_bindir}/${name}-ibase.png
|
||||
${icon_bindir}/${name}-${size}d24.png
|
||||
DEPENDS
|
||||
${icon_srcdir}/square.pl
|
||||
${icon_bindir}/${name}-ibase.png)
|
||||
list(APPEND output_icon_files ${icon_bindir}/${name}-${size}d24.png)
|
||||
|
||||
# And reduce the colour depth of that one to make an 8-bit
|
||||
# version.
|
||||
add_custom_command(OUTPUT ${icon_bindir}/${name}-${size}d8.png
|
||||
COMMAND ${CONVERT}
|
||||
-colors 256
|
||||
${icon_bindir}/${name}-${size}d24.png
|
||||
${icon_bindir}/${name}-${size}d8.png
|
||||
DEPENDS ${icon_bindir}/${name}-${size}d24.png)
|
||||
list(APPEND output_icon_files ${icon_bindir}/${name}-${size}d8.png)
|
||||
endforeach()
|
||||
|
||||
foreach(size ${win_icon_sizes})
|
||||
# 4-bit icons are only needed for Windows. We make each one by
|
||||
# first shrinking the large 4-bit image we made above ...
|
||||
add_custom_command(OUTPUT ${icon_bindir}/${name}-${size}d4pre.png
|
||||
COMMAND ${icon_srcdir}/square.pl
|
||||
${CONVERT} ${size} ${border_${size}}
|
||||
${icon_bindir}/${name}-ibase4.png
|
||||
${icon_bindir}/${name}-${size}d4pre.png
|
||||
DEPENDS
|
||||
${icon_srcdir}/square.pl
|
||||
${icon_bindir}/${name}-ibase4.png)
|
||||
|
||||
# ... and then re-coercing the output back to 16 colours, since
|
||||
# that shrink operation will have introduced intermediate colour
|
||||
# values again.
|
||||
add_custom_command(OUTPUT ${icon_bindir}/${name}-${size}d4.png
|
||||
COMMAND ${CONVERT}
|
||||
-colors 16
|
||||
+dither
|
||||
-set colorspace RGB
|
||||
-map ${icon_srcdir}/win16pal.xpm
|
||||
${icon_bindir}/${name}-${size}d4pre.png
|
||||
${icon_bindir}/${name}-${size}d4.png
|
||||
DEPENDS ${icon_bindir}/${name}-${size}d4pre.png)
|
||||
list(APPEND output_icon_files ${icon_bindir}/${name}-${size}d4.png)
|
||||
endforeach()
|
||||
|
||||
# Make the Windows icon.
|
||||
set(icon_pl_args)
|
||||
set(icon_pl_deps)
|
||||
foreach(depth 24 8 4)
|
||||
list(APPEND icon_pl_args -${depth})
|
||||
foreach(size ${win_icon_sizes})
|
||||
list(APPEND icon_pl_args ${icon_bindir}/${name}-${size}d${depth}.png)
|
||||
list(APPEND icon_pl_deps ${icon_bindir}/${name}-${size}d${depth}.png)
|
||||
endforeach()
|
||||
endforeach()
|
||||
add_custom_command(OUTPUT ${icon_bindir}/${name}.ico
|
||||
COMMAND ${icon_srcdir}/icon.pl
|
||||
--convert=${CONVERT}
|
||||
${icon_pl_args} > ${icon_bindir}/${name}.ico
|
||||
DEPENDS
|
||||
${icon_srcdir}/icon.pl
|
||||
${icon_pl_deps})
|
||||
list(APPEND output_icon_files ${icon_bindir}/${name}.ico)
|
||||
|
||||
# Make a C source file containing XPMs of all the 24-bit images.
|
||||
set(cicon_pl_infiles)
|
||||
foreach(size ${all_icon_sizes})
|
||||
list(APPEND cicon_pl_infiles ${icon_bindir}/${name}-${size}d24.png)
|
||||
endforeach()
|
||||
add_custom_command(OUTPUT ${icon_bindir}/${name}-icon.c
|
||||
COMMAND ${icon_srcdir}/cicon.pl
|
||||
${CONVERT} ${cicon_pl_infiles} > ${icon_bindir}/${name}-icon.c
|
||||
DEPENDS
|
||||
${icon_srcdir}/cicon.pl
|
||||
${cicon_pl_infiles})
|
||||
|
||||
add_custom_target(${name}-icons DEPENDS ${output_icon_files})
|
||||
add_dependencies(icons ${name}-icons)
|
||||
endfunction()
|
Reference in New Issue
Block a user