From 0e971c4165ddf29ada55e2c8a93adc1e9ce93bf3 Mon Sep 17 00:00:00 2001 From: v4hn Date: Fri, 24 Jun 2016 13:38:18 +0200 Subject: [PATCH] add option to disable octomap in build This is a quasi-standard pattern to allow users to test the library without its optional-dependency even if the dependency is available. --- CMakeLists.txt | 54 ++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3370573b7..d256457e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,32 +66,38 @@ endif() # Find Octomap (optional) find_package(PkgConfig QUIET) + +option(WITH_OCTOMAP "octomap library support" TRUE) set(FCL_HAVE_OCTOMAP 0) -if(PKG_CONFIG_FOUND) - pkg_check_modules(OCTOMAP QUIET octomap) -endif() -if(NOT OCTOMAP_FOUND) - # if pkfconfig is not installed, then fall back on more fragile detection - # of octomap - find_path(OCTOMAP_INCLUDE_DIRS octomap.h - PATH_SUFFIXES octomap) - find_library(OCTOMAP_LIBRARY_DIRS - ${CMAKE_SHARED_LIBRARY_PREFIX}octomap${CMAKE_SHARED_LIBRARY_SUFFIX}) - if(OCTOMAP_INCLUDE_DIRS AND OCTOMAP_LIBRARY_DIRS) - set(OCTOMAP_LIBRARIES "octomap;octomath") - endif() -endif() -if (OCTOMAP_FOUND OR (OCTOMAP_INCLUDE_DIRS AND OCTOMAP_LIBRARY_DIRS)) - string(REPLACE "." ";" VERSION_LIST ${OCTOMAP_VERSION}) - list(GET VERSION_LIST 0 OCTOMAP_MAJOR_VERSION) - list(GET VERSION_LIST 1 OCTOMAP_MINOR_VERSION) - list(GET VERSION_LIST 2 OCTOMAP_PATCH_VERSION) - include_directories(${OCTOMAP_INCLUDE_DIRS}) - link_directories(${OCTOMAP_LIBRARY_DIRS}) - set(FCL_HAVE_OCTOMAP 1) - message(STATUS "FCL uses Octomap") +if(WITH_OCTOMAP) + if(PKG_CONFIG_FOUND) + pkg_check_modules(OCTOMAP QUIET octomap) + endif() + if(NOT OCTOMAP_FOUND) + # if pkgconfig is not installed, then fall back on more fragile detection + # of octomap + find_path(OCTOMAP_INCLUDE_DIRS octomap.h + PATH_SUFFIXES octomap) + find_library(OCTOMAP_LIBRARY_DIRS + ${CMAKE_SHARED_LIBRARY_PREFIX}octomap${CMAKE_SHARED_LIBRARY_SUFFIX}) + if(OCTOMAP_INCLUDE_DIRS AND OCTOMAP_LIBRARY_DIRS) + set(OCTOMAP_LIBRARIES "octomap;octomath") + endif() + endif() + if (OCTOMAP_FOUND OR (OCTOMAP_INCLUDE_DIRS AND OCTOMAP_LIBRARY_DIRS)) + string(REPLACE "." ";" VERSION_LIST ${OCTOMAP_VERSION}) + list(GET VERSION_LIST 0 OCTOMAP_MAJOR_VERSION) + list(GET VERSION_LIST 1 OCTOMAP_MINOR_VERSION) + list(GET VERSION_LIST 2 OCTOMAP_PATCH_VERSION) + include_directories(${OCTOMAP_INCLUDE_DIRS}) + link_directories(${OCTOMAP_LIBRARY_DIRS}) + set(FCL_HAVE_OCTOMAP 1) + message(STATUS "FCL uses Octomap") + else() + message(STATUS "FCL does not use Octomap") + endif() else() - message(STATUS "FCL does not use Octomap") + message(STATUS "FCL does not use Octomap (as requested)") endif()