Merge branch 'refactor-cmakelists-and-config' into 'master'

Refactor cmakelists and config

See merge request micro-ROS/ros_tracing/ros2_tracing!143
This commit is contained in:
Christophe Bedard 2020-02-29 19:23:53 +00:00
commit 0e94145cf6
4 changed files with 17 additions and 13 deletions

View file

@ -19,21 +19,23 @@ if(WIN32)
else() else()
set(DISABLED_DEFAULT OFF) set(DISABLED_DEFAULT OFF)
endif() endif()
option(TRACETOOLS_DISABLED "Explicitly disable support for tracing with LTTng" ${DISABLED_DEFAULT}) option(TRACETOOLS_DISABLED "Explicitly disable support for tracing" ${DISABLED_DEFAULT})
if(NOT TRACETOOLS_DISABLED) if(NOT TRACETOOLS_DISABLED)
# Set TRACING_ENABLED if we can find lttng-ust # Set TRACETOOLS_LTTNG_ENABLED if we can find lttng-ust
find_package(PkgConfig) find_package(PkgConfig)
if(PkgConfig_FOUND) if(PkgConfig_FOUND)
pkg_check_modules(LTTNG lttng-ust) pkg_check_modules(LTTNG lttng-ust)
if(LTTNG_FOUND) if(LTTNG_FOUND)
set(TRACING_ENABLED TRUE) set(TRACETOOLS_LTTNG_ENABLED TRUE)
message("LTTng found: tracing enabled") message("LTTng found: tracing enabled")
endif() endif()
endif() endif()
endif() endif()
# store configuration variables for runtime use # store configuration variables for runtime use
# TRACETOOLS_DISABLED
# TRACETOOLS_LTTNG_ENABLED
configure_file(include/${PROJECT_NAME}/config.h.in include/${PROJECT_NAME}/config.h) configure_file(include/${PROJECT_NAME}/config.h.in include/${PROJECT_NAME}/config.h)
# add both source and output include, to capture config.h # add both source and output include, to capture config.h
@ -44,7 +46,7 @@ set(SOURCES
src/tracetools.c src/tracetools.c
src/utils.cpp src/utils.cpp
) )
if(TRACING_ENABLED) if(TRACETOOLS_LTTNG_ENABLED)
list(APPEND SOURCES list(APPEND SOURCES
include/tracetools/tp_call.h include/tracetools/tp_call.h
src/tp_call.c src/tp_call.c
@ -52,8 +54,7 @@ if(TRACING_ENABLED)
endif() endif()
add_library(${PROJECT_NAME} ${SOURCES}) add_library(${PROJECT_NAME} ${SOURCES})
if(TRACING_ENABLED) if(TRACETOOLS_LTTNG_ENABLED)
target_compile_definitions(${PROJECT_NAME} PUBLIC TRACETOOLS_LTTNG_ENABLED)
target_link_libraries(${PROJECT_NAME} ${LTTNG_LIBRARIES}) target_link_libraries(${PROJECT_NAME} ${LTTNG_LIBRARIES})
endif() endif()
if(WIN32) if(WIN32)
@ -95,7 +96,7 @@ install(
) )
ament_export_include_directories(include) ament_export_include_directories(include)
if(TRACING_ENABLED) if(TRACETOOLS_LTTNG_ENABLED)
ament_export_libraries(${PROJECT_NAME} ${LTTNG_LIBRARIES}) ament_export_libraries(${PROJECT_NAME} ${LTTNG_LIBRARIES})
else() else()
ament_export_libraries(${PROJECT_NAME}) ament_export_libraries(${PROJECT_NAME})
@ -109,7 +110,7 @@ if(BUILD_TESTING)
ament_lint_auto_find_test_dependencies() ament_lint_auto_find_test_dependencies()
# Only build tracetools utils tests if LTTng is enabled and found # Only build tracetools utils tests if LTTng is enabled and found
if(TRACING_ENABLED) if(TRACETOOLS_LTTNG_ENABLED)
ament_add_gtest(test_utils test/test_utils.cpp) ament_add_gtest(test_utils test/test_utils.cpp)
if(TARGET test_utils) if(TARGET test_utils)
target_link_libraries(test_utils ${PROJECT_NAME} -rdynamic) target_link_libraries(test_utils ${PROJECT_NAME} -rdynamic)

View file

@ -16,5 +16,6 @@
#define TRACETOOLS__CONFIG_H_ #define TRACETOOLS__CONFIG_H_
#cmakedefine TRACETOOLS_DISABLED #cmakedefine TRACETOOLS_DISABLED
#cmakedefine TRACETOOLS_LTTNG_ENABLED
#endif // TRACETOOLS__CONFIG_H_ #endif // TRACETOOLS__CONFIG_H_

View file

@ -16,7 +16,7 @@
#ifndef TRACETOOLS_DISABLED #ifndef TRACETOOLS_DISABLED
#if defined(TRACETOOLS_LTTNG_ENABLED) #ifdef TRACETOOLS_LTTNG_ENABLED
# include "tracetools/tp_call.h" # include "tracetools/tp_call.h"
# define CONDITIONAL_TP(...) \ # define CONDITIONAL_TP(...) \
tracepoint(TRACEPOINT_PROVIDER, __VA_ARGS__) tracepoint(TRACEPOINT_PROVIDER, __VA_ARGS__)
@ -26,7 +26,7 @@
bool ros_trace_compile_status() bool ros_trace_compile_status()
{ {
#if defined(TRACETOOLS_LTTNG_ENABLED) #ifdef TRACETOOLS_LTTNG_ENABLED
return true; return true;
#else #else
return false; return false;

View file

@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#if defined(TRACETOOLS_LTTNG_ENABLED) #include "tracetools/config.h"
#ifdef TRACETOOLS_LTTNG_ENABLED
#include <dlfcn.h> #include <dlfcn.h>
#include <cxxabi.h> #include <cxxabi.h>
#endif #endif
@ -20,7 +22,7 @@
const char * _demangle_symbol(const char * mangled) const char * _demangle_symbol(const char * mangled)
{ {
#if defined(TRACETOOLS_LTTNG_ENABLED) #ifdef TRACETOOLS_LTTNG_ENABLED
char * demangled = nullptr; char * demangled = nullptr;
int status; int status;
demangled = abi::__cxa_demangle(mangled, NULL, 0, &status); demangled = abi::__cxa_demangle(mangled, NULL, 0, &status);
@ -35,7 +37,7 @@ const char * _demangle_symbol(const char * mangled)
const char * _get_symbol_funcptr(void * funcptr) const char * _get_symbol_funcptr(void * funcptr)
{ {
#if defined(TRACETOOLS_LTTNG_ENABLED) #ifdef TRACETOOLS_LTTNG_ENABLED
Dl_info info; Dl_info info;
if (dladdr(funcptr, &info) == 0) { if (dladdr(funcptr, &info) == 0) {
return SYMBOL_UNKNOWN; return SYMBOL_UNKNOWN;