xref: /OK3568_Linux_fs/buildroot/package/flann/0001-src-cpp-fix-cmake-3.11-build.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1From fa5ec96a94646492a3f908e12905b3e48a8e800b Mon Sep 17 00:00:00 2001
2From: Romain Naour <romain.naour@gmail.com>
3Date: Wed, 18 Apr 2018 20:24:13 +0200
4Subject: [PATCH] src/cpp: fix cmake >= 3.11 build
5
6CMake < 3.11 doesn't support add_library() without any source file
7(i.e add_library(foo SHARED)). But flann CMake use a trick that use
8an empty string "" as source list (i.e add_library(foo SHARED "")).
9This look like a bug in CMake < 3.11.
10
11With CMake >= 3.11, the new behaviour of add_library() break the
12existing flann CMake code.
13
14From CMake Changelog [1]:
15"add_library() and add_executable() commands can now be called without
16 any sources and will not complain as long as sources are added later
17 via the target_sources() command."
18
19Note: flann CMake code doesn't use target_sources() since no source file
20are provided intentionally since the flann shared library is created by
21linking with the flann_cpp_s static library with this line:
22
23target_link_libraries(flann_cpp -Wl,-whole-archive flann_cpp_s -Wl,-no-whole-archive)
24
25If you try to use "add_library(flann_cpp SHARED ${CPP_SOURCES})" (as it should
26be normally done), the link fail due to already defined symbol.
27
28They are building the shared version using the static library "to speedup the
29build time" [3]
30
31This issue is already reported upstream [2] with a proposed solution.
32
33Upstream status: Pending
34
35Fixes:
36http://autobuild.buildroot.net/results/b2f/b2febfaf8c44ce477b3e4a5b9b976fd25e8d7454
37
38[1] https://cmake.org/cmake/help/v3.11/release/3.11.html
39[2] https://github.com/mariusmuja/flann/issues/369
40[3] https://github.com/mariusmuja/flann/commit/0fd62b43be2fbb0b8d791ee36290791224dc030c
41
42Signed-off-by: Romain Naour <romain.naour@gmail.com>
43---
44 src/cpp/CMakeLists.txt | 4 ++--
45 src/cpp/empty.cpp      | 1 +
46 2 files changed, 3 insertions(+), 2 deletions(-)
47 create mode 100644 src/cpp/empty.cpp
48
49diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt
50index b44a735..a816863 100644
51--- a/src/cpp/CMakeLists.txt
52+++ b/src/cpp/CMakeLists.txt
53@@ -29,7 +29,7 @@ if (BUILD_CUDA_LIB)
54 endif()
55
56 if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_COMPILER_IS_GNUCC)
57-    add_library(flann_cpp SHARED "")
58+    add_library(flann_cpp SHARED "empty.cpp")
59     set_target_properties(flann_cpp PROPERTIES LINKER_LANGUAGE CXX)
60     target_link_libraries(flann_cpp -Wl,-whole-archive flann_cpp_s -Wl,-no-whole-archive)
61
62@@ -85,7 +85,7 @@ if (BUILD_C_BINDINGS)
63     set_property(TARGET flann_s PROPERTY COMPILE_DEFINITIONS FLANN_STATIC)
64
65     if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_COMPILER_IS_GNUCC)
66-        add_library(flann SHARED "")
67+        add_library(flann SHARED "empty.cpp")
68         set_target_properties(flann PROPERTIES LINKER_LANGUAGE CXX)
69         target_link_libraries(flann -Wl,-whole-archive flann_s -Wl,-no-whole-archive)
70     else()
71diff --git a/src/cpp/empty.cpp b/src/cpp/empty.cpp
72new file mode 100644
73index 0000000..40a8c17
74--- /dev/null
75+++ b/src/cpp/empty.cpp
76@@ -0,0 +1 @@
77+/* empty */
78--
792.14.3
80
81