From 05d7b43ac24fd386bec90540df5a6adee82db1c9 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 15 Jul 2024 13:57:34 +0200 Subject: [PATCH] Fix vp_get_interface_link_libraries macro to support VTK 9.2.6 that brings Qt6 when ustk is used as an external contrib module --- cmake/VISPUtils.cmake | 47 ++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/cmake/VISPUtils.cmake b/cmake/VISPUtils.cmake index 0b10ab4cec..6207c74f0f 100644 --- a/cmake/VISPUtils.cmake +++ b/cmake/VISPUtils.cmake @@ -342,15 +342,6 @@ macro(vp_list_filterout lst regex) endforeach() endmacro() -# remove all matching elements from the list -macro(vp_list_filterout lst regex) - foreach(item ${${lst}}) - if(item MATCHES "${regex}") - list(REMOVE_ITEM ${lst} "${item}") - endif() - endforeach() -endmacro() - # stable & safe duplicates removal macro macro(vp_list_unique __lst) if(${__lst}) @@ -372,6 +363,17 @@ macro(vp_list_remove_empty __lst) endif() endmacro() +# list directory elements removal macro +macro(vp_list_remove_directory lst) + if(${lst}) + foreach(item ${${lst}}) + if(IS_DIRECTORY ${item}) + list(REMOVE_ITEM ${lst} "${item}") + endif() + endforeach() + endif() +endmacro() + # needed by visp-java if(CMAKE_VERSION VERSION_LESS "3.2") macro(vp_cmake_byproducts var_name) @@ -1391,12 +1393,16 @@ macro(vp_get_interface_link_libraries libs link_libraries) set(__imported_libs ${${libs}}) set(__libs ${${libs}}) foreach(lib_ ${${libs}}) -# message("lib_: ${lib_}") if(TARGET ${lib_}) get_target_property(imported_libs_ ${lib_} INTERFACE_LINK_LIBRARIES) if(imported_libs_) - list(APPEND __imported_libs ${imported_libs_}) - list(APPEND __libs ${lib_}) + foreach(imp_ ${imported_libs_}) + if(NOT imp_ MATCHES "^\\$<") + list(APPEND __imported_libs ${imported_libs_}) + list(APPEND __libs ${lib_}) + endif() + endforeach() + else() list(APPEND __libs ${lib_}) endif() @@ -1404,45 +1410,35 @@ macro(vp_get_interface_link_libraries libs link_libraries) list(APPEND __libs ${lib_}) endif() endforeach() -# message("__imported_libs: ${__imported_libs}") -# message("__libs: ${__libs}") vp_list_unique(__imported_libs) vp_list_unique(__libs) -# message("fin __imported_libs: ${__imported_libs}") -# message("fin __libs: ${__libs}") while(__imported_libs) -# message("begin while __imported_libs: ${__imported_libs}") vp_list_pop_front(__imported_libs elt) -# message("Process elt: ${elt}") if(TARGET ${elt} AND NOT elt MATCHES "^-framework") # to avoid precessing -framework ApplicationServices -framework CoreServices -# message("elt is a target and not framework: ${elt}") get_target_property(imported_libs_ ${elt} INTERFACE_LINK_LIBRARIES) if(imported_libs_) list(APPEND __imported_libs ${imported_libs_}) else() list(APPEND __libs ${elt}) endif() - else() + elseif(NOT elt MATCHES "^\\$<") list(APPEND __libs ${elt}) endif() + vp_list_unique(__imported_libs) endwhile() vp_list_unique(__libs) -# message("fin2 __imported_libs: ${__imported_libs}") -# message("fin2 __libs: ${__libs}") set(__config "RELEASE" "DEBUG") foreach(config_ ${__config}) foreach(lib_ ${__libs}) -# message("lib_: ${lib_}") if(TARGET ${lib_}) get_target_property(imported_libs_ ${lib_} IMPORTED_IMPLIB_${config_}) if(NOT EXISTS ${imported_libs_}) get_target_property(lib_location_ ${lib_} IMPORTED_LOCATION_${config_}) endif() - # message("lib_location_: ${lib_location_}") if(WIN32 AND EXISTS "${lib_location_}" AND "${config_}" MATCHES "RELEASE") # also valid for RELEASEWITHDEBINFO list(APPEND ${link_libraries} optimized "${lib_location_}") elseif(WIN32 AND EXISTS "${lib_location_}" AND "${config_}" MATCHES "DEBUG") @@ -1452,7 +1448,6 @@ macro(vp_get_interface_link_libraries libs link_libraries) endif() get_target_property(lib_deps_ ${lib_} IMPORTED_LINK_INTERFACE_LIBRARIES_${config_}) - # message("lib_deps_ ---------: ${lib_deps_}") if(lib_deps_) foreach(deps_ ${lib_deps_}) get_target_property(deps_location_ ${deps_} IMPORTED_LOCATION_${config_}) @@ -1486,6 +1481,8 @@ macro(vp_get_interface_link_libraries libs link_libraries) endforeach() endforeach() vp_list_unique(${link_libraries}) + # Additional check to remove directories like /usr/X11R6/lib that can be exported by VTK + vp_list_remove_directory(${link_libraries}) # message("link_libraries: ${link_libraries}") endmacro()