From 1213d1b5bd069208c1b55bd50a73abec8b0a5b88 Mon Sep 17 00:00:00 2001
From: Slávek Banko <slavek.banko@axis.cz>
Date: Sun, 23 Aug 2026 18:40:47 +0200
Subject: Remove repeated inclusion of the same imported target in tde_import.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Because our exported targets are now always global when imported,
there is no need to include exported target file repeatedly. At the
same time, protection has been added so that multiple inclusions of an
exported target file do not cause an attempt to redefine the target.

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
---
 modules/TDEMacros.cmake            |  5 -----
 templates/tde_export_library.cmake | 20 ++++++++++++--------
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/modules/TDEMacros.cmake b/modules/TDEMacros.cmake
index 3082e9e..276a96b 100644
--- a/modules/TDEMacros.cmake
+++ b/modules/TDEMacros.cmake
@@ -890,11 +890,6 @@ macro( tde_import _library )
       message( STATUS "Checking for '${_library}' - ok, found import file" )
       set( TDE_IMPORT_${_library} "import:${tde_import_include}" CACHE INTERNAL "Library ${_library} imported" )
     endif()
-  else()
-    if( "${TDE_IMPORT_${_library}}" MATCHES "^import:" )
-      string( REGEX REPLACE "^import:" "" tde_import_include "${TDE_IMPORT_${_library}}" )
-      include( "${tde_import_include}" )
-    endif()
   endif()
 endmacro()
 
diff --git a/templates/tde_export_library.cmake b/templates/tde_export_library.cmake
index 66d9fd0..3a92264 100644
--- a/templates/tde_export_library.cmake
+++ b/templates/tde_export_library.cmake
@@ -1,9 +1,13 @@
-add_library( @_target@ @_realtype@ IMPORTED GLOBAL )
-@_target_alias_line@
+if( NOT TARGET "@_target@" )
 
-set_target_properties( @_target@ PROPERTIES
-  INTERFACE_COMPILE_FEATURES "@_cxx_features@"
-  IMPORTED_LINK_INTERFACE_LIBRARIES "@_shared_libs@"
-  IMPORTED_LOCATION "@_location@"
-  @_other_properties@
-)
+  add_library( @_target@ @_realtype@ IMPORTED GLOBAL )
+  @_target_alias_line@
+
+  set_target_properties( @_target@ PROPERTIES
+    INTERFACE_COMPILE_FEATURES "@_cxx_features@"
+    IMPORTED_LINK_INTERFACE_LIBRARIES "@_shared_libs@"
+    IMPORTED_LOCATION "@_location@"
+    @_other_properties@
+  )
+
+endif()
-- 
cgit v1.2.3

