如何使用CMake生成Windows

如何使用CMake生成Windows

本文介绍了如何使用CMake生成Windows DLL版本信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CMake构建共享库,但是对于Windows DLL,我需要版本信息,例如:

I'm using CMake to build a shared library, however for the Windows DLL I need the versioning information, like:


  • FileDescription

  • FileVersion

  • InternalName

  • LegalCopyright

  • OriginalFilename

  • ProductName

  • ProductVersion

  • FileDescription
  • FileVersion
  • InternalName
  • LegalCopyright
  • OriginalFilename
  • ProductName
  • ProductVersion

到目前为止,我具有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})

我发现了(请参见底部的示例),但希望继续

I've found manual methods (see example at the bottom) but would prefer to contain this within CMake.

帮助?

推荐答案

您可以使用您的CMake变量值以及 version.rc.in 文件和命令。

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@.@[email protected]\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@\0"
//
// ...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版本信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 04:15