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.
This commit is contained in:
Simon Tatham
2023-11-19 11:54:48 +00:00
parent 595338fa43
commit 08365fb260
5 changed files with 75 additions and 9 deletions

View File

@ -17,6 +17,7 @@ in puzzles do perl -e 'print "\n\\versionid Simon Tatham'\''s Portable Puzzle Co
# 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

View File

@ -43,10 +43,48 @@ function(set_platform_gui_target_properties TARGET)
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)

View File

@ -8,5 +8,3 @@ set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
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)

View File

@ -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

View File

@ -9,3 +9,5 @@
*/
#define VER "Unidentified build"
#define VERSIONINFO_BINARY_VERSION 0,0,0,0