Skip to content

Commit c0c0064

Browse files
3Descapelarshgmvieth
authored
Use real ALIAS(cmake >=3.18) target for flann to preserve properties on original target. (#5861)
* 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. * Use appropriate comparison operator Co-authored-by: Lars Glud <larshg@gmail.com> * Only use ALIAS Target for CMAKE >= 3.18 * Use appropriate comparison operator Co-authored-by: Markus Vieth <39675748+mvieth@users.noreply.github.com> --------- Co-authored-by: Lars Glud <larshg@gmail.com> Co-authored-by: Markus Vieth <39675748+mvieth@users.noreply.github.com>
1 parent 8c81110 commit c0c0064

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

cmake/Modules/FindFLANN.cmake

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,33 +48,41 @@ if(flann_FOUND)
4848
unset(flann_FOUND)
4949
set(FLANN_FOUND ON)
5050

51-
# Create interface library that effectively becomes an alias for the appropriate (static/dynamic) imported FLANN target
52-
add_library(FLANN::FLANN INTERFACE IMPORTED)
53-
5451
if(TARGET flann::flann_cpp_s AND TARGET flann::flann_cpp)
5552
if(PCL_FLANN_REQUIRED_TYPE MATCHES "SHARED")
56-
set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp)
5753
set(FLANN_LIBRARY_TYPE SHARED)
5854
elseif(PCL_FLANN_REQUIRED_TYPE MATCHES "STATIC")
59-
set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp_s)
6055
set(FLANN_LIBRARY_TYPE STATIC)
6156
else()
6257
if(PCL_SHARED_LIBS)
63-
set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp)
6458
set(FLANN_LIBRARY_TYPE SHARED)
6559
else()
66-
set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp_s)
6760
set(FLANN_LIBRARY_TYPE STATIC)
6861
endif()
6962
endif()
7063
elseif(TARGET flann::flann_cpp_s)
71-
set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp_s)
7264
set(FLANN_LIBRARY_TYPE STATIC)
7365
else()
74-
set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp)
7566
set(FLANN_LIBRARY_TYPE SHARED)
7667
endif()
7768

69+
if(CMAKE_VERSION VERSION_LESS 3.18.0)
70+
# Create interface library that effectively becomes an alias for the appropriate (static/dynamic) imported FLANN target
71+
add_library(FLANN::FLANN INTERFACE IMPORTED)
72+
73+
if(FLANN_LIBRARY_TYPE MATCHES SHARED)
74+
set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp)
75+
else()
76+
set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp_s)
77+
endif()
78+
else()
79+
if(FLANN_LIBRARY_TYPE MATCHES SHARED)
80+
add_library(FLANN::FLANN ALIAS flann::flann_cpp)
81+
else()
82+
add_library(FLANN::FLANN ALIAS flann::flann_cpp_s)
83+
endif()
84+
endif()
85+
7886
# Determine FLANN installation root based on the path to the processed Config file
7987
get_filename_component(_config_dir "${flann_CONFIG}" DIRECTORY)
8088
get_filename_component(FLANN_ROOT "${_config_dir}/../../.." ABSOLUTE)

0 commit comments

Comments
 (0)