From 2797a50846a471fb754b4796c2b93f75536aba1b Mon Sep 17 00:00:00 2001
From: Guillaume Pasero <guillaume.pasero@c-s.fr>
Date: Mon, 30 Apr 2018 15:55:34 +0200
Subject: [PATCH] PKG: also parse ITK targets

---
 Packaging/prepare_file_list.cmake    | 11 +++++++++++
 Packaging/process_file_recurse.cmake |  7 ++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/Packaging/prepare_file_list.cmake b/Packaging/prepare_file_list.cmake
index 5f0aaef717..89a07e9a6a 100644
--- a/Packaging/prepare_file_list.cmake
+++ b/Packaging/prepare_file_list.cmake
@@ -89,6 +89,17 @@ function(prepare_file_list file_list_result)
       list(APPEND file_list ${otb_test_exe_name})
     endif()
   endforeach()
+
+  # find ITK targets
+  set(_itk_targets_path
+    "${SUPERBUILD_INSTALL_DIR}/lib/cmake/ITK-${PKG_ITK_SB_VERSION}")
+  file(GLOB _itk_targets_config_files "${_itk_targets_path}/ITKTargets-*.cmake")
+  foreach(f ${_itk_targets_config_files})
+    file(STRINGS ${f} _f_content REGEX " IMPORTED_LOCATION_[A-Z]+ ")
+    string(REGEX REPLACE " +IMPORTED_LOCATION_[A-Z]+ \"([^\"]+)\"" "\\1;" _filtered ${_f_content})
+    string(CONFIGURE "${_filtered}" _configured)
+    list(APPEND file_list "${_configured}")
+  endforeach()
   
   # special case for msvc: ucrtbase.dll must be explicitly vetted.
   # for proj.dll, see Mantis-1424
diff --git a/Packaging/process_file_recurse.cmake b/Packaging/process_file_recurse.cmake
index cc0e9f991e..2fcde9aaec 100644
--- a/Packaging/process_file_recurse.cmake
+++ b/Packaging/process_file_recurse.cmake
@@ -43,6 +43,12 @@ function(process_file_recurse input_file)
     message(FATAL_ERROR "${input_file} not found. searched in ${PKG_SEARCHDIRS}")
   endif()
 
+  get_filename_component(bn_name ${input_file_full_path} NAME)
+  if(${bn_name}_RESOLVED)
+    # item already resolved
+    return()
+  endif()
+
   if(NOT PKG_DEBUG)
     message("Processing ${input_file_full_path}")
   endif()
@@ -67,7 +73,6 @@ function(process_file_recurse input_file)
   string(REPLACE ";" "\\;" candidates "${loader_ov}")
   string(REPLACE "\n" "${LOADER_REGEX_EOL};" candidates "${candidates}")
   
-  get_filename_component(bn_name ${input_file_full_path} NAME)
   set(${bn_name}_USED TRUE CACHE INTERNAL "")
 
   if(PKG_DEBUG)
-- 
GitLab