Skip to content

Commit

Permalink
Set metadata in SRT DLL on Windows (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
lewk2 authored and rndi committed Nov 4, 2019
1 parent cd04144 commit 291bdf2
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ build_script:
- ps: if ( $VS_VERSION -eq '2015' -and $Env:PLATFORM -eq 'x64' ) { $CMAKE_GENERATOR = 'Visual Studio 14 2015 Win64' }
- ps: if ( $VS_VERSION -eq '2015' ) { $ENABLE_UNITTESTS = 'ON' } else { $ENABLE_UNITTESTS = 'OFF' }
- ps: cmake . -G"$CMAKE_GENERATOR" -DCMAKE_BUILD_TYPE=$Env:CONFIGURATION -DENABLE_UNITTESTS="$ENABLE_UNITTESTS"
- ps: Update-AppveyorBuild -Version "1.0.0-$Env:APPVEYOR_BUILD_NUMBER"
- ps: ./scripts/set-version-metadata.ps1
- ps: msbuild SRT.sln /p:Configuration=$Env:CONFIGURATION /p:Platform=$DEVENV_PLATFORM

test_script:
Expand Down
22 changes: 20 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ endif()
if (PTHREAD_LIBRARY AND PTHREAD_INCLUDE_DIR)
message(STATUS "Pthread library: ${PTHREAD_LIBRARY}")
message(STATUS "Pthread include dir: ${PTHREAD_INCLUDE_DIR}")
elseif (WIN32 AND NOT MINGW)
elseif (MICROSOFT)
find_package(pthreads QUIET)

if (NOT PTHREAD_INCLUDE_DIR OR NOT PTHREAD_LIBRARY)
Expand Down Expand Up @@ -583,6 +583,12 @@ MafReadDir(srtcore filelist.maf
)

# Auto generated version file and add it to the HEADERS_srt list.
if(DEFINED ENV{APPVEYOR_BUILD_NUMBER})
set(SRT_VERSION_BUILD ON)
set(APPVEYOR_BUILD_NUMBER_STRING $ENV{APPVEYOR_BUILD_NUMBER})
message(STATUS "AppVeyor build environment detected: Adding build number to version header")
endif()

configure_file("srtcore/version.h.in" "version.h" @ONLY)

list(INSERT HEADERS_srt 0 "${CMAKE_CURRENT_BINARY_DIR}/version.h")
Expand All @@ -595,6 +601,17 @@ if (ENABLE_SHARED)
foreach (tar srt_virtual haicrypt_virtual)
set_target_properties(${tar} PROPERTIES POSITION_INDEPENDENT_CODE 1)
endforeach()

#add resource files to shared library, to set DLL metadata on Windows DLLs
if (MICROSOFT)
MafReadDir(srtcore filelist.maf
SOURCES_WIN32_SHARED SOURCES_srt_shared_win32
PRIVATE_HEADERS_WIN32_SHARED HEADERS_srt_shared_win32
)

message(STATUS "WINDOWS detected: Adding sources to SRT shared project: ${SOURCES_srt_shared_win32}")
message(STATUS "WINDOWS detected: Adding private headers to SRT shared project: ${HEADERS_srt_shared_win32}")
endif()
endif()

# Manual handling of dependency on virtual library
Expand All @@ -604,7 +621,7 @@ endif()
set (VIRTUAL_srt $<TARGET_OBJECTS:srt_virtual> $<TARGET_OBJECTS:haicrypt_virtual>)

if (srt_libspec_shared)
add_library(${TARGET_srt}_shared SHARED ${OBJECT_LIB_SUPPORT} ${VIRTUAL_srt})
add_library(${TARGET_srt}_shared SHARED ${OBJECT_LIB_SUPPORT} ${VIRTUAL_srt} ${SOURCES_srt_shared_win32} ${HEADERS_srt_shared_win32})
# shared libraries need PIC
set (CMAKE_POSITION_INDEPENDENT_CODE ON)
set_property(TARGET ${TARGET_srt}_shared PROPERTY OUTPUT_NAME ${TARGET_srt})
Expand All @@ -615,6 +632,7 @@ if (srt_libspec_shared)
endif()
if (MICROSOFT)
target_link_libraries(${TARGET_srt}_shared PRIVATE ws2_32.lib)
set_target_properties(${TARGET_srt}_shared PROPERTIES LINK_FLAGS "/DELAYLOAD:libeay32.dll")
elseif (MINGW)
target_link_libraries(${TARGET_srt}_shared PRIVATE wsock32.lib ws2_32.lib)
elseif (APPLE)
Expand Down
2 changes: 2 additions & 0 deletions scripts/haiUtil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ MACRO(MafReadDir directory maffile)
PUBLIC_HEADERS # installable headers for include
PROTECTED_HEADERS # installable headers used by other headers
PRIVATE_HEADERS # non-installable headers
SOURCES_WIN32_SHARED # windows specific SOURCES
PRIVATE_HEADERS_WIN32_SHARED # windows specific PRIVATE_HEADERS
OPTIONS
)
cmake_parse_arguments(MAFREAD_VAR "" "${MAFREAD_TAGS}" "" ${ARGN})
Expand Down
47 changes: 47 additions & 0 deletions scripts/set-version-metadata.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Script for reading generated version values and updating metadata properties

