windows: add resource.rc files to dll builds

Windows uses a mechanism known as 'resource files' which provides, among
other things, metadata to a given executable/dll/driver/etc, and add a
layer of polish to a project which it would otherwise lack.
This commit is contained in:
Marty E. Plummer 2018-03-15 19:38:34 -05:00 committed by Lukas Dürrenberger
parent a7e5d3c386
commit 6ad96cf9b7
2 changed files with 83 additions and 0 deletions

View File

@ -74,6 +74,26 @@ macro(sfml_add_library target)
# include the major version number in Windows shared library names (but not import library names)
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
set_target_properties(${target} PROPERTIES SUFFIX "-${VERSION_MAJOR}${CMAKE_SHARED_LIBRARY_SUFFIX}")
# fill out all variables we use to generate the .rc file
string(TIMESTAMP RC_CURRENT_YEAR "%Y")
string(REGEX REPLACE "sfml-([a-z])([a-z]*)" "\\1" RC_MODULE_NAME_HEAD "${target}")
string(REGEX REPLACE "sfml-([a-z])([a-z]*)" "\\2" RC_MODULE_NAME_TAIL "${target}")
string(TOUPPER "${RC_MODULE_NAME_HEAD}" RC_MODULE_NAME_HEAD)
set(RC_MODULE_NAME "${RC_MODULE_NAME_HEAD}${RC_MODULE_NAME_TAIL}")
set(RC_VERSION_SUFFIX "") # Add something like the git revision short SHA-1 in the future
set(RC_PRERELEASE "0") # Set to 1 to mark the DLL as a pre-release DLL
set(RC_TARGET_NAME "${target}")
set(RC_TARGET_FILE_NAME_SUFFIX "-${VERSION_MAJOR}${CMAKE_SHARED_LIBRARY_SUFFIX}")
# generate the .rc file
configure_file(
"${SFML_SOURCE_DIR}/tools/windows/resource.rc.in"
"${CMAKE_CURRENT_BINARY_DIR}/${target}.rc"
@ONLY
)
target_sources(${target} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/${target}.rc")
source_group("" FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}.rc")
else()
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
endif()

View File

@ -0,0 +1,63 @@
#include "winresrc.h"
#define VER_COMPANYNAME_STR "\0"
#define VER_LEGALCOPYRIGHT_STR "Copyright (C) 2007-@RC_CURRENT_YEAR@ Laurent Gomila\0"
#define VER_FILEDESCRIPTION_STR "SFML @RC_MODULE_NAME@ Module\0"
#define VER_PRODUCTNAME_STR "Simple and Fast Multimedia Library\0"
#define VER_FILEVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@,0
#define VER_FILEVERSION_STR "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@@RC_VERSION_SUFFIX@\0"
#define VER_PRODUCTVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@,0
#define VER_PRODUCTVERSION_STR "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@@RC_VERSION_SUFFIX@\0"
#ifndef DEBUG
#define VER_INTERNALNAME_STR "@RC_TARGET_NAME@@RC_TARGET_FILE_NAME_SUFFIX@\0"
#define VER_ORIGINALFILENAME_STR "@RC_TARGET_NAME@@RC_TARGET_FILE_NAME_SUFFIX@\0"
#else
#define VER_INTERNALNAME_STR "@RC_TARGET_NAME@-d@RC_TARGET_FILE_NAME_SUFFIX@\0"
#define VER_ORIGINALFILENAME_STR "@RC_TARGET_NAME@-d@RC_TARGET_FILE_NAME_SUFFIX@\0"
#endif
#if @RC_PRERELEASE@
#define VER_PRERELEASE 0
#else
#define VER_PRERELEASE VS_FF_PRERELEASE
#endif
#ifndef DEBUG
#define VER_DEBUG 0
#else
#define VER_DEBUG VS_FF_DEBUG
#endif
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILEVERSION
PRODUCTVERSION VER_PRODUCTVERSION
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEFLAGS (VER_PRERELEASE | VER_DEBUG)
FILEOS VOS_NT
FILETYPE VFT_DLL
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", VER_COMPANYNAME_STR
VALUE "FileDescription", VER_FILEDESCRIPTION_STR
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "InternalName", VER_INTERNALNAME_STR
VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR
VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR
VALUE "ProductName", VER_PRODUCTNAME_STR
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1252 //en-US
END
END