From f29483773346105da81f73878b5d0832b2d541b8 Mon Sep 17 00:00:00 2001 From: Johnny Jazeix Date: Wed, 23 Feb 2022 22:17:35 +0100 Subject: [PATCH] CMake/Windows: store Expat version in the dll Fixes #555 Tested with msvc2019 and mingw8.1 --- expat/CMakeLists.txt | 23 ++++++++++++++++------- expat/Makefile.am | 3 ++- expat/win32/expat.iss | 1 + expat/win32/version.rc | 17 +++++++++++++++++ 4 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 expat/win32/version.rc diff --git a/expat/CMakeLists.txt b/expat/CMakeLists.txt index a36b1d06..624771f4 100644 --- a/expat/CMakeLists.txt +++ b/expat/CMakeLists.txt @@ -381,7 +381,7 @@ endforeach() # # C library # -set(expat_SRCS +set(_EXPAT_C_SOURCES lib/xmlparse.c lib/xmlrole.c lib/xmltok.c @@ -393,13 +393,18 @@ set(expat_SRCS if(EXPAT_SHARED_LIBS) set(_SHARED SHARED) if(MSVC) - set(expat_SRCS ${expat_SRCS} lib/libexpat.def) + set(_EXPAT_EXTRA_SOURCES ${_EXPAT_EXTRA_SOURCES} lib/libexpat.def) + endif() + if(WIN32) + # Add DLL version + string(REPLACE "." "," _EXPAT_DLL_VERSION ${PROJECT_VERSION}.0) + set(_EXPAT_EXTRA_SOURCES ${_EXPAT_EXTRA_SOURCES} win32/version.rc) endif() else() set(_SHARED STATIC) endif() -add_library(expat ${_SHARED} ${expat_SRCS}) +add_library(expat ${_SHARED} ${_EXPAT_C_SOURCES} ${_EXPAT_EXTRA_SOURCES}) if(_EXPAT_LIBM_FOUND) target_link_libraries(expat m) endif() @@ -434,8 +439,12 @@ target_include_directories(expat $ ) -if(NOT EXPAT_SHARED_LIBS AND WIN32) - target_compile_definitions(expat PUBLIC -DXML_STATIC) +if(WIN32) + if(EXPAT_SHARED_LIBS) + target_compile_definitions(expat PRIVATE VER_FILEVERSION=${_EXPAT_DLL_VERSION}) + else() + target_compile_definitions(expat PUBLIC -DXML_STATIC) + endif() endif() expat_install(TARGETS expat EXPORT expat @@ -550,7 +559,7 @@ if(EXPAT_BUILD_TESTS) tests/memcheck.c tests/minicheck.c tests/structdata.c - ${expat_SRCS} + ${_EXPAT_C_SOURCES} ) if(NOT MSVC) @@ -619,7 +628,7 @@ if(EXPAT_BUILD_FUZZERS) set(encoding_types UTF-16 UTF-8 ISO-8859-1 US-ASCII UTF-16BE UTF-16LE) set(fuzz_targets xml_parse_fuzzer xml_parsebuffer_fuzzer) - add_library(fuzzpat STATIC ${expat_SRCS}) + add_library(fuzzpat STATIC ${_EXPAT_C_SOURCES}) if(NOT EXPAT_OSSFUZZ_BUILD) target_compile_options(fuzzpat PRIVATE -fsanitize=fuzzer-no-link) endif() diff --git a/expat/Makefile.am b/expat/Makefile.am index e6e7971e..9fc2e9d5 100644 --- a/expat/Makefile.am +++ b/expat/Makefile.am @@ -82,7 +82,8 @@ _EXTRA_DIST_WINDOWS = \ win32/build_expat_iss.bat \ win32/expat.iss \ win32/MANIFEST.txt \ - win32/README.txt + win32/README.txt \ + win32/version.rc EXTRA_DIST = \ $(_EXTRA_DIST_CMAKE) \ diff --git a/expat/win32/expat.iss b/expat/win32/expat.iss index 2bbfdab7..e4d82745 100644 --- a/expat/win32/expat.iss +++ b/expat/win32/expat.iss @@ -76,6 +76,7 @@ Flags: ignoreversion; Source: doc\*.css; DestDir: "{app}\Doc" Flags: ignoreversion; Source: doc\*.xml; DestDir: "{app}\Doc" Flags: ignoreversion; Source: win32\bin\Release\*.dll; DestDir: "{app}\Bin" Flags: ignoreversion; Source: win32\bin\Release\*.lib; DestDir: "{app}\Bin" +Flags: ignoreversion; Source: win32\version.rc; DestDir: "{app}\Bin" Flags: ignoreversion; Source: win32\README.txt; DestDir: "{app}\Source" Flags: ignoreversion; Source: AUTHORS; DestDir: "{app}\Source" Flags: ignoreversion; Source: Changes; DestDir: "{app}\Source" diff --git a/expat/win32/version.rc b/expat/win32/version.rc new file mode 100644 index 00000000..64a4dadf --- /dev/null +++ b/expat/win32/version.rc @@ -0,0 +1,17 @@ +1 VERSIONINFO +FILEVERSION VER_FILEVERSION +PRODUCTVERSION VER_FILEVERSION +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + BEGIN + VALUE "FileVersion", "VER_FILEVERSION" + VALUE "ProductVersion", "VER_FILEVERSION" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 1252 + END +END