From db35e13b46c5aa5cc7933d03a4acc2dc4c839d9a Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 20 Jun 2017 13:55:17 +0300 Subject: [PATCH] build: added VERSIONINFO resource --- .gitattributes | 2 ++ cmake/OpenCVModule.cmake | 26 +++++++++++++++++- cmake/OpenCVUtils.cmake | 46 ++++++++++++++++++++++++++++++++ cmake/OpenCVVersion.cmake | 7 +++++ cmake/templates/vs_version.rc.in | 38 ++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 cmake/templates/vs_version.rc.in diff --git a/.gitattributes b/.gitattributes index 7497ee1768..3feaef770c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -31,6 +31,8 @@ *.py text *.qrc text *.qss text +*.rc text +*.rc.in text *.S text *.sbt text *.scala text diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 2546ac5839..c0bb999624 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -800,11 +800,35 @@ macro(_ocv_create_module) endforeach() endif() + if(WIN32 AND BUILD_SHARED_LIBS AND NOT OPENCV_VS_VERSIONINFO_SKIP) + if(DEFINED OPENCV_VS_VERSIONINFO_FILE) + set(_VS_VERSION_FILE "${OPENCV_VS_VERSIONINFO_FILE}") + elseif(DEFINED OPENCV_VS_VERSIONINFO_${the_module}_FILE) + set(_VS_VERSION_FILE "${OPENCV_VS_VERSIONINFO_${the_module}_FILE") + elseif(NOT OPENCV_VS_VERSIONINFO_SKIP_GENERATION) + set(_VS_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/vs_version.rc") + ocv_generate_vs_version_file("${_VS_VERSION_FILE}" + NAME "${the_module}" + FILEDESCRIPTION "OpenCV module: ${OPENCV_MODULE_${the_module}_DESCRIPTION}" + INTERNALNAME "${the_module}${OPENCV_DLLVERSION}" + ORIGINALFILENAME "${the_module}${OPENCV_DLLVERSION}.dll" + ) + endif() + if(_VS_VERSION_FILE) + if(NOT EXISTS "${_VS_VERSION_FILE}") + message(STATUS "${the_module}: Required .rc file is missing: ${_VS_VERSION_FILE}") + endif() + source_group("Src" FILES "${_VS_VERSION_FILE}") + endif() + endif() + source_group("Include" FILES "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/cvconfig.h" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp") source_group("Src" FILES "${${the_module}_pch}") ocv_add_library(${the_module} ${OPENCV_MODULE_TYPE} ${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES} "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/cvconfig.h" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp" - ${${the_module}_pch} ${sub_objs}) + ${${the_module}_pch} ${sub_objs} + ${_VS_VERSION_FILE} + ) if (cuda_objs) target_link_libraries(${the_module} ${cuda_objs}) diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 4879eb699c..433e497dd0 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -1128,3 +1128,49 @@ macro(ocv_add_testdata basedir dest_subdir) endif() endif() endmacro() + +macro(ocv_generate_vs_version_file DESTINATION) + cmake_parse_arguments(VS_VER "" "NAME;FILEDESCRIPTION;FILEVERSION;INTERNALNAME;COPYRIGHT;ORIGINALFILENAME;PRODUCTNAME;PRODUCTVERSION;COMMENTS;FILEVERSION_QUAD;PRODUCTVERSION_QUAD" "" ${ARGN}) + + macro(__vs_ver_update_variable name) + if(VS_VER_NAME AND DEFINED OPENCV_${VS_VER_NAME}_VS_VER_${name}) + set(OPENCV_VS_VER_${name} "${OPENCV_${VS_VER_NAME}_VS_VER_${name}}") + elseif(VS_VER_${name}) + set(OPENCV_VS_VER_${name} "${VS_VER_${name}}") + endif() + endmacro() + + __vs_ver_update_variable(FILEVERSION_QUAD) + __vs_ver_update_variable(PRODUCTVERSION_QUAD) + + macro(__vs_ver_update_str_variable name) + if(VS_VER_NAME AND DEFINED OPENCV_${VS_VER_NAME}_VS_VER_${name}) + set(OPENCV_VS_VER_${name}_STR "${OPENCV_${VS_VER_NAME}_VS_VER_${name}}") + elseif(VS_VER_${name}) + set(OPENCV_VS_VER_${name}_STR "${VS_VER_${name}}") + endif() + endmacro() + + __vs_ver_update_str_variable(FILEDESCRIPTION) + __vs_ver_update_str_variable(FILEVERSION) + __vs_ver_update_str_variable(INTERNALNAME) + __vs_ver_update_str_variable(COPYRIGHT) + __vs_ver_update_str_variable(ORIGINALFILENAME) + __vs_ver_update_str_variable(PRODUCTNAME) + __vs_ver_update_str_variable(PRODUCTVERSION) + __vs_ver_update_str_variable(COMMENTS) + + if(OPENCV_VS_VER_COPYRIGHT_STR) + set(OPENCV_VS_VER_HAVE_COPYRIGHT_STR 1) + else() + set(OPENCV_VS_VER_HAVE_COPYRIGHT_STR 0) + endif() + + if(OPENCV_VS_VER_COMMENTS_STR) + set(OPENCV_VS_VER_HAVE_COMMENTS_STR 1) + else() + set(OPENCV_VS_VER_HAVE_COMMENTS_STR 0) + endif() + + configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/vs_version.rc.in" "${DESTINATION}" @ONLY) +endmacro() diff --git a/cmake/OpenCVVersion.cmake b/cmake/OpenCVVersion.cmake index 60ac16420a..dda0474227 100644 --- a/cmake/OpenCVVersion.cmake +++ b/cmake/OpenCVVersion.cmake @@ -16,3 +16,10 @@ set(OPENCV_LIBVERSION "${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_ # create a dependency on version file # we never use output of the following command but cmake will rerun automatically if the version file changes configure_file("${OPENCV_VERSION_FILE}" "${CMAKE_BINARY_DIR}/junk/version.junk" COPYONLY) + +ocv_update(OPENCV_VS_VER_FILEVERSION_QUAD "${OPENCV_VERSION_MAJOR},${OPENCV_VERSION_MINOR},${OPENCV_VERSION_PATCH},0") +ocv_update(OPENCV_VS_VER_PRODUCTVERSION_QUAD "${OPENCV_VERSION_MAJOR},${OPENCV_VERSION_MINOR},${OPENCV_VERSION_PATCH},0") +ocv_update(OPENCV_VS_VER_FILEVERSION_STR "${OPENCV_VERSION}") +ocv_update(OPENCV_VS_VER_PRODUCTVERSION_STR "${OPENCV_VERSION}") +ocv_update(OPENCV_VS_VER_PRODUCTNAME_STR "OpenCV library") +ocv_update(OPENCV_VS_VER_COMMENTS_STR "http://opencv.org/") diff --git a/cmake/templates/vs_version.rc.in b/cmake/templates/vs_version.rc.in new file mode 100644 index 0000000000..3da8c3dd53 --- /dev/null +++ b/cmake/templates/vs_version.rc.in @@ -0,0 +1,38 @@ +#include + +VS_VERSION_INFO VERSIONINFO + FILEVERSION @OPENCV_VS_VER_FILEVERSION_QUAD@ + PRODUCTVERSION @OPENCV_VS_VER_PRODUCTVERSION_QUAD@ + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS 1 +#else + FILEFLAGS 0 +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE 0 +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + BEGIN + VALUE "FileDescription", "@OPENCV_VS_VER_FILEDESCRIPTION_STR@\0" + VALUE "FileVersion", "@OPENCV_VS_VER_FILEVERSION_STR@\0" + VALUE "InternalName", "@OPENCV_VS_VER_INTERNALNAME_STR@\0" +#if @OPENCV_VS_VER_HAVE_COPYRIGHT_STR@ + VALUE "LegalCopyright", "@OPENCV_VS_VER_COPYRIGHT_STR@\0" +#endif + VALUE "OriginalFilename", "@OPENCV_VS_VER_ORIGINALFILENAME_STR@\0" + VALUE "ProductName", "@OPENCV_VS_VER_PRODUCTNAME_STR@\0" + VALUE "ProductVersion", "@OPENCV_VS_VER_PRODUCTVERSION_STR@\0" +#if @OPENCV_VS_VER_HAVE_COMMENTS_STR@ + VALUE "Comments", "@OPENCV_VS_VER_COMMENTS_STR@\0" +#endif + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 1252 + END +END