From 671f26bed4f722c8e81dbfb6930455946ab4f50b Mon Sep 17 00:00:00 2001 From: pappeste Date: Tue, 11 May 2021 19:06:07 -0700 Subject: [PATCH] fixing debug configuration and how we declare IMPORTED targets (instead of UNKNOW we use the actual type) --- cmake/LYWrappers.cmake | 26 +++++------ cmake/Platform/Common/Install_common.cmake | 46 +++++++++++-------- .../Common/RuntimeDependencies_common.cmake | 8 +++- cmake/install/TargetCMakeLists.txt.in | 2 +- 4 files changed, 46 insertions(+), 36 deletions(-) diff --git a/cmake/LYWrappers.cmake b/cmake/LYWrappers.cmake index fcf205238c..bddd1a6c66 100644 --- a/cmake/LYWrappers.cmake +++ b/cmake/LYWrappers.cmake @@ -87,8 +87,8 @@ function(ly_add_target) endif() if(NOT ly_add_target_IMPORTED AND NOT ly_add_target_HEADERONLY) if(NOT ly_add_target_FILES_CMAKE) - message(FATAL_ERROR "You must provide a list of _files.cmake files for the target") - endif() + message(FATAL_ERROR "You must provide a list of _files.cmake files for the target") + endif() endif() # If the GEM_MODULE tag is passed set the normal MODULE argument @@ -114,11 +114,10 @@ function(ly_add_target) set(linking_options ${PAL_LINKOPTION_MODULE}) set(linking_count "${linking_count}1") endif() - if(ly_add_target_HEADERONLY) set(linking_options INTERFACE) set(linking_count "${linking_count}1") - endif() + endif() if(ly_add_target_EXECUTABLE) set(linking_options EXECUTABLE) set(linking_count "${linking_count}1") @@ -127,12 +126,11 @@ function(ly_add_target) set(linking_options APPLICATION) set(linking_count "${linking_count}1") endif() - if(ly_add_target_IMPORTED) - set(linking_options UNKNOWN IMPORTED GLOBAL) - set(linking_count "${linking_count}1") - endif() if(NOT ("${linking_count}" STREQUAL "1")) - message(FATAL_ERROR "More than one of the following options [STATIC | SHARED | MODULE | HEADERONLY | EXECUTABLE | APPLICATION | IMPORTED] was specified and they are mutually exclusive") + message(FATAL_ERROR "More than one of the following options [STATIC | SHARED | MODULE | HEADERONLY | EXECUTABLE | APPLICATION ] was specified and they are mutually exclusive") + endif() + if(ly_add_target_IMPORTED) + list(APPEND linking_options IMPORTED GLOBAL) endif() if(ly_add_target_NAMESPACE) @@ -147,21 +145,23 @@ function(ly_add_target) ${ALLFILES} ${ly_add_target_GENERATED_FILES} ) ly_apply_platform_properties(${ly_add_target_NAME}) + if(ly_add_target_IMPORTED) + set_target_properties(${ly_add_target_NAME} PROPERTIES LINKER_LANGUAGE CXX) + endif() elseif(ly_add_target_APPLICATION) add_executable(${ly_add_target_NAME} ${PAL_EXECUTABLE_APPLICATION_FLAG} ${ALLFILES} ${ly_add_target_GENERATED_FILES} ) ly_apply_platform_properties(${ly_add_target_NAME}) + if(ly_add_target_IMPORTED) + set_target_properties(${ly_add_target_NAME} PROPERTIES LINKER_LANGUAGE CXX) + endif() elseif(ly_add_target_HEADERONLY) add_library(${ly_add_target_NAME} ${linking_options} ${ALLFILES} ${ly_add_target_GENERATED_FILES} ) - elseif(ly_add_target_IMPORTED) - add_library(${ly_add_target_NAME} - ${linking_options} - ) else() add_library(${ly_add_target_NAME} ${linking_options} diff --git a/cmake/Platform/Common/Install_common.cmake b/cmake/Platform/Common/Install_common.cmake index 0642e24690..64fc973701 100644 --- a/cmake/Platform/Common/Install_common.cmake +++ b/cmake/Platform/Common/Install_common.cmake @@ -94,10 +94,17 @@ function(ly_setup_target ALIAS_TARGET_NAME) set(NAME_PLACEHOLDER ${TARGET_NAME}) endif() - set(TARGET_TYPE_PLACEHOLDER "IMPORTED") + set(TARGET_TYPE_PLACEHOLDER "") get_target_property(target_type ${NAME_PLACEHOLDER} TYPE) - if(target_type STREQUAL INTERFACE_LIBRARY) - set(TARGET_TYPE_PLACEHOLDER "HEADERONLY") + # Remove the _LIBRARY since we dont need to pass that to ly_add_targets + string(REPLACE "_LIBRARY" "" TARGET_TYPE_PLACEHOLDER ${target_type}) + # For HEADER_ONLY libs we end up generating "INTERFACE" libraries, need to specify HEADERONLY instead + string(REPLACE "INTERFACE" "HEADERONLY" TARGET_TYPE_PLACEHOLDER ${TARGET_TYPE_PLACEHOLDER}) + if(TARGET_TYPE_PLACEHOLDER STREQUAL "MODULE") + get_target_property(gem_module ${NAME_PLACEHOLDER} GEM_MODULE) + if(gem_module) + set(TARGET_TYPE_PLACEHOLDER "GEM_MODULE") + endif() endif() get_target_property(COMPILE_DEFINITIONS_PLACEHOLDER ${TARGET_NAME} INTERFACE_COMPILE_DEFINITIONS) @@ -155,7 +162,7 @@ function(ly_setup_target ALIAS_TARGET_NAME) DESTINATION ${target_source_dir}/${NAME_PLACEHOLDER} COMPONENT ${ly_install_target_COMPONENT} ) - + # Config file set(target_file_contents "# Generated by O3DE install\n\n") if(NOT target_type STREQUAL INTERFACE_LIBRARY) @@ -163,29 +170,28 @@ function(ly_setup_target ALIAS_TARGET_NAME) unset(target_location) set(runtime_types EXECUTABLE APPLICATION) if(target_type IN_LIST runtime_types) - string(APPEND target_location "\"\${LY_ROOT_FOLDER}/${runtime_output_directory}/${PAL_PLATFORM_NAME}/$/${target_runtime_output_subdirectory}/$\"") + set(target_location "\${LY_ROOT_FOLDER}/${runtime_output_directory}/${PAL_PLATFORM_NAME}/$/${target_runtime_output_subdirectory}/$") elseif(target_type STREQUAL MODULE_LIBRARY) - string(APPEND target_location "\"\${LY_ROOT_FOLDER}/${library_output_directory}/${PAL_PLATFORM_NAME}/$/${target_library_output_subdirectory}/$\"") + set(target_location "\${LY_ROOT_FOLDER}/${library_output_directory}/${PAL_PLATFORM_NAME}/$/${target_library_output_subdirectory}/$") elseif(target_type STREQUAL SHARED_LIBRARY) - string(APPEND target_location "\"\${LY_ROOT_FOLDER}/${archive_output_directory}/${PAL_PLATFORM_NAME}/$/$\"") - string(APPEND target_file_contents "target_link_libraries(${TARGET_NAME} INTERFACE \"\${LY_ROOT_FOLDER}/${library_output_directory}/${PAL_PLATFORM_NAME}/$/${target_library_output_subdirectory}/$\")\n") + string(APPEND target_file_contents "set_property(TARGET ${TARGET_NAME} PROPERTY IMPORTED_IMPLIB_$ \"\${LY_ROOT_FOLDER}/${archive_output_directory}/${PAL_PLATFORM_NAME}/$/$\")\n") + set(target_location "\${LY_ROOT_FOLDER}/${library_output_directory}/${PAL_PLATFORM_NAME}/$/${target_library_output_subdirectory}/$") else() # STATIC_LIBRARY, OBJECT_LIBRARY, INTERFACE_LIBRARY - string(APPEND target_location "\"\${LY_ROOT_FOLDER}/${archive_output_directory}/${PAL_PLATFORM_NAME}/$/$\"") + set(target_location "\${LY_ROOT_FOLDER}/${archive_output_directory}/${PAL_PLATFORM_NAME}/$/$") endif() - string(APPEND target_file_contents -"set(target_location ${target_location}) -set_target_properties(${TARGET_NAME} - PROPERTIES - $<$:IMPORTED_LOCATION \"\${target_location}\"> - IMPORTED_LOCATION_$> \"\${target_location}\" + if(target_location) + string(APPEND target_file_contents +"set_property(TARGET ${TARGET_NAME} + APPEND_STRING PROPERTY IMPORTED_LOCATION + $<$$:${target_location}$ +) +set_property(TARGET ${TARGET_NAME} + PROPERTY IMPORTED_LOCATION_$> + ${target_location} ) -if(EXISTS \"\${target_location}\") - set(${NAME_PLACEHOLDER}_$_FOUND TRUE) -else() - set(${NAME_PLACEHOLDER}_$_FOUND FALSE) -endif() ") + endif() endif() file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/install/${NAME_PLACEHOLDER}/${NAME_PLACEHOLDER}_$.cmake" CONTENT "${target_file_contents}") diff --git a/cmake/Platform/Common/RuntimeDependencies_common.cmake b/cmake/Platform/Common/RuntimeDependencies_common.cmake index 333bbaaae2..d9d0fe4c7f 100644 --- a/cmake/Platform/Common/RuntimeDependencies_common.cmake +++ b/cmake/Platform/Common/RuntimeDependencies_common.cmake @@ -61,7 +61,7 @@ function(ly_get_runtime_dependencies ly_RUNTIME_DEPENDENCIES ly_TARGET) if(dependencies) list(APPEND link_dependencies ${dependencies}) endif() - if(NOT target_type MATCHES "INTERFACE") + if(NOT target_type STREQUAL "INTERFACE_LIBRARY") unset(dependencies) get_target_property(dependencies ${ly_TARGET} LINK_LIBRARIES) if(dependencies) @@ -105,11 +105,15 @@ function(ly_get_runtime_dependencies ly_RUNTIME_DEPENDENCIES ly_TARGET) set(skip_imported TRUE) endif() endif() + if(target_type MATCHES "(INTERFACE_LIBRARY|STATIC_LIBRARY)") + # No need to copy these dependencies since the outputs are not used at runtime + set(skip_imported TRUE) + endif() if(NOT skip_imported) # Add imported locations - if(target_type MATCHES "INTERFACE") + if(target_type STREQUAL "INTERFACE_LIBRARY") set(imported_property INTERFACE_IMPORTED_LOCATION) else() set(imported_property IMPORTED_LOCATION) diff --git a/cmake/install/TargetCMakeLists.txt.in b/cmake/install/TargetCMakeLists.txt.in index dd6fddcc9b..b2c8b9b6f6 100644 --- a/cmake/install/TargetCMakeLists.txt.in +++ b/cmake/install/TargetCMakeLists.txt.in @@ -12,7 +12,7 @@ # Generated by O3DE ly_add_target( - NAME @NAME_PLACEHOLDER@ @TARGET_TYPE_PLACEHOLDER@ + NAME @NAME_PLACEHOLDER@ IMPORTED @TARGET_TYPE_PLACEHOLDER@ @NAMESPACE_PLACEHOLDER@ COMPILE_DEFINITIONS INTERFACE