octovis library linking
LukeXH opened this issue · 0 comments
LukeXH commented
When trying to leverage the octovis API, it's not enough to just put in your CMakeLists.txt:
find_package(octovis)
.
.
.
add_executable( <executable name> <src files...>)
target_include_directories(<executable name> BEFORE PUBLIC ${OCTOVIS_INCLUDE_DIRS})
target_link_libraries(<executable name> ${OCTOVIS_LIBRARIES})
Because then cmake throws an error claiming it cannot find any of the associated Qt5 libraries
CMake Error at CMakeLists.txt:54 (add_executable):
Target "CreateEOG" links to target "Qt5::Core" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at CMakeLists.txt:54 (add_executable):
Target "CreateEOG" links to target "Qt5::Gui" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?
CMake Error at CMakeLists.txt:54 (add_executable):
Target "CreateEOG" links to target "Qt5::OpenGL" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at CMakeLists.txt:54 (add_executable):
Target "CreateEOG" links to target "Qt5::Widgets" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at CMakeLists.txt:54 (add_executable):
Target "CreateEOG" links to target "Qt5::Xml" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?
which results in a build error of:
/home/lhill/Apps/octomap/octovis/include/octovis/SceneObject.h:29:10: fatal error: qglobal.h: No such file or directory
29 | #include <qglobal.h>
| ^~~~~~~~~~~
compilation terminated.
This issue can be fixed on an individual basis by adding the find_package()
calls for each of the Qt5 packages above, resulting in:
find_package(octovis)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5OpenGL REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Xml REQUIRED)
.
.
.
add_executable( <executable name> <src files...>)
target_include_directories(<executable name> BEFORE PUBLIC ${OCTOVIS_INCLUDE_DIRS})
target_link_libraries(<executable name> ${OCTOVIS_LIBRARIES})
A more general solution would be to add the find_package calls for Qt5 to the octovis package via something like editing the octovis-config.cmake.in to looks something like:
# It defines the following variables
# OCTOVIS_INCLUDE_DIRS - include directories for OctoMap viewer
# OCTOVIS_LIBRARY_DIRS - library directories for OctoMap viewer
# OCTOVIS_LIBRARIES - libraries to link against
# OCTOVIS_MAJOR_VERSION - major version
# OCTOVIS_MINOR_VERSION - minor version
# OCTOVIS_PATCH_VERSION - patch version
# OCTOVIS_VERSION - major.minor.patch version
@PACKAGE_INIT@
set(OCTOVIS_MAJOR_VERSION "@OCTOVIS_MAJOR_VERSION@")
set(OCTOVIS_MINOR_VERSION "@OCTOVIS_MINOR_VERSION@")
set(OCTOVIS_PATCH_VERSION "@OCTOVIS_PATCH_VERSION@")
set(OCTOVIS_VERSION "@OCTOVIS_VERSION@")
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5OpenGL REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Xml REQUIRED)
set_and_check(OCTOVIS_INCLUDE_DIRS "@PACKAGE_OCTOVIS_INCLUDE_DIRS@" "@QGLViewer_INCLUDE_DIR@")
set_and_check(OCTOVIS_LIBRARY_DIRS "@PACKAGE_OCTOVIS_LIB_DIR@" "@QGLViewer_LIBRARY_DIR@")
# Set library names as absolute paths:
set(OCTOVIS_LIBRARIES
"@QGLViewer_LIBRARIES@"
"@QT_LIBRARIES@"
"@PACKAGE_OCTOVIS_LIB_DIR@/@OCTOVIS_LIBRARY@"
)
@OCTOVIS_INCLUDE_TARGETS@
Better solutions may exist.