VERSION target property does not set image version of DLL
The documentation for the VERSION
and SOVERSION
target properties state this:
For shared libraries and executables on Windows the
VERSION
attribute is parsed to extract a<major>.<minor>
version number. These numbers are used as the image version of the binary.
I was checking this and discovered it not to be the case. Demonstrator example:
CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(versioning)
add_library(Example SHARED ex.cpp)
include(GenerateExportHeader)
generate_export_header(Example)
set_target_properties(Example PROPERTIES
SOVERSION 2
VERSION 2.4.7
)
target_include_directories(Example PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
ex.h
#include "example_export.h"
EXAMPLE_EXPORT int foo();
ex.cpp
#include "ex.h"
int foo()
{
return 43;
}
Using the Visual Studio 2019 generator, I built this project and checked the resultant DLL using dumpbin /HEADERS
. The relevant part of the output from that command looks like this:
PE signature found
File Type: DLL
FILE HEADER VALUES
8664 machine (x64)
6 number of sections
5D5BF254 time date stamp Tue Aug 20 23:15:00 2019
0 file pointer to symbol table
0 number of symbols
F0 size of optional header
2022 characteristics
Executable
Application can handle large (>2GB) addresses
DLL
OPTIONAL HEADER VALUES
20B magic # (PE32+)
14.21 linker version
E00 size of code
1200 size of initialized data
0 size of uninitialized data
1328 entry point (0000000180001328)
1000 base of code
180000000 image base (0000000180000000 to 0000000180006FFF)
1000 section alignment
200 file alignment
6.00 operating system version
0.00 image version <<<<=============== VERSION SHOULD BE HERE
6.00 subsystem version
0 Win32 version
7000 size of image
400 size of headers
0 checksum
3 subsystem (Windows CUI)
160 DLL characteristics
High Entropy Virtual Addresses
Dynamic base
NX compatible
100000 size of stack reserve
...
Looking at the VS Solution file that CMake generated seems to confirm that the image version isn't being set. Open the solution in the IDE, go to the Properties for the Example target, look under the Linker -> General tab and the Version
field still has its default empty value.