CMakeLists.txt 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #
  2. # Copyright (c) 2008-2020 the Urho3D project.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. #
  22. # Set CMake minimum version
  23. cmake_minimum_required (VERSION 3.10.2)
  24. # Set project name
  25. project (Urho3D)
  26. # Set CMake modules search path
  27. set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
  28. #set (URHO3D_PCH FALSE)
  29. # Include UrhoCommon.cmake module after setting project name
  30. include (UrhoCommon)
  31. # Setup SDK install destinations
  32. set (PATH_SUFFIX Urho3D)
  33. if (WIN32)
  34. set (SCRIPT_EXT .bat)
  35. if (CMAKE_HOST_WIN32)
  36. set (PATH_SUFFIX .)
  37. if (URHO3D_64BIT AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  38. string (REPLACE " (x86)" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
  39. endif ()
  40. endif ()
  41. else ()
  42. set (SCRIPT_EXT .sh)
  43. endif ()
  44. if (URHO3D_64BIT)
  45. # Install to 'lib64' when one of these conditions is true
  46. if ((MINGW AND CMAKE_CROSSCOMPILING) OR URHO3D_USE_LIB64_RPM OR (HAS_LIB64 AND NOT URHO3D_USE_LIB_DEB))
  47. set (LIB_SUFFIX 64)
  48. endif ()
  49. endif ()
  50. set (DEST_INCLUDE_DIR include/Urho3D) # The include directory path contains the 'Urho3D' suffix regardless of PATH_SUFFIX variable
  51. set (DEST_SHARE_DIR share/${PATH_SUFFIX})
  52. set (DEST_BUNDLE_DIR ${DEST_SHARE_DIR}/Applications)
  53. # Note to package maintainer: ${PATH_SUFFIX} for library could be removed if the extra path is not desired, but if so then the RPATH setting in Source's CMakeLists.txt needs to be adjusted accordingly
  54. set (DEST_LIBRARY_DIR lib${LIB_SUFFIX}/${PATH_SUFFIX})
  55. set (DEST_PKGCONFIG_DIR lib${LIB_SUFFIX}/pkgconfig)
  56. # Install application launcher scripts
  57. file (GLOB APP_SCRIPTS ${CMAKE_SOURCE_DIR}/bin/*${SCRIPT_EXT})
  58. install (PROGRAMS ${APP_SCRIPTS} DESTINATION ${DEST_RUNTIME_DIR}) # DEST_RUNTIME_DIR variable is set by the set_output_directories() macro call in the UrhoCommon module
  59. # Install CMake modules and toolchains provided by and for Urho3D
  60. install (DIRECTORY ${CMAKE_SOURCE_DIR}/cmake/ DESTINATION ${DEST_SHARE_DIR}/cmake) # Note: the trailing slash is significant
  61. # Install CMake build scripts and rakefile
  62. file (GLOB CMAKE_SCRIPTS ${CMAKE_SOURCE_DIR}/script/*${SCRIPT_EXT})
  63. install (PROGRAMS ${CMAKE_SCRIPTS} DESTINATION ${DEST_SHARE_DIR}/scripts)
  64. install (FILES rakefile DESTINATION ${DEST_SHARE_DIR})
  65. # Setup package variables
  66. set (URHO3D_DESCRIPTION "Urho3D is a free lightweight, cross-platform 2D and 3D game engine implemented in C++ and released under the MIT license. Greatly inspired by OGRE (http://www.ogre3d.org) and Horde3D (http://www.horde3d.org).")
  67. set (CPACK_PACKAGE_DESCRIPTION_SUMMARY ${URHO3D_DESCRIPTION})
  68. set (URHO3D_URL "https://github.com/urho3d/Urho3D")
  69. set (CPACK_PACKAGE_VENDOR ${URHO3D_URL})
  70. set (CPACK_PACKAGE_CONTACT ${URHO3D_URL})
  71. execute_process (COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/Modules/GetUrhoRevision.cmake WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE URHO3D_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
  72. set (CPACK_PACKAGE_VERSION ${URHO3D_VERSION})
  73. string (REGEX MATCH "([^.]+)\\.([^.]+)\\.(.+)" MATCHED ${URHO3D_VERSION})
  74. if (MATCHED)
  75. set (CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1})
  76. set (CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
  77. set (CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
  78. endif ()
  79. set (CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
  80. set (CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
  81. set (CPACK_GENERATOR TGZ)
  82. if (ANDROID)
  83. set (CPACK_SYSTEM_NAME Android)
  84. elseif (IOS)
  85. set (CPACK_SYSTEM_NAME iOS)
  86. elseif (TVOS)
  87. set (CPACK_SYSTEM_NAME tvOS)
  88. elseif (APPLE)
  89. set (CPACK_SYSTEM_NAME macOS)
  90. elseif (WIN32)
  91. if (MINGW)
  92. set (CPACK_SYSTEM_NAME MinGW) # MinGW implies Windows platform
  93. endif ()
  94. if (CMAKE_HOST_WIN32)
  95. set (CPACK_GENERATOR ZIP) # Differentiate artifacts generated from Windows host system
  96. endif ()
  97. elseif (WEB)
  98. set (CPACK_SYSTEM_NAME Web)
  99. elseif (CPACK_SYSTEM_NAME STREQUAL Linux)
  100. if (RPI)
  101. set (CPACK_SYSTEM_NAME Raspberry-Pi)
  102. set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE armhf)
  103. elseif (ARM)
  104. set (CPACK_SYSTEM_NAME ARM) # Generic ARM
  105. if (URHO3D_64BIT)
  106. set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE arm64)
  107. else ()
  108. set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE armhf)
  109. endif ()
  110. elseif (NOT URHO3D_64BIT)
  111. set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
  112. set (CPACK_RPM_PACKAGE_ARCHITECTURE i686) # The 'package' target should be built with the help of 'setarch i686' command on a 64-bit host system
  113. endif ()
  114. # TODO: Temporary disable RPM and DEB package generation for CI as it has run out of disk space for a few of the target platforms.
  115. if (NOT DEFINED ENV{CI})
  116. if (NOT URHO3D_64BIT OR HAS_LIB64)
  117. list (APPEND CPACK_GENERATOR RPM)
  118. endif ()
  119. if (NOT URHO3D_64BIT OR NOT HAS_LIB64)
  120. list (APPEND CPACK_GENERATOR DEB)
  121. endif ()
  122. if (URHO3D_64BIT)
  123. if (URHO3D_USE_LIB64_RPM AND NOT HAS_LIB64)
  124. set (CPACK_GENERATOR RPM)
  125. elseif (URHO3D_USE_LIB_DEB AND HAS_LIB64)
  126. set (CPACK_GENERATOR DEB)
  127. endif ()
  128. endif ()
  129. endif ()
  130. endif ()
  131. if (URHO3D_64BIT)
  132. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-64bit)
  133. endif ()
  134. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-${URHO3D_LIB_TYPE})
  135. if (WIN32 AND NOT URHO3D_OPENGL)
  136. if (URHO3D_D3D11)
  137. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-3D11) # The artifact name has a space constraint on our website when viewed in a mobile browser, 3D11 stands for Direct3D 11
  138. else ()
  139. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-3D9)
  140. endif ()
  141. elseif (ANDROID)
  142. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-${ANDROID_ABI})
  143. elseif (RPI AND RPI_ABI MATCHES ^armeabi-v7a)
  144. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-v7a)
  145. elseif (ARM_ABI_FLAGS)
  146. string (REGEX REPLACE "^.*mcpu=([^ ]+).*$" -\\1 CPU_NAME "${ARM_ABI_FLAGS}")
  147. string (REGEX REPLACE .*- - CPU_NAME "${CPU_NAME}")
  148. string (TOUPPER "${CPU_NAME}" CPU_NAME)
  149. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}${CPU_NAME})
  150. endif ()
  151. if (NOT DEFINED ENV{RELEASE_TAG})
  152. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-snapshot)
  153. endif ()
  154. include (CPack)
  155. # Setup macOS, iOS, and tvOS bundle variables
  156. if (URHO3D_MACOSX_BUNDLE OR (APPLE AND ARM))
  157. if (NOT MACOSX_BUNDLE_ICON_FILE)
  158. set (MACOSX_BUNDLE_ICON_FILE UrhoIcon)
  159. endif ()
  160. if (NOT MACOSX_BUNDLE_BUNDLE_VERSION)
  161. set (MACOSX_BUNDLE_BUNDLE_VERSION ${URHO3D_VERSION})
  162. endif ()
  163. if (NOT MACOSX_BUNDLE_LONG_VERSION_STRING)
  164. set (MACOSX_BUNDLE_LONG_VERSION_STRING ${URHO3D_VERSION})
  165. endif ()
  166. if (NOT MACOSX_BUNDLE_SHORT_VERSION_STRING)
  167. set (MACOSX_BUNDLE_SHORT_VERSION_STRING ${URHO3D_VERSION})
  168. endif ()
  169. if (NOT MACOSX_BUNDLE_COPYRIGHT)
  170. set (MACOSX_BUNDLE_COPYRIGHT "Copyright (c) 2008-2020 the Urho3D project.")
  171. endif ()
  172. endif ()
  173. # Setup SDK-like include dir in the build tree for building the Urho3D library
  174. set (THIRD_PARTY_INCLUDE_DIR ${CMAKE_BINARY_DIR}/${DEST_INCLUDE_DIR}/ThirdParty)
  175. file (MAKE_DIRECTORY ${THIRD_PARTY_INCLUDE_DIR})
  176. # Urho3D source
  177. add_subdirectory (Source)
  178. # Urho3D documentation
  179. add_subdirectory (Docs)