CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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/ROS2Sensors/Code/Platform/<platorm_name> or
  13. # <restricted_folder>/<platform_name>/Gems/ROS2Sensors/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. # Check to see if building the Gem Modules are supported for the current platform
  20. if(NOT PAL_TRAIT_ROS2SENSORS_SUPPORTED)
  21. return()
  22. endif()
  23. # Add the ROS2Sensors.Lidar.Static target
  24. # Note: this target will include all helper methods that are used by any Lidar implementation
  25. ly_add_target(
  26. NAME ${gem_name}.Lidar.Static STATIC
  27. NAMESPACE Gem
  28. FILES_CMAKE
  29. ros2sensors_lidar_api_files.cmake
  30. ros2sensors_lidar_shared_files.cmake
  31. INCLUDE_DIRECTORIES
  32. PUBLIC
  33. Include
  34. PRIVATE
  35. Source
  36. BUILD_DEPENDENCIES
  37. PUBLIC
  38. AZ::AzCore
  39. AZ::AzFramework
  40. Gem::LmbrCentral.API
  41. )
  42. # The ${gem_name}.API target declares the common interface that users of this gem should depend on in their targets
  43. ly_add_target(
  44. NAME ${gem_name}.API INTERFACE
  45. NAMESPACE Gem
  46. FILES_CMAKE
  47. ros2sensors_api_files.cmake
  48. ${pal_dir}/ros2sensors_api_files.cmake
  49. INCLUDE_DIRECTORIES
  50. INTERFACE
  51. Include
  52. BUILD_DEPENDENCIES
  53. INTERFACE
  54. AZ::AzCore
  55. )
  56. # The ${gem_name}.Private.Object target is an internal target
  57. # It should not be used outside of this Gems CMakeLists.txt
  58. ly_add_target(
  59. NAME ${gem_name}.Private.Object STATIC
  60. NAMESPACE Gem
  61. FILES_CMAKE
  62. ros2sensors_private_files.cmake
  63. ${pal_dir}/ros2sensors_private_files.cmake
  64. TARGET_PROPERTIES
  65. O3DE_PRIVATE_TARGET TRUE
  66. INCLUDE_DIRECTORIES
  67. PRIVATE
  68. Include
  69. Source
  70. BUILD_DEPENDENCIES
  71. PUBLIC
  72. AZ::AzCore
  73. AZ::AzFramework
  74. Gem::Atom_Feature_Common.Public # Camera Sensor
  75. Gem::PhysX5.Static # Imu Sensor
  76. Gem::ROS2
  77. Gem::LevelGeoreferencing.API
  78. ${gem_name}.Lidar.Static
  79. )
  80. target_depends_on_ros2_packages(${gem_name}.Private.Object rclcpp sensor_msgs nav_msgs)
  81. # Here add ${gem_name} target, it depends on the Private Object library and Public API interface
  82. ly_add_target(
  83. NAME ${gem_name} ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
  84. NAMESPACE Gem
  85. FILES_CMAKE
  86. ros2sensors_shared_files.cmake
  87. ${pal_dir}/ros2sensors_shared_files.cmake
  88. INCLUDE_DIRECTORIES
  89. PUBLIC
  90. Include
  91. PRIVATE
  92. Source
  93. BUILD_DEPENDENCIES
  94. PUBLIC
  95. Gem::${gem_name}.API
  96. PRIVATE
  97. Gem::${gem_name}.Private.Object
  98. )
  99. # Include the gem name into the Client Module source file
  100. # for use with the AZ_DECLARE_MODULE_CLASS macro
  101. # This is to allow renaming of the gem to also cause
  102. # the CreateModuleClass_Gem_<gem-name> function which
  103. # is used to bootstrap the gem in monolithic builds to link to the new gem name
  104. ly_add_source_properties(
  105. SOURCES
  106. Source/Clients/ROS2SensorsModule.cpp
  107. PROPERTY COMPILE_DEFINITIONS
  108. VALUES
  109. O3DE_GEM_NAME=${gem_name}
  110. O3DE_GEM_VERSION=${gem_version})
  111. # By default, we will specify that the above target ${gem_name} would be used by
  112. # Client and Server type targets when this gem is enabled. If you don't want it
  113. # active in Clients or Servers by default, delete one of both of the following lines:
  114. ly_create_alias(NAME ${gem_name}.Clients NAMESPACE Gem TARGETS Gem::${gem_name})
  115. ly_create_alias(NAME ${gem_name}.Servers NAMESPACE Gem TARGETS Gem::${gem_name})
  116. ly_create_alias(NAME ${gem_name}.Unified NAMESPACE Gem TARGETS Gem::${gem_name})
  117. # For the Client and Server variants of ${gem_name} Gem, an alias to the ${gem_name}.API target will be made
  118. ly_create_alias(NAME ${gem_name}.Clients.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  119. ly_create_alias(NAME ${gem_name}.Servers.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  120. ly_create_alias(NAME ${gem_name}.Unified.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  121. # Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
  122. # for the Clients, Servers, Unified gem variants
  123. o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Clients Servers Unified)
  124. # If we are on a host platform, we want to add the host tools targets like the ${gem_name}.Editor MODULE target
  125. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  126. # The ${gem_name}.Editor.API target can be used by other gems that want to interact with the ${gem_name}.Editor module
  127. ly_add_target(
  128. NAME ${gem_name}.Editor.API INTERFACE
  129. NAMESPACE Gem
  130. FILES_CMAKE
  131. ros2sensors_editor_api_files.cmake
  132. ${pal_dir}/ros2sensors_editor_api_files.cmake
  133. INCLUDE_DIRECTORIES
  134. INTERFACE
  135. Include
  136. BUILD_DEPENDENCIES
  137. INTERFACE
  138. AZ::AzToolsFramework
  139. )
  140. # The ${gem_name}.Editor.Private.Object target is an internal target
  141. # which is only to be used by this gems CMakeLists.txt and any subdirectories
  142. # Other gems should not use this target
  143. ly_add_target(
  144. NAME ${gem_name}.Editor.Private.Object STATIC
  145. NAMESPACE Gem
  146. FILES_CMAKE
  147. ros2sensors_editor_private_files.cmake
  148. TARGET_PROPERTIES
  149. O3DE_PRIVATE_TARGET TRUE
  150. INCLUDE_DIRECTORIES
  151. PRIVATE
  152. Include
  153. Source
  154. BUILD_DEPENDENCIES
  155. PUBLIC
  156. AZ::AzToolsFramework
  157. ${gem_name}.Private.Object
  158. )
  159. ly_add_target(
  160. NAME ${gem_name}.Editor GEM_MODULE
  161. NAMESPACE Gem
  162. AUTOMOC
  163. FILES_CMAKE
  164. ros2sensors_editor_shared_files.cmake
  165. INCLUDE_DIRECTORIES
  166. PRIVATE
  167. Source
  168. PUBLIC
  169. Include
  170. BUILD_DEPENDENCIES
  171. PUBLIC
  172. Gem::${gem_name}.Editor.API
  173. PRIVATE
  174. Gem::${gem_name}.Editor.Private.Object
  175. )
  176. # Include the gem name into the Editor Module source file
  177. # for use with the AZ_DECLARE_MODULE_CLASS macro
  178. # This is to allow renaming of the gem to also cause
  179. # the CreateModuleClass_Gem_<gem-name> function which
  180. # is used to bootstrap the gem in monolithic builds to link to the new gem name
  181. ly_add_source_properties(
  182. SOURCES
  183. Source/Tools/ROS2SensorsEditorModule.cpp
  184. PROPERTY COMPILE_DEFINITIONS
  185. VALUES
  186. O3DE_GEM_NAME=${gem_name}
  187. O3DE_GEM_VERSION=${gem_version})
  188. # By default, we will specify that the above target ${gem_name} would be used by
  189. # Tool and Builder type targets when this gem is enabled. If you don't want it
  190. # active in Tools or Builders by default, delete one of both of the following lines:
  191. ly_create_alias(NAME ${gem_name}.Tools NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  192. ly_create_alias(NAME ${gem_name}.Builders NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  193. # For the Tools and Builders variants of ${gem_name} Gem, an alias to the ${gem_name}.Editor API target will be made
  194. ly_create_alias(NAME ${gem_name}.Tools.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)
  195. ly_create_alias(NAME ${gem_name}.Builders.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)
  196. # Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
  197. # for the Tools and Builders gem variants
  198. o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Tools Builders)
  199. endif()
  200. ################################################################################
  201. # Tests
  202. ################################################################################
  203. # See if globally, tests are supported
  204. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  205. # We globally support tests, see if we support tests on this platform for ${gem_name}.Tests
  206. if(PAL_TRAIT_ROS2SENSORS_TEST_SUPPORTED)
  207. # We support ${gem_name}.Tests on this platform, add dependency on the Private Object target
  208. ly_add_target(
  209. NAME ${gem_name}.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  210. NAMESPACE Gem
  211. FILES_CMAKE
  212. ros2sensors_tests_files.cmake
  213. INCLUDE_DIRECTORIES
  214. PRIVATE
  215. Tests
  216. Source
  217. Include
  218. BUILD_DEPENDENCIES
  219. PRIVATE
  220. AZ::AzTest
  221. AZ::AzFramework
  222. Gem::${gem_name}.Private.Object
  223. )
  224. # Add ${gem_name}.Tests to googletest
  225. ly_add_googletest(
  226. NAME Gem::${gem_name}.Tests
  227. )
  228. endif()
  229. # If we are a host platform we want to add tools test like editor tests here
  230. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  231. # We are a host platform, see if Editor tests are supported on this platform
  232. if(PAL_TRAIT_ROS2SENSORS_EDITOR_TEST_SUPPORTED)
  233. # We support ${gem_name}.Editor.Tests on this platform, add ${gem_name}.Editor.Tests target which depends on
  234. # private ${gem_name}.Editor.Private.Object target
  235. ly_add_target(
  236. NAME ${gem_name}.Editor.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  237. NAMESPACE Gem
  238. FILES_CMAKE
  239. ros2sensors_editor_tests_files.cmake
  240. INCLUDE_DIRECTORIES
  241. PRIVATE
  242. Tests
  243. Source
  244. Include
  245. BUILD_DEPENDENCIES
  246. PRIVATE
  247. AZ::AzTest
  248. Gem::${gem_name}.Editor.Private.Object
  249. )
  250. # Add ${gem_name}.Editor.Tests to googletest
  251. ly_add_googletest(
  252. NAME Gem::${gem_name}.Editor.Tests
  253. )
  254. endif()
  255. endif()
  256. endif()