From 641dc4846e74b356dc137bdc0d25b78be5234f43 Mon Sep 17 00:00:00 2001 From: 3Descape Date: Sat, 28 Oct 2023 16:28:09 +0200 Subject: [PATCH] Use real ALIAS target for flann to preserve properties on original target. With the current method all properties set on the flann::flann_cpp and flann::flann_cpp target are lost, as they are not copied to the new FLANN::FLANN interface target. However, there are cases, where we would like preserve these, e.g. to keep the INTERFACE_INCLUDE_DIRECTORIES property that includes the path to the LZ4 headers. Therefore this patch first checks for the appropriate SHARED or STATIC version and then aliases FLANN::FLANN to the respective library. --- cmake/Modules/FindFLANN.cmake | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/cmake/Modules/FindFLANN.cmake b/cmake/Modules/FindFLANN.cmake index 16ee72fbe8a..27f39200419 100644 --- a/cmake/Modules/FindFLANN.cmake +++ b/cmake/Modules/FindFLANN.cmake @@ -48,33 +48,30 @@ if(flann_FOUND) unset(flann_FOUND) set(FLANN_FOUND ON) - # Create interface library that effectively becomes an alias for the appropriate (static/dynamic) imported FLANN target - add_library(FLANN::FLANN INTERFACE IMPORTED) - if(TARGET flann::flann_cpp_s AND TARGET flann::flann_cpp) if(PCL_FLANN_REQUIRED_TYPE MATCHES "SHARED") - set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp) set(FLANN_LIBRARY_TYPE SHARED) elseif(PCL_FLANN_REQUIRED_TYPE MATCHES "STATIC") - set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp_s) set(FLANN_LIBRARY_TYPE STATIC) else() if(PCL_SHARED_LIBS) - set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp) set(FLANN_LIBRARY_TYPE SHARED) else() - set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp_s) set(FLANN_LIBRARY_TYPE STATIC) endif() endif() elseif(TARGET flann::flann_cpp_s) - set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp_s) set(FLANN_LIBRARY_TYPE STATIC) else() - set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp) set(FLANN_LIBRARY_TYPE SHARED) endif() + if(FLANN_LIBRARY_TYPE EQUAL SHARED) + add_library(FLANN::FLANN ALIAS flann::flann_cpp) + else() + add_library(FLANN::FLANN ALIAS flann::flann_cpp_s) + endif() + # Determine FLANN installation root based on the path to the processed Config file get_filename_component(_config_dir "${flann_CONFIG}" DIRECTORY) get_filename_component(FLANN_ROOT "${_config_dir}/../../.." ABSOLUTE)