DLL version info on WIndows

Nicolás Alvarez nicolas.alvarez at gmail.com
Mon Nov 3 19:41:08 UTC 2014


Windows has a way for executables and shared libraries (DLLs) to
contain version information in a machine-readable format. This
information can be seen in Explorer in the file properties
(http://goo.gl/UbJGte) and also in the tooltip when hovering the file.
It's also used by Windows Installer to avoid overwriting an existing
DLL with an older version.

Qt libraries contain appropriate VERSIONINFO resources for this
(although plugins don't; I'll submit a bug report soon). Nothing in
KDE has this version information though.

Version information is stored in a VERSIONINFO "resource". The format
is described here:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa381058.aspx

Apart from the version number, this resource contains information like
the "product name", "file description", "company name", and
"copyright". While optional, if we're going to add a version resource,
we might as well fill these in properly; why not? :)

Example of a version.rc file for kcoreaddons:

VS_VERSION_INFO VERSIONINFO
    FILEVERSION 5,4,0,0
    PRODUCTVERSION 5,4,0,0
    FILEFLAGSMASK 0x3fL
    FILEFLAGS 0x0L
    FILEOS VOS__WINDOWS32
    FILETYPE VFT_DLL
    FILESUBTYPE 0x0L
    BEGIN
        BLOCK "StringFileInfo"
        BEGIN
            BLOCK "040904b0"
            BEGIN
                VALUE "FileVersion", "5.4.0\0"
                VALUE "ProductVersion", "5.4.0\0"

                VALUE "CompanyName", "KDE Community\0"
                VALUE "LegalCopyright", "Copyright (c) 2014 KDE Community\0"

                VALUE "FileDescription", "Addons to QtCore\0"
                VALUE "OriginalFilename", "KF5CoreAddons.dll\0"
                VALUE "ProductName", "KCoreAddons\0"
            END
        END
        BLOCK "VarFileInfo"
        BEGIN
            VALUE "Translation", 0x0409, 1200
        END
    END

(isn't it horrible? welcome to the 80s)

There are several ways to do this in our build system.

1. Add this resource script as a normal version.rc source file and
update it manually. On every release we'd have to change the version
number in both CMakeLists.txt and version.rc, which makes it a
terrible option that the release guys will hate :)

2. Add this resource script as a version.rc.in file with placeholders
for the version number, and have the CMakeLists.txt fill it in from
PROJECT_VERSION. Thus every framework would have its own .rc.in file
with stuff like the FileDescription and ProductName set properly, and
configure_file(version.rc.in version.rc) in CMake, plus adding
version.rc to the list of sources.

3. Put a template in ECM with placeholders in every value, and a macro to fill
it in. This way there won't be a .rc file in each framework, but every
framework will need CMake code like this:

include(ECMCreateVersionResource)
ecm_create_version_resource(version.rc
    PRODUCT_NAME KCoreAddons
    FILE_DESCRIPTION "Addons to QtCore"
    COMPANY_NAME "KDE Community"
    COPYRIGHT "Copyright (c) 2014 KDE Community"
    ORIG_FILENAME "KF5CoreAddons.dll"
)

plus adding version.rc to the list of sources.

I lean towards #3 (I couldn't find a way to get the ORIG_FILENAME
automatically; suggestions welcome)

-- 
Nicolás


More information about the Kde-buildsystem mailing list