shithub: puzzles

Download patch

ref: 08365fb260ae6e32442dd9f196e65d13facb4b33
parent: 595338fa43d40f356f04b8704f72f060651669e8
author: Simon Tatham <anakin@pobox.com>
date: Sun Nov 19 06:54:48 EST 2023

Windows: add a VERSIONINFO resource to the puzzle binaries.

This includes the textual version number in its existing
form (yyyymmdd followed by an abbreviated git hash). The four-part
binary version is set to 1 followed by year, month and day; if I ever
want to change that, I can increment the initial 1.

FileDescription is taken from the existing DESCRIPTION string provided
to each puzzle() statement in CMakeLists.txt.

This means that puzzles.rc now always defines at least one resource,
so we can remove the workaround for MinGW's windres not being able to
cope with an empty .rc file, which added a dummy resource in the
absence of an icon.

--- a/Buildscr
+++ b/Buildscr
@@ -17,6 +17,7 @@
 # Write out a version.h that contains the real version number.
 in puzzles do echo '/* Generated by automated build script */' > version.h
 in puzzles do echo '$#define VER "Version $(Version)"' >> version.h
+in puzzles do perl -e '$$ARGV[0] =~ m{(....)(..)(..)} or die; print "$#define VERSIONINFO_BINARY_VERSION 1,$$1,$$2,$$3\n"' $(!builddate) >> version.h
 
 # And do the same substitution in the OS X metadata. (This is a bit
 # icky in principle because it presumes that my version numbers don't
--- a/cmake/platforms/windows.cmake
+++ b/cmake/platforms/windows.cmake
@@ -43,10 +43,48 @@
   set_target_properties(${TARGET} PROPERTIES WIN32_EXECUTABLE ON)
 endfunction()
 
+# Escape a string to make it into a C string literal. Used for textual
+# #defines to put into VERSIONINFO resources.
+function(c_string_escape outvar value)
+  string(REPLACE "\\" "\\\\" value "${value}")
+  string(REPLACE "\"" "\\\"" value "${value}")
+  set("${outvar}" "${value}" PARENT_SCOPE)
+endfunction()
+
+# Set the character set for resource files, because we're going to use
+# a copyright sign in ours.
+if(CMAKE_C_COMPILER_ID MATCHES "MSVC" OR
+   CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
+  set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /nologo /C1252")
+else()
+  set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -c1252")
+endif()
+
+# Get the first line of LICENCE to put into VERSIONINFO resources.
+file(READ "${CMAKE_SOURCE_DIR}/LICENCE" LICENCE_TEXT)
+set(copyright_regex "This software is copyright ([^\n]*[^\n.])\\.?\n")
+string(REGEX MATCH "${copyright_regex}" COPYRIGHT_NOTICE "${LICENCE_TEXT}")
+string(REGEX REPLACE "${copyright_regex}" "\\1"
+  COPYRIGHT_NOTICE "${COPYRIGHT_NOTICE}")
+c_string_escape(COPYRIGHT_NOTICE "Copyright ${COPYRIGHT_NOTICE}")
+string(REGEX REPLACE "\\([Cc]\\)" "\\\\251"
+  COPYRIGHT_NOTICE "${COPYRIGHT_NOTICE}")
+
 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()
+
+  file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/${NAME})
+  c_string_escape(QUOTED_DESCRIPTION "${OPT_DESCRIPTION}")
+  file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/${NAME}/gamedetails.h" "\
+/* #defines for ${name}'s VERSIONINFO */
+#define VERSIONINFO_GAMENAME \"${NAME}\"
+#define VERSIONINFO_GAMEDESC \"${QUOTED_DESCRIPTION}\"
+#define VERSIONINFO_EXENAME \"${TARGET}\"
+#define VERSIONINFO_COPYRIGHT \"${COPYRIGHT_NOTICE}\"
+")
+  target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include/${NAME})
 endfunction()
 
 function(build_platform_extras)
--- a/cmake/toolchain-mingw.cmake
+++ b/cmake/toolchain-mingw.cmake
@@ -8,5 +8,3 @@
 set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
 set(CMAKE_AR          x86_64-w64-mingw32-ar)
 set(CMAKE_RANLIB      x86_64-w64-mingw32-ranlib)
-
-add_compile_definitions(MINGW32_FIX)
--- a/puzzles.rc
+++ b/puzzles.rc
@@ -1,12 +1,39 @@
 /* Windows resource file for all puzzles. */
 
+#include "version.h"
+#include "gamedetails.h"
+
 #if defined ICON_FILE
 200 ICON ICON_FILE
-#else
-#ifdef MINGW32_FIX
-/* XXX The MinGW toolchain (specifically, windres) doesn't like a resource
- * file with no resources. Give it a dummy one.
- * This can go if/when VERSIONINFO resources are added. */
-200 RCDATA { 0 }
 #endif
-#endif
+
+1 VERSIONINFO
+FILEVERSION	VERSIONINFO_BINARY_VERSION      /* version of this file */
+PRODUCTVERSION	VERSIONINFO_BINARY_VERSION	/* version of whole suite */
+FILEFLAGSMASK	0
+FILEFLAGS	0
+FILEOS		4 /* Win32 */
+FILETYPE	1 /* application */
+FILESUBTYPE	0 /* applications have no subtypes */
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+	/* "lang-charset" LLLLCCCC = (UK English, Unicode) */
+	BLOCK "080904B0"
+	BEGIN
+	    VALUE "CompanyName",	L"Simon Tatham"
+	    VALUE "ProductName",	L"Portable Puzzle Collection"
+	    VALUE "FileDescription",	VERSIONINFO_GAMEDESC
+	    VALUE "InternalName",	VERSIONINFO_GAMENAME
+	    VALUE "OriginalFilename",	VERSIONINFO_EXENAME
+	    VALUE "FileVersion",	VER
+	    VALUE "ProductVersion",	VER
+	    VALUE "LegalCopyright",	VERSIONINFO_COPYRIGHT
+	END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+	/* Once again -- same meanings -- apparently necessary */
+	VALUE "Translation", 0x809, 1200
+    END
+END
--- a/version.h
+++ b/version.h
@@ -9,3 +9,5 @@
  */
 
 #define VER "Unidentified build"
+
+#define VERSIONINFO_BINARY_VERSION 0,0,0,0