CMakeLists.txt 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 (DEST_PKGCONFIG_DIR lib${LIB_SUFFIX}/pkgconfig)
  70. 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)
  71. # Install application launcher scripts
  72. file (GLOB APP_SCRIPTS ${PROJECT_ROOT_DIR}/Bin/${SCRIPT_PATTERN})
  73. install (FILES ${APP_SCRIPTS} DESTINATION ${DEST_RUNTIME_DIR} PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) # 755
  74. # Install resource directories required by applications built with Urho3D library
  75. install (DIRECTORY ${PROJECT_ROOT_DIR}/Bin/CoreData ${PROJECT_ROOT_DIR}/Bin/Data DESTINATION ${DEST_RUNTIME_DIR} ${DEST_PERMISSIONS})
  76. # Install CMake modules and toolchains provided by and for Urho3D
  77. install (DIRECTORY ${PROJECT_ROOT_DIR}/Source/CMake/ DESTINATION ${DEST_SHARE_DIR}/CMake ${DEST_PERMISSIONS}) # Note: the trailing slash is significant
  78. # Install CMake launcher scripts
  79. file (GLOB CMAKE_SCRIPTS ${PROJECT_ROOT_DIR}/${SCRIPT_PATTERN})
  80. install (FILES ${CMAKE_SCRIPTS} DESTINATION ${DEST_SHARE_DIR}/Scripts PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
  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 ${PROJECT_SOURCE_DIR}/CMake/Modules/GetUrho3DRevision.cmake 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 ${PROJECT_ROOT_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 (RASPI)
  101. set (CPACK_SYSTEM_NAME Raspberry-Pi)
  102. list (APPEND CPACK_GENERATOR RPM DEB)
  103. elseif (IOS)
  104. set (CPACK_SYSTEM_NAME iOS)
  105. elseif (APPLE)
  106. set (CPACK_SYSTEM_NAME OSX)
  107. elseif (WIN32)
  108. set (CPACK_GENERATOR ZIP)
  109. elseif (CPACK_SYSTEM_NAME STREQUAL Linux)
  110. list (APPEND CPACK_GENERATOR RPM DEB)
  111. endif ()
  112. if (URHO3D_64BIT)
  113. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-64bit)
  114. endif ()
  115. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-${URHO3D_LIB_TYPE})
  116. if (WIN32 AND NOT URHO3D_OPENGL)
  117. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-D3D) # Stands for Direct 3D
  118. elseif (ANDROID AND X86) # Take advantage of Android toolchain setting X86 variable to true for both 'x86' and 'x86_64' ABIs
  119. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-IA) # Stands for Intel Architecture
  120. endif ()
  121. if (NOT DEFINED ENV{RELEASE_TAG})
  122. set (CPACK_SYSTEM_NAME ${CPACK_SYSTEM_NAME}-snapshot)
  123. endif ()
  124. include (CPack)
  125. # Setup RPATH settings
  126. if (NOT WIN32 AND NOT ANDROID)
  127. # Add RPATH entries when building
  128. set (CMAKE_SKIP_BUILD_RPATH FALSE)
  129. # But don't set them yet in the build tree
  130. set (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
  131. if (APPLE)
  132. if (CMAKE_VERSION VERSION_GREATER 2.8.12 OR CMAKE_VERSION VERSION_EQUAL 2.8.12)
  133. set (CMAKE_MACOSX_RPATH TRUE)
  134. endif ()
  135. set (ORIGIN @loader_path)
  136. else ()
  137. set (ORIGIN $ORIGIN)
  138. endif ()
  139. # When installing/packaging set the first RPATH entry to the library location relative to the executable
  140. set (CMAKE_INSTALL_RPATH ${ORIGIN}/../../../lib${LIB_SUFFIX}${PATH_SUFFIX}) # The library location is based on SDK install destination as defined above
  141. # The second entry to the install destination of the library, if the destination location is not in the system default search path
  142. list (FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX} isSystemDir)
  143. if (isSystemDir STREQUAL -1)
  144. list (APPEND CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${DEST_LIBRARY_DIR})
  145. endif ()
  146. endif ()
  147. # Add targets
  148. foreach (TARGET FreeType JO LZ4 PugiXml SDL StanHull STB)
  149. add_subdirectory (ThirdParty/${TARGET})
  150. endforeach ()
  151. if (URHO3D_ANGELSCRIPT)
  152. add_subdirectory (ThirdParty/AngelScript)
  153. endif ()
  154. if (URHO3D_LUA)
  155. add_subdirectory (Engine/LuaScript)
  156. add_subdirectory (ThirdParty/Lua${JIT})
  157. add_subdirectory (ThirdParty/toluapp/src/lib)
  158. endif ()
  159. if (URHO3D_NETWORK)
  160. add_subdirectory (ThirdParty/Civetweb)
  161. add_subdirectory (ThirdParty/kNet)
  162. endif ()
  163. if (URHO3D_NAVIGATION)
  164. add_subdirectory (ThirdParty/Detour)
  165. add_subdirectory (ThirdParty/Recast)
  166. endif ()
  167. if (URHO3D_PHYSICS)
  168. add_subdirectory (ThirdParty/Bullet)
  169. endif ()
  170. if (URHO3D_URHO2D)
  171. add_subdirectory (ThirdParty/Box2D)
  172. endif ()
  173. if (NOT IOS AND NOT ANDROID AND NOT RASPI)
  174. if (URHO3D_OPENGL)
  175. add_subdirectory (ThirdParty/GLEW)
  176. else ()
  177. add_subdirectory (ThirdParty/MojoShader)
  178. endif ()
  179. add_subdirectory (ThirdParty/LibCpuId)
  180. endif ()
  181. # Urho3D game engine library
  182. add_subdirectory (Engine)
  183. # Urho3D tools
  184. add_subdirectory (Tools)
  185. # Urho3D samples
  186. # Samples are built on iOS platform too when enabled. Currently there is no available mechanism to package each sample apps into individual *.apk
  187. # 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
  188. if (URHO3D_SAMPLES)
  189. add_subdirectory (Samples)
  190. endif ()
  191. # Urho3D extras
  192. # Do not build extras for iOS and Android
  193. if (NOT IOS AND NOT ANDROID AND URHO3D_EXTRAS)
  194. add_subdirectory (Extras)
  195. endif ()
  196. # Urho3D documentation
  197. add_subdirectory (../Docs ${PROJECT_BINARY_DIR}/Docs)