CMakeLists.txt 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. # Copyright (c) 2008-2022 the Urho3D project
  2. # License: MIT
  3. # Set CMake minimum version
  4. cmake_minimum_required (VERSION 3.15)
  5. # Set project name
  6. project (Urho3D)
  7. # Show command line options
  8. get_cmake_property (CACHE_VARS CACHE_VARIABLES)
  9. foreach (CACHE_VAR ${CACHE_VARS})
  10. get_property(CACHE_VAR_HELPSTRING CACHE ${CACHE_VAR} PROPERTY HELPSTRING)
  11. if (CACHE_VAR_HELPSTRING STREQUAL "No help, variable specified on the command line.")
  12. get_property(CACHE_VAR_TYPE CACHE ${CACHE_VAR} PROPERTY TYPE)
  13. if (CACHE_VAR_TYPE STREQUAL "UNINITIALIZED")
  14. set (CACHE_VAR_TYPE)
  15. else ()
  16. set (CACHE_VAR_TYPE ":${CACHE_VAR_TYPE}")
  17. endif()
  18. set (CMAKE_ARGS "${CMAKE_ARGS} -D ${CACHE_VAR}${CACHE_VAR_TYPE}=\"${${CACHE_VAR}}\"")
  19. endif ()
  20. endforeach ()
  21. message ("!! CMAKE_ARGS: ${CMAKE_ARGS}")
  22. # Set CMake modules search path
  23. set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
  24. # Include UrhoCommon.cmake module after setting project name
  25. include (UrhoCommon)
  26. # Setup SDK install destinations
  27. set (PATH_SUFFIX Urho3D)
  28. if (WIN32)
  29. set (SCRIPT_EXT .bat)
  30. if (CMAKE_HOST_WIN32)
  31. set (PATH_SUFFIX .)
  32. if (URHO3D_64BIT AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  33. string (REPLACE " (x86)" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
  34. endif ()
  35. endif ()
  36. else ()
  37. set (SCRIPT_EXT .sh)
  38. endif ()
  39. if (URHO3D_64BIT)
  40. # Install to 'lib64' when one of these conditions is true
  41. if ((MINGW AND CMAKE_CROSSCOMPILING) OR URHO3D_USE_LIB64_RPM OR (HAS_LIB64 AND NOT URHO3D_USE_LIB_DEB))
  42. set (LIB_SUFFIX 64)
  43. endif ()
  44. endif ()
  45. set (DEST_INCLUDE_DIR include/Urho3D) # The include directory path contains the 'Urho3D' suffix regardless of PATH_SUFFIX variable
  46. set (DEST_SHARE_DIR share/${PATH_SUFFIX})
  47. set (DEST_BUNDLE_DIR ${DEST_SHARE_DIR}/Applications)
  48. # 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
  49. set (DEST_LIBRARY_DIR lib${LIB_SUFFIX}/${PATH_SUFFIX})
  50. set (DEST_PKGCONFIG_DIR lib${LIB_SUFFIX}/pkgconfig)
  51. # Install application launcher scripts
  52. file (GLOB APP_SCRIPTS ${CMAKE_SOURCE_DIR}/bin/*${SCRIPT_EXT})
  53. 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
  54. # Install CMake modules and toolchains provided by and for Urho3D
  55. install (DIRECTORY ${CMAKE_SOURCE_DIR}/cmake/ DESTINATION ${DEST_SHARE_DIR}/cmake) # Note: the trailing slash is significant
  56. # Install CMake build scripts and rakefile
  57. file (GLOB CMAKE_SCRIPTS ${CMAKE_SOURCE_DIR}/script/*${SCRIPT_EXT})
  58. install (PROGRAMS ${CMAKE_SCRIPTS} DESTINATION ${DEST_SHARE_DIR}/scripts)
  59. install (FILES rakefile DESTINATION ${DEST_SHARE_DIR})
  60. # Setup package variables
  61. 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).")
  62. set (CPACK_PACKAGE_DESCRIPTION_SUMMARY ${URHO3D_DESCRIPTION})
  63. set (URHO3D_URL "https://github.com/urho3d/Urho3D")
  64. set (CPACK_PACKAGE_VENDOR ${URHO3D_URL})
  65. set (CPACK_PACKAGE_CONTACT ${URHO3D_URL})
  66. 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)
  67. set (CPACK_PACKAGE_VERSION ${URHO3D_VERSION})
  68. string (REGEX MATCH "([^.]+)\\.([^.]+)\\.(.+)" MATCHED ${URHO3D_VERSION})
  69. if (MATCHED)
  70. set (CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1})
  71. set (CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
  72. set (CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
  73. endif ()
  74. set (CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/licenses/urho3d/LICENSE)
  75. set (CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
  76. set (CPACK_GENERATOR TGZ)
  77. if (ANDROID)
  78. set (CPACK_SYSTEM_NAME Android)
  79. elseif (IOS)
  80. set (CPACK_SYSTEM_NAME iOS)
  81. elseif (TVOS)
  82. set (CPACK_SYSTEM_NAME tvOS)
  83. elseif (APPLE)
  84. set (CPACK_SYSTEM_NAME macOS)
  85. elseif (WIN32)
  86. if (MINGW)
  87. set (CPACK_SYSTEM_NAME MinGW) # MinGW implies Windows platform
  88. endif ()
  89. if (CMAKE_HOST_WIN32)
  90. set (CPACK_GENERATOR ZIP) # Differentiate artifacts generated from Windows host system
  91. endif ()
  92. elseif (WEB)
  93. set (CPACK_SYSTEM_NAME Web)
  94. elseif (CPACK_SYSTEM_NAME STREQUAL Linux)
  95. if (RPI)
  96. set (CPACK_SYSTEM_NAME Raspberry-Pi)
  97. set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE armhf)
  98. elseif (ARM)
  99. set (CPACK_SYSTEM_NAME ARM) # Generic ARM
  100. if (URHO3D_64BIT)
  101. set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE arm64)
  102. else ()
  103. set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE armhf)
  104. endif ()
  105. elseif (NOT URHO3D_64BIT)
  106. set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
  107. 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
  108. endif ()
  109. # 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.
  110. if (NOT DEFINED ENV{CI})
  111. if (NOT URHO3D_64BIT OR HAS_LIB64)
  112. list (APPEND CPACK_GENERATOR RPM)
  113. endif ()
  114. if (NOT URHO3D_64BIT OR NOT HAS_LIB64)
  115. list (APPEND CPACK_GENERATOR DEB)
  116. endif ()
  117. if (URHO3D_64BIT)
  118. if (URHO3D_USE_LIB64_RPM AND NOT HAS_LIB64)
  119. set (CPACK_GENERATOR RPM)
  120. elseif (URHO3D_USE_LIB_DEB AND HAS_LIB64)
  121. set (CPACK_GENERATOR DEB)
  122. endif ()
  123. endif ()
  124. endif ()
  125. endif ()
  126. if (URHO3D_64BIT)
  127. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-64bit)
  128. endif ()
  129. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-${URHO3D_LIB_TYPE})
  130. if (WIN32 AND NOT URHO3D_OPENGL)
  131. if (URHO3D_D3D11)
  132. 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
  133. else ()
  134. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-3D9)
  135. endif ()
  136. elseif (ANDROID)
  137. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-${ANDROID_ABI})
  138. elseif (RPI AND RPI_ABI MATCHES ^armeabi-v7a)
  139. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-v7a)
  140. elseif (ARM_ABI_FLAGS)
  141. string (REGEX REPLACE "^.*mcpu=([^ ]+).*$" -\\1 CPU_NAME "${ARM_ABI_FLAGS}")
  142. string (REGEX REPLACE .*- - CPU_NAME "${CPU_NAME}")
  143. string (TOUPPER "${CPU_NAME}" CPU_NAME)
  144. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}${CPU_NAME})
  145. endif ()
  146. if (NOT DEFINED ENV{RELEASE_TAG})
  147. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-snapshot)
  148. endif ()
  149. include (CPack)
  150. # Setup macOS, iOS, and tvOS bundle variables
  151. if (URHO3D_MACOSX_BUNDLE OR (APPLE AND ARM))
  152. if (NOT MACOSX_BUNDLE_ICON_FILE)
  153. set (MACOSX_BUNDLE_ICON_FILE UrhoIcon)
  154. endif ()
  155. if (NOT MACOSX_BUNDLE_BUNDLE_VERSION)
  156. set (MACOSX_BUNDLE_BUNDLE_VERSION ${URHO3D_VERSION})
  157. endif ()
  158. if (NOT MACOSX_BUNDLE_LONG_VERSION_STRING)
  159. set (MACOSX_BUNDLE_LONG_VERSION_STRING ${URHO3D_VERSION})
  160. endif ()
  161. if (NOT MACOSX_BUNDLE_SHORT_VERSION_STRING)
  162. set (MACOSX_BUNDLE_SHORT_VERSION_STRING ${URHO3D_VERSION})
  163. endif ()
  164. if (NOT MACOSX_BUNDLE_COPYRIGHT)
  165. set (MACOSX_BUNDLE_COPYRIGHT "Copyright (c) 2008-2022 the Urho3D project.")
  166. endif ()
  167. endif ()
  168. # Setup SDK-like include dir in the build tree for building the Urho3D library
  169. set (THIRD_PARTY_INCLUDE_DIR ${CMAKE_BINARY_DIR}/${DEST_INCLUDE_DIR}/ThirdParty)
  170. file (MAKE_DIRECTORY ${THIRD_PARTY_INCLUDE_DIR})
  171. # Urho3D source
  172. add_subdirectory (Source)
  173. # Urho3D documentation
  174. add_subdirectory (Docs)