From a65077439243f4df4dc643a264cd1aa865f78e76 Mon Sep 17 00:00:00 2001 From: Sergey Alexandrov Date: Wed, 3 Jul 2019 13:52:16 +0200 Subject: [PATCH 1/2] Add support for config-based FLANN discovery --- cmake/Modules/FindFLANN.cmake | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/FindFLANN.cmake b/cmake/Modules/FindFLANN.cmake index cf04457eef9..a37033eb6d3 100644 --- a/cmake/Modules/FindFLANN.cmake +++ b/cmake/Modules/FindFLANN.cmake @@ -2,7 +2,8 @@ # FindFLANN # -------- # -# Try to find FLANN library and include files. +# Try to find FLANN library and headers. This module supports both old released versions +# of FLANN ≤ 1.9.1 and newer development versions that ship with a modern config file. # # IMPORTED Targets # ^^^^^^^^^^^^^^^^ @@ -38,6 +39,22 @@ # target_link_libraries(foo FLANN::FLANN) # +# First try to locate FLANN using modern config +find_package(flann NO_MODULE ${FLANN_FIND_VERSION} QUIET) +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(FLANN_USE_STATIC) + set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp_s) + else() + set_property(TARGET FLANN::FLANN APPEND PROPERTY INTERFACE_LINK_LIBRARIES flann::flann_cpp) + endif() + return() +endif() + +# Second try to locate FLANN using pkgconfig find_package(PkgConfig QUIET) if(FLANN_FIND_VERSION) pkg_check_modules(PC_FLANN flann>=${FLANN_FIND_VERSION}) From 2785b03cae3cff19262e96ebc1b73e37d85af3f3 Mon Sep 17 00:00:00 2001 From: Sergey Alexandrov Date: Wed, 3 Jul 2019 13:52:53 +0200 Subject: [PATCH 2/2] Remove unused variables in FLANN finder script --- cmake/Modules/FindFLANN.cmake | 60 +++++++++++------------------------ 1 file changed, 19 insertions(+), 41 deletions(-) diff --git a/cmake/Modules/FindFLANN.cmake b/cmake/Modules/FindFLANN.cmake index a37033eb6d3..97decc361ac 100644 --- a/cmake/Modules/FindFLANN.cmake +++ b/cmake/Modules/FindFLANN.cmake @@ -21,12 +21,6 @@ # :: # # FLANN_FOUND True in case FLANN is found, otherwise false -# FLANN_DEFINITIONS Compiler flags for FLANN. -# FLANN_INCLUDE_DIR Location of FLANN header files -# FLANN_INCLUDE_DIRS Location of FLANN header files (including dependencies) -# FLANN_LIBRARY FLANN release library -# FLANN_LIBRARY_DEBUG FLANN debug library -# FLANN_LIBRARIES FLANN release and debug library # # Example usage # ^^^^^^^^^^^^^ @@ -62,16 +56,6 @@ else() pkg_check_modules(PC_FLANN flann) endif() -set(FLANN_DEFINITIONS ${PC_FLANN_CFLAGS_OTHER}) - -if(FLANN_USE_STATIC) - set(FLANN_RELEASE_NAME flann_cpp_s) - set(FLANN_DEBUG_NAME flann_cpp_s-gd) -else() - set(FLANN_RELEASE_NAME flann_cpp) - set(FLANN_DEBUG_NAME flann_cpp-gd) -endif() - find_path(FLANN_INCLUDE_DIR NAMES flann/flann.hpp @@ -86,6 +70,16 @@ find_path(FLANN_INCLUDE_DIR include ) +if(FLANN_USE_STATIC) + set(FLANN_RELEASE_NAME flann_cpp_s) + set(FLANN_DEBUG_NAME flann_cpp_s-gd) + set(FLANN_LIBRARY_TYPE STATIC) +else() + set(FLANN_RELEASE_NAME flann_cpp) + set(FLANN_DEBUG_NAME flann_cpp-gd) + set(FLANN_LIBRARY_TYPE SHARED) +endif() + find_library(FLANN_LIBRARY NAMES ${FLANN_RELEASE_NAME} @@ -114,39 +108,23 @@ find_library(FLANN_LIBRARY_DEBUG lib ) -if(FLANN_LIBRARY AND FLANN_LIBRARY_DEBUG) - set(FLANN_LIBRARIES optimized ${FLANN_LIBRARY} debug ${FLANN_LIBRARY_DEBUG}) -else() - set(FLANN_LIBRARIES ${FLANN_LIBRARY}) -endif() - -set(FLANN_INCLUDE_DIRS - ${FLANN_INCLUDE_DIR} -) - include(FindPackageHandleStandardArgs) find_package_handle_standard_args( FLANN DEFAULT_MSG - FLANN_LIBRARIES FLANN_INCLUDE_DIR + FLANN_LIBRARY FLANN_INCLUDE_DIR ) if(FLANN_FOUND) if(NOT TARGET FLANN::FLANN) - if (FLANN_USE_STATIC) - add_library(FLANN::FLANN STATIC IMPORTED) + add_library(FLANN::FLANN ${FLANN_LIBRARY_TYPE} IMPORTED) + set_target_properties(FLANN::FLANN PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FLANN_INCLUDE_DIR}") + set_target_properties(FLANN::FLANN PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${PC_FLANN_CFLAGS_OTHER}") + set_property(TARGET FLANN::FLANN APPEND PROPERTY IMPORTED_CONFIGURATIONS "RELEASE") + set_target_properties(FLANN::FLANN PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX") + if(WIN32 AND NOT FLANN_USE_STATIC) + set_target_properties(FLANN::FLANN PROPERTIES IMPORTED_IMPLIB_RELEASE "${FLANN_LIBRARY}") else() - add_library(FLANN::FLANN SHARED IMPORTED) - endif() - set_target_properties(FLANN::FLANN PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FLANN_INCLUDE_DIRS}") - set_target_properties(FLANN::FLANN PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${FLANN_DEFINITIONS}") - if(FLANN_LIBRARY) - set_property(TARGET FLANN::FLANN APPEND PROPERTY IMPORTED_CONFIGURATIONS "RELEASE") - set_target_properties(FLANN::FLANN PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX") - if(WIN32 AND NOT FLANN_USE_STATIC) - set_target_properties(FLANN::FLANN PROPERTIES IMPORTED_IMPLIB_RELEASE "${FLANN_LIBRARY}") - else() - set_target_properties(FLANN::FLANN PROPERTIES IMPORTED_LOCATION_RELEASE "${FLANN_LIBRARY}") - endif() + set_target_properties(FLANN::FLANN PROPERTIES IMPORTED_LOCATION_RELEASE "${FLANN_LIBRARY}") endif() if(FLANN_LIBRARY_DEBUG) set_property(TARGET FLANN::FLANN APPEND PROPERTY IMPORTED_CONFIGURATIONS "DEBUG")