Skip to content

Commit

Permalink
added CMake package / module config for external projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Armin Hornung committed Jul 25, 2011
1 parent 52f22cd commit 7684acb
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 36 deletions.
73 changes: 38 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PROJECT( octomap )
set(OCTOMAP_MAJOR_VERSION 1)
set(OCTOMAP_MINOR_VERSION 1)
set(OCTOMAP_PATCH_VERSION 0)

set(OCTOMAP_VERSION ${OCTOMAP_MAJOR_VERSION}.${OCTOMAP_MINOR_VERSION}.${OCTOMAP_PATCH_VERSION})
# get rid of a useless warning:
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
Expand All @@ -15,6 +15,7 @@ endif(COMMAND cmake_policy)
INCLUDE(CMakeModules/CompilerSettings.cmake)

#If we are compiling with ROS support, we need to get the appropriate includes and link flags and such
# (thx to E.Perko for patch!)
if(WITH_ROS)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
set(ROSBUILD_DONT_REDEFINE_PROJECT true)
Expand Down Expand Up @@ -60,6 +61,40 @@ install(FILES ${octomap_HDRS} DESTINATION include/octomap)
file(GLOB octomap_math_HDRS ${CMAKE_SOURCE_DIR}/include/octomap/math/*.h)
install(FILES ${octomap_math_HDRS} DESTINATION include/octomap/math)

# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
export(PACKAGE octomap)

# Create a octomap-config.cmake file for the use from the build tree
set(OCTOMAP_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/include")
set(OCTOMAP_LIB_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
# not used right now (export depends?)
#set(OCTOMAP_CMAKE_DIR "${PROJECT_BINARY_DIR}")
configure_file(octomap-config.cmake.in
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/octomap/octomap-config.cmake" @ONLY)
configure_file(octomap-config-version.cmake.in
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/octomap/octomap-config-version.cmake" @ONLY)

# Install the export set for use with the install-tree
#install(EXPORT FooBarLibraryDepends DESTINATION
# "${INSTALL_DATA_DIR}/FooBar/CMake"
# COMPONENT dev)

# Create a octomap-config.cmake file for the use from the install tree
# and install it
set(OCTOMAP_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include")
set(OCTOMAP_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
#set(OCTOMAP_CMAKE_DIR "${INSTALL_DATA_DIR}/FooBar/CMake")
configure_file(octomap-config.cmake.in
"${PROJECT_BINARY_DIR}/InstallFiles/octomap-config.cmake" @ONLY)
configure_file(octomap-config-version.cmake.in
"${PROJECT_BINARY_DIR}/InstallFiles/octomap-config-version.cmake" @ONLY)
install(FILES
"${PROJECT_BINARY_DIR}/InstallFiles/octomap-config.cmake"
"${PROJECT_BINARY_DIR}/InstallFiles/octomap-config-version.cmake"
DESTINATION lib/cmake/octomap/)



# Documentation
FIND_PACKAGE(Doxygen)
Expand All @@ -69,40 +104,8 @@ IF(DOXYGEN_FOUND)
COMMENT "Generating documentation (Doxygen)...")
ENDIF(DOXYGEN_FOUND)


SET( BUILD_VIEWER 0)

FIND_PACKAGE(OpenGL)
IF(NOT OPENGL_FOUND)
MESSAGE ( "\n")
MESSAGE ( "OpenGL not found. \n")
ELSE()
MESSAGE (STATUS "OpenGL found at ${OPENGL_LIBRARY}")

# Look for Qt4
FIND_PACKAGE(Qt4)
IF(QT4_FOUND)
FIND_PACKAGE(QGLViewer)
IF(QGLViewer_FOUND)
SET( BUILD_VIEWER 1)
ELSE()
MESSAGE ( "\n")
MESSAGE ( "libQGLViewer could not be found or generated.")
ENDIF()
ELSE()
MESSAGE ( "\n")
MESSAGE ( "Qt4 development environment could not be found.")
ENDIF()
ENDIF()

IF(BUILD_VIEWER)
MESSAGE(STATUS "\n")
MESSAGE(STATUS "viewer octovis will be built")
ADD_SUBDIRECTORY( src/octovis )
ELSE()
MESSAGE ( "Unfortunately, the viewer (octovis) can not be built because some requirements are missing.")
MESSAGE ( "See README.txt or http://octomap.sf.net for further information.\n")
ENDIF()
# Build viewer if available:
INCLUDE(CMakeModules/BuildGLViewer.cmake)

# Needs to be last statement:
INCLUDE(CMakeModules/CPackSettings.cmake)
Expand Down
34 changes: 34 additions & 0 deletions CMakeModules/BuildGLViewer.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Builds the "octovis" viewer based on OpenGL and libQGLViewer, if dependencies available
SET( BUILD_VIEWER 0)

FIND_PACKAGE(OpenGL)
IF(NOT OPENGL_FOUND)
MESSAGE ( "\n")
MESSAGE ( "OpenGL not found. \n")
ELSE()
MESSAGE (STATUS "OpenGL found at ${OPENGL_LIBRARY}")

# Look for Qt4
FIND_PACKAGE(Qt4)
IF(QT4_FOUND)
FIND_PACKAGE(QGLViewer)
IF(QGLViewer_FOUND)
SET( BUILD_VIEWER 1)
ELSE()
MESSAGE ( "\n")
MESSAGE ( "libQGLViewer could not be found or generated.")
ENDIF()
ELSE()
MESSAGE ( "\n")
MESSAGE ( "Qt4 development environment could not be found.")
ENDIF()
ENDIF()

IF(BUILD_VIEWER)
MESSAGE(STATUS "\n")
MESSAGE(STATUS "viewer octovis will be built")
ADD_SUBDIRECTORY( src/octovis )
ELSE()
MESSAGE ( "Unfortunately, the viewer (octovis) can not be built because some requirements are missing.")
MESSAGE ( "See README.txt or http://octomap.sf.net for further information.\n")
ENDIF()
2 changes: 1 addition & 1 deletion CMakeModules/CPackSettings.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Package building stuff - Experimental!
SET(CPACK_PACKAGE_VERSION "${OCTOMAP_MAJOR_VERSION}.${OCTOMAP_MINOR_VERSION}.${OCTOMAP_PATCH_VERSION}")
SET(CPACK_PACKAGE_VERSION "${OCTOMAP_VERSION}")
SET(CPACK_PACKAGE_VERSION_MAJOR "${OCTOMAP_MAJOR_VERSION}")
SET(CPACK_PACKAGE_VERSION_MINOR "${OCTOMAP_MINOR_VERSION}")
SET(CPACK_PACKAGE_VERSION_PATCH "${OCTOMAP_PATCH_VERSION}")
Expand Down
11 changes: 11 additions & 0 deletions octomap-config-version.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(PACKAGE_VERSION "@OCTOMAP_VERSION@")

# Check whether the requested PACKAGE_FIND_VERSION is compatible
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
17 changes: 17 additions & 0 deletions octomap-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# - Config file for the OctoMap package
# (example from http://www.vtk.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file)
# It defines the following variables
# OCTOMAP_INCLUDE_DIRS - include directories for OctoMap
# OCTOMAP_LIBRARY_DIRS - library directories for OctoMap (normally not used!)
# OCTOMAP_LIBRARIES - libraries to link against

# Tell the user project where to find our headers and libraries
set(OCTOMAP_INCLUDE_DIRS "@OCTOMAP_INCLUDE_DIRS@")
set(OCTOMAP_LIBRARY_DIRS "@OCTOMAP_LIB_DIR@")

# Our library dependencies (contains definitions for IMPORTED targets)
# include("@FOOBAR_CMAKE_DIR@/FooBarLibraryDepends.cmake")

set(OCTOMAP_LIBRARIES octomap octomath)

#set(FOOBAR_EXECUTABLE bar)

0 comments on commit 7684acb

Please sign in to comment.