From 08365fb260ae6e32442dd9f196e65d13facb4b33 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 19 Nov 2023 11:54:48 +0000 Subject: 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. --- cmake/platforms/windows.cmake | 38 ++++++++++++++++++++++++++++++++++++++ cmake/toolchain-mingw.cmake | 2 -- 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'cmake') diff --git a/cmake/platforms/windows.cmake b/cmake/platforms/windows.cmake index 5a0cf18..b34fc09 100644 --- a/cmake/platforms/windows.cmake +++ b/cmake/platforms/windows.cmake @@ -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) diff --git a/cmake/toolchain-mingw.cmake b/cmake/toolchain-mingw.cmake index 68ee249..a00fc7d 100644 --- a/cmake/toolchain-mingw.cmake +++ b/cmake/toolchain-mingw.cmake @@ -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) -- cgit v1.1