CMakeLists.txt 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #
  2. # Copyright (c) 2008-2014 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. cmake_policy (SET CMP0022 NEW) # INTERFACE_LINK_LIBRARIES defines the link interface
  30. endif ()
  31. if (CMAKE_VERSION VERSION_GREATER 3.0.0 OR CMAKE_VERSION VERSION_EQUAL 3.0.0)
  32. cmake_policy (SET CMP0026 OLD) # Disallow use of the LOCATION target property - therefore we set to OLD as we still need it
  33. cmake_policy (SET CMP0042 NEW) # MACOSX_RPATH is enabled by default
  34. endif ()
  35. endif ()
  36. # Set CMake modules search path
  37. set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
  38. # Include Urho3D cmake common module
  39. include (Urho3D-CMake-common)
  40. # Check existence of stdint.h for LibCpuId
  41. include (CheckIncludeFiles)
  42. CHECK_INCLUDE_FILES (stdint.h HAVE_STDINT_H)
  43. if (HAVE_STDINT_H)
  44. add_definitions (-DHAVE_STDINT_H)
  45. endif ()
  46. # Setup SDK install destinations
  47. if (CMAKE_HOST_WIN32)
  48. # CMake already automatically appends "Urho3D" to CMAKE_INSTALL_PREFIX on Windows platform
  49. set (SCRIPT_PATTERN *.bat)
  50. else ()
  51. set (PATH_SUFFIX /Urho3D)
  52. if (URHO3D_64BIT)
  53. if (NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/lib64)
  54. # Probably target system is a RedHat-based distro
  55. set (LIB_SUFFIX 64)
  56. endif ()
  57. endif ()
  58. if (IOS)
  59. # Use 'ios' arch subdirectory to differentiate, in case both Mac OS X and iOS build are installed at the same destination
  60. set (LIB_SUFFIX ${LIB_SUFFIX}/ios)
  61. endif ()
  62. set (SCRIPT_PATTERN *.sh)
  63. endif ()
  64. set (DEST_INCLUDE_DIR include${PATH_SUFFIX})
  65. set (DEST_SHARE_DIR share${PATH_SUFFIX})
  66. set (DEST_RUNTIME_DIR ${DEST_SHARE_DIR}/Bin)
  67. # Note: ${PATH_SUFFIX} for library could be removed if the extra path is not desirable, but if so then the RPATH setting below needs to be adjusted accordingly
  68. set (DEST_LIBRARY_DIR lib${LIB_SUFFIX}${PATH_SUFFIX})
  69. set (SYSROOT ${ANDROID_TOOLCHAIN_ROOT} ${RASPI_SYSROOT} ${MINGW_SYSROOT}) # SYSROOT is empty for native build
  70. string (REPLACE "${SYSROOT}" "" DEST_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) # Our CMAKE_INSTALL_PREFIX is rooted, use DEST_INSTALL_PREFIX for the non-rooted version
  71. set (DEST_PKGCONFIG_DIR lib${LIB_SUFFIX}/pkgconfig)
  72. set (DEST_PERMISSIONS FILE_PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ DIRECTORY_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
  73. # Install application launcher scripts
  74. file (GLOB APP_SCRIPTS ${PROJECT_ROOT_DIR}/Bin/${SCRIPT_PATTERN})
  75. install (FILES ${APP_SCRIPTS} DESTINATION ${DEST_RUNTIME_DIR} PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) # 755
  76. # Install resource directories required by applications built with Urho3D library
  77. install (DIRECTORY ${PROJECT_ROOT_DIR}/Bin/CoreData ${PROJECT_ROOT_DIR}/Bin/Data DESTINATION ${DEST_RUNTIME_DIR} ${DEST_PERMISSIONS})
  78. # Install CMake modules and toolchains provided by and for Urho3D
  79. install (DIRECTORY ${PROJECT_ROOT_DIR}/Source/CMake/ DESTINATION ${DEST_SHARE_DIR}/CMake ${DEST_PERMISSIONS}) # Note: the trailing slash is significant
  80. # Install CMake launcher scripts
  81. file (GLOB CMAKE_SCRIPTS ${PROJECT_ROOT_DIR}/${SCRIPT_PATTERN})
  82. install (FILES ${CMAKE_SCRIPTS} DESTINATION ${DEST_SHARE_DIR}/Scripts PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
  83. # Setup package variables
  84. 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).")
  85. set (CPACK_PACKAGE_DESCRIPTION_SUMMARY ${URHO3D_DESCRIPTION})
  86. set (URHO3D_URL "https://github.com/urho3d/Urho3D")
  87. set (CPACK_PACKAGE_VENDOR ${URHO3D_URL})
  88. set (CPACK_PACKAGE_CONTACT ${URHO3D_URL})
  89. execute_process (COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/CMake/Modules/GetUrho3DRevision.cmake OUTPUT_VARIABLE URHO3D_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
  90. set (CPACK_PACKAGE_VERSION ${URHO3D_VERSION})
  91. string (REGEX MATCH "([^.]+)\\.([^.]+)\\.(.+)" MATCHED ${URHO3D_VERSION})
  92. if (MATCHED)
  93. set (CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1})
  94. set (CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
  95. set (CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
  96. endif ()
  97. set (CPACK_RESOURCE_FILE_LICENSE ${PROJECT_ROOT_DIR}/License.txt)
  98. set (CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
  99. set (CPACK_GENERATOR TGZ)
  100. if (ANDROID)
  101. set (CPACK_SYSTEM_NAME Android)
  102. elseif (IOS)
  103. set (CPACK_SYSTEM_NAME iOS)
  104. elseif (APPLE)
  105. set (CPACK_SYSTEM_NAME OSX)
  106. elseif (WIN32)
  107. set (CPACK_GENERATOR ZIP)
  108. elseif (CPACK_SYSTEM_NAME STREQUAL Linux)
  109. if (RASPI)
  110. set (CPACK_SYSTEM_NAME Raspberry-Pi)
  111. endif ()
  112. list (APPEND CPACK_GENERATOR RPM DEB)
  113. set (CPACK_PACKAGING_INSTALL_PREFIX ${DEST_INSTALL_PREFIX})
  114. endif ()
  115. if (URHO3D_64BIT)
  116. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-64bit)
  117. endif ()
  118. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-${URHO3D_LIB_TYPE})
  119. if (WIN32 AND NOT URHO3D_OPENGL)
  120. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-D3D) # Stands for Direct 3D
  121. elseif (ANDROID AND X86) # Take advantage of Android toolchain setting X86 variable to true for both 'x86' and 'x86_64' ABIs
  122. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-IA) # Stands for Intel Architecture
  123. endif ()
  124. if (NOT DEFINED ENV{RELEASE_TAG})
  125. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-snapshot)
  126. endif ()
  127. include (CPack)
  128. # Setup RPATH settings
  129. if (NOT WIN32 AND NOT ANDROID)
  130. # Add RPATH entries when building
  131. set (CMAKE_SKIP_BUILD_RPATH FALSE)
  132. # But don't set them yet in the build tree
  133. set (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
  134. if (APPLE)
  135. if (CMAKE_VERSION VERSION_GREATER 2.8.12 OR CMAKE_VERSION VERSION_EQUAL 2.8.12)
  136. set (CMAKE_MACOSX_RPATH TRUE)
  137. endif ()
  138. set (ORIGIN @loader_path)
  139. else ()
  140. set (ORIGIN $ORIGIN)
  141. endif ()
  142. # When installing/packaging set the first RPATH entry to the library location relative to the executable
  143. set (CMAKE_INSTALL_RPATH ${ORIGIN}/../../../lib${LIB_SUFFIX}${PATH_SUFFIX}) # The library location is based on SDK install destination as defined above
  144. # The second entry to the install destination of the library, if the destination location is not in the system default search path
  145. list (FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX} isSystemDir)
  146. if (isSystemDir STREQUAL -1)
  147. list (APPEND CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${DEST_LIBRARY_DIR})
  148. endif ()
  149. endif ()
  150. # Add targets
  151. foreach (TARGET FreeType JO LZ4 PugiXml SDL StanHull STB)
  152. add_subdirectory (ThirdParty/${TARGET})
  153. endforeach ()
  154. if (URHO3D_ANGELSCRIPT)
  155. add_subdirectory (ThirdParty/AngelScript)
  156. endif ()
  157. if (URHO3D_LUA)
  158. add_subdirectory (Engine/LuaScript)
  159. add_subdirectory (ThirdParty/Lua${JIT})
  160. add_subdirectory (ThirdParty/toluapp/src/lib)
  161. endif ()
  162. if (URHO3D_NETWORK)
  163. add_subdirectory (ThirdParty/Civetweb)
  164. add_subdirectory (ThirdParty/kNet)
  165. endif ()
  166. if (URHO3D_NAVIGATION)
  167. add_subdirectory (ThirdParty/Detour)
  168. add_subdirectory (ThirdParty/Recast)
  169. endif ()
  170. if (URHO3D_PHYSICS)
  171. add_subdirectory (ThirdParty/Bullet)
  172. endif ()
  173. if (URHO3D_URHO2D)
  174. add_subdirectory (ThirdParty/Box2D)
  175. endif ()
  176. if (NOT IOS AND NOT ANDROID AND NOT RASPI)
  177. if (URHO3D_OPENGL)
  178. add_subdirectory (ThirdParty/GLEW)
  179. else ()
  180. add_subdirectory (ThirdParty/MojoShader)
  181. endif ()
  182. add_subdirectory (ThirdParty/LibCpuId)
  183. endif ()
  184. # Urho3D game engine library
  185. add_subdirectory (Engine)
  186. # Urho3D tools
  187. add_subdirectory (Tools)
  188. # Urho3D samples
  189. # Samples are built on iOS platform too when enabled. Currently there is no available mechanism to package each sample apps into individual *.apk
  190. # for Android platform, so we deploy all samples into one apk and use a simple list view activity launcher to select the sample to run
  191. if (URHO3D_SAMPLES)
  192. add_subdirectory (Samples)
  193. endif ()
  194. # Urho3D extras
  195. # Do not build extras for iOS and Android
  196. if (NOT IOS AND NOT ANDROID AND URHO3D_EXTRAS)
  197. add_subdirectory (Extras)
  198. endif ()
  199. # Urho3D documentation
  200. add_subdirectory (../Docs ${PROJECT_BINARY_DIR}/Docs)