FindUrho3D.cmake 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. # Find Urho3D library and include directories in the project root tree or installed location
  23. # For project root tree detection to work, Urho3D library must be already been built
  24. #
  25. # URHO3D_FOUND
  26. # URHO3D_INCLUDE_DIRS
  27. # URHO3D_LIBRARIES
  28. # URHO3D_LIBRARIES_REL
  29. # URHO3D_LIBRARIES_DBG
  30. #
  31. if (URHO3D_FOUND)
  32. return ()
  33. endif ()
  34. # If the URHO3D_LIB_TYPE build option changes then invalidate the found library cache
  35. if (NOT URHO3D_LIB_TYPE STREQUAL URHO3D_FOUND_LIB_TYPE)
  36. unset (URHO3D_LIBRARIES CACHE)
  37. set (URHO3D_FOUND_LIB_TYPE ${URHO3D_LIB_TYPE} CACHE INTERNAL "Lib type when Urho3D library was last found")
  38. # Urho3D prefers static library type by default while CMake prefers shared one, so we need to change CMake preference to agree with Urho3D
  39. if (NOT URHO3D_LIB_TYPE STREQUAL SHARED)
  40. list (REVERSE CMAKE_FIND_LIBRARY_SUFFIXES)
  41. endif ()
  42. endif ()
  43. set (URHO3D_LIB_NAMES Urho3D)
  44. if (WIN32)
  45. set (URHO3D_LIB_NAMES_DBG Urho3D_d)
  46. endif ()
  47. if (CMAKE_PROJECT_NAME STREQUAL Urho3D AND PROJECT_ROOT_DIR)
  48. set (URHO3D_HOME ${PROJECT_ROOT_DIR} CACHE PATH "Path to Urho3D project root tree" FORCE)
  49. set (IS_INTERNAL 1)
  50. elseif (NOT URHO3D_HOME AND DEFINED ENV{URHO3D_HOME})
  51. file (TO_CMAKE_PATH "$ENV{URHO3D_HOME}" URHO3D_HOME)
  52. set (URHO3D_HOME ${URHO3D_HOME} CACHE PATH "Path to Urho3D project root tree")
  53. endif ()
  54. if (URHO3D_HOME)
  55. # Construct source tree paths from URHO3D_HOME environment variable
  56. find_file (URHO3D_SOURCE_TREE Urho3D.h.in ${URHO3D_HOME}/Source/Engine DOC "Path to Urho3D project source tree" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
  57. if (URHO3D_SOURCE_TREE)
  58. get_filename_component (URHO3D_SOURCE_TREE ${URHO3D_SOURCE_TREE} PATH)
  59. set (URHO3D_INCLUDE_DIRS ${URHO3D_SOURCE_TREE})
  60. foreach (DIR Audio Container Core Engine Graphics Input IO LuaScript Math Navigation Network Physics Resource Scene Script UI UIX Urho2D)
  61. list (APPEND URHO3D_INCLUDE_DIRS ${URHO3D_SOURCE_TREE}/${DIR}) # Note: variable change to list context after this
  62. endforeach ()
  63. set (DIRS SDL/include)
  64. if (URHO3D_ANGELSCRIPT)
  65. list (APPEND DIRS AngelScript/include)
  66. endif ()
  67. if (URHO3D_NETWORK)
  68. list (APPEND DIRS kNet/include)
  69. endif ()
  70. if (URHO3D_PHYSICS)
  71. list (APPEND DIRS Bullet/src)
  72. endif ()
  73. if (URHO3D_URHO2D)
  74. list (APPEND DIRS Box2D)
  75. endif ()
  76. foreach (DIR ${DIRS})
  77. list (APPEND URHO3D_INCLUDE_DIRS ${URHO3D_HOME}/Source/ThirdParty/${DIR})
  78. endforeach ()
  79. # For non Urho3D project using Urho3D as external library, Urho3D project itself must be built using predefined build directory as per specified in the provided build scripts.
  80. if (IS_INTERNAL)
  81. set (BINARY_DIR ${CMAKE_BINARY_DIR})
  82. elseif (ANDROID AND CMAKE_HOST_WIN32 AND NOT URHO3D_MKLINK)
  83. set (BINARY_DIR ${URHO3D_HOME}/Source/Android)
  84. else ()
  85. set (BINARY_DIR ${URHO3D_HOME}/${PLATFORM_PREFIX}Build)
  86. endif ()
  87. list (APPEND URHO3D_INCLUDE_DIRS ${BINARY_DIR}/Engine)
  88. if (ANDROID)
  89. if (IS_INTERNAL)
  90. set (URHO3D_LIB_SEARCH_PATH ${ANDROID_LIBRARY_OUTPUT_PATH})
  91. else ()
  92. set (URHO3D_LIB_SEARCH_PATH ${BINARY_DIR}/libs/${ANDROID_NDK_ABI_NAME})
  93. endif ()
  94. else ()
  95. set (URHO3D_LIB_SEARCH_PATH ${URHO3D_HOME}/${PLATFORM_PREFIX}Lib)
  96. endif ()
  97. if (TARGET Urho3D)
  98. set (URHO3D_LIBRARIES Urho3D)
  99. set (FOUND_MESSAGE "Found Urho3D: as CMake target")
  100. else ()
  101. find_library (URHO3D_LIBRARIES NAMES ${URHO3D_LIB_NAMES} PATHS ${URHO3D_LIB_SEARCH_PATH} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
  102. if (WIN32)
  103. find_library (URHO3D_LIBRARIES_DBG NAMES ${URHO3D_LIB_NAMES_DBG} PATHS ${URHO3D_LIB_SEARCH_PATH} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
  104. endif ()
  105. endif ()
  106. endif ()
  107. else ()
  108. # If Urho3D SDK is not being installed in the default system location, use the CMAKE_PREFIX_PATH environment variable to specify the prefix path to that location
  109. # Note that the prefix path should not contain the "/include" or "/lib"
  110. # For example on Windows platform: CMAKE_PREFIX_PATH=C:/Users/john/Urho3D if the SDK is installed using CMAKE_INSTALL_PREFIX=C:/Users/john/Urho3D
  111. # For example on Linux platform: CMAKE_PREFIX_PATH=/home/john/usr/local if the SDK is installed using DESTDIR=/home/john and CMAKE_INSTALL_PREFIX=/usr/local
  112. if (CMAKE_HOST_WIN32)
  113. set (URHO3D_INC_SEARCH_PATH include)
  114. set (URHO3D_LIB_SEARCH_PATH lib)
  115. else ()
  116. set (PATH_SUFFIX Urho3D)
  117. if (IOS)
  118. set (CMAKE_LIBRARY_ARCHITECTURE ios)
  119. endif ()
  120. endif ()
  121. # Additional search paths are added by CMake by default which should already include most common platform specific paths
  122. find_path (URHO3D_INCLUDE_DIRS Urho3D.h PATHS ${URHO3D_INC_SEARCH_PATH} PATH_SUFFIXES ${PATH_SUFFIX})
  123. find_library (URHO3D_LIBRARIES NAMES ${URHO3D_LIB_NAMES} PATHS ${URHO3D_LIB_SEARCH_PATH} PATH_SUFFIXES ${PATH_SUFFIX})
  124. if (WIN32)
  125. find_library (URHO3D_LIBRARIES_DBG NAMES ${URHO3D_LIB_NAMES_DBG} PATHS ${URHO3D_LIB_SEARCH_PATH} PATH_SUFFIXES ${PATH_SUFFIX})
  126. endif ()
  127. if (URHO3D_INCLUDE_DIRS)
  128. set (BASE_DIR ${URHO3D_INCLUDE_DIRS})
  129. set (DIRS SDL)
  130. if (URHO3D_ANGELSCRIPT)
  131. list (APPEND DIRS AngelScript)
  132. endif ()
  133. if (URHO3D_NETWORK)
  134. list (APPEND DIRS kNet)
  135. endif ()
  136. if (URHO3D_PHYSICS)
  137. list (APPEND DIRS Bullet)
  138. endif ()
  139. if (URHO3D_URHO2D)
  140. list (APPEND DIRS Box2D)
  141. endif ()
  142. foreach (DIR ${DIRS})
  143. list (APPEND URHO3D_INCLUDE_DIRS ${BASE_DIR}/${DIR}) # Note: variable change to list context after this, so we need BASE_DIR to remain the same
  144. endforeach ()
  145. endif ()
  146. endif ()
  147. if (WIN32)
  148. set (URHO3D_LIBRARIES_REL ${URHO3D_LIBRARIES})
  149. if (URHO3D_LIBRARIES)
  150. if (URHO3D_LIBRARIES_DBG)
  151. list (APPEND URHO3D_LIBRARIES ${URHO3D_LIBRARIES_DBG})
  152. endif ()
  153. else ()
  154. set (URHO3D_LIBRARIES ${URHO3D_LIBRARIES_DBG})
  155. endif ()
  156. endif ()
  157. if (URHO3D_INCLUDE_DIRS AND URHO3D_LIBRARIES)
  158. set (URHO3D_FOUND 1)
  159. if (NOT FOUND_MESSAGE)
  160. set (FOUND_MESSAGE "Found Urho3D: ${URHO3D_LIBRARIES}")
  161. endif ()
  162. endif ()
  163. if (URHO3D_FOUND)
  164. include (FindPackageMessage)
  165. FIND_PACKAGE_MESSAGE (Urho3D ${FOUND_MESSAGE} "[${URHO3D_LIBRARIES}][${URHO3D_INCLUDE_DIRS}]")
  166. else ()
  167. if (Urho3D_FIND_REQUIRED)
  168. message (FATAL_ERROR
  169. "Could not find Urho3D library in default SDK installation location or Urho3D project root tree. "
  170. "For searching in a non-default Urho3D SDK installation, use 'CMAKE_PREFIX_PATH' environment variable to specify the prefix path of the installation location. "
  171. "For searching in a build tree of Urho3D project, use 'URHO3D_HOME' environment variable to specify the Urho3D project root directory. The Urho3D library itself must already be built successfully.")
  172. endif ()
  173. endif ()
  174. mark_as_advanced (URHO3D_INCLUDE_DIRS URHO3D_LIBRARIES URHO3D_SOURCE_TREE)