From 5b8e759c2d29e2d75e343d79d8134f6d8c3e8c4b Mon Sep 17 00:00:00 2001 From: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> Date: Wed, 26 May 2021 23:59:49 -0500 Subject: [PATCH] Implemented changes in the ly_setup_target() command to forward the ly_create_alias() command calls to the configured CMakeLists.txt per installed target --- cmake/Gems.cmake | 15 +++++++++++++-- cmake/Platform/Common/Install_common.cmake | 19 +++++++++++++++++++ cmake/cmake_files.cmake | 1 + cmake/install/TargetCMakeLists.txt.in | 1 + 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/cmake/Gems.cmake b/cmake/Gems.cmake index caa5b74c93..a90cf09639 100644 --- a/cmake/Gems.cmake +++ b/cmake/Gems.cmake @@ -47,6 +47,10 @@ function(ly_create_alias) if (NOT TARGET ${ly_create_alias_NAME}) add_library(${ly_create_alias_NAME} ALIAS ${de_aliased_target_name}) endif() + # Store off the arguments needed used ly_create_alias into a DIRECTORY property + # This will be used to re-create the calls in the generated CMakeLists.txt in the INSTALL step + string(REPLACE ";" " " create_alias_args "${ly_create_alias_NAME},${ly_create_alias_NAMESPACE},${ly_create_alias_TARGETS}") + set_property(DIRECTORY APPEND PROPERTY LY_CREATE_ALIAS_ARGUMENTS "${ly_create_alias_NAME},${ly_create_alias_NAMESPACE},${ly_create_alias_TARGETS}") return() endif() @@ -75,6 +79,13 @@ function(ly_create_alias) # now add the final alias: add_library(${ly_create_alias_NAMESPACE}::${ly_create_alias_NAME} ALIAS ${ly_create_alias_NAME}) + + # Store off the arguments needed used ly_create_alias into a DIRECTORY property + # This will be used to re-create the calls in the generated CMakeLists.txt in the INSTALL step + + # Replace the CMake list separator with a space to replicate the space separated TARGETS arguments + string(REPLACE ";" " " create_alias_args "${ly_create_alias_NAME},${ly_create_alias_NAMESPACE},${ly_create_alias_TARGETS}") + set_property(DIRECTORY APPEND PROPERTY LY_CREATE_ALIAS_ARGUMENTS "${create_alias_args}") endfunction() # ly_enable_gems @@ -143,7 +154,7 @@ endfunction() function(ly_enable_gems_delayed) get_property(ly_delayed_enable_gems GLOBAL PROPERTY LY_DELAYED_ENABLE_GEMS) foreach(project_target_variant ${ly_delayed_enable_gems}) - # we expect a colon seperated list of + # we expect a colon separated list of # PROJECT_NAME,target_name,variant_name string(REPLACE "," ";" project_target_variant_list "${project_target_variant}") list(LENGTH project_target_variant_list project_target_variant_length) @@ -152,7 +163,7 @@ function(ly_enable_gems_delayed) endif() if(NOT project_target_variant_length EQUAL 3) - message(FATAL_ERROR "Invalid specificaiton of gems, expected 'project','target','variant' and got ${project_target_variant}") + message(FATAL_ERROR "Invalid specification of gems, expected 'project','target','variant' and got ${project_target_variant}") endif() list(POP_BACK project_target_variant_list variant) diff --git a/cmake/Platform/Common/Install_common.cmake b/cmake/Platform/Common/Install_common.cmake index 04f0a0ff23..27b8d83a9c 100644 --- a/cmake/Platform/Common/Install_common.cmake +++ b/cmake/Platform/Common/Install_common.cmake @@ -155,6 +155,25 @@ function(ly_setup_target ALIAS_TARGET_NAME) list(REMOVE_DUPLICATES INTERFACE_BUILD_DEPENDENCIES_PLACEHOLDER) string(REPLACE ";" "\n" INTERFACE_BUILD_DEPENDENCIES_PLACEHOLDER "${INTERFACE_BUILD_DEPENDENCIES_PLACEHOLDER}") + # Replicate the ly_create_alias() calls based on the SOURCE_DIR for each target that generates an installed CMakeLists.txt + string(JOIN "\n" create_alias_template + "if(NOT TARGET @ALIAS_NAME@)" + " ly_create_alias(NAME @ALIAS_NAME@ NAMESPACE @ALIAS_NAMESPACE@ TARGETS @ALIAS_TARGETS@)" + "endif()" + "" + ) + get_property(create_alias_commands_arg_list DIRECTORY ${absolute_target_source_dir} PROPERTY LY_CREATE_ALIAS_ARGUMENTS) + foreach(create_alias_single_command_arg_list ${create_alias_commands_arg_list}) + # Split the ly_create_alias arguments back out based on commas + string(REPLACE "," ";" create_alias_single_command_arg_list "${create_alias_single_command_arg_list}") + list(POP_FRONT create_alias_single_command_arg_list ALIAS_NAME) + list(POP_FRONT create_alias_single_command_arg_list ALIAS_NAMESPACE) + # The rest of the list are the target dependencies + set(ALIAS_TARGETS ${create_alias_single_command_arg_list}) + string(CONFIGURE "${create_alias_template}" create_alias_command @ONLY) + string(APPEND CREATE_ALIASES_PLACEHOLDER ${create_alias_command}) + endforeach() + # Since a CMakeLists.txt could contain multiple targets, we generate it in a folder per target configure_file(${LY_ROOT_FOLDER}/cmake/install/TargetCMakeLists.txt.in ${CMAKE_CURRENT_BINARY_DIR}/install/${NAME_PLACEHOLDER}/CMakeLists.txt @ONLY) diff --git a/cmake/cmake_files.cmake b/cmake/cmake_files.cmake index b42d29c9c2..a1fd66a06d 100644 --- a/cmake/cmake_files.cmake +++ b/cmake/cmake_files.cmake @@ -20,6 +20,7 @@ set(FILES EngineJson.cmake FileUtil.cmake Findo3de.cmake + Gems.cmake GeneralSettings.cmake Install.cmake LyAutoGen.cmake diff --git a/cmake/install/TargetCMakeLists.txt.in b/cmake/install/TargetCMakeLists.txt.in index b2c8b9b6f6..06cd022898 100644 --- a/cmake/install/TargetCMakeLists.txt.in +++ b/cmake/install/TargetCMakeLists.txt.in @@ -27,6 +27,7 @@ ly_add_target( @RUNTIME_DEPENDENCIES_PLACEHOLDER@ ) +@CREATE_ALIASES_PLACEHOLDER@ set(configs @CMAKE_CONFIGURATION_TYPES@) foreach(config ${configs}) include("@NAME_PLACEHOLDER@_${config}.cmake" OPTIONAL)