Skip to content

Commit 148bb8a

Browse files
jessey-gitlgritz
authored andcommitted
build: Include Windows version information on produced binaries (AcademySoftwareFoundation#4696)
This change embeds version information into our Windows binaries. This is done by ways of a `version_win32.rc` resource file[1] populated at CMake configure time with our major.minor.patch version information. This not only allows at a glance to discover what version a particular OIIO binary is (see screenshot), but it also impacts certain MSI installer behaviors. If this is a MSI install which updates a prior installation, and the shared libs/dlls don't have version information, then the installer assumes the binaries are equal and just skips them. This can be problematic for applications that package OIIO etc. Old on left, New on right: ![old-vs-new](https://github.com/user-attachments/assets/2ff354ab-54a9-4dfb-8d97-90b138472bd7) [1] https://learn.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource --------- Signed-off-by: Jesse Yurkovich <[email protected]>
1 parent 97e2a40 commit 148bb8a

File tree

4 files changed

+92
-3
lines changed

4 files changed

+92
-3
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <winver.h>
2+
3+
#define VER_FILEVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@,0
4+
#define VER_FILEVERSION_STR "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@[email protected]\0"
5+
6+
#define VER_PRODUCTVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@,0
7+
#define VER_PRODUCTVERSION_STR "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@\0"
8+
9+
#ifndef DEBUG
10+
#define VER_DEBUG 0
11+
#else
12+
#define VER_DEBUG VS_FF_DEBUG
13+
#endif
14+
15+
VS_VERSION_INFO VERSIONINFO
16+
FILEVERSION VER_FILEVERSION
17+
PRODUCTVERSION VER_PRODUCTVERSION
18+
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
19+
FILEFLAGS (VER_DEBUG)
20+
FILEOS VOS__WINDOWS32
21+
FILETYPE VFT_DLL
22+
FILESUBTYPE VFT2_UNKNOWN
23+
BEGIN
24+
BLOCK "StringFileInfo"
25+
BEGIN
26+
BLOCK "040904E4"
27+
BEGIN
28+
VALUE "FileDescription", "OpenImageIO"
29+
VALUE "FileVersion", VER_FILEVERSION_STR
30+
VALUE "InternalName", "OpenImageIO"
31+
VALUE "ProductName", "OpenImageIO"
32+
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
33+
END
34+
END
35+
36+
BLOCK "VarFileInfo"
37+
BEGIN
38+
/* The following line should only be modified for localized versions. */
39+
/* It consists of any number of WORD,WORD pairs, with each pair */
40+
/* describing a language,codepage combination supported by the file. */
41+
/* */
42+
/* For example, a file might have values "0x409,1252" indicating that it */
43+
/* supports English language (0x409) in the Windows ANSI codepage (1252). */
44+
45+
VALUE "Translation", 0x409, 1252
46+
47+
END
48+
END

src/libOpenImageIO/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ set (libOpenImageIO_srcs
7878
${libOpenImageIO_hdrs}
7979
)
8080

81-
82-
add_library (OpenImageIO ${libOpenImageIO_srcs})
81+
if (WIN32)
82+
configure_file(../build-scripts/version_win32.rc.in "${CMAKE_CURRENT_BINARY_DIR}/version_win32.rc" @ONLY)
83+
add_library (OpenImageIO ${libOpenImageIO_srcs} ${CMAKE_CURRENT_BINARY_DIR}/version_win32.rc)
84+
else ()
85+
add_library (OpenImageIO ${libOpenImageIO_srcs})
86+
endif ()
8387

8488
# If the 'EMBEDPLUGINS' option is set, we want to compile the source for
8589
# all the plugins into libOpenImageIO.
@@ -290,4 +294,9 @@ if (OIIO_BUILD_TESTS AND BUILD_TESTING)
290294
FOLDER "Unit Tests" NO_INSTALL)
291295
add_test (unit_compute ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/compute_test)
292296

297+
if (WIN32)
298+
set (version_string "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.0")
299+
add_test (NAME win32_versioning COMMAND powershell ${CMAKE_SOURCE_DIR}/testsuite/win32/version_check.ps1 "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/" ${version_string})
300+
endif ()
301+
293302
endif ()

src/libutil/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ function (setup_oiio_util_library targetname)
3636
else ()
3737
set (libtype STATIC)
3838
endif ()
39-
add_library (${targetname} ${libtype} ${libOpenImageIO_Util_srcs})
39+
40+
if (WIN32)
41+
configure_file(../build-scripts/version_win32.rc.in "${CMAKE_CURRENT_BINARY_DIR}/version_win32.rc" @ONLY)
42+
add_library (${targetname} ${libtype} ${libOpenImageIO_Util_srcs} ${CMAKE_CURRENT_BINARY_DIR}/version_win32.rc)
43+
else ()
44+
add_library (${targetname} ${libtype} ${libOpenImageIO_Util_srcs})
45+
endif ()
4046

4147
target_compile_definitions(${targetname} PRIVATE
4248
${${PROJECT_NAME}_compile_definitions})

testsuite/win32/version_check.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Write-Host "Arguments : $args"
2+
$bin_path = $args[0]
3+
$file_version = $args[1]
4+
$product_version = [String]::Join(".", $file_version.Split(".")[0..1])
5+
6+
# Extract version information from the relevant binaries
7+
$oiio = Join-Path $bin_path "OpenImageIO.dll"
8+
$oiio_util = Join-Path $bin_path "OpenImageIO_Util.dll"
9+
$ver_oiio = (Get-ItemProperty $oiio).VersionInfo
10+
$ver_oiio_util = (Get-ItemProperty $oiio_util).VersionInfo
11+
12+
# Stringify the version info for easy comparison
13+
$expected = "OpenImageIO|$file_version|$product_version"
14+
$actual_oiio = [String]::Join("|", $ver_oiio.FileDescription, $ver_oiio.FileVersion, $ver_oiio.ProductVersion)
15+
$actual_oiio_util = [String]::Join("|", $ver_oiio_util.FileDescription, $ver_oiio_util.FileVersion, $ver_oiio_util.ProductVersion)
16+
17+
Write-Host "Expected : $expected"
18+
Write-Host "Actual : $actual_oiio"
19+
Write-Host " : $actual_oiio_util"
20+
21+
# Return 0 back to the shell if everything matches successfully
22+
if (($actual_oiio -eq $expected) -and ($actual_oiio_util -eq $expected)) {
23+
exit 0 # success
24+
}
25+
26+
exit -1

0 commit comments

Comments
 (0)