Skip to content

Commit

Permalink
[lz4, flann] port patches from #5169 (#6294)
Browse files Browse the repository at this point in the history
* [lz4, flann] port patches from #5169

* [lz4] use vcpkg_fixup_cmake_targets

* [flann] improve target handling

* [lz4] remove unnecessary debug message

* [openmvg] many many fixes to build it on windows

* [pcl] use official FLANN cmake config file instead of custom module

* [pcl] fix patch for flann targets

* [pcl] Bump CONTROL version
  • Loading branch information
cenit authored and vicroms committed May 19, 2019
1 parent 77af264 commit 69e86fd
Show file tree
Hide file tree
Showing 16 changed files with 1,027 additions and 380 deletions.
3 changes: 2 additions & 1 deletion ports/flann/CONTROL
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Source: flann
Version: 1.9.1-9
Version: jan2019
Build-Depends: lz4
Description: Fast Library for Approximate Nearest Neighbors
12 changes: 0 additions & 12 deletions ports/flann/export-all-symbols-of-flann-cpp.patch

This file was deleted.

243 changes: 243 additions & 0 deletions ports/flann/fix_targets.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f4b94d2..e55195b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -146,9 +146,6 @@ if (BUILD_CUDA_LIB)
endif(CUDA_FOUND)
endif(BUILD_CUDA_LIB)

-find_package(PkgConfig REQUIRED)
-pkg_check_modules(LZ4 REQUIRED liblz4)
-
#set the C/C++ include path to the "include" directory
include_directories(BEFORE ${PROJECT_SOURCE_DIR}/src/cpp)

diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in
index 6b95a71..2c95b6e 100644
--- a/cmake/Config.cmake.in
+++ b/cmake/Config.cmake.in
@@ -3,3 +3,5 @@
include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake")
check_required_components("flann")

+include(CMakeFindDependencyMacro)
+find_dependency(lz4)
diff --git a/cmake/flann_utils.cmake b/cmake/flann_utils.cmake
index afe4742..0cf8289 100644
--- a/cmake/flann_utils.cmake
+++ b/cmake/flann_utils.cmake
@@ -1,8 +1,7 @@
macro(GET_OS_INFO)
string(REGEX MATCH "Linux" OS_IS_LINUX ${CMAKE_SYSTEM_NAME})
- set(FLANN_LIB_INSTALL_DIR "lib${LIB_SUFFIX}")
- set(FLANN_INCLUDE_INSTALL_DIR
- "include/${PROJECT_NAME_LOWER}-${FLANN_MAJOR_VERSION}.${FLANN_MINOR_VERSION}")
+ set(FLANN_LIB_INSTALL_DIR "lib")
+ set(FLANN_INCLUDE_INSTALL_DIR "include")
endmacro(GET_OS_INFO)


