Skip to content
Snippets Groups Projects
Unverified Commit 93813398 authored by Louis Montaut's avatar Louis Montaut
Browse files

Core: add logging macros

The logging is activated by default in Debug mode, and can be
activated by defining the preprocessor macro `HPP_FCL_ENABLE_LOGGING`.
parent fc3d2788
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
/*
* 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
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment