Reputation: 125
On macOS 11.0, I downloaded and built g2o (https://github.com/RainerKuemmerle/g2o) and installed it using cmake --install .
I then tried to include it in my own project via CMake like this (CMakeLists.txt):
cmake_minimum_required (VERSION 3.14)
project (MY-PROJECT)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# PkgConfig to find other packages easily
find_package(PkgConfig REQUIRED)
# find required modules
pkg_check_modules(OpenCV REQUIRED opencv4)
find_package(Eigen3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(G2O REQUIRED)
message(STATUS "G2O FOUND: ")
message(STATUS ${G2O_FOUND}) # prints 1
message(STATUS "G2O INCLUDE DIRS: ")
message(STATUS ${G2O_INCLUDE_DIRS}) # prints nothing
message(STATUS "G2O Link Libraries: ")
message(STATUS ${G2O_LINK_LIBRARIES}) # prints nothing
message(STATUS "EIGEN3 INCLUDE DIRS: ")
message(STATUS ${EIGEN3_INCLUDE_DIRS}) # prints /usr/local/include/eigen3
CMake sets G2O_FOUND
to 1, indicating that it successfully found g2o. However, the other two variables are not set, so the include- and library-files are not found. I solved this by adding
set(G2O_INCLUDE_DIRS
/usr/local/include)
set(G2O_LIBS
/usr/local/lib/libg2o_core.dylib
/usr/local/lib/libg2o_types_slam3d.dylib
#...
)
include_directories(
G2O_INCLUDE_DIRS
)
target_link_libraries(
MY-PROJECT
${G2O_LIBS}
)
to CMakeLists.txt, but I am still curious why CMake did find g2o but not set the variables accordingly.
Upvotes: 0
Views: 1289
Reputation: 141688
why CMake did find g2o but not set the variables accordingly.
FindG2O.cmake does not set these variables, so they are not set. The variables checked for G2O_FOUND
to be set are G2O_STUFF_LIBRARY AND G2O_CORE_LIBRARY AND G2O_INCLUDE_DIR AND G2O_SOLVERS_FOUND
.
There is no rule that find_package
has to set _LIBRARIES
or _INCLUDE_DIRS
variables - every package is a little different, consult that particular package. If writing FindXXX
file, use interface or imported libraries instead of variables.
Upvotes: 1