diff --git a/tracetools/CMakeLists.txt b/tracetools/CMakeLists.txt index 6f48054..b9ed653 100644 --- a/tracetools/CMakeLists.txt +++ b/tracetools/CMakeLists.txt @@ -48,13 +48,18 @@ if(TRACING_ENABLED) target_compile_definitions(${PROJECT_NAME} PUBLIC TRACETOOLS_LTTNG_ENABLED) target_link_libraries(${PROJECT_NAME} ${LTTNG_LIBRARIES} -ldl) endif() +if(WIN32) + # Causes the visibility macros to use dllexport rather than dllimport + # which is appropriate when building the dll but not consuming it. + target_compile_definitions(${PROJECT_NAME} + PRIVATE "TRACETOOLS_BUILDING_DLL") +endif() ament_export_interfaces(${PROJECT_NAME}_export HAS_LIBRARY_TARGET) # Status checking tool add_executable(status src/status.c - src/tracetools.c src/utils.cpp ) target_link_libraries(status diff --git a/tracetools/include/tracetools/tracetools.h b/tracetools/include/tracetools/tracetools.h index a7f6603..141bfb8 100644 --- a/tracetools/include/tracetools/tracetools.h +++ b/tracetools/include/tracetools/tracetools.h @@ -19,12 +19,13 @@ #include #include #include "tracetools/config.h" +#include "tracetools/visibility_control.hpp" #ifndef TRACETOOLS_DISABLED # define TRACEPOINT(event_name, ...) \ (ros_trace_ ## event_name)(__VA_ARGS__) # define DECLARE_TRACEPOINT(event_name, ...) \ - void(ros_trace_ ## event_name)(__VA_ARGS__); + TRACETOOLS_PUBLIC void(ros_trace_ ## event_name)(__VA_ARGS__); #else # define TRACEPOINT(event_name, ...) # define DECLARE_TRACEPOINT(event_name, ...) @@ -38,7 +39,7 @@ extern "C" /** * Report whether tracing is compiled in */ -bool ros_trace_compile_status(); +TRACETOOLS_PUBLIC bool ros_trace_compile_status(); /** * tp: rcl_init diff --git a/tracetools/include/tracetools/visibility_control.hpp b/tracetools/include/tracetools/visibility_control.hpp new file mode 100644 index 0000000..44c2f9b --- /dev/null +++ b/tracetools/include/tracetools/visibility_control.hpp @@ -0,0 +1,56 @@ +// Copyright 2015 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/* This header must be included by all TRACETOOLS headers which declare symbols + * which are defined in the TRACETOOLS library. When not building the TRACETOOLS + * library, i.e. when using the headers in other package's code, the contents + * of this header change the visibility of certain symbols which the TRACETOOLS + * library cannot have, but the consuming code must have inorder to link. + */ + +#ifndef TRACETOOLS__VISIBILITY_CONTROL_HPP_ +#define TRACETOOLS__VISIBILITY_CONTROL_HPP_ + +// This logic was borrowed (then namespaced) from the examples on the gcc wiki: +// https://gcc.gnu.org/wiki/Visibility + +#if defined _WIN32 || defined __CYGWIN__ + #ifdef __GNUC__ + #define TRACETOOLS_EXPORT __attribute__ ((dllexport)) + #define TRACETOOLS_IMPORT __attribute__ ((dllimport)) + #else + #define TRACETOOLS_EXPORT __declspec(dllexport) + #define TRACETOOLS_IMPORT __declspec(dllimport) + #endif + #ifdef TRACETOOLS_BUILDING_LIBRARY + #define TRACETOOLS_PUBLIC TRACETOOLS_EXPORT + #else + #define TRACETOOLS_PUBLIC TRACETOOLS_IMPORT + #endif + #define TRACETOOLS_PUBLIC_TYPE TRACETOOLS_PUBLIC + #define TRACETOOLS_LOCAL +#else + #define TRACETOOLS_EXPORT __attribute__ ((visibility("default"))) + #define TRACETOOLS_IMPORT + #if __GNUC__ >= 4 + #define TRACETOOLS_PUBLIC __attribute__ ((visibility("default"))) + #define TRACETOOLS_LOCAL __attribute__ ((visibility("hidden"))) + #else + #define TRACETOOLS_PUBLIC + #define TRACETOOLS_LOCAL + #endif + #define TRACETOOLS_PUBLIC_TYPE +#endif + +#endif // TRACETOOLS__VISIBILITY_CONTROL_HPP_