CMakeLists.txt 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #
  2. # Copyright (c) 2008-2015 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 project name
  23. project (Urho3D)
  24. # Set minimum version
  25. cmake_minimum_required (VERSION 2.8.6)
  26. if (COMMAND cmake_policy)
  27. cmake_policy (SET CMP0003 NEW)
  28. if (CMAKE_VERSION VERSION_GREATER 2.8.12 OR CMAKE_VERSION VERSION_EQUAL 2.8.12)
  29. # INTERFACE_LINK_LIBRARIES defines the link interface
  30. cmake_policy (SET CMP0022 NEW)
  31. endif ()
  32. if (CMAKE_VERSION VERSION_GREATER 3.0.0 OR CMAKE_VERSION VERSION_EQUAL 3.0.0)
  33. # Disallow use of the LOCATION target property - therefore we set to OLD as we still need it
  34. cmake_policy (SET CMP0026 OLD)
  35. # MACOSX_RPATH is enabled by default
  36. cmake_policy (SET CMP0042 NEW)
  37. endif ()
  38. endif ()
  39. # Set CMake modules search path
  40. set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
  41. # Include Urho3D Cmake common module
  42. include (Urho3D-CMake-common)
  43. # Setup SDK install destinations
  44. if (WIN32)
  45. set (SCRIPT_EXT .bat)
  46. else ()
  47. set (SCRIPT_EXT .sh)
  48. endif ()
  49. set (PATH_SUFFIX Urho3D)
  50. if (ANDROID)
  51. # For Android platform, install to a path similar to ANDROID_LIBRARY_OUTPUT_PATH variable, e.g. libs/armeabi-v7a
  52. set (LIB_SUFFIX s/${ANDROID_NDK_ABI_NAME})
  53. elseif (URHO3D_64BIT)
  54. if (EXISTS /usr/lib64)
  55. set (HAS_LIB64 TRUE)
  56. endif ()
  57. # Install to 'lib64' when one of these conditions is true
  58. if (WIN32 OR URHO3D_USE_LIB64_RPM OR (HAS_LIB64 AND NOT URHO3D_USE_LIB_DEB))
  59. set (LIB_SUFFIX 64)
  60. endif ()
  61. endif ()
  62. set (DEST_INCLUDE_DIR include/${PATH_SUFFIX})
  63. set (DEST_SHARE_DIR share/${PATH_SUFFIX})
  64. set (DEST_RUNTIME_DIR bin)
  65. set (DEST_BUNDLE_DIR ${DEST_SHARE_DIR}/Applications)
  66. # 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
  67. set (DEST_LIBRARY_DIR lib${LIB_SUFFIX}/${PATH_SUFFIX})
  68. # TODO: Investigate the implication of using CMAKE_SYSROOT variable (available since 3.0.0) instead of our own SYSROOT variable
  69. set (SYSROOT ${ANDROID_TOOLCHAIN_ROOT} ${RPI_SYSROOT} ${MINGW_SYSROOT} ${IOS_SYSROOT} ${EMSCRIPTEN_SYSROOT} CACHE INTERNAL "Path to system root of the cross-compiling target") # SYSROOT is empty for native build
  70. set (DEST_PKGCONFIG_DIR lib${LIB_SUFFIX}/pkgconfig)
  71. # Install application launcher scripts
  72. file (GLOB APP_SCRIPTS ${CMAKE_SOURCE_DIR}/bin/*${SCRIPT_EXT})
  73. install (PROGRAMS ${APP_SCRIPTS} DESTINATION ${DEST_RUNTIME_DIR})
  74. # Install resource directories required by applications built with Urho3D library
  75. install (DIRECTORY ${CMAKE_SOURCE_DIR}/bin/CoreData ${CMAKE_SOURCE_DIR}/bin/Data DESTINATION ${DEST_SHARE_DIR}/Resources)
  76. # Install CMake modules and toolchains provided by and for Urho3D
  77. install (DIRECTORY ${CMAKE_SOURCE_DIR}/CMake/ DESTINATION ${DEST_SHARE_DIR}/CMake) # Note: the trailing slash is significant
  78. # Install CMake build scripts
  79. file (GLOB CMAKE_SCRIPTS ${CMAKE_SOURCE_DIR}/*${SCRIPT_EXT})
  80. install (PROGRAMS ${CMAKE_SCRIPTS} DESTINATION ${DEST_SHARE_DIR}/Scripts)
  81. # Setup package variables
  82. 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).")
  83. set (CPACK_PACKAGE_DESCRIPTION_SUMMARY ${URHO3D_DESCRIPTION})
  84. set (URHO3D_URL "https://github.com/urho3d/Urho3D")
  85. set (CPACK_PACKAGE_VENDOR ${URHO3D_URL})
  86. set (CPACK_PACKAGE_CONTACT ${URHO3D_URL})
  87. execute_process (COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/CMake/Modules/GetUrho3DRevision.cmake WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE URHO3D_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
  88. set (CPACK_PACKAGE_VERSION ${URHO3D_VERSION})
  89. string (REGEX MATCH "([^.]+)\\.([^.]+)\\.(.+)" MATCHED ${URHO3D_VERSION})
  90. if (MATCHED)
  91. set (CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1})
  92. set (CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
  93. set (CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
  94. endif ()
  95. set (CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/License.txt)
  96. set (CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
  97. set (CPACK_GENERATOR TGZ)
  98. if (ANDROID)
  99. set (CPACK_SYSTEM_NAME Android)
  100. elseif (IOS)
  101. set (CPACK_SYSTEM_NAME iOS)
  102. elseif (APPLE)
  103. set (CPACK_SYSTEM_NAME OSX)
  104. elseif (WIN32)
  105. set (CPACK_GENERATOR ZIP)
  106. elseif (EMSCRIPTEN)
  107. set (CPACK_SYSTEM_NAME HTML5)
  108. elseif (CPACK_SYSTEM_NAME STREQUAL Linux)
  109. if (RPI)
  110. set (CPACK_SYSTEM_NAME Raspberry-Pi)
  111. endif ()
  112. if (NOT URHO3D_64BIT OR HAS_LIB64)
  113. list (APPEND CPACK_GENERATOR RPM)
  114. endif ()
  115. if (NOT URHO3D_64BIT OR NOT HAS_LIB64)
  116. list (APPEND CPACK_GENERATOR DEB)
  117. endif ()
  118. if (URHO3D_64BIT)
  119. if (URHO3D_USE_LIB64_RPM AND NOT HAS_LIB64)
  120. set (CPACK_GENERATOR RPM)
  121. elseif (URHO3D_USE_LIB_DEB AND HAS_LIB64)
  122. set (CPACK_GENERATOR DEB)
  123. endif ()
  124. endif ()
  125. # Note to package maintainer: comment out below line to revert the prefix from '/usr/local' (default for CMAKE_INSTALL_PREFIX) to '/usr' (default for CPACK_PACKAGING_INSTALL_PREFIX)
  126. set (CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
  127. endif ()
  128. if (URHO3D_64BIT)
  129. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-64bit)
  130. else ()
  131. set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
  132. 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
  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 AND X86) # Take advantage of Android toolchain setting X86 variable to true for both 'x86' and 'x86_64' ABIs
  142. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-IA) # Stands for Intel Architecture
  143. elseif (RPI AND RPI_ABI MATCHES ^armeabi-v7a)
  144. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-v7a)
  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 MacOSX and iOS bundle variables
  151. if (IOS OR URHO3D_MACOSX_BUNDLE)
  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-2015 the Urho3D project.")
  166. endif ()
  167. endif ()
  168. # Setup SDK-like include dir in the build tree for building the Urho3D library
  169. file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${DEST_INCLUDE_DIR}/ThirdParty)
  170. # Urho3D source
  171. add_subdirectory (Source)
  172. # Urho3D documentation
  173. add_subdirectory (Docs)