shithub: puzzles

Download patch

ref: d5b53853aad6c3bbfe255c063c045e7986de33ad
parent: b54702168b5c0759604302f198d85bc28af40feb
author: Simon Tatham <anakin@pobox.com>
date: Sun May 23 06:01:06 EDT 2021

Permit building GUI helper tools.

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.

--- a/cmake/platforms/emscripten.cmake
+++ b/cmake/platforms/emscripten.cmake
@@ -35,9 +35,13 @@
 -s EXTRA_EXPORTED_RUNTIME_METHODS='[cwrap,callMain]'")
 
 set(build_cli_programs FALSE)
+set(build_gui_programs FALSE)
 
 function(get_platform_puzzle_extra_source_files OUTVAR NAME)
   set(${OUTVAR} PARENT_SCOPE)
+endfunction()
+
+function(set_platform_gui_target_properties TARGET)
 endfunction()
 
 function(set_platform_puzzle_target_properties NAME TARGET)
--- a/cmake/platforms/nestedvm.cmake
+++ b/cmake/platforms/nestedvm.cmake
@@ -15,7 +15,7 @@
   set(${OUTVAR} PARENT_SCOPE)
 endfunction()
 
-function(set_platform_puzzle_target_properties NAME TARGET)
+function(set_platform_gui_target_properties TARGET)
   set(build_subdir ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}-tmp)
 
   add_custom_command(OUTPUT ${build_subdir}
@@ -54,6 +54,9 @@
       ${CMAKE_BINARY_DIR}/PuzzleApplet.class
       ${build_subdir}/PuzzleApplet.class
       ${build_subdir}/PuzzleEngine.class)
+endfunction()
+
+function(set_platform_puzzle_target_properties NAME TARGET)
 endfunction()
 
 function(build_platform_extras)
--- a/cmake/platforms/osx.cmake
+++ b/cmake/platforms/osx.cmake
@@ -6,8 +6,13 @@
 include(CPack)
 set(build_individual_puzzles FALSE)
 
+set(build_gui_programs FALSE) # they don't really fit in the OS X GUI model
+
 function(get_platform_puzzle_extra_source_files OUTVAR NAME)
   set(${OUTVAR} PARENT_SCOPE)
+endfunction()
+
+function(set_platform_gui_target_properties TARGET)
 endfunction()
 
 function(set_platform_puzzle_target_properties NAME TARGET)
--- a/cmake/platforms/unix.cmake
+++ b/cmake/platforms/unix.cmake
@@ -75,6 +75,9 @@
   set(${OUTVAR} ${c_icon_file} PARENT_SCOPE)
 endfunction()
 
+function(set_platform_gui_target_properties TARGET)
+endfunction()
+
 function(set_platform_puzzle_target_properties NAME TARGET)
   get_target_property(official ${TARGET} official)
   get_target_property(exename ${TARGET} exename)
--- a/cmake/platforms/windows.cmake
+++ b/cmake/platforms/windows.cmake
@@ -37,11 +37,14 @@
   set(${OUTVAR} ${CMAKE_SOURCE_DIR}/puzzles.rc PARENT_SCOPE)
 endfunction()
 
+function(set_platform_gui_target_properties TARGET)
+  set_target_properties(${TARGET} PROPERTIES WIN32_EXECUTABLE ON)
+endfunction()
+
 function(set_platform_puzzle_target_properties NAME TARGET)
   if(DEFINED ICO_DIR AND EXISTS ${ICO_DIR}/${NAME}.ico)
     target_compile_definitions(${TARGET} PRIVATE ICON_FILE=\"${ICO_DIR}/${NAME}.ico\")
   endif()
-  set_target_properties(${TARGET} PROPERTIES WIN32_EXECUTABLE ON)
 endfunction()
 
 function(build_platform_extras)
--- a/cmake/setup.cmake
+++ b/cmake/setup.cmake
@@ -4,6 +4,7 @@
 
 set(build_individual_puzzles TRUE)
 set(build_cli_programs TRUE)
+set(build_gui_programs TRUE)
 set(build_icons FALSE)
 set(need_c_icons FALSE)
 
@@ -90,6 +91,7 @@
     set_property(TARGET ${EXENAME} PROPERTY objective ${OPT_OBJECTIVE})
     set_property(TARGET ${EXENAME} PROPERTY official ${official})
     set_platform_puzzle_target_properties(${NAME} ${EXENAME})
+    set_platform_gui_target_properties(${EXENAME})
   endif()
 endfunction()
 
@@ -106,6 +108,24 @@
     if(OPT_COMPILE_DEFINITIONS)
       target_compile_definitions(${NAME} PRIVATE ${OPT_COMPILE_DEFINITIONS})
     endif()
+  endif()
+endfunction()
+
+# Similar to cliprogram, but builds a GUI helper tool, linked against
+# the normal puzzle frontend.
+function(guiprogram NAME)
+  cmake_parse_arguments(OPT
+    "" "COMPILE_DEFINITIONS" "" ${ARGN})
+
+  if(build_gui_programs)
+    get_platform_puzzle_extra_source_files(extra_files nullgame)
+    add_executable(${NAME} ${OPT_UNPARSED_ARGUMENTS} ${extra_files})
+    target_link_libraries(${NAME}
+      common ${platform_gui_libs} ${platform_libs})
+    if(OPT_COMPILE_DEFINITIONS)
+      target_compile_definitions(${NAME} PRIVATE ${OPT_COMPILE_DEFINITIONS})
+    endif()
+    set_platform_gui_target_properties(${NAME})
   endif()
 endfunction()