CMakeLists.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. # Currently we are in the Code folder: ${CMAKE_CURRENT_LIST_DIR}
  9. # Get the platform specific folder ${pal_dir} for the current folder: ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME}
  10. # Note: o3de_pal_dir will take care of the details for us, as this may be a restricted platform
  11. # in which case it will see if that platform is present here or in the restricted folder.
  12. # i.e. It could here in our gem : Gems/${gem_name}/Code/Platform/<platorm_name> or
  13. # <restricted_folder>/<platform_name>/Gems/${gem_name}/Code
  14. o3de_pal_dir(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME} "${gem_restricted_path}" "${gem_path}" "${gem_parent_relative_path}")
  15. # Now that we have the platform abstraction layer (PAL) folder for this folder, thats where we will find the
  16. # traits for this platform. Traits for a platform are defines for things like whether or not something in this gem
  17. # is supported by this platform.
  18. include(${pal_dir}/PAL_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
  19. # Add RecastNavigation dependency using FetchContent
  20. # Note: RecastNavigation::Detour requires lowering of the warning level to compile.
  21. include(FetchContent)
  22. FetchContent_Declare(
  23. RecastNavigation
  24. GIT_REPOSITORY "https://github.com/recastnavigation/recastnavigation"
  25. GIT_TAG "5a870d427e47abd4a8e4ce58a95582ec049434d5" # main branch
  26. )
  27. set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
  28. set(RECASTNAVIGATION_DEMO OFF)
  29. set(RECASTNAVIGATION_TESTS OFF)
  30. set(RECASTNAVIGATION_EXAMPLES OFF)
  31. get_property(
  32. compile_options
  33. DIRECTORY
  34. PROPERTY COMPILE_OPTIONS
  35. )
  36. include(${pal_dir}/PAL_recast_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
  37. # Temporarily disable CMake deprecation warnings from Recast library having a lower
  38. # minimum required CMake version than us.
  39. set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "" FORCE)
  40. # Include compiler settings for Recast libraries
  41. set(common_platform_dir "${CMAKE_CURRENT_LIST_DIR}/Platform/Common")
  42. include(${common_platform_dir}/${PAL_TRAIT_COMPILER_ID}/PAL_recast_${PAL_TRAIT_COMPILER_ID_LOWERCASE}.cmake)
  43. set_property(
  44. DIRECTORY
  45. APPEND
  46. PROPERTY COMPILE_DEFINITIONS DT_POLYREF64
  47. )
  48. FetchContent_MakeAvailable(RecastNavigation)
  49. # Restore compile options
  50. set_property(
  51. DIRECTORY
  52. PROPERTY COMPILE_OPTIONS ${compile_options}
  53. )
  54. unset(compile_options)
  55. # Enable CMake deprecation warnings
  56. set(CMAKE_WARN_DEPRECATED ON CACHE BOOL "" FORCE)
  57. # Place external recast libraries under RecastNavigation gem.
  58. get_property(recastnavigation_gem_root GLOBAL PROPERTY "@GEMROOT:${gem_name}@")
  59. ly_get_engine_relative_source_dir(${recastnavigation_gem_root} relative_recastnavigation_gem_root)
  60. set(recastLibraries DebugUtils;Detour;DetourCrowd;DetourTileCache;Recast)
  61. foreach(recastLibrary ${recastLibraries})
  62. set_property(TARGET ${recastLibrary} PROPERTY FOLDER "${relative_recastnavigation_gem_root}/External")
  63. endforeach()
  64. # Export external recast navigation targets for installers.
  65. set_property(DIRECTORY APPEND PROPERTY O3DE_SUBDIRECTORY_INSTALL_CODE [[
  66. set(recastLibraries DebugUtils;Detour;DetourCrowd;DetourTileCache;Recast)
  67. foreach(recastLibrary ${recastLibraries})
  68. add_library(RecastNavigation::${recastLibrary} STATIC IMPORTED GLOBAL)
  69. set_target_properties(RecastNavigation::${recastLibrary}
  70. PROPERTIES
  71. IMPORTED_LOCATION
  72. "${LY_ROOT_FOLDER}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}${recastLibrary}${CMAKE_STATIC_LIBRARY_SUFFIX}")
  73. target_compile_definitions(RecastNavigation::${recastLibrary}
  74. INTERFACE
  75. DT_POLYREF64)
  76. ly_target_include_system_directories(TARGET RecastNavigation::${recastLibrary}
  77. INTERFACE
  78. "${LY_ROOT_FOLDER}/include/recastnavigation")
  79. endforeach()
  80. ]]
  81. )
  82. # The ${gem_name}.API target declares the common interface that users of this gem should depend on in their targets
  83. ly_add_target(
  84. NAME ${gem_name}.API INTERFACE
  85. NAMESPACE Gem
  86. FILES_CMAKE
  87. recastnavigation_api_files.cmake
  88. ${pal_dir}/recastnavigation_api_files.cmake
  89. INCLUDE_DIRECTORIES
  90. INTERFACE
  91. Include
  92. BUILD_DEPENDENCIES
  93. INTERFACE
  94. AZ::AzCore
  95. RecastNavigation::Detour
  96. RecastNavigation::Recast
  97. )
  98. # The ${gem_name}.Private.Object target is an internal target
  99. # It should not be used outside of this Gems CMakeLists.txt
  100. ly_add_target(
  101. NAME ${gem_name}.Private.Object STATIC
  102. NAMESPACE Gem
  103. FILES_CMAKE
  104. recastnavigation_private_files.cmake
  105. ${pal_dir}/recastnavigation_private_files.cmake
  106. TARGET_PROPERTIES
  107. O3DE_PRIVATE_TARGET TRUE
  108. INCLUDE_DIRECTORIES
  109. PRIVATE
  110. Include
  111. Source
  112. BUILD_DEPENDENCIES
  113. PUBLIC
  114. AZ::AzCore
  115. AZ::AzFramework
  116. RecastNavigation::DebugUtils
  117. RecastNavigation::Detour
  118. RecastNavigation::Recast
  119. Gem::LmbrCentral.Static
  120. Gem::DebugDraw.API
  121. )
  122. # Here add ${gem_name} target, it depends on the Private Object library and Public API interface
  123. ly_add_target(
  124. NAME ${gem_name} ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
  125. NAMESPACE Gem
  126. FILES_CMAKE
  127. recastnavigation_shared_files.cmake
  128. ${pal_dir}/recastnavigation_shared_files.cmake
  129. INCLUDE_DIRECTORIES
  130. PUBLIC
  131. Include
  132. PRIVATE
  133. Source
  134. BUILD_DEPENDENCIES
  135. PUBLIC
  136. Gem::${gem_name}.API
  137. PRIVATE
  138. Gem::${gem_name}.Private.Object
  139. )
  140. # Inject the gem name into the Module source file
  141. ly_add_source_properties(
  142. SOURCES
  143. Source/RecastNavigationModule.cpp
  144. PROPERTY COMPILE_DEFINITIONS
  145. VALUES
  146. O3DE_GEM_NAME=${gem_name}
  147. O3DE_GEM_VERSION=${gem_version})
  148. # By default, we will specify that the above target ${gem_name} would be used by
  149. # Client and Server type targets when this gem is enabled. If you don't want it
  150. # active in Clients or Servers by default, delete one of both of the following lines:
  151. ly_create_alias(NAME ${gem_name}.Clients NAMESPACE Gem TARGETS Gem::${gem_name})
  152. ly_create_alias(NAME ${gem_name}.Servers NAMESPACE Gem TARGETS Gem::${gem_name})
  153. ly_create_alias(NAME ${gem_name}.Unified NAMESPACE Gem TARGETS Gem::${gem_name})
  154. # For the Client and Server variants of ${gem_name} Gem, an alias to the ${gem_name}.API target will be made
  155. ly_create_alias(NAME ${gem_name}.Clients.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  156. ly_create_alias(NAME ${gem_name}.Servers.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  157. ly_create_alias(NAME ${gem_name}.Unified.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  158. # If we are on a host platform, we want to add the host tools targets like the ${gem_name}.Editor MODULE target
  159. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  160. # The ${gem_name}.Editor.API target can be used by other gems that want to interact with the ${gem_name}.Editor module
  161. ly_add_target(
  162. NAME ${gem_name}.Editor.API INTERFACE
  163. NAMESPACE Gem
  164. FILES_CMAKE
  165. recastnavigation_editor_api_files.cmake
  166. ${pal_dir}/recastnavigation_editor_api_files.cmake
  167. INCLUDE_DIRECTORIES
  168. INTERFACE
  169. Include
  170. BUILD_DEPENDENCIES
  171. INTERFACE
  172. AZ::AzToolsFramework
  173. )
  174. # The ${gem_name}.Editor.Private.Object target is an internal target
  175. # which is only to be used by this gems CMakeLists.txt and any subdirectories
  176. # Other gems should not use this target
  177. ly_add_target(
  178. NAME ${gem_name}.Editor.Private.Object STATIC
  179. NAMESPACE Gem
  180. FILES_CMAKE
  181. recastnavigation_editor_private_files.cmake
  182. TARGET_PROPERTIES
  183. O3DE_PRIVATE_TARGET TRUE
  184. INCLUDE_DIRECTORIES
  185. PRIVATE
  186. Include
  187. Source
  188. BUILD_DEPENDENCIES
  189. PUBLIC
  190. AZ::AzToolsFramework
  191. Gem::${gem_name}.Private.Object
  192. Gem::LmbrCentral.Static
  193. Gem::DebugDraw.API
  194. )
  195. ly_add_target(
  196. NAME ${gem_name}.Editor GEM_MODULE
  197. NAMESPACE Gem
  198. AUTOMOC
  199. FILES_CMAKE
  200. recastnavigation_editor_shared_files.cmake
  201. INCLUDE_DIRECTORIES
  202. PRIVATE
  203. Source
  204. PUBLIC
  205. Include
  206. BUILD_DEPENDENCIES
  207. PUBLIC
  208. Gem::${gem_name}.Editor.API
  209. PRIVATE
  210. Gem::${gem_name}.Editor.Private.Object
  211. )
  212. # Inject the gem name into the Module source file
  213. ly_add_source_properties(
  214. SOURCES
  215. Source/RecastNavigationEditorModule.cpp
  216. PROPERTY COMPILE_DEFINITIONS
  217. VALUES
  218. O3DE_GEM_NAME=${gem_name}
  219. O3DE_GEM_VERSION=${gem_version})
  220. # By default, we will specify that the above target ${gem_name} would be used by
  221. # Tool and Builder type targets when this gem is enabled. If you don't want it
  222. # active in Tools or Builders by default, delete one of both of the following lines:
  223. ly_create_alias(NAME ${gem_name}.Tools NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  224. ly_create_alias(NAME ${gem_name}.Builders NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  225. # For the Tools and Builders variants of ${gem_name} Gem, an alias to the ${gem_name}.Editor API target will be made
  226. ly_create_alias(NAME ${gem_name}.Tools.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)
  227. ly_create_alias(NAME ${gem_name}.Builders.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)
  228. endif()
  229. ################################################################################
  230. # Tests
  231. ################################################################################
  232. # See if globally, tests are supported
  233. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  234. # We globally support tests, see if we support tests on this platform for ${gem_name}.Tests
  235. if(PAL_TRAIT_RECASTNAVIGATION_TEST_SUPPORTED)
  236. # We support ${gem_name}.Tests on this platform, add dependency on the Private Object target
  237. ly_add_target(
  238. NAME ${gem_name}.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  239. NAMESPACE Gem
  240. FILES_CMAKE
  241. recastnavigation_tests_files.cmake
  242. INCLUDE_DIRECTORIES
  243. PRIVATE
  244. Tests
  245. Source
  246. BUILD_DEPENDENCIES
  247. PRIVATE
  248. AZ::AzTest
  249. AZ::AzFramework
  250. Gem::${gem_name}.Private.Object
  251. Gem::${gem_name}.API
  252. Gem::LmbrCentral.API
  253. Gem::PhysX.Mocks
  254. )
  255. # Add ${gem_name}.Tests to googletest
  256. ly_add_googletest(
  257. NAME Gem::${gem_name}.Tests
  258. LABELS REQUIRES_tiaf
  259. )
  260. endif()
  261. # If we are a host platform we want to add tools test like editor tests here
  262. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  263. # We are a host platform, see if Editor tests are supported on this platform
  264. if(PAL_TRAIT_RECASTNAVIGATION_EDITOR_TEST_SUPPORTED)
  265. # We support ${gem_name}.Editor.Tests on this platform, add ${gem_name}.Editor.Tests target which depends on
  266. # private ${gem_name}.Editor.Private.Object target
  267. ly_add_target(
  268. NAME ${gem_name}.Editor.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  269. NAMESPACE Gem
  270. FILES_CMAKE
  271. recastnavigation_editor_tests_files.cmake
  272. INCLUDE_DIRECTORIES
  273. PRIVATE
  274. Tests
  275. Source
  276. BUILD_DEPENDENCIES
  277. PRIVATE
  278. AZ::AzTest
  279. AZ::AzToolsFramework
  280. Gem::${gem_name}.Private.Object
  281. Gem::${gem_name}.Editor.Private.Object
  282. Gem::${gem_name}.API
  283. Gem::LmbrCentral.API
  284. Gem::PhysX.Mocks
  285. )
  286. # Add ${gem_name}.Editor.Tests to googletest
  287. # Commented out as currently there are no ${gem_name} Editor tests
  288. # ly_add_googletest(
  289. # NAME Gem::${gem_name}.Editor.Tests
  290. # )
  291. endif()
  292. endif()
  293. endif()