Skip to contentSkip to conversation

package/flann: fix build with cmake >= 3.11

PATCH New Romain Naour 2 participants 3 messages Apr 18, 2018 – Apr 20, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/flann: fix build with cmake >= 3.11

CMake 3.11 changed the behaviour of add_library() that break the existing flann CMake code.

From [1]:
"add_library() and add_executable() commands can now be called without
any sources and will not complain as long as sources are added later via the target_sources() command."

This issue is already reported upstream [2] with a proposed solution.

Fixes:
http://autobuild.buildroot.net/results/b2f/b2febfaf8c44ce477b3e4a5b9b976fd25e8d7454

[1] https://cmake.org/cmake/help/v3.11/release/3.11.html
[2] https://github.com/mariusmuja/flann/issues/369

Cc Davide Viti <[email protected]>
Cc Bernd Kuhls <[email protected]>
---
 .../flann/0001-src-cpp-fix-cmake-3.11-build.patch  | 48 ++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 package/flann/0001-src-cpp-fix-cmake-3.11-build.patch
package/flann/0001-src-cpp-fix-cmake-3.11-build.patch new file +48 -0
new file mode 100644
index 0000000000..5542c3cfc8
@@ -0,0 +1,48 @@
+From fa5ec96a94646492a3f908e12905b3e48a8e800b Mon Sep 17 00:00:00 2001
+From: Romain Naour <[email protected]>
+Date: Wed, 18 Apr 2018 20:24:13 +0200
+Subject: [PATCH] src/cpp: fix cmake >= 3.11 build
+
+Upstream status: Pending
+
+https://github.com/mariusmuja/flann/issues/369
+
+Signed-off-by: Romain Naour <[email protected]>
+---
+ src/cpp/CMakeLists.txt | 4 ++--
+ src/cpp/empty.cpp      | 1 +
+ 2 files changed, 3 insertions(+), 2 deletions(-)
+ create mode 100644 src/cpp/empty.cpp
+
+diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt
+index b44a735..a816863 100644
+--- a/src/cpp/CMakeLists.txt
++++ b/src/cpp/CMakeLists.txt
+@@ -29,7 +29,7 @@ if (BUILD_CUDA_LIB)
+ endif()
+ 
+ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_COMPILER_IS_GNUCC)
+-    add_library(flann_cpp SHARED "")
++    add_library(flann_cpp SHARED "empty.cpp")
+     set_target_properties(flann_cpp PROPERTIES LINKER_LANGUAGE CXX)
+     target_link_libraries(flann_cpp -Wl,-whole-archive flann_cpp_s -Wl,-no-whole-archive)
+ 
+@@ -85,7 +85,7 @@ if (BUILD_C_BINDINGS)
+     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 "")
++        add_library(flann SHARED "empty.cpp")
+         set_target_properties(flann PROPERTIES LINKER_LANGUAGE CXX)
+         target_link_libraries(flann -Wl,-whole-archive flann_s -Wl,-no-whole-archive)
+     else()
+diff --git a/src/cpp/empty.cpp b/src/cpp/empty.cpp
+new file mode 100644
+index 0000000..40a8c17
+--- /dev/null
++++ b/src/cpp/empty.cpp
+@@ -0,0 +1 @@
++/* empty */
+-- 
+2.14.3
+
Signature · 1 line
2.14.3
#1 lore raw

PATCH 1/1 package/flann: fix build with cmake >= 3.11

Hello Romain,

Quoted 4 lines · Romain Naour

From [1]:
"add_library() and add_executable() commands can now be called without
any sources and will not complain as long as sources are added later via the target_sources() command."

I must be misunderstanding something then. The code currently is:

add_library(flann_cpp SHARED "")

So it has no source code, and this works fine with CMake < 3.11. And you're saying that it's only in CMake >= 3.11 that having no source code is valid.

And you fix that by adding a dummy source code file. I'm totally confused here.

Also, why do they build a library with nothing inside ? Does it make sense ?

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

PATCH 1/1 package/flann: fix build with cmake >= 3.11

Hi Thomas,

Le 19/04/2018 ? 22:54, Thomas Petazzoni a ?crit?:

Quoted 9 lines

Hello Romain,

Quoted 4 lines · Romain Naour

From [1]:
"add_library() and add_executable() commands can now be called without
any sources and will not complain as long as sources are added later via the target_sources() command."

Quoted 7 lines

I must be misunderstanding something then. The code currently is:

add_library(flann_cpp SHARED "")

So it has no source code, and this works fine with CMake < 3.11. And you're saying that it's only in CMake >= 3.11 that having no source code is valid.

Well, it seems a bug in CMake < 3.11.

Quoted 3 lines

And you fix that by adding a dummy source code file. I'm totally confused here.

So do I. I don't understand how it can work with older CMake.

Quoted 2 lines

Also, why do they build a library with nothing inside ? Does it make sense ?

The library is created by linking with the flann_cpp_s static library with this line:

target_link_libraries(flann_cpp -Wl,-whole-archive flann_cpp_s -Wl,-no-whole-archive)

If you try to use "add_library(flann_cpp SHARED ${CPP_SOURCES})" (as it should be normally done), the link fail due to already defined symbol.

They are building the shared version using the static library "to speedup the build time":

https://github.com/mariusmuja/flann/commit/0fd62b43be2fbb0b8d791ee36290791224dc030c

Alpinelinux removed/commented retentively this part of the CMake code:
https://github.com/alpinelinux/aports/commit/fe5137a340af202cefe6b67601af0133b6b660bd

Best regards,
Romain

Quoted 5 lines

Thanks,

Thomas