CMake Error at CMakeLists.txt:24

问题:CMake Error at CMakeLists.txt:24 (add_subdirectory):
add_subdirectory given source "gtest" which is not an existing directory.

解答:

Cmake < 3.11 doesn't support add_library without any source file, but flann CMake use a trick that use an empty string "" as source list (i.e add_library(foo SHARED "")).
The existing flann Cmake code violates the new behavior of add_library() for Cmake>=3.11.
buildroot/buildroot@45a39b3

It turns out in Cmake 3.11, "add_library()" and "add_executable()" commands can be called without any sources and won't complain as long as sources are added later via "target_sources()" command.
https://blog.kitware.com/cmake-3-11-0-available-for-download/

Fix is proposed here:
mariusmuja/flann#369
The proposed solution is
(1)create a file named "empty.cpp" under flann/src/cpp/
(2)change several lines in CMakeLists.txt under flann/src/cpp/CMakeList:
line 32: add_library(flann_cpp SHARED "empty.cpp")
line 44: add_library(flann_cpp SHARED empty.cpp ${CPP_SOURCES})
line 86: add_library(flann SHARED "empty.cpp")
line 90: add_library(flann SHARED empty.cpp ${C_SOURCES})

你可能感兴趣的:(C++)