#read major / minor version values from version.h (generated by cmake via version.h.in)
$majorVer=99
$minorVer=99
$patchVer=0
$buildNum=0

#define regular expressions to be used when checking for #define statements
$versionSniffingRegex = "(\s*#define\s+(\S+)\s+)(\d+)"

#read generated file, load values from this with regular expression
Get-Content ".\version.h" | Where-Object { $_ -match $versionSniffingRegex } | ForEach-Object {
switch ($Matches[2])
{
"SRT_VERSION_MAJOR" { $majorVer = $Matches[3] }
"SRT_VERSION_MINOR" { $minorVer = $Matches[3] }
"SRT_VERSION_PATCH" { $patchVer = $Matches[3] }
"SRT_VERSION_BUILD" { $buildNum = $Matches[3] }
}
}

$FileDescriptionBranchCommitValue = "SRT Local Build"

if($Env:APPVEYOR){
#make AppVeyor update with this new version number
Update-AppveyorBuild -Version "$majorVer.$minorVer.$patchVer.$buildNum"
$FileDescriptionBranchCommitValue = "$Env:APPVEYOR_REPO_NAME - $($Env:APPVEYOR_REPO_BRANCH) ($($Env:APPVEYOR_REPO_COMMIT.substring(0,8)))"
}

#find C++ resource files and update file description with branch / commit details
$FileDescriptionStringRegex = '(\bVALUE\s+\"FileDescription\"\s*\,\s*\")([^\"]*\\\")*[^\"]*(\")'

Get-ChildItem -Path "./srtcore/srt_shared.rc" | ForEach-Object {
$fileName = $_
Write-Host "Processing metadata changes for file: $fileName"

$FileLines = Get-Content -path $fileName

for($i=0;$i -lt $FileLines.Count;$i++)
{
$FileLines[$i] = $FileLines[$i] -Replace $FileDescriptionStringRegex, "`${1}$FileDescriptionBranchCommitValue`${3}"
}

[System.IO.File]::WriteAllLines($fileName.FullName, $FileLines)
}

6 changes: 6 additions & 0 deletions srtcore/filelist.maf
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ threadname.h
utilities.h
window.h

SOURCES WIN32 SHARED
srt_shared.rc

PRIVATE HEADERS WIN32 SHARED
../version.h

45 changes: 45 additions & 0 deletions srtcore/srt_shared.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Microsoft Visual C++ generated resource script.
//
#include "version.h"
#include "winres.h"

/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
#ifdef SRT_VERSION_BUILD
FILEVERSION SRT_VERSION_MAJOR, SRT_VERSION_MINOR, SRT_VERSION_PATCH, SRT_VERSION_BUILD
#else
FILEVERSION SRT_VERSION_MAJOR, SRT_VERSION_MINOR, SRT_VERSION_PATCH
#endif
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904b0"
BEGIN
VALUE "CompanyName", "SRT Alliance"
VALUE "FileDescription", "SRT Local Build"
VALUE "InternalName", "srt.dll"
VALUE "LegalCopyright", ""
VALUE "OriginalFilename", "srt.dll"
VALUE "ProductName", "SRT"
VALUE "ProductVersion", SRT_VERSION_STRING
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x809, 1200
END
END

1 change: 1 addition & 0 deletions srtcore/version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ written by
#define SRT_VERSION_MAJOR @SRT_VERSION_MAJOR@
#define SRT_VERSION_MINOR @SRT_VERSION_MINOR@
#define SRT_VERSION_PATCH @SRT_VERSION_PATCH@
#cmakedefine SRT_VERSION_BUILD @APPVEYOR_BUILD_NUMBER_STRING@

#define SRT_VERSION_STRING "@SRT_VERSION@"
#define SRT_VERSION_VALUE \
Expand Down

0 comments on commit 291bdf2

Please sign in to comment.