Install_common.cmake 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  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. include(cmake/FileUtil.cmake)
  9. set(LY_INSTALL_EXTERNAL_BUILD_DIRS "" CACHE PATH "External build directories to be included in the install process. This allows to package non-monolithic and monolithic.")
  10. unset(normalized_external_build_dirs)
  11. foreach(external_dir ${LY_INSTALL_EXTERNAL_BUILD_DIRS})
  12. cmake_path(ABSOLUTE_PATH external_dir BASE_DIRECTORY ${LY_ROOT_FOLDER} NORMALIZE)
  13. list(APPEND normalized_external_build_dirs ${external_dir})
  14. endforeach()
  15. set(LY_INSTALL_EXTERNAL_BUILD_DIRS ${normalized_external_build_dirs})
  16. set(CMAKE_INSTALL_MESSAGE NEVER) # Simplify messages to reduce output noise
  17. define_property(TARGET PROPERTY LY_INSTALL_GENERATE_RUN_TARGET
  18. BRIEF_DOCS "Defines if a \"RUN\" targets should be created when installing this target Gem"
  19. FULL_DOCS [[
  20. Property which is set on targets that should generate a "RUN"
  21. target when installed. This \"RUN\" target helps to run the
  22. binary from the installed location directly from the IDE.
  23. ]]
  24. )
  25. # We can have elements being installed under the following components:
  26. # - Core (required for all) (default)
  27. # - Default
  28. # - Default_$<CONFIG>
  29. # - Monolithic
  30. # - Monolithic_$<CONFIG>
  31. # Debug/Monolithic are build permutations, so for a CMake run, it can only generate
  32. # one of the permutations. Each build permutation can generate only one cmake_install.cmake.
  33. # Each build permutation will generate the same elements in Core.
  34. # CPack is able to put the two together by taking Core from one permutation and then taking
  35. # each permutation.
  36. ly_set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME CORE)
  37. if(LY_MONOLITHIC_GAME)
  38. set(LY_BUILD_PERMUTATION Monolithic)
  39. else()
  40. set(LY_BUILD_PERMUTATION Default)
  41. endif()
  42. string(TOUPPER ${LY_BUILD_PERMUTATION} LY_INSTALL_PERMUTATION_COMPONENT)
  43. cmake_path(RELATIVE_PATH CMAKE_RUNTIME_OUTPUT_DIRECTORY BASE_DIRECTORY ${CMAKE_BINARY_DIR} OUTPUT_VARIABLE runtime_output_directory)
  44. cmake_path(RELATIVE_PATH CMAKE_LIBRARY_OUTPUT_DIRECTORY BASE_DIRECTORY ${CMAKE_BINARY_DIR} OUTPUT_VARIABLE library_output_directory)
  45. # Get the output folders, archive is always the same, but runtime/library can be in subfolders defined per target
  46. cmake_path(RELATIVE_PATH CMAKE_ARCHIVE_OUTPUT_DIRECTORY BASE_DIRECTORY ${CMAKE_BINARY_DIR} OUTPUT_VARIABLE archive_output_directory)
  47. cmake_path(APPEND archive_output_directory "${PAL_PLATFORM_NAME}/$<CONFIG>/${LY_BUILD_PERMUTATION}")
  48. cmake_path(APPEND library_output_directory "${PAL_PLATFORM_NAME}/$<CONFIG>/${LY_BUILD_PERMUTATION}")
  49. cmake_path(APPEND runtime_output_directory "${PAL_PLATFORM_NAME}/$<CONFIG>/${LY_BUILD_PERMUTATION}")
  50. #! ly_setup_target: Setup the data needed to re-create the cmake target commands for a single target
  51. function(ly_setup_target OUTPUT_CONFIGURED_TARGET ALIAS_TARGET_NAME absolute_target_source_dir)
  52. # De-alias target name
  53. ly_de_alias_target(${ALIAS_TARGET_NAME} TARGET_NAME)
  54. # Get the target source directory relative to the LY root folder
  55. ly_get_engine_relative_source_dir(${absolute_target_source_dir} relative_target_source_dir)
  56. # All include directories marked PUBLIC or INTERFACE will be installed. We dont use PUBLIC_HEADER because in order to do that
  57. # we need to set the PUBLIC_HEADER property of the target for all the headers we are exporting. After doing that, installing the
  58. # headers end up in one folder instead of duplicating the folder structure of the public/interface include directory.
  59. # Instead, we install them with install(DIRECTORY)
  60. get_target_property(include_directories ${TARGET_NAME} INTERFACE_INCLUDE_DIRECTORIES)
  61. if (include_directories)
  62. unset(public_headers)
  63. foreach(include_directory ${include_directories})
  64. string(GENEX_STRIP ${include_directory} include_genex_expr)
  65. if(include_genex_expr STREQUAL include_directory) # only for cases where there are no generation expressions
  66. unset(current_public_headers)
  67. cmake_path(NORMAL_PATH include_directory)
  68. string(REGEX REPLACE "/$" "" include_directory "${include_directory}")
  69. cmake_path(IS_PREFIX LY_ROOT_FOLDER ${absolute_target_source_dir} NORMALIZE include_directory_child_of_o3de_root)
  70. if(NOT include_directory_child_of_o3de_root)
  71. # Include directory is outside of the O3DE root folder ${LY_ROOT_FOLDER}.
  72. # For the INSTALL step, the O3DE root folder must be a prefix of all include directories.
  73. continue()
  74. endif()
  75. # For some cases (e.g. codegen) we generate headers that end up in the BUILD_DIR. Since the BUILD_DIR
  76. # is per-permutation, we need to install such headers per permutation. For the other cases, we can install
  77. # under the default component since they are shared across permutations/configs.
  78. cmake_path(IS_PREFIX CMAKE_BINARY_DIR ${include_directory} NORMALIZE include_directory_child_of_build)
  79. # In order to combine profile and release monolithic, we use the CORE component
  80. # because CPack will fail if it finds duplicated content in CORE and DEFAULT/MONOLITHIC
  81. set(include_directory_component ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
  82. unset(rel_include_dir)
  83. if(include_directory_child_of_build)
  84. # We need to use the path relative to the binary folder otherwise you will get an invalid
  85. # relative path if the build folder is outside the engine root.
  86. cmake_path(RELATIVE_PATH include_directory BASE_DIRECTORY ${CMAKE_BINARY_DIR} OUTPUT_VARIABLE rel_include_dir)
  87. else()
  88. cmake_path(RELATIVE_PATH include_directory BASE_DIRECTORY ${LY_ROOT_FOLDER} OUTPUT_VARIABLE rel_include_dir)
  89. endif()
  90. cmake_path(APPEND rel_include_dir "..")
  91. cmake_path(NORMAL_PATH rel_include_dir OUTPUT_VARIABLE destination_dir)
  92. ly_install(DIRECTORY ${include_directory}
  93. DESTINATION ${destination_dir}
  94. COMPONENT ${include_directory_component}
  95. FILES_MATCHING
  96. PATTERN *.h
  97. PATTERN *.hpp
  98. PATTERN *.inl
  99. PATTERN *.hxx
  100. PATTERN *.jinja # LyAutoGen files
  101. )
  102. endif()
  103. endforeach()
  104. endif()
  105. get_target_property(target_runtime_output_directory ${TARGET_NAME} RUNTIME_OUTPUT_DIRECTORY)
  106. if(target_runtime_output_directory)
  107. cmake_path(RELATIVE_PATH target_runtime_output_directory BASE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} OUTPUT_VARIABLE target_runtime_output_subdirectory)
  108. endif()
  109. get_target_property(target_library_output_directory ${TARGET_NAME} LIBRARY_OUTPUT_DIRECTORY)
  110. if(target_library_output_directory)
  111. cmake_path(RELATIVE_PATH target_library_output_directory BASE_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} OUTPUT_VARIABLE target_library_output_subdirectory)
  112. endif()
  113. if(COMMAND ly_setup_target_install_targets_override)
  114. # Mac needs special handling because of a cmake issue
  115. ly_setup_target_install_targets_override(TARGET ${TARGET_NAME}
  116. ARCHIVE_DIR ${archive_output_directory}
  117. LIBRARY_DIR ${library_output_directory}
  118. RUNTIME_DIR ${runtime_output_directory}
  119. LIBRARY_SUBDIR ${target_library_output_subdirectory}
  120. RUNTIME_SUBDIR ${target_runtime_output_subdirectory}
  121. )
  122. else()
  123. foreach(conf IN LISTS CMAKE_CONFIGURATION_TYPES)
  124. string(TOUPPER ${conf} UCONF)
  125. ly_install(TARGETS ${TARGET_NAME}
  126. ARCHIVE
  127. DESTINATION ${archive_output_directory}
  128. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}
  129. CONFIGURATIONS ${conf}
  130. LIBRARY
  131. DESTINATION ${library_output_directory}/${target_library_output_subdirectory}
  132. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}
  133. CONFIGURATIONS ${conf}
  134. RUNTIME
  135. DESTINATION ${runtime_output_directory}/${target_runtime_output_subdirectory}
  136. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}
  137. CONFIGURATIONS ${conf}
  138. )
  139. endforeach()
  140. endif()
  141. # CMakeLists.txt related files
  142. string(REGEX MATCH "(.*)::(.*)$" match ${ALIAS_TARGET_NAME})
  143. if(match)
  144. set(NAMESPACE_PLACEHOLDER "NAMESPACE ${CMAKE_MATCH_1}")
  145. set(NAME_PLACEHOLDER ${CMAKE_MATCH_2})
  146. else()
  147. set(NAMESPACE_PLACEHOLDER "")
  148. set(NAME_PLACEHOLDER ${TARGET_NAME})
  149. endif()
  150. get_target_property(should_create_helper ${TARGET_NAME} LY_INSTALL_GENERATE_RUN_TARGET)
  151. if(should_create_helper)
  152. set(NAME_PLACEHOLDER ${NAME_PLACEHOLDER}.Imported)
  153. endif()
  154. set(TARGET_TYPE_PLACEHOLDER "")
  155. get_target_property(target_type ${TARGET_NAME} TYPE)
  156. # Remove the _LIBRARY since we dont need to pass that to ly_add_targets
  157. string(REPLACE "_LIBRARY" "" TARGET_TYPE_PLACEHOLDER ${target_type})
  158. # For HEADER_ONLY libs we end up generating "INTERFACE" libraries, need to specify HEADERONLY instead
  159. string(REPLACE "INTERFACE" "HEADERONLY" TARGET_TYPE_PLACEHOLDER ${TARGET_TYPE_PLACEHOLDER})
  160. # In non-monolithic mode, gem targets are MODULE libraries, In monolithic mode gem targets are STATIC libraries
  161. set(GEM_LIBRARY_TYPES "MODULE" "STATIC")
  162. if(TARGET_TYPE_PLACEHOLDER IN_LIST GEM_LIBRARY_TYPES)
  163. get_target_property(gem_module ${TARGET_NAME} GEM_MODULE)
  164. if(gem_module)
  165. string(PREPEND TARGET_TYPE_PLACEHOLDER "GEM_")
  166. endif()
  167. endif()
  168. string(REPEAT " " 12 PLACEHOLDER_INDENT)
  169. get_target_property(COMPILE_DEFINITIONS_PLACEHOLDER ${TARGET_NAME} INTERFACE_COMPILE_DEFINITIONS)
  170. if(COMPILE_DEFINITIONS_PLACEHOLDER)
  171. set(COMPILE_DEFINITIONS_PLACEHOLDER "${PLACEHOLDER_INDENT}${COMPILE_DEFINITIONS_PLACEHOLDER}")
  172. list(JOIN COMPILE_DEFINITIONS_PLACEHOLDER "\n${PLACEHOLDER_INDENT}" COMPILE_DEFINITIONS_PLACEHOLDER)
  173. else()
  174. unset(COMPILE_DEFINITIONS_PLACEHOLDER)
  175. endif()
  176. # Includes need additional processing to add the install root
  177. foreach(include IN LISTS include_directories)
  178. string(GENEX_STRIP ${include} include_genex_expr)
  179. if(include_genex_expr STREQUAL include) # only for cases where there are no generation expressions
  180. # Make the include path relative to the source dir where the target will be declared
  181. cmake_path(IS_PREFIX CMAKE_BINARY_DIR ${include} NORMALIZE include_directory_child_of_build)
  182. if(include_directory_child_of_build)
  183. # Some autogen files are placed in the build folder so remove the build folder prefix
  184. # and use it to calculate the relative path
  185. cmake_path(RELATIVE_PATH include BASE_DIRECTORY ${CMAKE_BINARY_DIR} OUTPUT_VARIABLE rel_include)
  186. cmake_path(SET base_path ${LY_ROOT_FOLDER})
  187. cmake_path(APPEND base_path ${rel_include} OUTPUT_VARIABLE absolute_include)
  188. cmake_path(RELATIVE_PATH absolute_include BASE_DIRECTORY ${absolute_target_source_dir} OUTPUT_VARIABLE target_include)
  189. else()
  190. cmake_path(RELATIVE_PATH include BASE_DIRECTORY ${absolute_target_source_dir} OUTPUT_VARIABLE target_include)
  191. endif()
  192. list(APPEND INCLUDE_DIRECTORIES_PLACEHOLDER "${PLACEHOLDER_INDENT}${target_include}")
  193. endif()
  194. endforeach()
  195. list(JOIN INCLUDE_DIRECTORIES_PLACEHOLDER "\n" INCLUDE_DIRECTORIES_PLACEHOLDER)
  196. string(REPEAT " " 12 PLACEHOLDER_INDENT)
  197. get_property(interface_build_dependencies_props TARGET ${TARGET_NAME} PROPERTY LY_DELAYED_LINK)
  198. unset(INTERFACE_BUILD_DEPENDENCIES_PLACEHOLDER)
  199. # We can have private build dependencies that contains direct or indirect runtime dependencies.
  200. # Since imported targets cannot contain build dependencies, we need another way to propagate the runtime dependencies.
  201. # We dont want to put such dependencies in the interface because a user can mistakenly use a symbol that is not available
  202. # when using the engine from source (and that the author of the target didn't want to set public).
  203. # To overcome this, we will actually expose the private build dependencies as runtime dependencies. Our runtime dependency
  204. # algorithm will walk recursively also through static libraries and will only copy binaries to the output.
  205. unset(RUNTIME_DEPENDENCIES_PLACEHOLDER)
  206. if(interface_build_dependencies_props)
  207. cmake_parse_arguments(build_deps "" "" "PRIVATE;PUBLIC;INTERFACE" ${interface_build_dependencies_props})
  208. # Interface and public dependencies should always be exposed
  209. set(build_deps_target ${build_deps_INTERFACE})
  210. if(build_deps_PUBLIC)
  211. set(build_deps_target "${build_deps_target};${build_deps_PUBLIC}")
  212. endif()
  213. # Private dependencies should only be exposed if it is a static library, since in those cases, link
  214. # dependencies are transfered to the downstream dependencies
  215. if("${target_type}" STREQUAL "STATIC_LIBRARY")
  216. set(build_deps_target "${build_deps_target};${build_deps_PRIVATE}")
  217. endif()
  218. # But we will also pass the private dependencies as runtime dependencies (as long as they are targets, note the comment above)
  219. foreach(build_dep_private IN LISTS build_deps_PRIVATE)
  220. if(TARGET ${build_dep_private})
  221. list(APPEND RUNTIME_DEPENDENCIES_PLACEHOLDER "${build_dep_private}")
  222. endif()
  223. endforeach()
  224. foreach(build_dependency IN LISTS build_deps_target)
  225. # Skip wrapping produced when targets are not created in the same directory
  226. if(build_dependency)
  227. list(APPEND INTERFACE_BUILD_DEPENDENCIES_PLACEHOLDER "${PLACEHOLDER_INDENT}${build_dependency}")
  228. endif()
  229. endforeach()
  230. endif()
  231. list(JOIN INTERFACE_BUILD_DEPENDENCIES_PLACEHOLDER "\n" INTERFACE_BUILD_DEPENDENCIES_PLACEHOLDER)
  232. string(REPEAT " " 8 PLACEHOLDER_INDENT)
  233. get_target_property(manually_added_dependencies ${TARGET_NAME} MANUALLY_ADDED_DEPENDENCIES)
  234. if(manually_added_dependencies) # not found properties return the name of the variable with a "-NOTFOUND" at the end, here we set it to empty if not found
  235. list(APPEND RUNTIME_DEPENDENCIES_PLACEHOLDER ${manually_added_dependencies})
  236. endif()
  237. if(RUNTIME_DEPENDENCIES_PLACEHOLDER)
  238. set(RUNTIME_DEPENDENCIES_PLACEHOLDER "${PLACEHOLDER_INDENT}${RUNTIME_DEPENDENCIES_PLACEHOLDER}")
  239. list(JOIN RUNTIME_DEPENDENCIES_PLACEHOLDER "\n${PLACEHOLDER_INDENT}" RUNTIME_DEPENDENCIES_PLACEHOLDER)
  240. else()
  241. unset(RUNTIME_DEPENDENCIES_PLACEHOLDER)
  242. endif()
  243. string(REPEAT " " 8 PLACEHOLDER_INDENT)
  244. # If a target has an LY_PROJECT_NAME property, forward that property to new target
  245. get_target_property(target_project_association ${TARGET_NAME} LY_PROJECT_NAME)
  246. if(target_project_association)
  247. list(APPEND TARGET_PROPERTIES_PLACEHOLDER "${PLACEHOLDER_INDENT}LY_PROJECT_NAME ${target_project_association}")
  248. endif()
  249. # If the target is an executable/application, add a custom target so we can debug the target in project-centric workflow
  250. if(should_create_helper)
  251. string(REPLACE ".Imported" "" RUN_TARGET_NAME ${NAME_PLACEHOLDER})
  252. set(target_types_with_debugging_helper EXECUTABLE APPLICATION)
  253. if(NOT target_type IN_LIST target_types_with_debugging_helper)
  254. message(FATAL_ERROR "Cannot generate a RUN target for ${TARGET_NAME}, type is ${target_type}")
  255. endif()
  256. set(TARGET_RUN_HELPER
  257. "add_custom_target(${RUN_TARGET_NAME})
  258. set_target_properties(${RUN_TARGET_NAME} PROPERTIES
  259. FOLDER \"O3DE_SDK\"
  260. VS_DEBUGGER_COMMAND \$<GENEX_EVAL:\$<TARGET_PROPERTY:${NAME_PLACEHOLDER},IMPORTED_LOCATION>>
  261. VS_DEBUGGER_COMMAND_ARGUMENTS \"--project-path=\${LY_DEFAULT_PROJECT_PATH}\"
  262. )
  263. set_property(GLOBAL APPEND PROPERTY LY_ALL_TARGETS ${RUN_TARGET_NAME})
  264. "
  265. )
  266. endif()
  267. # Config files
  268. set(target_file_contents "# Generated by O3DE install\n\n")
  269. if(NOT target_type STREQUAL INTERFACE_LIBRARY)
  270. unset(target_location)
  271. set(runtime_types EXECUTABLE APPLICATION)
  272. if(target_type IN_LIST runtime_types)
  273. set(target_location "\${LY_ROOT_FOLDER}/${runtime_output_directory}/${target_runtime_output_subdirectory}/$<TARGET_FILE_NAME:${TARGET_NAME}>")
  274. elseif(target_type STREQUAL MODULE_LIBRARY)
  275. set(target_location "\${LY_ROOT_FOLDER}/${library_output_directory}/${target_library_output_subdirectory}/$<TARGET_FILE_NAME:${TARGET_NAME}>")
  276. elseif(target_type STREQUAL SHARED_LIBRARY)
  277. string(APPEND target_file_contents
  278. "set_property(TARGET ${NAME_PLACEHOLDER}
  279. APPEND_STRING PROPERTY IMPORTED_IMPLIB
  280. $<$<CONFIG:$<CONFIG>$<ANGLE-R>:\"\${LY_ROOT_FOLDER}/${archive_output_directory}/$<TARGET_LINKER_FILE_NAME:${TARGET_NAME}>\"$<ANGLE-R>
  281. )
  282. ")
  283. string(APPEND target_file_contents
  284. "set_property(TARGET ${NAME_PLACEHOLDER}
  285. PROPERTY IMPORTED_IMPLIB_$<UPPER_CASE:$<CONFIG>>
  286. \"\${LY_ROOT_FOLDER}/${archive_output_directory}/$<TARGET_LINKER_FILE_NAME:${TARGET_NAME}>\"
  287. )
  288. ")
  289. set(target_location "\${LY_ROOT_FOLDER}/${library_output_directory}/${target_library_output_subdirectory}/$<TARGET_FILE_NAME:${TARGET_NAME}>")
  290. elseif(target_type STREQUAL STATIC_LIBRARY) # STATIC_LIBRARY, OBJECT_LIBRARY, INTERFACE_LIBRARY
  291. set(target_location "\${LY_ROOT_FOLDER}/${archive_output_directory}/$<TARGET_LINKER_FILE_NAME:${TARGET_NAME}>")
  292. else() # OBJECT_LIBRARY has no output target
  293. endif()
  294. if(target_location)
  295. string(APPEND target_file_contents
  296. "set_property(TARGET ${NAME_PLACEHOLDER}
  297. APPEND_STRING PROPERTY IMPORTED_LOCATION
  298. $<$<CONFIG:$<CONFIG>$<ANGLE-R>:${target_location}$<ANGLE-R>
  299. )
  300. set_property(TARGET ${NAME_PLACEHOLDER}
  301. PROPERTY IMPORTED_LOCATION_$<UPPER_CASE:$<CONFIG>>
  302. ${target_location}
  303. )
  304. ")
  305. endif()
  306. endif()
  307. set(target_install_source_dir ${CMAKE_CURRENT_BINARY_DIR}/install/${relative_target_source_dir})
  308. file(GENERATE OUTPUT "${target_install_source_dir}/Platform/${PAL_PLATFORM_NAME}/${LY_BUILD_PERMUTATION}/${NAME_PLACEHOLDER}_$<CONFIG>.cmake" CONTENT "${target_file_contents}")
  309. foreach(conf IN LISTS CMAKE_CONFIGURATION_TYPES)
  310. string(TOUPPER ${conf} UCONF)
  311. ly_install(FILES "${target_install_source_dir}/Platform/${PAL_PLATFORM_NAME}/${LY_BUILD_PERMUTATION}/${NAME_PLACEHOLDER}_${conf}.cmake"
  312. DESTINATION ${relative_target_source_dir}/Platform/${PAL_PLATFORM_NAME}/${LY_BUILD_PERMUTATION}
  313. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}
  314. CONFIGURATIONS ${conf}
  315. )
  316. endforeach()
  317. # Since a CMakeLists.txt could contain multiple targets, we generate it in a folder per target
  318. ly_file_read(${LY_ROOT_FOLDER}/cmake/install/InstalledTarget.in target_cmakelists_template)
  319. string(CONFIGURE ${target_cmakelists_template} output_cmakelists_data @ONLY)
  320. set(${OUTPUT_CONFIGURED_TARGET} ${output_cmakelists_data} PARENT_SCOPE)
  321. endfunction()
  322. #! ly_setup_subdirectories: setups all targets on a per directory basis
  323. function(ly_setup_subdirectories)
  324. get_property(all_subdirectories GLOBAL PROPERTY LY_ALL_TARGET_DIRECTORIES)
  325. foreach(target_subdirectory IN LISTS all_subdirectories)
  326. ly_setup_subdirectory(${target_subdirectory})
  327. endforeach()
  328. endfunction()
  329. #! ly_setup_subdirectory: setup all targets in the subdirectory
  330. function(ly_setup_subdirectory absolute_target_source_dir)
  331. ly_get_engine_relative_source_dir(${absolute_target_source_dir} relative_target_source_dir)
  332. # The builtin BUILDSYSTEM_TARGETS property isn't being used here as that returns the de-alised
  333. # TARGET and we need the alias namespace for recreating the CMakeLists.txt in the install layout
  334. get_property(ALIAS_TARGETS_NAME DIRECTORY ${absolute_target_source_dir} PROPERTY LY_DIRECTORY_TARGETS)
  335. foreach(ALIAS_TARGET_NAME IN LISTS ALIAS_TARGETS_NAME)
  336. ly_setup_target(configured_target ${ALIAS_TARGET_NAME} ${absolute_target_source_dir})
  337. string(APPEND all_configured_targets "${configured_target}")
  338. endforeach()
  339. # Initialize the target install source directory to path underneath the current binary directory
  340. set(target_install_source_dir "${CMAKE_CURRENT_BINARY_DIR}/install/${relative_target_source_dir}")
  341. ly_file_read(${LY_ROOT_FOLDER}/cmake/install/Copyright.in cmake_copyright_comment)
  342. # 1. Create the base CMakeLists.txt that will just include a cmake file per platform
  343. string(CONFIGURE [[
  344. @cmake_copyright_comment@
  345. include(Platform/${PAL_PLATFORM_NAME}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
  346. ]] subdirectory_cmakelist_content @ONLY)
  347. # Store off the generated CMakeLists.txt into a DIRECTORY property based on the subdirectory being visited
  348. # In the ly_setup_assets() function, it generates an empty CMakeLists.txt into the gem root directory
  349. # if one does not exist by checking if this property is set
  350. set_property(DIRECTORY "${absolute_target_source_dir}" APPEND_STRING PROPERTY O3DE_SUBDIRECTORY_CMAKELIST_CONTENT "${subdirectory_cmakelist_content}")
  351. file(WRITE "${target_install_source_dir}/CMakeLists.txt" "${subdirectory_cmakelist_content}")
  352. ly_install(FILES "${target_install_source_dir}/CMakeLists.txt"
  353. DESTINATION ${relative_target_source_dir}
  354. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  355. )
  356. # 2. For this platform file, create a Platform/${PAL_PLATFORM_NAME}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake file
  357. # that will include different configuration permutations (e.g. monolithic vs non-monolithic)
  358. file(CONFIGURE OUTPUT "${target_install_source_dir}/Platform/${PAL_PLATFORM_NAME}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake" CONTENT [[
  359. @cmake_copyright_comment@
  360. if(LY_MONOLITHIC_GAME)
  361. include(Platform/${PAL_PLATFORM_NAME}/Monolithic/permutation.cmake OPTIONAL)
  362. else()
  363. include(Platform/${PAL_PLATFORM_NAME}/Default/permutation.cmake)
  364. endif()
  365. ]])
  366. ly_install(FILES "${target_install_source_dir}/Platform/${PAL_PLATFORM_NAME}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake"
  367. DESTINATION ${relative_target_source_dir}/Platform/${PAL_PLATFORM_NAME}
  368. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  369. )
  370. # 3. For this configuration permutation, generate a Platform/${PAL_PLATFORM_NAME}/${permutation}/permutation.cmake
  371. # that will declare the target and configure it
  372. ly_setup_subdirectory_create_alias("${absolute_target_source_dir}" CREATE_ALIASES_PLACEHOLDER)
  373. ly_setup_subdirectory_set_gem_variant_to_load("${absolute_target_source_dir}" GEM_VARIANT_TO_LOAD_PLACEHOLDER)
  374. ly_setup_add_variant_dependencies_for_gem_dependencies("${absolute_target_source_dir}" O3DE_ADD_VARIANT_DEPS_FOR_GEM_DEPS)
  375. ly_setup_subdirectory_enable_gems("${absolute_target_source_dir}" ENABLE_GEMS_PLACEHOLDER)
  376. ly_setup_subdirectory_install_code("${absolute_target_source_dir}" O3DE_INSTALL_CODE_PLACEHOLDER)
  377. # Write out all the aggregated ly_add_target function calls and the final ly_create_alias() calls to the target CMakeLists.txt
  378. file(WRITE "${target_install_source_dir}/Platform/${PAL_PLATFORM_NAME}/${LY_BUILD_PERMUTATION}/permutation.cmake"
  379. "${cmake_copyright_comment}"
  380. "${O3DE_INSTALL_CODE_PLACEHOLDER}"
  381. "${all_configured_targets}"
  382. "\n"
  383. "${CREATE_ALIASES_PLACEHOLDER}"
  384. "${GEM_VARIANT_TO_LOAD_PLACEHOLDER}"
  385. "${O3DE_ADD_VARIANT_DEPS_FOR_GEM_DEPS}"
  386. "${ENABLE_GEMS_PLACEHOLDER}"
  387. )
  388. ly_install(FILES "${target_install_source_dir}/Platform/${PAL_PLATFORM_NAME}/${LY_BUILD_PERMUTATION}/permutation.cmake"
  389. DESTINATION ${relative_target_source_dir}/Platform/${PAL_PLATFORM_NAME}/${LY_BUILD_PERMUTATION}
  390. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}
  391. )
  392. endfunction()
  393. #! ly_setup_cmake_install: install the "cmake" folder
  394. function(ly_setup_cmake_install)
  395. ly_install(DIRECTORY "${LY_ROOT_FOLDER}/cmake"
  396. DESTINATION .
  397. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  398. PATTERN "__pycache__" EXCLUDE
  399. PATTERN "Findo3de.cmake" EXCLUDE
  400. PATTERN "cmake/ConfigurationTypes.cmake" EXCLUDE
  401. REGEX "3rdParty/Platform\/.*\/BuiltInPackages_.*\.cmake" EXCLUDE
  402. )
  403. # Connect configuration types
  404. ly_install(FILES "${LY_ROOT_FOLDER}/cmake/install/ConfigurationTypes.cmake"
  405. DESTINATION cmake
  406. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  407. )
  408. # generate each ConfigurationType_<CONFIG>.cmake file and install it under that configuration
  409. foreach(conf IN LISTS CMAKE_CONFIGURATION_TYPES)
  410. string(TOUPPER ${conf} UCONF)
  411. configure_file("${LY_ROOT_FOLDER}/cmake/install/ConfigurationType_config.cmake.in"
  412. "${CMAKE_BINARY_DIR}/cmake/Platform/${PAL_PLATFORM_NAME}/${LY_BUILD_PERMUTATION}/ConfigurationTypes_${conf}.cmake"
  413. @ONLY
  414. )
  415. ly_install(FILES "${CMAKE_BINARY_DIR}/cmake/Platform/${PAL_PLATFORM_NAME}/${LY_BUILD_PERMUTATION}/ConfigurationTypes_${conf}.cmake"
  416. DESTINATION cmake/Platform/${PAL_PLATFORM_NAME}/${LY_BUILD_PERMUTATION}
  417. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}
  418. CONFIGURATIONS ${conf}
  419. )
  420. endforeach()
  421. # Transform the list of all external subdirectories used by the engine + projects into a json array
  422. set(indent " ")
  423. get_external_subdirectories_in_use(external_subdirs)
  424. foreach(external_subdir ${external_subdirs})
  425. # If an external subdirectory is not a subdirectory of the engine root, then
  426. # prepend "External" to its subdirectory root
  427. ly_get_root_subdirectory_which_is_parent(${external_subdir} root_subdir_of_external_subdir)
  428. cmake_path(RELATIVE_PATH external_subdir BASE_DIRECTORY ${root_subdir_of_external_subdir} OUTPUT_VARIABLE engine_rel_external_subdir)
  429. cmake_path(IS_PREFIX LY_ROOT_FOLDER ${external_subdir} is_subdirectory_of_engine)
  430. if(NOT is_subdirectory_of_engine)
  431. cmake_path(GET root_subdir_of_external_subdir FILENAME root_subdir_dirname)
  432. set(relative_subdir ${engine_rel_external_subdir})
  433. unset(engine_rel_external_subdir)
  434. cmake_path(APPEND engine_rel_external_subdir "External" ${root_subdir_dirname} ${relative_subdir})
  435. endif()
  436. set(quoted_engine_rel_external_subdir "\"${engine_rel_external_subdir}\"")
  437. if (quoted_engine_rel_external_subdir IN_LIST relative_external_subdirs)
  438. message(WARNING "An external subdirectory \"${external_subdir}\" has been found twice when generating the engine.json for the install layout")
  439. else()
  440. list(APPEND relative_external_subdirs "\"${engine_rel_external_subdir}\"")
  441. endif()
  442. endforeach()
  443. # Sort the external subdirectories before joining them with commas
  444. list(SORT relative_external_subdirs CASE INSENSITIVE)
  445. list(JOIN relative_external_subdirs ",\n${indent}" O3DE_INSTALL_EXTERNAL_SUBDIRS)
  446. # Use the cache list of "gem_names" from the engine.json to populate
  447. # the generated engine.json file
  448. # The O3DE_INSTALL_ENGINE_GEMS is the configure placeholder that needs to be set
  449. # at the end
  450. get_property(active_engine_gems GLOBAL PROPERTY "O3DE_EXPLICIT_ACTIVE_GEMS_ENGINE")
  451. if (active_engine_gems)
  452. foreach(active_engine_gem IN LISTS active_engine_gems)
  453. list(APPEND quoted_active_engine_gems "\"${active_engine_gem}\"")
  454. endforeach()
  455. list(SORT quoted_active_engine_gems CASE INSENSITIVE)
  456. list(JOIN quoted_active_engine_gems ",\n${indent}" O3DE_INSTALL_ENGINE_GEMS)
  457. endif()
  458. # Read the "templates" key from the source engine.json
  459. o3de_read_json_array(engine_templates ${LY_ROOT_FOLDER}/engine.json "templates")
  460. if(engine_templates)
  461. foreach(template_path IN LISTS engine_templates)
  462. list(APPEND relative_templates "\"${template_path}\"")
  463. endforeach()
  464. list(SORT relative_templates CASE INSENSITIVE)
  465. list(JOIN relative_templates ",\n${indent}" O3DE_INSTALL_TEMPLATES)
  466. endif()
  467. # Read the "repos" key from the source engine.json
  468. o3de_read_json_array(engine_repos ${LY_ROOT_FOLDER}/engine.json "repos")
  469. if(engine_repos)
  470. foreach(repo_uri ${engine_repos})
  471. list(APPEND repos "\"${repo_uri}\"")
  472. endforeach()
  473. list(SORT repos CASE INSENSITIVE)
  474. list(JOIN repos ",\n${indent}" O3DE_INSTALL_REPOS)
  475. endif()
  476. # Read the "api_versions" key from the source engine.json
  477. o3de_read_json_key(O3DE_INSTALL_API_VERSIONS ${LY_ROOT_FOLDER}/engine.json "api_versions")
  478. configure_file(${LY_ROOT_FOLDER}/cmake/install/engine.json.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/engine.json @ONLY)
  479. ly_install(FILES
  480. "${LY_ROOT_FOLDER}/CMakeLists.txt"
  481. "${CMAKE_CURRENT_BINARY_DIR}/cmake/engine.json"
  482. DESTINATION .
  483. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  484. )
  485. # Collect all Find files that were added with ly_add_external_target_path
  486. unset(additional_find_files)
  487. unset(additional_platform_files)
  488. get_property(additional_module_paths GLOBAL PROPERTY LY_ADDITIONAL_MODULE_PATH)
  489. foreach(additional_module_path ${additional_module_paths})
  490. unset(find_files)
  491. file(GLOB find_files "${additional_module_path}/Find*.cmake")
  492. list(APPEND additional_find_files "${find_files}")
  493. foreach(find_file ${find_files})
  494. # also copy the Platform/<current_platform> to the destination
  495. cmake_path(GET find_file PARENT_PATH find_file_parent)
  496. unset(plat_files)
  497. file(GLOB plat_files "${find_file_parent}/Platform/${PAL_PLATFORM_NAME}/*.cmake")
  498. list(APPEND additional_platform_files "${plat_files}")
  499. endforeach()
  500. endforeach()
  501. ly_install(FILES ${additional_find_files}
  502. DESTINATION cmake/3rdParty
  503. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  504. )
  505. ly_install(FILES ${additional_platform_files}
  506. DESTINATION cmake/3rdParty/Platform/${PAL_PLATFORM_NAME}
  507. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  508. )
  509. # Findo3de.cmake file: we generate a different Findo3de.cmake file than the one we have in the source dir.
  510. configure_file(${LY_ROOT_FOLDER}/cmake/install/Findo3de.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/Findo3de.cmake @ONLY)
  511. ly_install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/Findo3de.cmake"
  512. DESTINATION cmake
  513. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  514. )
  515. unset(find_subdirectories)
  516. # Add to find_subdirectories all directories in which ly_add_target were called in
  517. get_property(all_subdirectories GLOBAL PROPERTY LY_ALL_TARGET_DIRECTORIES)
  518. foreach(target_subdirectory IN LISTS all_subdirectories)
  519. # If the subdirectory is an external_subdirectory, then it is being added in the engine.json file
  520. # Therefore it is not added to the o3de_subdirectories_<Platform>.cmake file to avoid
  521. # invoking add_subdirectory twice
  522. get_property(is_external_subdir GLOBAL PROPERTY "O3DE_SUBDIRECTORY_${target_subdirectory}" SET)
  523. if(is_external_subdir)
  524. continue()
  525. endif()
  526. ly_get_root_subdirectory_which_is_parent(${target_subdirectory} root_subdir_of_target)
  527. cmake_path(RELATIVE_PATH target_subdirectory BASE_DIRECTORY ${root_subdir_of_target} OUTPUT_VARIABLE relative_target_subdirectory)
  528. cmake_path(IS_PREFIX LY_ROOT_FOLDER ${target_subdirectory} is_subdirectory_of_engine)
  529. if(NOT is_subdirectory_of_engine)
  530. cmake_path(GET root_subdir_of_target FILENAME root_subdir_dirname)
  531. set(relative_subdir ${relative_target_subdirectory})
  532. unset(relative_target_subdirectory)
  533. cmake_path(APPEND relative_target_subdirectory "External" ${root_subdir_dirname} ${relative_subdir})
  534. endif()
  535. string(APPEND find_subdirectories "add_subdirectory(${relative_target_subdirectory})\n")
  536. endforeach()
  537. set(permutation_find_subdirectories ${CMAKE_CURRENT_BINARY_DIR}/cmake/Platform/${PAL_PLATFORM_NAME}/${LY_BUILD_PERMUTATION}/o3de_subdirectories_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
  538. file(GENERATE OUTPUT ${permutation_find_subdirectories}
  539. CONTENT
  540. "# Generated by O3DE install\n
  541. ${find_subdirectories}
  542. "
  543. )
  544. ly_install(FILES "${permutation_find_subdirectories}"
  545. DESTINATION cmake/Platform/${PAL_PLATFORM_NAME}/${LY_BUILD_PERMUTATION}
  546. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}
  547. )
  548. set(pal_builtin_file ${CMAKE_CURRENT_BINARY_DIR}/cmake/3rdParty/Platform/${PAL_PLATFORM_NAME}/BuiltInPackages_${PAL_PLATFORM_NAME_LOWERCASE}${LY_HOST_ARCHITECTURE_NAME_EXTENSION}.cmake)
  549. file(GENERATE OUTPUT ${pal_builtin_file}
  550. CONTENT
  551. "# Generated by O3DE install\n
  552. if(LY_MONOLITHIC_GAME)
  553. include(cmake/3rdParty/Platform/${PAL_PLATFORM_NAME}/Monolithic/BuiltInPackages_${PAL_PLATFORM_NAME_LOWERCASE}${LY_HOST_ARCHITECTURE_NAME_EXTENSION}.cmake)
  554. else()
  555. include(cmake/3rdParty/Platform/${PAL_PLATFORM_NAME}/Default/BuiltInPackages_${PAL_PLATFORM_NAME_LOWERCASE}${LY_HOST_ARCHITECTURE_NAME_EXTENSION}.cmake)
  556. endif()
  557. "
  558. )
  559. ly_install(FILES "${pal_builtin_file}"
  560. DESTINATION cmake/3rdParty/Platform/${PAL_PLATFORM_NAME}
  561. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  562. )
  563. # ${LY_BUILD_PERMUTATION}/BuiltInPackage_<platform>.cmake: since associations could happen in any cmake file across the engine. We collect
  564. # all the associations in ly_associate_package and then generate them into BuiltInPackages_<platform>.cmake. This will consolidate all
  565. # associations in one file
  566. # Associations are sensitive to platform and build permutation, so we make different files for each.
  567. get_property(all_package_names GLOBAL PROPERTY LY_PACKAGE_NAMES)
  568. list(REMOVE_DUPLICATES all_package_names)
  569. set(builtinpackages "# Generated by O3DE install\n\n")
  570. foreach(package_name IN LISTS all_package_names)
  571. get_property(package_hash GLOBAL PROPERTY LY_PACKAGE_HASH_${package_name})
  572. get_property(targets GLOBAL PROPERTY LY_PACKAGE_TARGETS_${package_name})
  573. list(REMOVE_DUPLICATES targets)
  574. string(APPEND builtinpackages "ly_associate_package(PACKAGE_NAME ${package_name} TARGETS ${targets} PACKAGE_HASH ${package_hash})\n")
  575. endforeach()
  576. # Allow the BuiltinPackages_<platform>.cmake script to propagate additional cmake code to be executed in the Install layout configure step
  577. get_property(builtin_packages_inject_code GLOBAL PROPERTY O3DE_BUILTIN_PACKAGES_INSTALL_CODE)
  578. if (builtin_packages_inject_code)
  579. string(APPEND builtinpackages "${builtin_packages_inject_code}\n")
  580. endif()
  581. set(permutation_builtin_file ${CMAKE_CURRENT_BINARY_DIR}/cmake/3rdParty/Platform/${PAL_PLATFORM_NAME}/${LY_BUILD_PERMUTATION}/BuiltInPackages_${PAL_PLATFORM_NAME_LOWERCASE}${LY_HOST_ARCHITECTURE_NAME_EXTENSION}.cmake)
  582. file(GENERATE OUTPUT ${permutation_builtin_file}
  583. CONTENT "${builtinpackages}"
  584. )
  585. ly_install(FILES "${permutation_builtin_file}"
  586. DESTINATION cmake/3rdParty/Platform/${PAL_PLATFORM_NAME}/${LY_BUILD_PERMUTATION}
  587. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}
  588. )
  589. endfunction()
  590. #! ly_setup_runtime_dependencies: install runtime dependencies
  591. function(ly_setup_runtime_dependencies)
  592. # Common functions used by the bellow code
  593. if(COMMAND ly_setup_runtime_dependencies_copy_function_override)
  594. ly_setup_runtime_dependencies_copy_function_override()
  595. else()
  596. # despite this copy function being the same, we need to install it per component that uses it
  597. # (which is per-configuration per-permutation component)
  598. # The template is needed to replace the @LY_COPY_PERMISSIONS@ variable with the permissions
  599. # that should be used for the copied file
  600. set(install_runtime_ly_copy_template [[
  601. function(ly_copy source_files relative_target_directory)
  602. set(options)
  603. set(oneValueArgs TARGET_FILE_DIR SOURCE_TYPE SOURCE_GEM_MODULE)
  604. set(multiValueArgs)
  605. cmake_parse_arguments("${CMAKE_CURRENT_FUNCTION}" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  606. set(target_file_dir "${${CMAKE_CURRENT_FUNCTION}_TARGET_FILE_DIR}")
  607. set(source_type "${${CMAKE_CURRENT_FUNCTION}_SOURCE_TYPE}")
  608. set(source_is_gem "${${CMAKE_CURRENT_FUNCTION}_SOURCE_GEM_MODULE}")
  609. # Create the full path to the target directory
  610. cmake_path(APPEND target_directory "${target_file_dir}" "${relative_target_directory}")
  611. foreach(source_file IN LISTS source_files)
  612. cmake_path(GET source_file FILENAME target_filename)
  613. cmake_path(APPEND full_target_directory "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}" "${target_directory}")
  614. cmake_path(APPEND target_file "${full_target_directory}" "${target_filename}")
  615. if("${source_file}" IS_NEWER_THAN "${target_file}")
  616. message(STATUS "Copying ${source_file} to ${full_target_directory}...")
  617. file(COPY "${source_file}" DESTINATION "${full_target_directory}" FILE_PERMISSIONS @LY_COPY_PERMISSIONS@ FOLLOW_SYMLINK_CHAIN)
  618. file(TOUCH_NOCREATE "${target_file}")
  619. endif()
  620. endforeach()
  621. endfunction()
  622. ]])
  623. # replace the @...@ placeholders
  624. string(CONFIGURE "${install_runtime_ly_copy_template}" install_runtime_ly_copy @ONLY)
  625. foreach(conf IN LISTS CMAKE_CONFIGURATION_TYPES)
  626. string(TOUPPER ${conf} UCONF)
  627. ly_install(CODE "${install_runtime_ly_copy}"
  628. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}
  629. )
  630. endforeach()
  631. endif()
  632. unset(runtime_commands)
  633. get_property(all_targets GLOBAL PROPERTY LY_ALL_TARGETS)
  634. foreach(alias_target IN LISTS all_targets)
  635. ly_de_alias_target(${alias_target} target)
  636. # Exclude targets that dont produce runtime outputs
  637. get_target_property(target_type ${target} TYPE)
  638. if(NOT target_type IN_LIST LY_TARGET_TYPES_WITH_RUNTIME_OUTPUTS)
  639. continue()
  640. endif()
  641. get_target_property(target_runtime_output_directory ${target} RUNTIME_OUTPUT_DIRECTORY)
  642. if(target_runtime_output_directory)
  643. cmake_path(RELATIVE_PATH target_runtime_output_directory BASE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} OUTPUT_VARIABLE target_runtime_output_subdirectory)
  644. endif()
  645. # runtime dependencies that need to be copied to the output
  646. set(target_file_dir "${runtime_output_directory}/${target_runtime_output_subdirectory}")
  647. unset(target_copy_dependencies)
  648. unset(target_target_dependencies)
  649. unset(target_link_dependencies)
  650. unset(target_imported_dependencies)
  651. o3de_get_dependencies_for_target(
  652. TARGET "${target}"
  653. COPY_DEPENDENCIES_VAR target_copy_dependencies
  654. TARGET_DEPENDENCIES_VAR target_target_dependencies
  655. LINK_DEPENDENCIES_VAR target_link_dependencies
  656. IMPORTED_DEPENDENCIES_VAR target_imported_dependencies
  657. )
  658. foreach(dependency_for_target IN LISTS target_copy_dependencies target_target_dependencies
  659. target_link_dependencies target_imported_dependencies)
  660. unset(runtime_command)
  661. o3de_get_command_for_dependency(COMMAND_VAR runtime_command
  662. DEPENDENCY ${dependency_for_target})
  663. string(CONFIGURE "${runtime_command}" runtime_command @ONLY)
  664. list(APPEND runtime_commands ${runtime_command})
  665. endforeach()
  666. endforeach()
  667. list(REMOVE_DUPLICATES runtime_commands)
  668. list(JOIN runtime_commands " " runtime_commands_str) # the spaces are just to see the right identation in the cmake_install.cmake file
  669. foreach(conf IN LISTS CMAKE_CONFIGURATION_TYPES)
  670. string(TOUPPER ${conf} UCONF)
  671. ly_install(CODE "${runtime_commands_str}"
  672. COMPONENT ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}
  673. )
  674. endforeach()
  675. endfunction()
  676. #! ly_setup_assets: install asset directories required by the engine
  677. function(ly_setup_assets)
  678. # Gem Source Assets and configuration files
  679. # Find all gem directories relative to the CMake Source Dir
  680. # This first loop is to filter out transient and .gitignore'd folders that should be added to
  681. # the install layout from the root directory. Such as <external-subdirectory-root>/Cache.
  682. # This is also done to avoid globbing thousands of files in subdirectories that shouldn't
  683. # be processed.
  684. get_external_subdirectories_in_use(external_subdirs)
  685. foreach(gem_candidate_dir IN LISTS external_subdirs)
  686. file(REAL_PATH ${gem_candidate_dir} gem_candidate_dir BASE_DIRECTORY ${LY_ROOT_FOLDER})
  687. # Don't recurse immediately in order to exclude transient source artifacts
  688. file(GLOB
  689. external_subdir_files
  690. LIST_DIRECTORIES TRUE
  691. "${gem_candidate_dir}/*"
  692. )
  693. # Exclude transient artifacts that shouldn't be copied to the install layout
  694. list(FILTER external_subdir_files EXCLUDE REGEX "/([Bb]uild|[Cc]ache|[Uu]ser)$")
  695. # Storing a "mapping" of gem candidate directories, to external_subdirectory files using
  696. # a DIRECTORY property for the "value" and the GLOBAL property for the "key"
  697. set_property(DIRECTORY ${gem_candidate_dir} APPEND PROPERTY directory_filtered_asset_paths "${external_subdir_files}")
  698. set_property(GLOBAL APPEND PROPERTY global_gem_candidate_dirs_prop ${gem_candidate_dir})
  699. endforeach()
  700. # Iterate over each gem candidate directories and populate a directory property
  701. # containing the files to copy over
  702. get_property(gem_candidate_dirs GLOBAL PROPERTY global_gem_candidate_dirs_prop)
  703. foreach(gem_candidate_dir IN LISTS gem_candidate_dirs)
  704. get_property(filtered_asset_paths DIRECTORY ${gem_candidate_dir} PROPERTY directory_filtered_asset_paths)
  705. # Check if the gem is a subdirectory of the engine
  706. cmake_path(IS_PREFIX LY_ROOT_FOLDER ${gem_candidate_dir} is_gem_subdirectory_of_engine)
  707. # At this point the filtered_assets_paths contains the list of all directories and files
  708. # that are non-excluded candidates that can be scanned for target directories and files
  709. # to copy over to the install layout
  710. foreach(filtered_asset_path IN LISTS filtered_asset_paths)
  711. if(IS_DIRECTORY ${filtered_asset_path})
  712. file(GLOB_RECURSE
  713. recurse_assets_paths
  714. LIST_DIRECTORIES TRUE
  715. "${filtered_asset_path}/*"
  716. )
  717. set(gem_file_paths ${recurse_assets_paths})
  718. # Make sure to prepend the current path iteration to the gem_dirs_path to filter
  719. set(gem_dir_paths ${filtered_asset_path} ${recurse_assets_paths})
  720. # Gather directories to copy over
  721. # Currently only the Assets, Registry and Config directories are copied over
  722. list(FILTER gem_dir_paths INCLUDE REGEX "/(Assets|Registry|Config|Editor/Scripts)$")
  723. set_property(DIRECTORY ${gem_candidate_dir} APPEND PROPERTY gems_assets_paths ${gem_dir_paths})
  724. else()
  725. set(gem_file_paths ${filtered_asset_path})
  726. endif()
  727. # Gather files to copy over
  728. # Currently only the gem.json file is copied over
  729. list(FILTER gem_file_paths INCLUDE REGEX "/(gem.json|preview.png)$")
  730. set_property(DIRECTORY ${gem_candidate_dir} APPEND PROPERTY gems_assets_paths "${gem_file_paths}")
  731. endforeach()
  732. # gem directories and files to install
  733. get_property(gems_assets_paths DIRECTORY ${gem_candidate_dir} PROPERTY gems_assets_paths)
  734. foreach(gem_absolute_path IN LISTS gems_assets_paths)
  735. # If an external subdirectory is not a subdirectory of the engine root, then
  736. # prepend "External" to its subdirectory root
  737. ly_get_root_subdirectory_which_is_parent(${gem_candidate_dir} root_subdir_of_gem)
  738. cmake_path(RELATIVE_PATH gem_absolute_path BASE_DIRECTORY ${root_subdir_of_gem} OUTPUT_VARIABLE gem_install_dest_dir)
  739. if(NOT is_gem_subdirectory_of_engine)
  740. cmake_path(GET root_subdir_of_gem FILENAME root_subdir_dirname)
  741. set(relative_subdir ${gem_install_dest_dir})
  742. unset(gem_install_dest_dir)
  743. cmake_path(APPEND gem_install_dest_dir "External" ${root_subdir_dirname} ${relative_subdir})
  744. endif()
  745. cmake_path(GET gem_install_dest_dir PARENT_PATH gem_install_dest_dir)
  746. if (NOT gem_install_dest_dir)
  747. cmake_path(SET gem_install_dest_dir .)
  748. endif()
  749. if(IS_DIRECTORY ${gem_absolute_path})
  750. ly_install(DIRECTORY "${gem_absolute_path}"
  751. DESTINATION ${gem_install_dest_dir}
  752. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  753. )
  754. elseif (EXISTS ${gem_absolute_path})
  755. # Special case for the gem.json file, generate an empty CMakeLists.txt with the gem.json file
  756. # if there is not already a CMakeLists.txy being installed to gem root directory
  757. cmake_path(GET gem_absolute_path FILENAME filename)
  758. cmake_path(COMPARE "${filename}" EQUAL "gem.json" is_gem_root)
  759. get_property(has_gem_root_cmakelist_content DIRECTORY "${gem_candidate_dir}" PROPERTY O3DE_SUBDIRECTORY_CMAKELIST_CONTENT SET)
  760. if (is_gem_root AND NOT has_gem_root_cmakelist_content)
  761. ly_file_read(${LY_ROOT_FOLDER}/cmake/install/Copyright.in cmake_copyright_comment)
  762. # Generate an empty CMakeLists.txt inside the cmake binary directory
  763. # to allow it to be installed next to the gem.json
  764. set(gem_scratch_binary_dir "${CMAKE_CURRENT_BINARY_DIR}/install/${gem_install_dest_dir}")
  765. # 1. Create the base CMakeLists.txt that will just include a cmake file per platform
  766. string(CONFIGURE [[
  767. @cmake_copyright_comment@
  768. o3de_read_json_key(GEM_TYPE ${CMAKE_CURRENT_SOURCE_DIR}/gem.json "type")
  769. if (GEM_TYPE STREQUAL "Asset")
  770. include(Platform/${PAL_PLATFORM_NAME}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
  771. endif()
  772. ]] subdirectory_cmakelist_content @ONLY)
  773. # Store off the generated CMakeLists.txt into a DIRECTORY property based on the subdirectory being visited
  774. # In the ly_setup_assets() function, it generates an empty CMakeLists.txt into the gem root directory
  775. # if one does not exist by checking if this property is set
  776. set_property(DIRECTORY "${absolute_target_source_dir}" APPEND_STRING PROPERTY O3DE_SUBDIRECTORY_CMAKELIST_CONTENT "${subdirectory_cmakelist_content}")
  777. # copy the empty CMakeList.txt into the gem root directory, to allow add_subdirectory
  778. # calls to succeed on the gem root in the install layout
  779. file(WRITE "${gem_scratch_binary_dir}/CMakeLists.txt" "${subdirectory_cmakelist_content}")
  780. ly_install(FILES "${gem_scratch_binary_dir}/CMakeLists.txt"
  781. DESTINATION ${gem_install_dest_dir}
  782. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  783. )
  784. endif()
  785. ly_install(FILES ${gem_absolute_path}
  786. DESTINATION ${gem_install_dest_dir}
  787. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  788. )
  789. endif()
  790. endforeach()
  791. endforeach()
  792. endfunction()
  793. #! ly_setup_add_variant_dependencies_for_gem_dependencies: Replicates the call to
  794. #! the `o3de_add_variant_dependencies_for_gem_dependencies` function
  795. #! within the generated CMakeLists.txt in the same relative install layout directory
  796. function(ly_setup_add_variant_dependencies_for_gem_dependencies absolute_target_source_dir output_script)
  797. # Replicate the create_alias() calls made in the SOURCE_DIR into the generated CMakeLists.txt
  798. string(JOIN "\n" add_variant_dependencies_for_gem_dependencies_template
  799. "o3de_add_variant_dependencies_for_gem_dependencies(@add_variant_dependencies_for_gem_dependencies_args@)"
  800. "")
  801. unset(${output_script} PARENT_SCOPE)
  802. get_property(add_variant_dependencies_for_gem_dependencies_args_list
  803. DIRECTORY ${absolute_target_source_dir}
  804. PROPERTY O3DE_ADD_VARIANT_DEPENDENCIES_FOR_GEM_DEPENDENCIES_ARGUMENTS)
  805. unset(add_variant_dependencies_for_gem_dependencies_calls)
  806. foreach(add_variant_dependencies_for_gem_dependencies_args IN LISTS add_variant_dependencies_for_gem_dependencies_args_list)
  807. string(CONFIGURE "${add_variant_dependencies_for_gem_dependencies_template}" add_variant_dependencies_for_gem_dependencies_command @ONLY)
  808. string(APPEND add_variant_dependencies_for_gem_dependencies_calls ${add_variant_dependencies_for_gem_dependencies_command})
  809. endforeach()
  810. set(${output_script} ${add_variant_dependencies_for_gem_dependencies_calls} PARENT_SCOPE)
  811. endfunction()
  812. #! ly_setup_subdirectory_create_alias: Replicates the call to the `ly_create_alias` function
  813. #! within the generated CMakeLists.txt in the same relative install layout directory
  814. function(ly_setup_subdirectory_create_alias absolute_target_source_dir output_script)
  815. # Replicate the create_alias() calls made in the SOURCE_DIR into the generated CMakeLists.txt
  816. string(JOIN "\n" create_alias_template
  817. "if(NOT TARGET @alias_name@)"
  818. " ly_create_alias(@create_alias_args@)"
  819. "endif()"
  820. "")
  821. unset(${output_script} PARENT_SCOPE)
  822. get_property(create_alias_args_list DIRECTORY ${absolute_target_source_dir} PROPERTY LY_CREATE_ALIAS_ARGUMENTS)
  823. foreach(create_alias_args IN LISTS create_alias_args_list)
  824. # Create a list out of the comma separated arguments and store it into the same variable
  825. string(REPLACE "," ";" create_alias_args ${create_alias_args})
  826. # The first argument of the create alias argument list is the ALIAS NAME so pop it from the list
  827. # It is used to protect against registering the same alias twice
  828. list(POP_FRONT create_alias_args alias_name)
  829. string(CONFIGURE "${create_alias_template}" create_alias_command @ONLY)
  830. string(APPEND create_alias_calls ${create_alias_command})
  831. endforeach()
  832. set(${output_script} ${create_alias_calls} PARENT_SCOPE)
  833. endfunction()
  834. #! ly_setup_subdirectory_set_gem_variant_to_load: Replicates the call to the `ly_set_gem_variant_to_load` function
  835. #! within the generated CMakeLists.txt in the same relative install layout directory
  836. function(ly_setup_subdirectory_set_gem_variant_to_load absolute_target_source_dir output_script)
  837. # Replicate the ly_set_gem_variant_to_load() calls made in the SOURCE_DIR for into the generated CMakeLists.txt
  838. set(set_gem_variant_args_template "ly_set_gem_variant_to_load(@set_gem_variant_args@)\n")
  839. unset(${output_script} PARENT_SCOPE)
  840. get_property(set_gem_variant_args_lists DIRECTORY ${absolute_target_source_dir} PROPERTY LY_SET_GEM_VARIANT_TO_LOAD_ARGUMENTS)
  841. foreach(set_gem_variant_args IN LISTS set_gem_variant_args_lists)
  842. string(CONFIGURE "${set_gem_variant_args_template}" set_gem_variant_to_load_command @ONLY)
  843. string(APPEND set_gem_variant_calls ${set_gem_variant_to_load_command})
  844. endforeach()
  845. set(${output_script} ${set_gem_variant_calls} PARENT_SCOPE)
  846. endfunction()
  847. #! ly_setup_subdirectory_enable_gems: Replicates the call to the `ly_enable_gems` function
  848. #! within the generated CMakeLists.txt in the same relative install layout directory
  849. function(ly_setup_subdirectory_enable_gems absolute_target_source_dir output_script)
  850. # Replicate the ly_set_gem_variant_to_load() calls made in the SOURCE_DIR into the generated CMakeLists.txt
  851. set(enable_gems_template "ly_enable_gems(@enable_gems_args@)\n")
  852. unset(${output_script} PARENT_SCOPE)
  853. get_property(enable_gems_args_list DIRECTORY ${absolute_target_source_dir} PROPERTY LY_ENABLE_GEMS_ARGUMENTS)
  854. foreach(enable_gems_args IN LISTS enable_gems_args_list)
  855. string(CONFIGURE "${enable_gems_template}" enable_gems_command @ONLY)
  856. string(APPEND enable_gems_calls ${enable_gems_command})
  857. endforeach()
  858. set(${output_script} ${enable_gems_calls} PARENT_SCOPE)
  859. endfunction()
  860. #! ly_setup_subdirectory_install_code: Add the CMake code specified in the O3DE_SUBDIRECTORY_INSTALL_CODE
  861. #! DIRECTORY property to the beginning of the generated CMakeLists.txt in the same relative install layout diredctory
  862. #! within the generated CMakeLists.txt in the same relative install layout directory
  863. function(ly_setup_subdirectory_install_code absolute_target_source_dir output_script)
  864. unset(${output_script} PARENT_SCOPE)
  865. get_property(subdirectory_install_code DIRECTORY ${absolute_target_source_dir} PROPERTY O3DE_SUBDIRECTORY_INSTALL_CODE)
  866. set(${output_script} ${subdirectory_install_code} PARENT_SCOPE)
  867. endfunction()
  868. #! ly_setup_o3de_install: orchestrates the installation of the different parts. This is the entry point from the root CMakeLists.txt
  869. function(ly_setup_o3de_install)
  870. ly_setup_subdirectories()
  871. ly_setup_cmake_install()
  872. ly_setup_runtime_dependencies()
  873. ly_setup_assets()
  874. # Misc
  875. ly_install(FILES
  876. ${LY_ROOT_FOLDER}/pytest.ini
  877. ${LY_ROOT_FOLDER}/LICENSE.txt
  878. ${LY_ROOT_FOLDER}/README.md
  879. ${LY_ROOT_FOLDER}/CMakePresets.json
  880. DESTINATION .
  881. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  882. )
  883. # Inject other build directories
  884. foreach(external_dir ${LY_INSTALL_EXTERNAL_BUILD_DIRS})
  885. ly_install(CODE
  886. "set(LY_CORE_COMPONENT_ALREADY_INCLUDED TRUE)
  887. include(${external_dir}/cmake_install.cmake)
  888. set(LY_CORE_COMPONENT_ALREADY_INCLUDED FALSE)"
  889. ALL_COMPONENTS
  890. )
  891. endforeach()
  892. if(COMMAND ly_post_install_steps)
  893. ly_post_install_steps()
  894. endif()
  895. endfunction()