From 660885e8696ccda4f3b1b98425d8b2553c395db9 Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 22 Jul 2022 14:07:22 +1000 Subject: [PATCH 01/11] Add library ALIAS --- SwiftTargets.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SwiftTargets.cmake b/SwiftTargets.cmake index 4d4a1b9..4b651c5 100644 --- a/SwiftTargets.cmake +++ b/SwiftTargets.cmake @@ -316,6 +316,10 @@ function(swift_add_target target type) message(FATAL_ERROR "Unknown Swift target type ${type}") endif() + if((type STREQUAL "library") OR (type STREQUAL "test_library") OR (type STREQUAL "tool_library")) + add_library(swift::${target} ALIAS ${target}) + endif() + # # This edge case is needed for cmake version < 3.19.0 where INTERFACE # classes cannot contain any property other than those prefixed with From fbcae0df9b5820a14770d068362427c7cd971c01 Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 22 Jul 2022 15:20:28 +1000 Subject: [PATCH 02/11] Fix namespace setup --- SwiftTargets.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SwiftTargets.cmake b/SwiftTargets.cmake index 4b651c5..5f31d00 100644 --- a/SwiftTargets.cmake +++ b/SwiftTargets.cmake @@ -316,8 +316,9 @@ function(swift_add_target target type) message(FATAL_ERROR "Unknown Swift target type ${type}") endif() + set(project_alias "swift") if((type STREQUAL "library") OR (type STREQUAL "test_library") OR (type STREQUAL "tool_library")) - add_library(swift::${target} ALIAS ${target}) + add_library(${project_alias}::${target} ALIAS ${target}) endif() # From 37dedc4b449cf2a3989b7d4fcb83070a9110ba86 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 25 Jul 2022 10:02:18 +1000 Subject: [PATCH 03/11] Update namespace + set cache --- SwiftTargets.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SwiftTargets.cmake b/SwiftTargets.cmake index 5f31d00..b7cde62 100644 --- a/SwiftTargets.cmake +++ b/SwiftTargets.cmake @@ -184,6 +184,8 @@ define_property(TARGET BRIEF_DOCS "Target's source directory" FULL_DOCS "Identical use as SOURCE_DIR except that this applies to ALL target types, including INTERFACE") +set(project_alias "swiftnav" CACHE STRING "Alias for project") + macro(swift_collate_arguments prefix name) set(exclusion_list ${ARGN}) set(${name}_args "") @@ -316,7 +318,6 @@ function(swift_add_target target type) message(FATAL_ERROR "Unknown Swift target type ${type}") endif() - set(project_alias "swift") if((type STREQUAL "library") OR (type STREQUAL "test_library") OR (type STREQUAL "tool_library")) add_library(${project_alias}::${target} ALIAS ${target}) endif() From 8ab1350630d6515db59b1bbf85a7e3c064bf499d Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 25 Jul 2022 20:11:58 +1000 Subject: [PATCH 04/11] Add condition check to force the call of alias --- SwiftTargets.cmake | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/SwiftTargets.cmake b/SwiftTargets.cmake index b7cde62..37689db 100644 --- a/SwiftTargets.cmake +++ b/SwiftTargets.cmake @@ -386,4 +386,19 @@ function(swift_validate_targets) message(FATAL_ERROR "Can't identify type of target ${target}, was it added with the correct Swift function (swift_add_*)?") endif() endforeach() + + swift_list_compilable_targets(all_targets ONLY_THIS_REPO SWIFT_TYPES "executable" "library" "tool_library" "test_library" "test") + foreach(target ${all_targets}) + get_target_property(target_dependencies ${target} LINK_LIBRARIES) + foreach(target_dependency ${target_dependencies}) + if (TARGET ${target_dependency}) + get_target_property(swift_type ${target_dependency} SWIFT_TYPE) + get_target_property(swift_alias ${target_dependency} ALIASED_TARGET) + if(swift_type AND (NOT swift_alias)) + message(WARNING "Using target \"${target_dependency}\" as \"${target}\" dependency. Please use alias \"${project_alias}::${target_dependency}\" instead.") + endif() + endif() + endforeach() + endforeach() + endfunction() From 08e79b1db9882c276f992870000bf50a72f1eff9 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 25 Jul 2022 21:20:57 +1000 Subject: [PATCH 05/11] Fix message to make sense --- SwiftTargets.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftTargets.cmake b/SwiftTargets.cmake index 37689db..e71f9d8 100644 --- a/SwiftTargets.cmake +++ b/SwiftTargets.cmake @@ -395,7 +395,7 @@ function(swift_validate_targets) get_target_property(swift_type ${target_dependency} SWIFT_TYPE) get_target_property(swift_alias ${target_dependency} ALIASED_TARGET) if(swift_type AND (NOT swift_alias)) - message(WARNING "Using target \"${target_dependency}\" as \"${target}\" dependency. Please use alias \"${project_alias}::${target_dependency}\" instead.") + message(WARNING "Calling \"${target_dependency}\" as a dependency of target \"${target}\". Please use alias \"${project_alias}::${target_dependency}\" instead.") endif() endif() endforeach() From 593dff1504e64bc755c52596fb3cb1b245f018e9 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 26 Jul 2022 12:36:59 +1000 Subject: [PATCH 06/11] Exclude INTERFACE_LIBRARY when scanning target dependency as alias --- SwiftTargets.cmake | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/SwiftTargets.cmake b/SwiftTargets.cmake index e71f9d8..09eceaf 100644 --- a/SwiftTargets.cmake +++ b/SwiftTargets.cmake @@ -392,10 +392,13 @@ function(swift_validate_targets) get_target_property(target_dependencies ${target} LINK_LIBRARIES) foreach(target_dependency ${target_dependencies}) if (TARGET ${target_dependency}) - get_target_property(swift_type ${target_dependency} SWIFT_TYPE) - get_target_property(swift_alias ${target_dependency} ALIASED_TARGET) - if(swift_type AND (NOT swift_alias)) - message(WARNING "Calling \"${target_dependency}\" as a dependency of target \"${target}\". Please use alias \"${project_alias}::${target_dependency}\" instead.") + get_target_property(link_type ${target_dependency} TYPE) + if(NOT link_type STREQUAL "INTERFACE_LIBRARY") + get_target_property(swift_type ${target_dependency} SWIFT_TYPE) + get_target_property(swift_alias ${target_dependency} ALIASED_TARGET) + if(swift_type AND (NOT swift_alias)) + message(WARNING "Linking \"${target_dependency}\" as a dependency of target \"${target}\". Please use alias \"${project_alias}::${target_dependency}\" instead.") + endif() endif() endif() endforeach() From 3dadc57f1bdfddc62041a4fef603f6799a12c981 Mon Sep 17 00:00:00 2001 From: Lucas Date: Wed, 27 Jul 2022 12:55:51 +1000 Subject: [PATCH 07/11] Temporarily fix swift_validate_targets to scan all target. Note: next goal is to get aliases of all target --- SwiftTargets.cmake | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/SwiftTargets.cmake b/SwiftTargets.cmake index 09eceaf..0074fd5 100644 --- a/SwiftTargets.cmake +++ b/SwiftTargets.cmake @@ -387,16 +387,25 @@ function(swift_validate_targets) endif() endforeach() - swift_list_compilable_targets(all_targets ONLY_THIS_REPO SWIFT_TYPES "executable" "library" "tool_library" "test_library" "test") + swift_list_compilable_targets(all_targets ONLY_THIS_REPO SWIFT_TYPES) foreach(target ${all_targets}) get_target_property(target_dependencies ${target} LINK_LIBRARIES) + if (NOT target_dependencies) + continue() + endif() + foreach(target_dependency ${target_dependencies}) if (TARGET ${target_dependency}) - get_target_property(link_type ${target_dependency} TYPE) - if(NOT link_type STREQUAL "INTERFACE_LIBRARY") - get_target_property(swift_type ${target_dependency} SWIFT_TYPE) - get_target_property(swift_alias ${target_dependency} ALIASED_TARGET) - if(swift_type AND (NOT swift_alias)) + get_target_property(swift_alias ${target_dependency} ALIASED_TARGET) + if (NOT swift_alias) + get_target_property(link_type ${target_dependency} TYPE) + if (link_type STREQUAL "INTERFACE_LIBRARY") + get_target_property(swift_type ${target_dependency} INTERFACE_SWIFT_TYPE) + else() + get_target_property(swift_type ${target_dependency} SWIFT_TYPE) + endif() + + if (swift_type) message(WARNING "Linking \"${target_dependency}\" as a dependency of target \"${target}\". Please use alias \"${project_alias}::${target_dependency}\" instead.") endif() endif() From 7304b15c214faaf768ff8d13f6ff151bdff79fc7 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 28 Jul 2022 15:13:22 +1000 Subject: [PATCH 08/11] Add check for project alias b4 sending warning message; Update variable names --- SwiftTargets.cmake | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/SwiftTargets.cmake b/SwiftTargets.cmake index 0074fd5..3548625 100644 --- a/SwiftTargets.cmake +++ b/SwiftTargets.cmake @@ -387,6 +387,7 @@ function(swift_validate_targets) endif() endforeach() + # Check for the use of alias for swift dependencies. swift_list_compilable_targets(all_targets ONLY_THIS_REPO SWIFT_TYPES) foreach(target ${all_targets}) get_target_property(target_dependencies ${target} LINK_LIBRARIES) @@ -396,17 +397,20 @@ function(swift_validate_targets) foreach(target_dependency ${target_dependencies}) if (TARGET ${target_dependency}) - get_target_property(swift_alias ${target_dependency} ALIASED_TARGET) - if (NOT swift_alias) - get_target_property(link_type ${target_dependency} TYPE) - if (link_type STREQUAL "INTERFACE_LIBRARY") - get_target_property(swift_type ${target_dependency} INTERFACE_SWIFT_TYPE) + get_target_property(swift_dep_alias ${target_dependency} ALIASED_TARGET) + if (NOT swift_dep_alias) + get_target_property(target_dep_type ${target_dependency} TYPE) + if (target_dep_type STREQUAL "INTERFACE_LIBRARY") + get_target_property(swift_dep_type ${target_dependency} INTERFACE_SWIFT_TYPE) else() - get_target_property(swift_type ${target_dependency} SWIFT_TYPE) + get_target_property(swift_dep_type ${target_dependency} SWIFT_TYPE) endif() - if (swift_type) - message(WARNING "Linking \"${target_dependency}\" as a dependency of target \"${target}\". Please use alias \"${project_alias}::${target_dependency}\" instead.") + if (swift_dep_type) + get_target_property(_swift_dep_alias ${project_alias}::${target_dependency} ALIASED_TARGET) + if (${_swift_dep_alias} STREQUAL ${target_dependency}) + message(WARNING "Linking \"${target_dependency}\" as a dependency of target \"${target}\". Please use alias \"${project_alias}::${target_dependency}\" instead.") + endif() endif() endif() endif() From 508a9238dec3d1173552bd2c843dda508d8803e9 Mon Sep 17 00:00:00 2001 From: lucasle-sn Date: Tue, 9 Aug 2022 14:42:32 +1000 Subject: [PATCH 09/11] Fix after review: Change global var to capital letters; avoid using nested conditions --- SwiftTargets.cmake | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/SwiftTargets.cmake b/SwiftTargets.cmake index 3548625..1616a18 100644 --- a/SwiftTargets.cmake +++ b/SwiftTargets.cmake @@ -184,7 +184,7 @@ define_property(TARGET BRIEF_DOCS "Target's source directory" FULL_DOCS "Identical use as SOURCE_DIR except that this applies to ALL target types, including INTERFACE") -set(project_alias "swiftnav" CACHE STRING "Alias for project") +set(SWIFTNAV_ALIAS swiftnav) macro(swift_collate_arguments prefix name) set(exclusion_list ${ARGN}) @@ -319,7 +319,7 @@ function(swift_add_target target type) endif() if((type STREQUAL "library") OR (type STREQUAL "test_library") OR (type STREQUAL "tool_library")) - add_library(${project_alias}::${target} ALIAS ${target}) + add_library(${SWIFTNAV_ALIAS}::${target} ALIAS ${target}) endif() # @@ -396,23 +396,29 @@ function(swift_validate_targets) endif() foreach(target_dependency ${target_dependencies}) - if (TARGET ${target_dependency}) - get_target_property(swift_dep_alias ${target_dependency} ALIASED_TARGET) - if (NOT swift_dep_alias) - get_target_property(target_dep_type ${target_dependency} TYPE) - if (target_dep_type STREQUAL "INTERFACE_LIBRARY") - get_target_property(swift_dep_type ${target_dependency} INTERFACE_SWIFT_TYPE) - else() - get_target_property(swift_dep_type ${target_dependency} SWIFT_TYPE) - endif() - - if (swift_dep_type) - get_target_property(_swift_dep_alias ${project_alias}::${target_dependency} ALIASED_TARGET) - if (${_swift_dep_alias} STREQUAL ${target_dependency}) - message(WARNING "Linking \"${target_dependency}\" as a dependency of target \"${target}\". Please use alias \"${project_alias}::${target_dependency}\" instead.") - endif() - endif() - endif() + if (NOT TARGET ${target_dependency}) + continue() + endif() + + get_target_property(swift_dep_alias ${target_dependency} ALIASED_TARGET) + if (swift_dep_alias) + continue() + endif() + + get_target_property(target_dep_type ${target_dependency} TYPE) + if (target_dep_type STREQUAL "INTERFACE_LIBRARY") + get_target_property(swift_dep_type ${target_dependency} INTERFACE_SWIFT_TYPE) + else() + get_target_property(swift_dep_type ${target_dependency} SWIFT_TYPE) + endif() + + if (NOT swift_dep_type) + continue() + endif() + + get_target_property(_swift_dep_alias ${SWIFTNAV_ALIAS}::${target_dependency} ALIASED_TARGET) + if (${_swift_dep_alias} STREQUAL ${target_dependency}) + message(WARNING "Linking \"${target_dependency}\" as a dependency of target \"${target}\". Please use alias \"${SWIFTNAV_ALIAS}::${target_dependency}\" instead.") endif() endforeach() endforeach() From 6b7b3d90da5d8d6f5f12e2ad47ec71dee7e935c4 Mon Sep 17 00:00:00 2001 From: lucasle-sn Date: Tue, 9 Aug 2022 17:39:03 +1000 Subject: [PATCH 10/11] Add alias pattern check to ensure the recommended alias matches the real alias --- SwiftTargets.cmake | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/SwiftTargets.cmake b/SwiftTargets.cmake index 1616a18..2ec523d 100644 --- a/SwiftTargets.cmake +++ b/SwiftTargets.cmake @@ -416,7 +416,16 @@ function(swift_validate_targets) continue() endif() + # Check if swift's ${target_dependency} has an ALIAS following the pattern ${SWIFTNAV_ALIAS}::${target_dependency} + if (NOT TARGET ${SWIFTNAV_ALIAS}::${target_dependency}) + continue() + endif() + get_target_property(_swift_dep_alias ${SWIFTNAV_ALIAS}::${target_dependency} ALIASED_TARGET) + if (NOT _swift_dep_alias) + continue() + endif() + if (${_swift_dep_alias} STREQUAL ${target_dependency}) message(WARNING "Linking \"${target_dependency}\" as a dependency of target \"${target}\". Please use alias \"${SWIFTNAV_ALIAS}::${target_dependency}\" instead.") endif() From a6630936b94dea080d1599a8275c0da3d4d502db Mon Sep 17 00:00:00 2001 From: lucasle-sn Date: Wed, 10 Aug 2022 19:27:23 +1000 Subject: [PATCH 11/11] Revert set CACHE for SWIFTNAV_ALIAS -> Fix issue on starling --- SwiftTargets.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftTargets.cmake b/SwiftTargets.cmake index 2ec523d..9e29064 100644 --- a/SwiftTargets.cmake +++ b/SwiftTargets.cmake @@ -184,7 +184,7 @@ define_property(TARGET BRIEF_DOCS "Target's source directory" FULL_DOCS "Identical use as SOURCE_DIR except that this applies to ALL target types, including INTERFACE") -set(SWIFTNAV_ALIAS swiftnav) +set(SWIFTNAV_ALIAS "swiftnav" CACHE STRING "Alias for Swiftnav's projects") macro(swift_collate_arguments prefix name) set(exclusion_list ${ARGN})