From b44ce82435b7f737bca73bcf25e553d6c7b23f27 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Fri, 12 Nov 2021 08:40:56 -0800 Subject: [PATCH] Private dependencies are not propagated to other targets in generated install layout (#5581) * transfering private dependencies as runtime dependencies for the generated targets in the install layout Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> * Update cmake/Platform/Common/Install_common.cmake Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Update cmake/Platform/Common/Install_common.cmake Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> --- cmake/Platform/Common/Install_common.cmake | 30 +++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/cmake/Platform/Common/Install_common.cmake b/cmake/Platform/Common/Install_common.cmake index f22f4c43c9..f844b1bec9 100644 --- a/cmake/Platform/Common/Install_common.cmake +++ b/cmake/Platform/Common/Install_common.cmake @@ -167,18 +167,16 @@ function(ly_setup_target OUTPUT_CONFIGURED_TARGET ALIAS_TARGET_NAME absolute_tar endforeach() list(JOIN INCLUDE_DIRECTORIES_PLACEHOLDER "\n" INCLUDE_DIRECTORIES_PLACEHOLDER) - string(REPEAT " " 8 PLACEHOLDER_INDENT) - get_target_property(RUNTIME_DEPENDENCIES_PLACEHOLDER ${TARGET_NAME} MANUALLY_ADDED_DEPENDENCIES) - if(RUNTIME_DEPENDENCIES_PLACEHOLDER) # not found properties return the name of the variable with a "-NOTFOUND" at the end, here we set it to empty if not found - set(RUNTIME_DEPENDENCIES_PLACEHOLDER "${PLACEHOLDER_INDENT}${RUNTIME_DEPENDENCIES_PLACEHOLDER}") - list(JOIN RUNTIME_DEPENDENCIES_PLACEHOLDER "\n${PLACEHOLDER_INDENT}" RUNTIME_DEPENDENCIES_PLACEHOLDER) - else() - unset(RUNTIME_DEPENDENCIES_PLACEHOLDER) - endif() - string(REPEAT " " 12 PLACEHOLDER_INDENT) get_property(interface_build_dependencies_props TARGET ${TARGET_NAME} PROPERTY LY_DELAYED_LINK) unset(INTERFACE_BUILD_DEPENDENCIES_PLACEHOLDER) + # We can have private build dependencies that contains direct or indirect runtime dependencies. + # Since imported targets cannot contain build dependencies, we need another way to propagate the runtime dependencies. + # We dont want to put such dependencies in the interface because a user can mistakenly use a symbol that is not available + # when using the engine from source (and that the author of the target didn't want to set public). + # To overcome this, we will actually expose the private build dependencies as runtime dependencies. Our runtime dependency + # algorithm will walk recursively also through static libraries and will only copy binaries to the output. + unset(RUNTIME_DEPENDENCIES_PLACEHOLDER) if(interface_build_dependencies_props) cmake_parse_arguments(build_deps "" "" "PRIVATE;PUBLIC;INTERFACE" ${interface_build_dependencies_props}) # Interface and public dependencies should always be exposed @@ -191,6 +189,8 @@ function(ly_setup_target OUTPUT_CONFIGURED_TARGET ALIAS_TARGET_NAME absolute_tar if("${target_type}" STREQUAL "STATIC_LIBRARY") set(build_deps_target "${build_deps_target};${build_deps_PRIVATE}") endif() + # But we will also pass the private dependencies as runtime dependencies (note the comment above) + set(RUNTIME_DEPENDENCIES_PLACEHOLDER ${build_deps_PRIVATE}) foreach(build_dependency IN LISTS build_deps_target) # Skip wrapping produced when targets are not created in the same directory if(build_dependency) @@ -200,6 +200,18 @@ function(ly_setup_target OUTPUT_CONFIGURED_TARGET ALIAS_TARGET_NAME absolute_tar endif() list(JOIN INTERFACE_BUILD_DEPENDENCIES_PLACEHOLDER "\n" INTERFACE_BUILD_DEPENDENCIES_PLACEHOLDER) + string(REPEAT " " 8 PLACEHOLDER_INDENT) + get_target_property(manually_added_dependencies ${TARGET_NAME} MANUALLY_ADDED_DEPENDENCIES) + 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 + list(APPEND RUNTIME_DEPENDENCIES_PLACEHOLDER ${manually_added_dependencies}) + endif() + if(RUNTIME_DEPENDENCIES_PLACEHOLDER) + set(RUNTIME_DEPENDENCIES_PLACEHOLDER "${PLACEHOLDER_INDENT}${RUNTIME_DEPENDENCIES_PLACEHOLDER}") + list(JOIN RUNTIME_DEPENDENCIES_PLACEHOLDER "\n${PLACEHOLDER_INDENT}" RUNTIME_DEPENDENCIES_PLACEHOLDER) + else() + unset(RUNTIME_DEPENDENCIES_PLACEHOLDER) + endif() + string(REPEAT " " 8 PLACEHOLDER_INDENT) # If a target has an LY_PROJECT_NAME property, forward that property to new target get_target_property(target_project_association ${TARGET_NAME} LY_PROJECT_NAME)