How to Generate Windows DLL versioning information with CMake

前端 未结 3 1067
一生所求
一生所求 2020-12-12 17:39

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

  • FileDescription
  • FileVersion
3条回答
  •  感情败类
    2020-12-12 18:04

    I'm had same problem and have automated version generation for my projects. You need three files from github:

    • generate_product_version.cmake
    • VersionInfo.in
    • VersionResource.rc

    Put it in cmake subdirectory of your project and make sure to include it to CMAKE_MODULE_PATH like:

    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
    

    Then before add_executable() or add_library(SHARED) your target, use:

    include(generate_product_version)
    generate_product_version(
       VersionFilesOutputVariable
       NAME "My Great Project"
       ICON ${PATH_TO_APPLICATION_ICON}
       VERSION_MAJOR 1
       VERSION_MINOR 3
       VERSION_PATCH ${BUILD_COUNTER}
       VERSION_REVISION ${BUILD_REVISION}
    )
    

    Full list of supported resource strings see in generate_product_version.cmake.

    VersionInfo.h and VersionResource.rc will be generated to cmake binaries folder. Variable VersionFilesOutputVariable will hold paths to these files. Just add this list to your target:

    add_executable(MyGreatProject ${your-target-sources} ${VersionFilesOutputVariable})
    

    UPDATE: Corrected generate_product_version script parameters from VERSION_PATH to VERSION_PATCH.

提交回复
热议问题