From 84cf3bffde3ba8202923bcbb2c82f56aed777a13 Mon Sep 17 00:00:00 2001 From: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> Date: Wed, 26 May 2021 20:49:52 -0500 Subject: [PATCH] Updating the Install_common.cmake script to copy over the source engine.json templates array to the generated installed engine.json --- cmake/O3DEJson.cmake | 45 +++++++++++++--------- cmake/Platform/Common/Install_common.cmake | 15 +++++--- cmake/install/engine.json.in | 2 +- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/cmake/O3DEJson.cmake b/cmake/O3DEJson.cmake index 5d748e9681..ab5f95bc8c 100644 --- a/cmake/O3DEJson.cmake +++ b/cmake/O3DEJson.cmake @@ -14,35 +14,42 @@ include_guard() set(LY_EXTERNAL_SUBDIRS "" CACHE STRING "List of subdirectories to recurse into when running cmake against the engine's CMakeLists.txt") #! read_json_external_subdirs -# Read the "external_subdirectories" array from a *.json file -# External subdirectories are any folders with CMakeLists.txt in them -# This could be regular subdirectories, Gems(contains an additional gem.json), -# Restricted folders(contains an additional restricted.json), etc... -# -# \arg:output_external_subdirs name of output variable to store external subdirectories into -# \arg:input_json_path path to the *.json file to load and read the external subdirectories from -# \return: external subdirectories as is from the json file. +# Read the "external_subdirectories" array from a *.json file +# External subdirectories are any folders with CMakeLists.txt in them +# This could be regular subdirectories, Gems(contains an additional gem.json), +# Restricted folders(contains an additional restricted.json), etc... +# +# \arg:output_external_subdirs name of output variable to store external subdirectories into +# \arg:input_json_path path to the *.json file to load and read the external subdirectories from +# \return: external subdirectories as is from the json file. function(read_json_external_subdirs output_external_subdirs input_json_path) + o3de_read_json_array(json_array ${input_json_path} "external_subdirectories") + set(${output_external_subdirs} ${json_array} PARENT_SCOPE) +endfunction() + +#! read_json_array +# Reads the a json array field into a cmake list variable +function(o3de_read_json_array read_output_array input_json_path array_key) file(READ ${input_json_path} manifest_json_data) - string(JSON external_subdirs_count ERROR_VARIABLE manifest_json_error - LENGTH ${manifest_json_data} "external_subdirectories") + string(JSON array_count ERROR_VARIABLE manifest_json_error + LENGTH ${manifest_json_data} ${array_key}) if(manifest_json_error) - # There is "external_subdirectories" key, so theire are no subdirectories to read + # There is no key, return return() endif() - if(external_subdirs_count GREATER 0) - math(EXPR external_subdir_range "${external_subdirs_count}-1") - foreach(external_subdir_index RANGE ${external_subdir_range}) - string(JSON external_subdir ERROR_VARIABLE manifest_json_error - GET ${manifest_json_data} "external_subdirectories" "${external_subdir_index}") + if(array_count GREATER 0) + math(EXPR array_range "${array_count}-1") + foreach(array_index RANGE ${array_range}) + string(JSON array_element ERROR_VARIABLE manifest_json_error + GET ${manifest_json_data} ${array_key} "${array_index}") if(manifest_json_error) - message(FATAL_ERROR "Error reading field at index ${external_subdir_index} in \"external_subdirectories\" JSON array: ${manifest_json_error}") + message(FATAL_ERROR "Error reading field at index ${array_index} in \"${array_key}\" JSON array: ${manifest_json_error}") endif() - list(APPEND external_subdirs ${external_subdir}) + list(APPEND array_elements ${array_element}) endforeach() endif() - set(${output_external_subdirs} ${external_subdirs} PARENT_SCOPE) + set(${read_output_array} ${array_elements} PARENT_SCOPE) endfunction() function(o3de_read_json_key output_value input_json_path key) diff --git a/cmake/Platform/Common/Install_common.cmake b/cmake/Platform/Common/Install_common.cmake index 7bf71d7e01..04f0a0ff23 100644 --- a/cmake/Platform/Common/Install_common.cmake +++ b/cmake/Platform/Common/Install_common.cmake @@ -225,14 +225,19 @@ function(ly_setup_cmake_install) ) # Transform the LY_EXTERNAL_SUBDIRS list into a json array - set(LY_INSTALL_EXTERNAL_SUBDIRS "[]") - set(external_subdir_index "0") + set(indent " ") foreach(external_subdir ${LY_EXTERNAL_SUBDIRS}) - math(EXPR external_subdir_index "${external_subdir_index} + 1") file(RELATIVE_PATH engine_rel_external_subdir ${LY_ROOT_FOLDER} ${external_subdir}) - string(JSON LY_INSTALL_EXTERNAL_SUBDIRS ERROR_VARIABLE external_subdir_error SET ${LY_INSTALL_EXTERNAL_SUBDIRS} - ${external_subdir_index} "\"${engine_rel_external_subdir}\"") + list(APPEND relative_external_subdirs "\"${engine_rel_external_subdir}\"") endforeach() + list(JOIN relative_external_subdirs ",\n${indent}" LY_INSTALL_EXTERNAL_SUBDIRS) + + # Read the "templates" key from the source engine.json + o3de_read_json_array(engine_templates ${LY_ROOT_FOLDER}/engine.json "templates") + foreach(template_path ${engine_templates}) + list(APPEND relative_templates "\"${template_path}\"") + endforeach() + list(JOIN relative_templates ",\n${indent}" LY_INSTALL_TEMPLATES) configure_file(${LY_ROOT_FOLDER}/cmake/install/engine.json.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/engine.json @ONLY) diff --git a/cmake/install/engine.json.in b/cmake/install/engine.json.in index 1cfb1826ce..ce2e1be25c 100644 --- a/cmake/install/engine.json.in +++ b/cmake/install/engine.json.in @@ -5,7 +5,7 @@ "O3DEVersion": "@LY_VERSION_STRING@", "O3DECopyrightYear": @LY_VERSION_COPYRIGHT_YEAR@, "O3DEBuildNumber": @LY_VERSION_BUILD_NUMBER@, - "external_subdirectories": @LY_INSTALL_EXTERNAL_SUBDIRS@, + "external_subdirectories": [@LY_INSTALL_EXTERNAL_SUBDIRS@], "projects": [@LY_INSTALL_PROJECTS@], "templates": [@LY_INSTALL_TEMPLATES@] }