diff --git a/AutomatedTesting/EngineFinder.cmake b/AutomatedTesting/EngineFinder.cmake index fbbe3d8cfe..eef3aa3cae 100644 --- a/AutomatedTesting/EngineFinder.cmake +++ b/AutomatedTesting/EngineFinder.cmake @@ -15,6 +15,8 @@ include_guard() # Read the engine name from the project_json file file(READ ${CMAKE_CURRENT_LIST_DIR}/project.json project_json) +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/project.json) + string(JSON LY_ENGINE_NAME_TO_USE ERROR_VARIABLE json_error GET ${project_json} engine) if(json_error) message(FATAL_ERROR "Unable to read key 'engine' from 'project.json', error: ${json_error}") @@ -30,6 +32,7 @@ endif() # Find a key that matches LY_ENGINE_NAME_TO_USE and use that as the engine path. if(EXISTS ${manifest_path}) file(READ ${manifest_path} manifest_json) + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${manifest_path}) string(JSON engines_path_count ERROR_VARIABLE json_error LENGTH ${manifest_json} engines_path) if(json_error) diff --git a/Code/LauncherUnified/launcher_generator.cmake b/Code/LauncherUnified/launcher_generator.cmake index 5fa0f7a0e3..2180aff7d8 100644 --- a/Code/LauncherUnified/launcher_generator.cmake +++ b/Code/LauncherUnified/launcher_generator.cmake @@ -26,7 +26,7 @@ foreach(project_name project_path IN ZIP_LISTS LY_PROJECTS_TARGET_NAME LY_PROJEC message(FATAL_ERROR "The specified project path of ${project_real_path} does not contain a project.json file") else() # Add the project_name to global LY_PROJECTS_TARGET_NAME property - file(READ "${project_real_path}/project.json" project_json) + ly_file_read("${project_real_path}/project.json" project_json) string(JSON project_name ERROR_VARIABLE json_error GET ${project_json} "project_name") if(json_error) message(FATAL_ERROR "There is an error reading the \"project_name\" key from the '${project_real_path}/project.json' file: ${json_error}") diff --git a/Templates/DefaultProject/Template/EngineFinder.cmake b/Templates/DefaultProject/Template/EngineFinder.cmake index cac0f6215c..f058f6e037 100644 --- a/Templates/DefaultProject/Template/EngineFinder.cmake +++ b/Templates/DefaultProject/Template/EngineFinder.cmake @@ -17,6 +17,8 @@ include_guard() # Read the engine name from the project_json file file(READ ${CMAKE_CURRENT_LIST_DIR}/project.json project_json) +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/project.json) + string(JSON LY_ENGINE_NAME_TO_USE ERROR_VARIABLE json_error GET ${project_json} engine) if(json_error) message(FATAL_ERROR "Unable to read key 'engine' from 'project.json', error: ${json_error}") @@ -32,6 +34,7 @@ endif() # Find a key that matches LY_ENGINE_NAME_TO_USE and use that as the engine path. if(EXISTS ${manifest_path}) file(READ ${manifest_path} manifest_json) + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${manifest_path}) string(JSON engines_path_count ERROR_VARIABLE json_error LENGTH ${manifest_json} engines_path) if(json_error) diff --git a/Templates/MinimalProject/Template/EngineFinder.cmake b/Templates/MinimalProject/Template/EngineFinder.cmake index cac0f6215c..f058f6e037 100644 --- a/Templates/MinimalProject/Template/EngineFinder.cmake +++ b/Templates/MinimalProject/Template/EngineFinder.cmake @@ -17,6 +17,8 @@ include_guard() # Read the engine name from the project_json file file(READ ${CMAKE_CURRENT_LIST_DIR}/project.json project_json) +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/project.json) + string(JSON LY_ENGINE_NAME_TO_USE ERROR_VARIABLE json_error GET ${project_json} engine) if(json_error) message(FATAL_ERROR "Unable to read key 'engine' from 'project.json', error: ${json_error}") @@ -32,6 +34,7 @@ endif() # Find a key that matches LY_ENGINE_NAME_TO_USE and use that as the engine path. if(EXISTS ${manifest_path}) file(READ ${manifest_path} manifest_json) + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${manifest_path}) string(JSON engines_path_count ERROR_VARIABLE json_error LENGTH ${manifest_json} engines_path) if(json_error) diff --git a/cmake/EngineJson.cmake b/cmake/EngineJson.cmake index c3ab29d09e..7922cd1a1b 100644 --- a/cmake/EngineJson.cmake +++ b/cmake/EngineJson.cmake @@ -22,7 +22,7 @@ set(LY_EXTERNAL_SUBDIRS "" CACHE STRING "List of subdirectories to recurse into # Restricted folders(contains an additional restricted.json), etc... # \arg:output_external_subdirs name of output variable to store external subdirectories into function(read_engine_external_subdirs output_external_subdirs) - file(READ ${LY_ROOT_FOLDER}/engine.json engine_json_data) + ly_file_read(${LY_ROOT_FOLDER}/engine.json engine_json_data) string(JSON external_subdirs_count ERROR_VARIABLE engine_json_error LENGTH ${engine_json_data} "external_subdirectories") if(engine_json_error) diff --git a/cmake/FileUtil.cmake b/cmake/FileUtil.cmake index 96923537ed..e530fe133c 100644 --- a/cmake/FileUtil.cmake +++ b/cmake/FileUtil.cmake @@ -118,4 +118,13 @@ override_pak_root=${LY_OVERRIDE_PAK_FOLDER_ROOT} endfunction() - +#! ly_file_read: wrap to file(READ) that adds the file to configuration tracking +# +# file(READ) does not add file tracking. So changes to the file being read will not cause a cmake regeneration +# +function(ly_file_read path content) + unset(file_content) + file(READ ${path} file_content) + set(${content} ${file_content} PARENT_SCOPE) + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${path}) +endfunction() diff --git a/cmake/Findo3de.cmake b/cmake/Findo3de.cmake index 0b4d0b75e7..f9eedf686c 100644 --- a/cmake/Findo3de.cmake +++ b/cmake/Findo3de.cmake @@ -22,6 +22,8 @@ o3de_current_file_path(current_path) # Make sure we are matching LY_ENGINE_NAME_TO_USE with the current engine file(READ ${current_path}/../engine.json engine_json) +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${current_path}/../engine.json) + string(JSON this_engine_name ERROR_VARIABLE json_error GET ${engine_json} engine_name) if(json_error) message(FATAL_ERROR "Unable to read key 'engine_name' from '${current_path}/../engine.json', error: ${json_error}") diff --git a/cmake/O3DEJson.cmake b/cmake/O3DEJson.cmake index ab5f95bc8c..500bd9a78c 100644 --- a/cmake/O3DEJson.cmake +++ b/cmake/O3DEJson.cmake @@ -30,7 +30,7 @@ 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) + ly_file_read(${input_json_path} manifest_json_data) string(JSON array_count ERROR_VARIABLE manifest_json_error LENGTH ${manifest_json_data} ${array_key}) if(manifest_json_error) @@ -53,7 +53,7 @@ function(o3de_read_json_array read_output_array input_json_path array_key) endfunction() function(o3de_read_json_key output_value input_json_path key) - file(READ ${input_json_path} manifest_json_data) + ly_file_read(${input_json_path} manifest_json_data) string(JSON value ERROR_VARIABLE manifest_json_error GET ${manifest_json_data} ${key}) if(manifest_json_error) message(FATAL_ERROR "Error reading field at key ${key} in file \"${input_json_path}\" : ${manifest_json_error}") diff --git a/cmake/PAL.cmake b/cmake/PAL.cmake index dca54e4731..4fe729f85a 100644 --- a/cmake/PAL.cmake +++ b/cmake/PAL.cmake @@ -30,7 +30,7 @@ endforeach() # \arg:restricted returns the restricted association element from an o3de json, otherwise engine 'o3de' is assumed # \arg:o3de_json_file name of the o3de json file function(o3de_restricted_id o3de_json_file restricted) - file(READ ${o3de_json_file} json_data) + ly_file_read(${o3de_json_file} json_data) string(JSON restricted_entry ERROR_VARIABLE json_error GET ${json_data} "restricted_name") if(json_error) message(WARNING "Unable to read restricted from '${o3de_json_file}', error: ${json_error}") @@ -46,7 +46,7 @@ endfunction() # \arg:restricted_name name of the restricted function(o3de_find_restricted_folder restricted_name restricted_path) # Read the restricted path from engine.json if one EXISTS - file(READ ${LY_ROOT_FOLDER}/engine.json engine_json_data) + ly_file_read(${LY_ROOT_FOLDER}/engine.json engine_json_data) string(JSON restricted_subdirs_count ERROR_VARIABLE engine_json_error LENGTH ${engine_json_data} "restricted") if(restricted_subdirs_count GREATER 0) string(JSON restricted_subdir ERROR_VARIABLE engine_json_error GET ${engine_json_data} "restricted" "0") @@ -66,7 +66,7 @@ function(o3de_find_restricted_folder restricted_name restricted_path) # Examine the o3de manifest file for the list of restricted directories set(o3de_manifest_path ${home_directory}/.o3de/o3de_manifest.json) if(EXISTS ${o3de_manifest_path}) - file(READ ${o3de_manifest_path} o3de_manifest_json_data) + ly_file_read(${o3de_manifest_path} o3de_manifest_json_data) string(JSON restricted_subdirs_count ERROR_VARIABLE engine_json_error LENGTH ${o3de_manifest_json_data} "restricted") if(restricted_subdirs_count GREATER 0) math(EXPR restricted_subdirs_range "${restricted_subdirs_count}-1") @@ -79,7 +79,7 @@ function(o3de_find_restricted_folder restricted_name restricted_path) # Iterate over the restricted directories from the manifest file foreach(restricted_entry ${restricted_subdirs}) set(restricted_json_file ${restricted_entry}/restricted.json) - file(READ ${restricted_json_file} restricted_json) + ly_file_read(${restricted_json_file} restricted_json) string(JSON this_restricted_name ERROR_VARIABLE json_error GET ${restricted_json} "restricted_name") if(json_error) message(WARNING "Unable to read restricted_name from '${restricted_json_file}', error: ${json_error}") diff --git a/cmake/Platform/Common/Install_common.cmake b/cmake/Platform/Common/Install_common.cmake index 0948cf68dd..edce52288f 100644 --- a/cmake/Platform/Common/Install_common.cmake +++ b/cmake/Platform/Common/Install_common.cmake @@ -240,7 +240,7 @@ set_property(TARGET ${TARGET_NAME} ) # Since a CMakeLists.txt could contain multiple targets, we generate it in a folder per target - file(READ ${LY_ROOT_FOLDER}/cmake/install/InstalledTarget.in target_cmakelists_template) + ly_file_read(${LY_ROOT_FOLDER}/cmake/install/InstalledTarget.in target_cmakelists_template) string(CONFIGURE ${target_cmakelists_template} output_cmakelists_data @ONLY) set(${OUTPUT_CONFIGURED_TARGET} ${output_cmakelists_data} PARENT_SCOPE) endfunction() @@ -317,8 +317,7 @@ function(ly_setup_subdirectory absolute_target_source_dir) string(APPEND ENABLE_GEMS_PLACEHOLDER ${enable_gems_command}) endforeach() - - file(READ ${LY_ROOT_FOLDER}/cmake/install/Copyright.in cmake_copyright_comment) + ly_file_read(${LY_ROOT_FOLDER}/cmake/install/Copyright.in cmake_copyright_comment) # Initialize the target install source directory to path underneath the current binary directory set(target_install_source_dir ${CMAKE_CURRENT_BINARY_DIR}/install/${relative_target_source_dir}) diff --git a/cmake/TestImpactFramework/LYTestImpactFramework.cmake b/cmake/TestImpactFramework/LYTestImpactFramework.cmake index d46b16bca5..8a088bddab 100644 --- a/cmake/TestImpactFramework/LYTestImpactFramework.cmake +++ b/cmake/TestImpactFramework/LYTestImpactFramework.cmake @@ -334,7 +334,7 @@ function(ly_test_impact_write_config_file CONFIG_TEMPLATE_FILE PERSISTENT_DATA_D ) # Substitute config file template with above vars - file(READ "${CONFIG_TEMPLATE_FILE}" config_file) + ly_file_read("${CONFIG_TEMPLATE_FILE}" config_file) string(CONFIGURE ${config_file} config_file) # Write out entire config contents to a file in the build directory of the test impact framework console target