如何使用 CMake 生成 Windows DLL 版本信息 [英] How to Generate Windows DLL versioning information with CMake
问题描述
我使用 CMake 构建共享库,但是对于 Windows DLL,我需要版本信息,例如:
I'm using CMake to build a shared library, however for the Windows DLL I need the versioning information, like:
- 文件说明
- 文件版本
- 内部名称
- 法律版权
- 原始文件名
- 产品名称
- 产品版本
到目前为止,我只有 VERSION 和 SOVERSION 属性,但这些似乎与我期望的 FileVersion 信息无关.
So far, all I have are the VERSION and SOVERSION properties, but these don't seem to correlate to the FileVersion information I was expecting.
set(LIC_TARGET MySharedLib)
add_library(${LIC_TARGET} SHARED ${SOURCES} )
SET_TARGET_PROPERTIES(${LIC_TARGET}
PROPERTIES
VERSION ${MY_PRODUCT_NUMBER}.${MY_PRODUCT_VERSION}.${MY_BUILD_NUMBER}
SOVERSION ${MY_PRODUCT_NUMBER})
我找到了手动方法(参见底部的示例)但更愿意将其包含在 CMake 中.
I've found manual methods (see example at the bottom) but would prefer to contain this within CMake.
帮助?
推荐答案
您可以将 CMake 变量值与 version.rc.in 文件和 configure_file 命令.
You could use your CMake variable values in conjunction with a version.rc.in file and the configure_file command.
// version.rc.in
#define VER_FILEVERSION @MY_PRODUCT_NUMBER@,@MY_PRODUCT_VERSION@,@MY_BUILD_NUMBER@,0
#define VER_FILEVERSION_STR "@MY_PRODUCT_NUMBER@.@MY_PRODUCT_VERSION@.@MY_BUILD_NUMBER@.0 "
#define VER_PRODUCTVERSION @MY_PRODUCT_NUMBER@,@MY_PRODUCT_VERSION@,@MY_BUILD_NUMBER@,0
#define VER_PRODUCTVERSION_STR "@MY_PRODUCT_NUMBER@.@MY_PRODUCT_VERSION@.@MY_BUILD_NUMBER@ "
//
// ...along with the rest of the file from your "manual methods" reference
然后,在您的 CMakeLists.txt 文件中:
And then, in your CMakeLists.txt file:
# CMakeLists.txt
set(MY_PRODUCT_NUMBER 3)
set(MY_PRODUCT_VERSION 5)
set(MY_BUILD_NUMBER 49)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in
${CMAKE_CURRENT_BINARY_DIR}/version.rc
@ONLY)
set(LIC_TARGET MySharedLib)
add_library(${LIC_TARGET} SHARED ${SOURCES}
${CMAKE_CURRENT_BINARY_DIR}/version.rc)
# Alternatively you could simply include version.rc in another rc file
# if there already is one in one of the files in ${SOURCES}
这篇关于如何使用 CMake 生成 Windows DLL 版本信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!