Skip to content

Commit

Permalink
build: add resource info for windows MSVC build (rime#845)
Browse files Browse the repository at this point in the history
  • Loading branch information
fxliang authored and graphemecluster committed Mar 11, 2024
1 parent e8c3823 commit 2d4eea9
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
53 changes: 53 additions & 0 deletions cmake/AddRCInfo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# check if git is installed in system
find_program(git_executable git)
# check if ${CMAKE_SOURCE_DIR} is git repository if git is installed
# and set git_branch
if(git_executable)
execute_process(
COMMAND git rev-parse --is-inside-work-tree
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE git_repo)
if(NOT git_repo EQUAL 0)
set(git_executable "")
else()
# git_branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE git_branch
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
endif()
# set build_release
if ("${git_branch}" STREQUAL "master")
# git_commit
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE git_commit
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(build_release OFF)
else()
set(build_release ON)
endif()
# generate tag_suffix for nightly and release
if(build_release)
set(tag_suffix ".0")
else(build_release)
# arch_suffix
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(arch_suffix "x64")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(arch_suffix "Win32")
endif()
# set tag_suffix
set(tag_suffix "-${git_commit} Nightly build ${arch_suffix}")
endif(build_release)
# set resource file
set(rime_resource_file "${CMAKE_CURRENT_SOURCE_DIR}/rime.rc")
# convert rime_version to comma separated format
string(REPLACE "." "," rime_version_comma_separated ${rime_version})
# configure resource file, make version info to actually value
configure_file(${rime_resource_file} ${CMAKE_CURRENT_BINARY_DIR}/rime.rc @ONLY)
# append resource file to source file list
list(APPEND rime_core_module_src ${CMAKE_CURRENT_BINARY_DIR}/rime.rc)
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ set(rime_core_module_src
${rime_api_src}
${rime_base_src}
${rime_config_src})

# add rc info for windows MSVC build
if(MSVC)
include(${CMAKE_SOURCE_DIR}/cmake/AddRCInfo.cmake)
endif()

set(rime_dict_module_src
${rime_algo_src}
${rime_dict_src})
Expand Down
58 changes: 58 additions & 0 deletions src/rime.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "winver.h"
#ifdef MSVC
#pragma code_page (65001)
#endif

VS_VERSION_INFO VERSIONINFO
FILEVERSION @rime_version_comma_separated@,0
PRODUCTVERSION @rime_version_comma_separated@,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080404b0"
BEGIN
VALUE "CompanyName", "式恕堂"
VALUE "FileDescription", "中州韵输入法引擎"
VALUE "InternalName", "librime"
VALUE "LegalCopyright", "式恕堂 版权所无"
VALUE "OriginalFilename", "rime.dll"
VALUE "ProductName", "中州韵输入法引擎"
VALUE "ProductVersion", "@rime_version@@tag_suffix@"
END
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "式恕堂"
VALUE "FileDescription", "中州韻輸入法引擎"
VALUE "InternalName", "librime"
VALUE "LegalCopyright", "式恕堂 版權所無"
VALUE "OriginalFilename", "rime.dll"
VALUE "ProductName", "中州韻輸入法引擎"
VALUE "ProductVersion", "@rime_version@@tag_suffix@"
END
BLOCK "040904E4"
BEGIN
VALUE "CompanyName", "Rime Developers"
VALUE "FileDescription", "Rime Input Method Engine"
VALUE "InternalName", "librime"
VALUE "LegalCopyright", "Copyleft Rime Developers"
VALUE "OriginalFilename", "rime.dll"
VALUE "ProductName", "Rime Input Method Engine"
VALUE "ProductVersion", "@rime_version@@tag_suffix@"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x804, 1200
VALUE "Translation", 0x409, 1200
VALUE "Translation", 0x409, 1252
END
END

0 comments on commit 2d4eea9

Please sign in to comment.