@@ -27,7 +26,7 @@ macro(find_hdf5)
set( HDF5_IS_PARALLEL FALSE )
foreach( _dir ${HDF5_INCLUDE_DIRS} )
if( EXISTS "${_dir}/H5pubconf.h" )
- file( STRINGS "${_dir}/H5pubconf.h"
+ file( STRINGS "${_dir}/H5pubconf.h"
HDF5_HAVE_PARALLEL_DEFINE
REGEX "HAVE_PARALLEL 1" )
if( HDF5_HAVE_PARALLEL_DEFINE )
@@ -106,7 +105,7 @@ endmacro(flann_add_pyunit)

macro(flann_download_test_data _name _md5)
string(REPLACE "/" "_" _dataset_name dataset_${_name})
-
+
add_custom_target(${_dataset_name}
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/bin/download_checkmd5.py http://people.cs.ubc.ca/~mariusm/uploads/FLANN/datasets/${_name} ${TEST_OUTPUT_PATH}/${_name} ${_md5}
VERBATIM)
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 3f4655a..918b94a 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,9 +1,10 @@
add_custom_target(examples ALL)

+find_package(lz4 REQUIRED)

if (BUILD_C_BINDINGS)
add_executable(flann_example_c flann_example.c)
- target_link_libraries(flann_example_c -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
+ target_link_libraries(flann_example_c lz4::lz4)
target_link_libraries(flann_example_c flann)
set_target_properties(flann_example_c PROPERTIES COMPILE_FLAGS -std=c99)

@@ -15,7 +16,7 @@ if (HDF5_FOUND)
include_directories(${HDF5_INCLUDE_DIR})

add_executable(flann_example_cpp flann_example.cpp)
- target_link_libraries(flann_example_cpp -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
+ target_link_libraries(flann_example_cpp lz4::lz4)
target_link_libraries(flann_example_cpp ${HDF5_LIBRARIES} flann_cpp)
if (HDF5_IS_PARALLEL)
target_link_libraries(flann_example_cpp ${MPI_LIBRARIES})
@@ -27,7 +28,7 @@ if (HDF5_FOUND)

if (USE_MPI AND HDF5_IS_PARALLEL)
add_executable(flann_example_mpi flann_example_mpi.cpp)
- target_link_libraries(flann_example_mpi -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
+ target_link_libraries(flann_example_mpi lz4::lz4)
target_link_libraries(flann_example_mpi flann_cpp ${HDF5_LIBRARIES} ${MPI_LIBRARIES} ${Boost_LIBRARIES})

add_dependencies(examples flann_example_mpi)
@@ -36,7 +37,3 @@ if (HDF5_FOUND)
else()
message("hdf5 library not found, not compiling flann_example.cpp")
endif()
-
-
-
-
diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt
index b30f3da..1535d37 100644
--- a/src/cpp/CMakeLists.txt
+++ b/src/cpp/CMakeLists.txt
@@ -8,12 +8,13 @@ file(GLOB_RECURSE C_SOURCES flann.cpp)
file(GLOB_RECURSE CPP_SOURCES flann_cpp.cpp)
file(GLOB_RECURSE CU_SOURCES *.cu)

-add_library(flann_cpp_s STATIC ${CPP_SOURCES})
-target_link_libraries(flann_cpp_s ${LZ4_LIBRARIES})
-if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
- set_target_properties(flann_cpp_s PROPERTIES COMPILE_FLAGS -fPIC)
-endif()
-set_property(TARGET flann_cpp_s PROPERTY COMPILE_DEFINITIONS FLANN_STATIC FLANN_USE_CUDA)
+find_package(lz4 REQUIRED)
+
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+
+add_library(flann_cpp STATIC ${CPP_SOURCES})
+target_link_libraries(flann_cpp PRIVATE lz4::lz4)
+set_property(TARGET flann_cpp PROPERTY COMPILE_DEFINITIONS FLANN_STATIC)

if (BUILD_CUDA_LIB)
SET(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-DFLANN_USE_CUDA")
@@ -25,48 +26,11 @@ if (BUILD_CUDA_LIB)
else()
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};" )
endif()
- cuda_add_library(flann_cuda_s STATIC ${CU_SOURCES})
- set_property(TARGET flann_cuda_s PROPERTY COMPILE_DEFINITIONS FLANN_STATIC)
-endif()
-
-if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_COMPILER_IS_GNUCC)
- add_library(flann_cpp SHARED "")
- set_target_properties(flann_cpp PROPERTIES LINKER_LANGUAGE CXX)
- target_link_libraries(flann_cpp -Wl,-whole-archive flann_cpp_s -Wl,-no-whole-archive)
-
- if (BUILD_CUDA_LIB)
- cuda_add_library(flann_cuda SHARED "")
- set_target_properties(flann_cuda PROPERTIES LINKER_LANGUAGE CXX)
- target_link_libraries(flann_cuda -Wl,-whole-archive flann_cuda_s -Wl,-no-whole-archive)
- set_property(TARGET flann_cpp_s PROPERTY COMPILE_DEFINITIONS FLANN_USE_CUDA)
- # target_link_libraries(flann_cuda cudpp_x86_64)
- endif()
-else()
- add_library(flann_cpp SHARED ${CPP_SOURCES})
- target_link_libraries(flann_cpp -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
- # export lz4 headers, so that MSVC to creates flann_cpp.lib
- set_target_properties(flann_cpp PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES)
- if (BUILD_CUDA_LIB)
- cuda_add_library(flann_cuda SHARED ${CPP_SOURCES})
- set_property(TARGET flann_cpp PROPERTY COMPILE_DEFINITIONS FLANN_USE_CUDA)
- endif()
-endif()
-
-set_target_properties(flann_cpp PROPERTIES
- VERSION ${FLANN_VERSION}
- SOVERSION ${FLANN_SOVERSION}
- DEFINE_SYMBOL FLANN_EXPORTS
-)
-
-if (BUILD_CUDA_LIB)
- set_target_properties(flann_cuda PROPERTIES
- VERSION ${FLANN_VERSION}
- SOVERSION ${FLANN_SOVERSION}
- DEFINE_SYMBOL FLANN_EXPORTS
- )
+ cuda_add_library(flann_cuda STATIC ${CU_SOURCES})
+ set_property(TARGET flann_cuda PROPERTY COMPILE_DEFINITIONS FLANN_STATIC)
+ set_property(TARGET flann_cpp PROPERTY COMPILE_DEFINITIONS FLANN_USE_CUDA)
endif()

-
if (USE_MPI AND HDF5_IS_PARALLEL)
add_executable(flann_mpi_server flann/mpi/flann_mpi_server.cpp)
target_link_libraries(flann_mpi_server flann_cpp ${HDF5_LIBRARIES} ${MPI_LIBRARIES} ${Boost_LIBRARIES})
@@ -80,31 +44,9 @@ endif()


if (BUILD_C_BINDINGS)
- add_library(flann_s STATIC ${C_SOURCES})
- target_link_libraries(flann_cpp -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
- if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
- set_target_properties(flann_s PROPERTIES COMPILE_FLAGS -fPIC)
- endif()
- set_property(TARGET flann_s PROPERTY COMPILE_DEFINITIONS FLANN_STATIC)
-
- if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_COMPILER_IS_GNUCC)
- add_library(flann SHARED "")
- set_target_properties(flann PROPERTIES LINKER_LANGUAGE CXX)
- target_link_libraries(flann -Wl,-whole-archive flann_s -Wl,-no-whole-archive)
- else()
- add_library(flann SHARED ${C_SOURCES})
- target_link_libraries(flann_cpp -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
-
- if(MINGW AND OPENMP_FOUND)
- target_link_libraries(flann gomp)
- endif()
- endif()
-
- set_target_properties(flann PROPERTIES
- VERSION ${FLANN_VERSION}
- SOVERSION ${FLANN_SOVERSION}
- DEFINE_SYMBOL FLANN_EXPORTS
- )
+ add_library(flann STATIC ${C_SOURCES})
+ target_link_libraries(flann PRIVATE lz4::lz4)
+ set_property(TARGET flann PROPERTY COMPILE_DEFINITIONS FLANN_STATIC)
endif()

if(WIN32)
@@ -118,9 +60,9 @@ endif(WIN32)


install (
- TARGETS flann_cpp flann_cpp_s
+ TARGETS flann_cpp
EXPORT ${targets_export_name}
- INCLUDES DESTINATION include
+ INCLUDES DESTINATION ${FLANN_INCLUDE_INSTALL_DIR}
RUNTIME DESTINATION bin
LIBRARY DESTINATION ${FLANN_LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${FLANN_LIB_INSTALL_DIR}
@@ -128,9 +70,9 @@ install (

if (BUILD_CUDA_LIB)
install (
- TARGETS flann_cuda flann_cuda_s
+ TARGETS flann_cuda
EXPORT ${targets_export_name}
- INCLUDES DESTINATION include
+ INCLUDES DESTINATION ${FLANN_INCLUDE_INSTALL_DIR}
RUNTIME DESTINATION bin
LIBRARY DESTINATION ${FLANN_LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${FLANN_LIB_INSTALL_DIR}
@@ -139,7 +81,7 @@ endif()

if (BUILD_C_BINDINGS)
install (
- TARGETS flann flann_s
+ TARGETS flann
EXPORT ${targets_export_name}
INCLUDES DESTINATION include
RUNTIME DESTINATION bin
22 changes: 0 additions & 22 deletions ports/flann/flann-linux.patch

This file was deleted.

19 changes: 0 additions & 19 deletions ports/flann/no-write-src-dir.patch

This file was deleted.

37 changes: 9 additions & 28 deletions ports/flann/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
include(vcpkg_common_functions)

#the port uses inside the CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS, which is discouraged by vcpkg.
#Since it's its author choice, we should not disallow it, but unfortunately looks like it's broken, so we block it anyway...
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO mariusmuja/flann
REF 1.9.1
SHA512 0da78bb14111013318160dd3dee1f93eb6ed077b18439fd6496017b62a8a6070cc859cfb3e08dad4c614e48d9dc1da5f7c4a21726ee45896d360506da074a6f7
REF aa40936816f4feaa714d3a09f92a495da017d95c
SHA512 f6f2e75f4ce4bc4bc4cc1feab27fe683b8a5f9f5dcea35de4df5136a683b5dff5e68776008821a16ccf1a52a9807cb053c0062deba4fe121948248acd52864ef
HEAD_REF master
PATCHES
export-all-symbols-of-flann-cpp.patch
no-write-src-dir.patch
flann-linux.patch
fix_targets.patch
)

vcpkg_configure_cmake(
Expand All @@ -21,36 +23,15 @@ vcpkg_configure_cmake(
-DBUILD_DOC=OFF
-DBUILD_PYTHON_BINDINGS=OFF
-DBUILD_MATLAB_BINDINGS=OFF
-DCMAKE_DEBUG_POSTFIX=-gd
-DCMAKE_DEBUG_POSTFIX=d
-DHDF5_NO_FIND_PACKAGE_CONFIG_FILE=ON
)

vcpkg_install_cmake()
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake/${PORT})

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)

if(NOT VCPKG_CMAKE_SYSTEM_NAME OR VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
set(LIB_PREFIX "")
set(LIB_SUFFIX ".lib")
else()
set(LIB_PREFIX "lib")
set(LIB_SUFFIX ".a")
endif()

if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin)
file(REMOVE ${CURRENT_PACKAGES_DIR}/lib/${LIB_PREFIX}flann${LIB_SUFFIX} ${CURRENT_PACKAGES_DIR}/debug/lib/${LIB_PREFIX}flann-gd${LIB_SUFFIX})
file(REMOVE ${CURRENT_PACKAGES_DIR}/lib/${LIB_PREFIX}flann_cpp${LIB_SUFFIX} ${CURRENT_PACKAGES_DIR}/debug/lib/${LIB_PREFIX}flann_cpp-gd${LIB_SUFFIX})

file(RENAME ${CURRENT_PACKAGES_DIR}/lib/${LIB_PREFIX}flann_s${LIB_SUFFIX} ${CURRENT_PACKAGES_DIR}/lib/${LIB_PREFIX}flann${LIB_SUFFIX})
file(RENAME ${CURRENT_PACKAGES_DIR}/debug/lib/${LIB_PREFIX}flann_s-gd${LIB_SUFFIX} ${CURRENT_PACKAGES_DIR}/debug/lib/${LIB_PREFIX}flann-gd${LIB_SUFFIX})
file(RENAME ${CURRENT_PACKAGES_DIR}/lib/${LIB_PREFIX}flann_cpp_s${LIB_SUFFIX} ${CURRENT_PACKAGES_DIR}/lib/${LIB_PREFIX}flann_cpp${LIB_SUFFIX})
file(RENAME ${CURRENT_PACKAGES_DIR}/debug/lib/${LIB_PREFIX}flann_cpp_s-gd${LIB_SUFFIX} ${CURRENT_PACKAGES_DIR}/debug/lib/${LIB_PREFIX}flann_cpp-gd${LIB_SUFFIX})
elseif(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
file(REMOVE ${CURRENT_PACKAGES_DIR}/lib/${LIB_PREFIX}flann_s${LIB_SUFFIX} ${CURRENT_PACKAGES_DIR}/debug/lib/${LIB_PREFIX}flann_s-gd${LIB_SUFFIX})
file(REMOVE ${CURRENT_PACKAGES_DIR}/lib/${LIB_PREFIX}flann_cpp_s${LIB_SUFFIX} ${CURRENT_PACKAGES_DIR}/debug/lib/${LIB_PREFIX}flann_cpp_s-gd${LIB_SUFFIX})
endif()

# Handle copyright
file(COPY ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/flann)
file(RENAME ${CURRENT_PACKAGES_DIR}/share/flann/COPYING ${CURRENT_PACKAGES_DIR}/share/flann/copyright)
Loading

0 comments on commit 69e86fd

Please sign in to comment.