GenerateProductVersion.cmake 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # The MIT License (MIT)
  2. #
  3. # Copyright (c) 2015, by [halex2005](mailto:akharlov@gmail.com)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. # this software and associated documentation files (the "Software"), to deal in
  7. # the Software without restriction, including without limitation the rights to
  8. # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. # the Software, and to permit persons to whom the Software is furnished to do so,
  10. # subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in all
  13. # copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  17. # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  19. # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. include (CMakeParseArguments)
  22. set (GenerateProductVersionCurrentDir ${CMAKE_CURRENT_LIST_DIR})
  23. # generate_product_version() function
  24. #
  25. # This function uses VersionInfo.in template file and VersionResource.rc file
  26. # to generate WIN32 resource with version information and general resource strings.
  27. #
  28. # Usage:
  29. # generate_product_version(
  30. # SomeOutputResourceVariable
  31. # NAME MyGreatProject
  32. # ICON ${PATH_TO_APP_ICON}
  33. # VERSION_MAJOR 2
  34. # VERSION_MINOR 3
  35. # VERSION_PATH ${BUILD_COUNTER}
  36. # VERSION_REVISION ${BUILD_REVISION}
  37. # )
  38. # where BUILD_COUNTER and BUILD_REVISION could be values from your CI server.
  39. #
  40. # You can use generated resource for your executable targets:
  41. # add_executable(target-name ${target-files} ${SomeOutputResourceVariable})
  42. #
  43. # You can specify resource strings in arguments:
  44. # NAME - name of executable (no defaults, ex: Microsoft Word)
  45. # BUNDLE - bundle (${NAME} is default, ex: Microsoft Office)
  46. # VERSION_MAJOR - 1 is default
  47. # VERSION_MINOR - 0 is default
  48. # VERSION_PATCH - 0 is default
  49. # COMPANY_NAME - your company name (no defaults)
  50. # COMPANY_COPYRIGHT - ${COMPANY_NAME} (C) Copyright ${CURRENT_YEAR} is default
  51. # COMMENTS - ${NAME} v${VERSION_MAJOR}.${VERSION_MINOR} is default
  52. # ORIGINAL_FILENAME - ${NAME} is default
  53. # INTERNAL_NAME - ${NAME} is default
  54. # FILE_DESCRIPTION - ${NAME} is default
  55. function(generate_product_version outfiles)
  56. set (options)
  57. set (oneValueArgs
  58. NAME
  59. BUNDLE
  60. VERSION_MAJOR
  61. VERSION_MINOR
  62. VERSION_PATCH
  63. COMPANY_NAME
  64. COMPANY_COPYRIGHT
  65. COMMENTS
  66. ORIGINAL_FILENAME
  67. INTERNAL_NAME
  68. FILE_DESCRIPTION)
  69. set (multiValueArgs)
  70. cmake_parse_arguments(PRODUCT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  71. if (NOT PRODUCT_BUNDLE OR "${PRODUCT_BUNDLE}" STREQUAL "")
  72. set(PRODUCT_BUNDLE "${PRODUCT_NAME}")
  73. endif()
  74. if (NOT PRODUCT_VERSION_MAJOR OR "${PRODUCT_VERSION_MAJOR}" STREQUAL "")
  75. set(PRODUCT_VERSION_MAJOR 1)
  76. endif()
  77. if (NOT PRODUCT_VERSION_MINOR OR "${PRODUCT_VERSION_MINOR}" STREQUAL "")
  78. set(PRODUCT_VERSION_MINOR 0)
  79. endif()
  80. if (NOT PRODUCT_VERSION_PATCH OR "${PRODUCT_VERSION_PATCH}" STREQUAL "")
  81. set(PRODUCT_VERSION_PATCH 0)
  82. endif()
  83. if (NOT PRODUCT_COMPANY_COPYRIGHT OR "${PRODUCT_COMPANY_COPYRIGHT}" STREQUAL "")
  84. string(TIMESTAMP PRODUCT_CURRENT_YEAR "%Y")
  85. set(PRODUCT_COMPANY_COPYRIGHT "Copyright (C) ${PRODUCT_CURRENT_YEAR} ${PRODUCT_COMPANY_NAME}")
  86. endif()
  87. if (NOT PRODUCT_COMMENTS OR "${PRODUCT_COMMENTS}" STREQUAL "")
  88. set(PRODUCT_COMMENTS "${PRODUCT_NAME} v${PRODUCT_VERSION_MAJOR}.${PRODUCT_VERSION_MINOR}.${PRODUCT_VERSION_PATCH}")
  89. endif()
  90. if (NOT PRODUCT_ORIGINAL_FILENAME OR "${PRODUCT_ORIGINAL_FILENAME}" STREQUAL "")
  91. set(PRODUCT_ORIGINAL_FILENAME "${PRODUCT_NAME}")
  92. endif()
  93. if (NOT PRODUCT_INTERNAL_NAME OR "${PRODUCT_INTERNAL_NAME}" STREQUAL "")
  94. set(PRODUCT_INTERNAL_NAME "${PRODUCT_NAME}")
  95. endif()
  96. if (NOT PRODUCT_FILE_DESCRIPTION OR "${PRODUCT_FILE_DESCRIPTION}" STREQUAL "")
  97. set(PRODUCT_FILE_DESCRIPTION "${PRODUCT_NAME}")
  98. endif()
  99. set (_VersionInfoFile ${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.h)
  100. set (_VersionResourceFile ${CMAKE_CURRENT_BINARY_DIR}/VersionResource.rc)
  101. configure_file(
  102. ${GenerateProductVersionCurrentDir}/VersionInfo.in
  103. ${_VersionInfoFile}
  104. @ONLY)
  105. configure_file(
  106. ${GenerateProductVersionCurrentDir}/VersionResource.rc
  107. ${_VersionResourceFile}
  108. COPYONLY)
  109. list(APPEND ${outfiles} ${_VersionInfoFile} ${_VersionResourceFile})
  110. set (${outfiles} ${${outfiles}} PARENT_SCOPE)
  111. endfunction()