diff --git a/CMakeLists.txt b/CMakeLists.txt index ddfc97997ee9c07271f8d55b3a7d53debe126252..115e02e188879f268464dcee247df566aeaf97f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,11 @@ SET(DOXYGEN_USE_TEMPLATE_CSS TRUE) # Need to be set before including base.cmake # ---------------------------------------------------- option(INSTALL_DOCUMENTATION "Generate and install the documentation" OFF) -option(HPP_FCL_TURN_ASSERT_INTO_EXCEPTION "turn some critical HPP-FCL asserts to exception." FALSE) +option(HPP_FCL_TURN_ASSERT_INTO_EXCEPTION "Turn some critical HPP-FCL asserts to exception." FALSE) +option(HPP_FCL_ENABLE_LOGGING "Activate logging for warnings or error messages. Turned on by default in Debug." FALSE) +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(HPP_FCL_ENABLE_LOGGING TRUE) +endif() # Check if the submodule cmake have been initialized set(JRL_CMAKE_MODULES "${CMAKE_CURRENT_LIST_DIR}/cmake") @@ -116,8 +120,14 @@ SET_BOOST_DEFAULT_OPTIONS() EXPORT_BOOST_DEFAULT_OPTIONS() IF(WIN32) ADD_PROJECT_DEPENDENCY(Boost REQUIRED COMPONENTS chrono thread date_time serialization filesystem) + if (HPP_FCL_ENABLE_LOGGING) + ADD_PROJECT_DEPENDENCY(Boost REQUIRED COMPONENTS log) + endif() ELSE(WIN32) ADD_PROJECT_DEPENDENCY(Boost REQUIRED chrono serialization filesystem) + if (HPP_FCL_ENABLE_LOGGING) + ADD_PROJECT_DEPENDENCY(Boost REQUIRED log) + endif() ENDIF(WIN32) if(BUILD_PYTHON_INTERFACE) find_package(Boost REQUIRED COMPONENTS system) @@ -247,6 +257,7 @@ SET(${PROJECT_NAME}_HEADERS include/hpp/fcl/collision_utility.h include/hpp/fcl/hfield.h include/hpp/fcl/fwd.hh + include/hpp/fcl/logging.h include/hpp/fcl/mesh_loader/assimp.h include/hpp/fcl/mesh_loader/loader.h include/hpp/fcl/internal/BV_fitter.h diff --git a/include/hpp/fcl/logging.h b/include/hpp/fcl/logging.h new file mode 100644 index 0000000000000000000000000000000000000000..c65624b3dde8b8e037fc80942be73675b5a700c2 --- /dev/null +++ b/include/hpp/fcl/logging.h @@ -0,0 +1,54 @@ +/* + * Software License Agreement (BSD License) + * + * Copyright (c) 2024, INRIA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Open Source Robotics Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/// This file defines basic logging macros for HPP-FCL, based on Boost.Log. +/// To enable logging, define the preprocessor macro `HPP_FCL_ENABLE_LOGGING`. + +#ifndef HPP_FCL_LOGGING_H +#define HPP_FCL_LOGGING_H + +#ifdef HPP_FCL_ENABLE_LOGGING +#include <boost/log/trivial.hpp> +#define HPP_FCL_LOG_INFO(message) BOOST_LOG_TRIVIAL(info) << message +#define HPP_FCL_LOG_DEBUG(message) BOOST_LOG_TRIVIAL(debug) << message +#define HPP_FCL_LOG_WARNING(message) BOOST_LOG_TRIVIAL(warning) << message +#define HPP_FCL_LOG_ERROR(message) BOOST_LOG_TRIVIAL(error) << message +#else +#define HPP_FCL_LOG_INFO(message) +#define HPP_FCL_LOG_DEBUG(message) +#define HPP_FCL_LOG_WARNING(message) +#define HPP_FCL_LOG_ERROR(message) +#endif + +#endif // HPP_FCL_LOGGING_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0b0abfb9767bbb91449de9b51a73206ea63bb68e..af5ddd37ec32cc5169bd4478e44de7c1627f9eed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -202,6 +202,12 @@ TARGET_LINK_LIBRARIES(${LIBRARY_NAME} Boost::filesystem ) +if (HPP_FCL_ENABLE_LOGGING) + TARGET_LINK_LIBRARIES(${LIBRARY_NAME} PUBLIC Boost::log) + # The compile flag `BOOST_LOG_DYN_LINK` is required here. + target_compile_definitions(${LIBRARY_NAME} PUBLIC -DHPP_FCL_ENABLE_LOGGING -DBOOST_LOG_DYN_LINK) +endif() + IF(WIN32) TARGET_LINK_LIBRARIES(${LIBRARY_NAME} INTERFACE