Skip to content

Commit

Permalink
Use real ALIAS target for flann to preserve properties on original ta…
Browse files Browse the repository at this point in the history
…rget.

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.
  • Loading branch information
3Descape authored Oct 28, 2023
1 parent be7a26c commit 641dc48
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions cmake/Modules/FindFLANN.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 641dc48

Please sign in to comment.