From 0d4ced49513c3268be17cc6f40d838011df649da Mon Sep 17 00:00:00 2001 From: fxliang Date: Mon, 11 Mar 2024 17:30:42 +0800 Subject: [PATCH 1/2] build: add resource info for windows MSVC build --- src/CMakeLists.txt | 40 ++++++++++++++++++++++++++++++++ src/rime.rc | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/rime.rc diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6ee20e8956..edf933eeaf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,6 +13,46 @@ set(rime_core_module_src ${rime_api_src} ${rime_base_src} ${rime_config_src}) + +# add rc info for windows MSVC build +if(MSVC) + # check if HEAD on master + execute_process( + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE git_branch + OUTPUT_STRIP_TRAILING_WHITESPACE) + if ("${git_branch}" STREQUAL "master") + 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() + execute_process( + COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE git_commit + OUTPUT_STRIP_TRAILING_WHITESPACE) + 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 "-${git_commit} Nightly build ${arch_suffix}") + endif() + # 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) +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 0000000000..de64c45e51 --- /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 From d1e03a7a8e4b352b228f15411c334d6ee50c0c44 Mon Sep 17 00:00:00 2001 From: fxliang Date: Tue, 12 Mar 2024 00:04:18 +0800 Subject: [PATCH 2/2] AddRCInfo.cmake as an individual cmake file resolved git dependency --- cmake/AddRCInfo.cmake | 53 +++++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 36 +---------------------------- 2 files changed, 54 insertions(+), 35 deletions(-) create mode 100644 cmake/AddRCInfo.cmake diff --git a/cmake/AddRCInfo.cmake b/cmake/AddRCInfo.cmake new file mode 100644 index 0000000000..449a6167e5 --- /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 edf933eeaf..15dea86a41 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,41 +16,7 @@ set(rime_core_module_src # add rc info for windows MSVC build if(MSVC) - # check if HEAD on master - execute_process( - COMMAND git rev-parse --abbrev-ref HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE git_branch - OUTPUT_STRIP_TRAILING_WHITESPACE) - if ("${git_branch}" STREQUAL "master") - 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() - execute_process( - COMMAND git rev-parse --short HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE git_commit - OUTPUT_STRIP_TRAILING_WHITESPACE) - 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 "-${git_commit} Nightly build ${arch_suffix}") - endif() - # 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) + include(${CMAKE_SOURCE_DIR}/cmake/AddRCInfo.cmake) endif() set(rime_dict_module_src