From 1496dc1a3d6a4e11da580dc145c55df7109ba695 Mon Sep 17 00:00:00 2001 From: fxliang Date: Tue, 12 Mar 2024 07:26:37 +0800 Subject: [PATCH] build: add resource info for windows MSVC build (#845) --- cmake/AddRCInfo.cmake | 53 +++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 6 +++++ src/rime.rc | 58 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 cmake/AddRCInfo.cmake create mode 100644 src/rime.rc diff --git a/cmake/AddRCInfo.cmake b/cmake/AddRCInfo.cmake new file mode 100644 index 000000000..449a6167e --- /dev/null +++ b/cmake/AddRCInfo.cmake @@ -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) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6ee20e895..15dea86a4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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}) diff --git a/src/rime.rc b/src/rime.rc new file mode 100644 index 000000000..de64c45e5 --- /dev/null +++ b/src/rime.rc @@ -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