From bef40ad2dd85beba55969b16c62adab2f0f94e79 Mon Sep 17 00:00:00 2001 From: Pablo Vela Date: Thu, 14 Nov 2024 13:24:56 +0800 Subject: [PATCH] Rework openvdb support options for beluga Signed-off-by: Pablo Vela --- beluga/CMakeLists.txt | 45 ++++++++++++++++++++++++++------ beluga/cmake/Config.cmake.in | 4 --- beluga/include/beluga/sensor.hpp | 2 +- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/beluga/CMakeLists.txt b/beluga/CMakeLists.txt index 242f2d5dc..17372d9f6 100644 --- a/beluga/CMakeLists.txt +++ b/beluga/CMakeLists.txt @@ -18,6 +18,14 @@ project(beluga VERSION 1.0) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +option( + USE_OPENVDB + "Compiles with OpenVDB, required for the 3D likelihood field sensor model" + Off) +set(OPENVDB_CMAKE_MODULE_PATH + ${OPENVDB_CMAKE_MODULE_PATH} + CACHE PATH "Path to OpenVDB CMake module") + if(NOT CMAKE_BUILD_TYPE) message(STATUS "Setting build type to 'Release' as none was specified.") set(CMAKE_BUILD_TYPE @@ -48,11 +56,31 @@ find_package(range-v3 REQUIRED) find_package(Sophus REQUIRED) find_package(TBB REQUIRED) -list(APPEND CMAKE_MODULE_PATH "/usr/lib/x86_64-linux-gnu/cmake/OpenVDB/") -list(APPEND CMAKE_MODULE_PATH "/usr/lib/aarch64-linux-gnu/cmake/OpenVDB") -find_package(OpenVDB QUIET) -if(OpenVDB_FOUND) - add_definitions(-USE_OPENVDB) +# If USE_OPENVDB is enabled, proceed with finding OpenVDB +if(USE_OPENVDB) + if(NOT OPENVDB_CMAKE_MODULE_PATH) + find_file( + OPENVDB_MODULE_PATH FindOpenVDB.cmake + PATHS /usr/lib/x86_64-linux-gnu/cmake/OpenVDB/ + /usr/lib/aarch64-linux-gnu/cmake/OpenVDB/ + NO_DEFAULT_PATH) + else() + find_file(OPENVDB_MODULE_PATH FindOpenVDB.cmake + PATHS ${OPENVDB_CMAKE_MODULE_PATH}) + endif() + + if(OPENVDB_MODULE_PATH) + get_filename_component(OPENVDB_CMAKE_MODULE_PATH ${OPENVDB_MODULE_PATH} + DIRECTORY) + message(STATUS "Found OpenVDB CMake module at ${OPENVDB_CMAKE_MODULE_PATH}") + list(APPEND CMAKE_MODULE_PATH ${OPENVDB_CMAKE_MODULE_PATH}) + find_package(Boost REQUIRED) + find_package(OpenVDB REQUIRED) + else() + message(FATAL_ERROR "FindOpenVDB.cmake not found in the speficied paths.") + endif() +else() + message(STATUS "USE_OPENVDB is Off, skipping OpenVDB setup.") endif() add_library(${PROJECT_NAME} INTERFACE) @@ -68,10 +96,11 @@ target_link_libraries( Sophus::Sophus TBB::tbb range-v3::range-v3 - $,OpenVDB::openvdb,>) + $,OpenVDB::openvdb,>) target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17) -target_compile_definitions(${PROJECT_NAME} INTERFACE EIGEN_NO_DEBUG - SOPHUS_USE_BASIC_LOGGING) +target_compile_definitions( + ${PROJECT_NAME} INTERFACE EIGEN_NO_DEBUG SOPHUS_USE_BASIC_LOGGING + $<$:BELUGA_OPENVDB_SUPPORT>) add_executable(clang_tidy_findable) target_sources(clang_tidy_findable PRIVATE src/clang_tidy_findable.cpp) diff --git a/beluga/cmake/Config.cmake.in b/beluga/cmake/Config.cmake.in index fdc510bec..8d7b0e44f 100644 --- a/beluga/cmake/Config.cmake.in +++ b/beluga/cmake/Config.cmake.in @@ -1,15 +1,11 @@ @PACKAGE_INIT@ -list(APPEND CMAKE_MODULE_PATH "/usr/lib/x86_64-linux-gnu/cmake/OpenVDB/") -list(APPEND CMAKE_MODULE_PATH "/usr/lib/aarch64-linux-gnu/cmake/OpenVDB") - include(CMakeFindDependencyMacro) find_dependency(Eigen3 REQUIRED NO_MODULE) find_dependency(range-v3 REQUIRED) find_dependency(HDF5 COMPONENTS CXX REQUIRED) find_dependency(Sophus REQUIRED) find_dependency(TBB REQUIRED) -find_dependency(OpenVDB REQUIRED) include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") diff --git a/beluga/include/beluga/sensor.hpp b/beluga/include/beluga/sensor.hpp index ca6fa507e..39dfeabf5 100644 --- a/beluga/include/beluga/sensor.hpp +++ b/beluga/include/beluga/sensor.hpp @@ -66,7 +66,7 @@ #include #include -#ifdef USE_OPENVDB +#ifdef BELUGA_OPENVDB_SUPPORT #include #endif