Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simpler QGLViewer detection #281

Open
wants to merge 4 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dynamicEDT3D/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ install(FILES
include(InstallPkgConfigFile)
install_pkg_config_file(dynamicEDT3D
CFLAGS
LIBS -ldynamicEDT3D
LIBS -ldynamicedt3d
REQUIRES
VERSION ${DYNAMICEDT3D_VERSION})

Expand Down
161 changes: 69 additions & 92 deletions octovis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,107 +60,84 @@ set(INSTALL_TARGETS_DEFAULT_ARGS
ARCHIVE DESTINATION lib
)

# Builds the "octovis" viewer based on OpenGL and
# libQGLViewer, if dependencies available
SET( BUILD_VIEWER 0)

option(OCTOVIS_QT5 "Link Octovis against Qt5?" ON)

# Look for required libraries:
FIND_PACKAGE(OpenGL)
FIND_PACKAGE(OpenGL REQUIRED)
if(NOT OCTOVIS_QT5)
FIND_PACKAGE(Qt4)
FIND_PACKAGE(Qt4 REQUIRED)
endif(NOT OCTOVIS_QT5)

IF (OpenGL-NOTFOUND OR Qt4-NOTFOUND)
MESSAGE ( "OpenGL and QT4 are required for octovis but could not be found.")
ELSE()
FIND_PACKAGE(QGLViewer)
IF(QGLViewer_FOUND)
SET( BUILD_VIEWER 1)
ELSE()
MESSAGE ( "\n")
MESSAGE ( "libQGLViewer could not be found or generated.")
ENDIF()
ENDIF()
FIND_PACKAGE(QGLViewer REQUIRED)

MESSAGE(STATUS "\n")
MESSAGE(STATUS "viewer octovis will be built")

IF(BUILD_VIEWER)
MESSAGE(STATUS "\n")
MESSAGE(STATUS "viewer octovis will be built")

set(INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include")
INCLUDE_DIRECTORIES(${INCLUDE_DIRS})

INCLUDE( CMakeLists_src.txt )

# Create an octovis-config.cmake file for the use from the build tree
set(OCTOVIS_INCLUDE_DIRS "${INCLUDE_DIRS}")
set(OCTOVIS_LIB_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
# Set library names as absolute paths
# Windows, spec. MSVC requires the .lib suffix for imported libs
IF(WIN32)
set(OCTOVIS_LIBRARY
"${CMAKE_IMPORT_LIBRARY_PREFIX}octovis${CMAKE_IMPORT_LIBRARY_SUFFIX}"
)
ELSE()
set(OCTOVIS_LIBRARY
"${CMAKE_SHARED_LIBRARY_PREFIX}octovis${CMAKE_SHARED_LIBRARY_SUFFIX}"
)
ENDIF()

include(CMakePackageConfigHelpers)

CONFIGURE_PACKAGE_CONFIG_FILE(
octovis-config.cmake.in
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/octovis/octovis-config.cmake"
PATH_VARS OCTOVIS_INCLUDE_DIRS OCTOVIS_LIB_DIR
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/share/octovis)

WRITE_BASIC_PACKAGE_VERSION_FILE(
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/octovis/octovis-config-version.cmake"
VERSION ${OCTOVIS_VERSION}
COMPATIBILITY AnyNewerVersion)

# not used right now (export depends?)
#set(OCTOMAP_CMAKE_DIR "${PROJECT_BINARY_DIR}")

# Create a octovis-config.cmake file for the use from the install tree
# and install it
set(OCTOVIS_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include")
set(OCTOVIS_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
#set(OCTOMAP_CMAKE_DIR "${INSTALL_DATA_DIR}/FooBar/CMake")

set(OCTOVIS_INCLUDE_TARGETS
"include(\${CMAKE_CURRENT_LIST_DIR}/octovis-targets.cmake)")

CONFIGURE_PACKAGE_CONFIG_FILE(
octovis-config.cmake.in
"${PROJECT_BINARY_DIR}/InstallFiles/octovis-config.cmake"
PATH_VARS OCTOVIS_INCLUDE_DIRS OCTOVIS_LIB_DIR
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/share/octovis)

WRITE_BASIC_PACKAGE_VERSION_FILE(
"${PROJECT_BINARY_DIR}/InstallFiles/octovis-config-version.cmake"
VERSION ${OCTOVIS_VERSION}
COMPATIBILITY AnyNewerVersion)

install(FILES
"${PROJECT_BINARY_DIR}/InstallFiles/octovis-config.cmake"
"${PROJECT_BINARY_DIR}/InstallFiles/octovis-config-version.cmake"
DESTINATION share/octovis/)

# #installation:
# # store all header files to install:
file(GLOB octovis_HDRS *.h *.hxx *.hpp)
install(FILES ${octovis_HDRS} DESTINATION include/octovis)

# Install catkin package.xml
install(FILES package.xml DESTINATION share/octovis)
set(INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include")
INCLUDE_DIRECTORIES(${INCLUDE_DIRS})

INCLUDE( CMakeLists_src.txt )

# Create an octovis-config.cmake file for the use from the build tree
set(OCTOVIS_INCLUDE_DIRS "${INCLUDE_DIRS}")
set(OCTOVIS_LIB_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
# Set library names as absolute paths
# Windows, spec. MSVC requires the .lib suffix for imported libs
IF(WIN32)
set(OCTOVIS_LIBRARY
"${CMAKE_IMPORT_LIBRARY_PREFIX}octovis${CMAKE_IMPORT_LIBRARY_SUFFIX}"
)
ELSE()
MESSAGE ( "Unfortunately, the viewer (octovis) can not be built because some requirements are missing.")
MESSAGE ( "This will not affect the compilation of the stand-alone library and tools (octomap)")
MESSAGE ( "See README.txt or http://octomap.sf.net for further information.\n")
set(OCTOVIS_LIBRARY
"${CMAKE_SHARED_LIBRARY_PREFIX}octovis${CMAKE_SHARED_LIBRARY_SUFFIX}"
)
ENDIF()

include(CMakePackageConfigHelpers)

CONFIGURE_PACKAGE_CONFIG_FILE(
octovis-config.cmake.in
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/octovis/octovis-config.cmake"
PATH_VARS OCTOVIS_INCLUDE_DIRS OCTOVIS_LIB_DIR
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/share/octovis)

WRITE_BASIC_PACKAGE_VERSION_FILE(
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/octovis/octovis-config-version.cmake"
VERSION ${OCTOVIS_VERSION}
COMPATIBILITY AnyNewerVersion)

# not used right now (export depends?)
#set(OCTOMAP_CMAKE_DIR "${PROJECT_BINARY_DIR}")

# Create a octovis-config.cmake file for the use from the install tree
# and install it
set(OCTOVIS_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include")
set(OCTOVIS_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
#set(OCTOMAP_CMAKE_DIR "${INSTALL_DATA_DIR}/FooBar/CMake")

set(OCTOVIS_INCLUDE_TARGETS
"include(\${CMAKE_CURRENT_LIST_DIR}/octovis-targets.cmake)")

CONFIGURE_PACKAGE_CONFIG_FILE(
octovis-config.cmake.in
"${PROJECT_BINARY_DIR}/InstallFiles/octovis-config.cmake"
PATH_VARS OCTOVIS_INCLUDE_DIRS OCTOVIS_LIB_DIR
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/share/octovis)

WRITE_BASIC_PACKAGE_VERSION_FILE(
"${PROJECT_BINARY_DIR}/InstallFiles/octovis-config-version.cmake"
VERSION ${OCTOVIS_VERSION}
COMPATIBILITY AnyNewerVersion)

install(FILES
"${PROJECT_BINARY_DIR}/InstallFiles/octovis-config.cmake"
"${PROJECT_BINARY_DIR}/InstallFiles/octovis-config-version.cmake"
DESTINATION share/octovis/)

# #installation:
# # store all header files to install:
file(GLOB octovis_HDRS *.h *.hxx *.hpp)
install(FILES ${octovis_HDRS} DESTINATION include/octovis)

# Install catkin package.xml
install(FILES package.xml DESTINATION share/octovis)
4 changes: 1 addition & 3 deletions octovis/CMakeLists_src.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ else(OCTOVIS_QT5)
QT4_ADD_RESOURCES(viewer_RES src/icons.qrc)
endif(OCTOVIS_QT5)

#found QGLViewer lib dir
link_directories(${QGLViewer_LIBRARY_DIR})

#found QGLViewer include dir
INCLUDE_DIRECTORIES(
${QGLViewer_INCLUDE_DIR}
)
Expand Down
129 changes: 12 additions & 117 deletions octovis/CMakeModules/FindQGLViewer.cmake
Original file line number Diff line number Diff line change
@@ -1,126 +1,21 @@
# Find QGLViewer library
# Looks for a system-wide version of libQGLViewer (qglviewer-qt4 or 5 in Ubuntu).
# If none is found, it builds and uses the local copy in "extern"
#
# Many thanks to L. Ott for assistance!
# Looks for a system-wide version of libQGLViewer.
#
# QGLViewer_INCLUDE_DIR where to find the include files
# QGLViewer_LIBRARY_DIR where to find the libraries
# QGLViewer_LIBRARIES list of libraries to link
# QGLViewer_FOUND true if QGLViewer was found

SET( QGLViewer_FOUND 0 CACHE BOOL "Do we have QGLViewer?" )

FIND_PATH( QGLVIEWER_BASE_DIR qglviewer.h
${CMAKE_SOURCE_DIR}/src/extern/QGLViewer
${CMAKE_SOURCE_DIR}/octovis/src/extern/QGLViewer
)

FIND_PATH( QGLViewer_INCLUDE_DIR qglviewer.h
/usr/include/qglviewer-qt4
/usr/include/QGLViewer
/opt/local/include/QGLViewer
${QGLVIEWER_BASE_DIR}
)

IF( QT4_FOUND )
FIND_LIBRARY( QGLViewer_LIBRARY_DIR_UBUNTU NAMES qglviewer-qt4 QGLViewer-qt4)
ELSE()
FIND_LIBRARY( QGLViewer_LIBRARY_DIR_UBUNTU NAMES qglviewer-qt5 QGLViewer-qt5)
ENDIF()
FIND_LIBRARY( QGLViewer_LIBRARY_DIR_WINDOWS QGLViewer2 ${QGLVIEWER_BASE_DIR})
FIND_LIBRARY( QGLViewer_LIBRARY_DIR_OTHER QGLViewer ${QGLVIEWER_BASE_DIR})

SET( BUILD_LIB_FROM_SOURCE 0)

IF( QGLViewer_INCLUDE_DIR )

MESSAGE(STATUS "QGLViewer includes found in ${QGLViewer_INCLUDE_DIR}")
IF (QGLViewer_LIBRARY_DIR_UBUNTU)
MESSAGE(STATUS "QGLViewer library found in ${QGLViewer_LIBRARY_DIR_UBUNTU}")
SET( QGLViewer_LIBRARIES ${QGLViewer_LIBRARY_DIR_UBUNTU})
SET( QGLViewer_FOUND 1 CACHE BOOL "Do we have QGLViewer?" FORCE )
ELSEIF(QGLViewer_LIBRARY_DIR_WINDOWS)
MESSAGE(STATUS "QGLViewer2 found in ${QGLViewer_LIBRARY_DIR_WINDOWS}")
SET( QGLViewer_LIBRARIES ${QGLViewer_LIBRARY_DIR_WINDOWS})
SET( QGLViewer_FOUND 1 CACHE BOOL "Do we have QGLViewer?" FORCE )
ELSEIF(QGLViewer_LIBRARY_DIR_OTHER)
MESSAGE(STATUS "QGLViewer found in ${QGLViewer_LIBRARY_DIR_OTHER}")
SET( QGLViewer_LIBRARIES ${QGLViewer_LIBRARY_DIR_OTHER})
SET( QGLViewer_FOUND 1 CACHE BOOL "Do we have QGLViewer?" FORCE )
ELSE()
MESSAGE(STATUS "QGLViewer library not found.")
SET( BUILD_LIB_FROM_SOURCE 1)
SET( QGLViewer_FOUND 0 CACHE BOOL "Do we have QGLViewer?" FORCE )
ENDIF()

ELSE()
SET( BUILD_LIB_FROM_SOURCE 1)
ENDIF()

# build own libQGLViewer
IF(BUILD_LIB_FROM_SOURCE)

IF (WIN32)
MESSAGE("Cannot generate QGLViewer2 from source automatically.")
MESSAGE("Please build libQGLViewer from source, instructions to do so")
MESSAGE("can be found in octovis/README.txt")
MESSAGE("Please rerun CMAKE when you are ready.")

ELSE (WIN32)
IF(QGLVIEWER_BASE_DIR)
MESSAGE(STATUS "Trying to build libQGLViewer from source in ${QGLVIEWER_BASE_DIR}")

FIND_PROGRAM(QMAKE-QT4 qmake-qt4)
IF (QMAKE-QT4)
MESSAGE(STATUS "\t generating Makefile using qmake-qt4")
EXECUTE_PROCESS(
WORKING_DIRECTORY ${QGLVIEWER_BASE_DIR}
COMMAND qmake-qt4
OUTPUT_QUIET
)
ELSE(QMAKE-QT4)
MESSAGE(STATUS "\t generating Makefile using qmake")
EXECUTE_PROCESS(
WORKING_DIRECTORY ${QGLVIEWER_BASE_DIR}
COMMAND qmake-qt4
OUTPUT_QUIET
)
ENDIF(QMAKE-QT4)

MESSAGE(STATUS "\t building library (this may take some time...)")
EXECUTE_PROCESS(
WORKING_DIRECTORY ${QGLVIEWER_BASE_DIR}
COMMAND make
OUTPUT_QUIET
)
ENDIF(QGLVIEWER_BASE_DIR)
ENDIF(WIN32)

ELSE(BUILD_LIB_FROM_SOURCE)
IF (NOT QGLViewer_FOUND)
MESSAGE(STATUS "QGLViewer sources NOT found. Exiting.")
ENDIF ()
ENDIF(BUILD_LIB_FROM_SOURCE)
find_path(QGLViewer_INCLUDE_DIR
NAMES qglviewer.h
PATH_SUFFIXES QGLViewer)

# verify that QGLViewer lib was build if we didnt find it elsewhere
IF (NOT QGLViewer_FOUND)
#FIND_LIBRARY(QGLViewer_LIBRARY_DIR_OTHER QGLViewer ${QGLVIEWER_BASE_DIR})
FIND_PATH(QGLLIB libQGLViewer.so ${QGLVIEWER_BASE_DIR})
IF (NOT QGLLIB)
MESSAGE(WARNING "Could not find libQGLViewer.so, failed to build?")
SET( QGLViewer_FOUND 0 CACHE BOOL "Do we have QGLViewer?" FORCE )
ELSE()
MESSAGE(STATUS "Successfully built library in:\n${QGLLIB}")
SET( QGLViewer_INCLUDE_DIR ${QGLVIEWER_BASE_DIR} CACHE PATH "QGLViewer Include directory" FORCE)
SET( QGLViewer_LIBRARY_DIR ${QGLVIEWER_BASE_DIR} CACHE PATH "QGLViewer Library directory" FORCE)
# TODO: also include "m pthread QGLViewerGen QGLViewerUtility"?
SET( QGLViewer_LIBRARIES QGLViewer)
SET( QGLViewer_FOUND 1 CACHE BOOL "Do we have QGLViewer?" FORCE )
ENDIF()
ENDIF()
find_library(QGLViewer_LIBRARIES
NAMES QGLViewer QGLViewer2 QGLViewer-qt5 QGLViewer-qt4)

# You need to use qmake of QT4. You are using QT3 if you get:
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
QGLViewer
DEFAULT_MSG
QGLViewer_LIBRARIES QGLViewer_INCLUDE_DIR)

#CMakeFiles/octovis.dir/ViewerWidget.cpp.o: In function `octomap::ViewerWidget::ViewerWidget(QWidget*)':
#ViewerWidget.cpp:(.text+0x1715): undefined reference to `QGLViewer::QGLViewer(QWidget*, QGLWidget const*, QFlags<Qt::WindowType>)'
mark_as_advanced(QGLViewer_INCLUDE_DIR QGLViewer_LIBRARIES)
30 changes: 12 additions & 18 deletions octovis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ Octovis is based on [QGLViewer](http://www.libqglviewer.com/), distributed under
(octovis/src/extern/QGLViewer/GPL_EXCEPTION).


LINUX
BUILD
-----

To compile the library you need:

* OpenGL
* cmake (http://www.cmake.org)
* Qt development environment
* QGLViewer

You can build octovis independently of octomap by following
the these steps:

Expand All @@ -28,17 +35,10 @@ the these steps:
You can manually set the location of the octomap library with the
`octomap_DIR` variable in CMake.

Note: If you get an error such as

> CMake Error at /usr/share/cmake-2.8/Modules/FindQt4.cmake:1148 (MESSAGE):
> Qt qmake not found!

but you have Qt4 installed, this probably means that both Qt3 and Qt4
are installed. In Ubuntu this can be resolved by executing:

sudo update-alternatives --config qmake

and choosing Qt4.
If you compiled QGLViewer on your own and CMake cannot find it,
you can use the variable `QGLViewer_INCLUDE_DIR` to specify
the header file location and `QGLViewer_LIBRARIES` to set
the library file to link against (e.g. libQGLViewer.so or QGLViewer.lib).


WINDOWS
Expand All @@ -48,12 +48,6 @@ The octomap viewer **octovis** can be compiled and used under
Windows although this has not been tested in-depth. Feedback
is welcome ("it works" is nice too :-))

To compile the library you need:

* OpenGL
* cmake (http://www.cmake.org)
* QT development environment (see below)


### MinGW ###

Expand Down
2 changes: 1 addition & 1 deletion octovis/octovis-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(OCTOVIS_PATCH_VERSION "@OCTOVIS_PATCH_VERSION@")
set(OCTOVIS_VERSION "@OCTOVIS_VERSION@")

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_and_check(OCTOVIS_LIBRARY_DIRS "@PACKAGE_OCTOVIS_LIB_DIR@")

# Set library names as absolute paths:
set(OCTOVIS_LIBRARIES
Expand Down