How to Generate Windows DLL versioning information with CMake

Issue

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

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.

Help?

Solution

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             @[email protected],@[email protected],@[email protected],0
#define VER_FILEVERSION_STR         "@[email protected]@[email protected]@[email protected]\0"

#define VER_PRODUCTVERSION          @[email protected],@[email protected],@[email protected],0
#define VER_PRODUCTVERSION_STR      "@[email protected]@[email protected]@[email protected]\0"
//
// ...along with the rest of the file from your "manual methods" reference

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}

Answered By – DLRdave

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published