Merge branch '37-cmakelists' into 'master'

Resolve "Library linkage issue on Windows"

Closes #37

See merge request micro-ROS/ros_tracing/ros2_tracing!74
This commit is contained in:
Ingo Lütkebohle 2019-08-01 10:56:18 +00:00
commit 7e40f8a459
3 changed files with 80 additions and 19 deletions

View file

@ -31,20 +31,6 @@ configure_file(include/${PROJECT_NAME}/config.h.in include/${PROJECT_NAME}/confi
# add both source and output include, to capture config.h # add both source and output include, to capture config.h
include_directories(include ${PROJECT_BINARY_DIR}/include) include_directories(include ${PROJECT_BINARY_DIR}/include)
# Status checking tool
add_executable(status
src/status.c
src/tracetools.c
src/utils.cpp
)
target_link_libraries(status
${PROJECT_NAME}
)
install(TARGETS
status
DESTINATION lib/${PROJECT_NAME}
)
# Tracetools lib # Tracetools lib
set(SOURCES set(SOURCES
src/tracetools.c src/tracetools.c
@ -57,15 +43,33 @@ if(TRACING_ENABLED)
) )
endif() endif()
add_library(${PROJECT_NAME} SHARED ${SOURCES}) add_library(${PROJECT_NAME} ${SOURCES})
if(TRACING_ENABLED) if(TRACING_ENABLED)
target_compile_definitions(${PROJECT_NAME} PUBLIC TRACETOOLS_LTTNG_ENABLED) target_compile_definitions(${PROJECT_NAME} PUBLIC TRACETOOLS_LTTNG_ENABLED)
target_link_libraries(${PROJECT_NAME} ${LTTNG_LIBRARIES} -ldl) target_link_libraries(${PROJECT_NAME} ${LTTNG_LIBRARIES} -ldl)
else() endif()
target_link_libraries(${PROJECT_NAME}) 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() endif()
ament_export_interfaces(${PROJECT_NAME}_export HAS_LIBRARY_TARGET) ament_export_interfaces(${PROJECT_NAME}_export HAS_LIBRARY_TARGET)
# Status checking tool
add_executable(status
src/status.c
src/utils.cpp
)
target_link_libraries(status
${PROJECT_NAME}
)
install(TARGETS
status
DESTINATION lib/${PROJECT_NAME}
)
install( install(
DIRECTORY include/ DIRECTORY include/
DESTINATION include DESTINATION include

View file

@ -19,12 +19,13 @@
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include "tracetools/config.h" #include "tracetools/config.h"
#include "tracetools/visibility_control.hpp"
#ifndef TRACETOOLS_DISABLED #ifndef TRACETOOLS_DISABLED
# define TRACEPOINT(event_name, ...) \ # define TRACEPOINT(event_name, ...) \
(ros_trace_ ## event_name)(__VA_ARGS__) (ros_trace_ ## event_name)(__VA_ARGS__)
# define DECLARE_TRACEPOINT(event_name, ...) \ # define DECLARE_TRACEPOINT(event_name, ...) \
void(ros_trace_ ## event_name)(__VA_ARGS__); TRACETOOLS_PUBLIC void(ros_trace_ ## event_name)(__VA_ARGS__);
#else #else
# define TRACEPOINT(event_name, ...) # define TRACEPOINT(event_name, ...)
# define DECLARE_TRACEPOINT(event_name, ...) # define DECLARE_TRACEPOINT(event_name, ...)
@ -38,7 +39,7 @@ extern "C"
/** /**
* Report whether tracing is compiled in * Report whether tracing is compiled in
*/ */
bool ros_trace_compile_status(); TRACETOOLS_PUBLIC bool ros_trace_compile_status();
/** /**
* tp: rcl_init * tp: rcl_init

View file

@ -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_