2019-05-16 12:55:31 +02:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
|
project(tracetools)
|
|
|
|
|
|
|
|
# Default to C++14
|
|
|
|
if(NOT CMAKE_CXX_STANDARD)
|
|
|
|
set(CMAKE_CXX_STANDARD 14)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2019-07-05 12:52:03 +02:00
|
|
|
add_compile_options(-Wall -Wextra -Wpedantic)
|
2019-08-02 16:35:16 +02:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
|
|
|
add_compile_options(/W4)
|
2019-05-16 12:55:31 +02:00
|
|
|
endif()
|
|
|
|
|
2019-07-05 10:42:37 +02:00
|
|
|
find_package(ament_cmake_ros REQUIRED)
|
2019-05-16 12:55:31 +02:00
|
|
|
|
2019-10-18 17:07:18 +00:00
|
|
|
if(WIN32)
|
|
|
|
set(DISABLED_DEFAULT ON)
|
|
|
|
else()
|
|
|
|
set(DISABLED_DEFAULT OFF)
|
|
|
|
endif()
|
2020-02-29 14:18:18 -05:00
|
|
|
option(TRACETOOLS_DISABLED "Explicitly disable support for tracing" ${DISABLED_DEFAULT})
|
2019-10-18 17:07:18 +00:00
|
|
|
|
2019-07-25 09:03:29 +02:00
|
|
|
if(NOT TRACETOOLS_DISABLED)
|
2020-02-28 17:45:57 -05:00
|
|
|
# Set TRACETOOLS_LTTNG_ENABLED if we can find lttng-ust
|
2019-07-19 10:02:56 +02:00
|
|
|
find_package(PkgConfig)
|
|
|
|
if(PkgConfig_FOUND)
|
|
|
|
pkg_check_modules(LTTNG lttng-ust)
|
|
|
|
if(LTTNG_FOUND)
|
2020-02-28 17:45:57 -05:00
|
|
|
set(TRACETOOLS_LTTNG_ENABLED TRUE)
|
2019-07-25 09:03:29 +02:00
|
|
|
message("LTTng found: tracing enabled")
|
2019-07-19 10:02:56 +02:00
|
|
|
endif()
|
|
|
|
endif()
|
2019-05-16 12:55:31 +02:00
|
|
|
endif()
|
|
|
|
|
2020-02-29 15:16:51 -05:00
|
|
|
# Store configuration variables for runtime use
|
2020-02-28 17:45:57 -05:00
|
|
|
# TRACETOOLS_DISABLED
|
|
|
|
# TRACETOOLS_LTTNG_ENABLED
|
2019-07-30 14:27:36 +00:00
|
|
|
configure_file(include/${PROJECT_NAME}/config.h.in include/${PROJECT_NAME}/config.h)
|
|
|
|
|
2019-05-16 12:55:31 +02:00
|
|
|
# Tracetools lib
|
|
|
|
set(SOURCES
|
|
|
|
src/tracetools.c
|
2019-06-04 16:37:11 +02:00
|
|
|
src/utils.cpp
|
2019-05-16 12:55:31 +02:00
|
|
|
)
|
2020-02-29 15:16:51 -05:00
|
|
|
set(HEADERS
|
|
|
|
include/${PROJECT_NAME}/tracetools.h
|
|
|
|
include/${PROJECT_NAME}/utils.hpp
|
|
|
|
include/${PROJECT_NAME}/visibility_control.hpp
|
|
|
|
)
|
2020-02-28 17:45:57 -05:00
|
|
|
if(TRACETOOLS_LTTNG_ENABLED)
|
2020-02-29 15:16:51 -05:00
|
|
|
# We only need these if we're using LTTng
|
2019-07-19 10:02:56 +02:00
|
|
|
list(APPEND SOURCES
|
2019-07-25 09:03:29 +02:00
|
|
|
src/tp_call.c
|
|
|
|
)
|
2020-02-29 15:16:51 -05:00
|
|
|
list(APPEND HEADERS
|
|
|
|
include/${PROJECT_NAME}/tp_call.h
|
|
|
|
)
|
2019-05-16 12:55:31 +02:00
|
|
|
endif()
|
|
|
|
|
2020-02-29 15:16:51 -05:00
|
|
|
# Copy select headers to the actual include/ directory that we will use and export
|
|
|
|
foreach(_header ${HEADERS})
|
|
|
|
configure_file(
|
|
|
|
${PROJECT_SOURCE_DIR}/${_header}
|
|
|
|
${PROJECT_BINARY_DIR}/${_header}
|
|
|
|
COPYONLY
|
|
|
|
)
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# Only use output/binary include directory
|
|
|
|
include_directories(
|
|
|
|
${PROJECT_BINARY_DIR}/include
|
|
|
|
)
|
|
|
|
|
2019-08-01 09:20:26 +02:00
|
|
|
add_library(${PROJECT_NAME} ${SOURCES})
|
2020-02-28 17:45:57 -05:00
|
|
|
if(TRACETOOLS_LTTNG_ENABLED)
|
2019-12-11 12:09:31 -08:00
|
|
|
target_link_libraries(${PROJECT_NAME} ${LTTNG_LIBRARIES})
|
2019-05-16 12:55:31 +02:00
|
|
|
endif()
|
2019-08-01 11:51:27 +02:00
|
|
|
if(WIN32)
|
2020-03-03 14:22:35 -08:00
|
|
|
# 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")
|
2019-08-01 11:51:27 +02:00
|
|
|
endif()
|
2019-05-16 12:55:31 +02:00
|
|
|
|
|
|
|
ament_export_interfaces(${PROJECT_NAME}_export HAS_LIBRARY_TARGET)
|
2019-08-01 09:52:32 +02:00
|
|
|
|
|
|
|
# Status checking tool
|
|
|
|
add_executable(status
|
|
|
|
src/status.c
|
|
|
|
)
|
|
|
|
target_link_libraries(status
|
|
|
|
${PROJECT_NAME}
|
|
|
|
)
|
|
|
|
install(TARGETS
|
|
|
|
status
|
|
|
|
DESTINATION lib/${PROJECT_NAME}
|
|
|
|
)
|
|
|
|
|
2019-05-16 12:55:31 +02:00
|
|
|
install(
|
2020-02-29 15:16:51 -05:00
|
|
|
DIRECTORY ${PROJECT_BINARY_DIR}/include/
|
2020-03-01 09:49:52 -05:00
|
|
|
DESTINATION include
|
2019-07-30 14:27:36 +00:00
|
|
|
)
|
2019-05-16 12:55:31 +02:00
|
|
|
install(
|
|
|
|
TARGETS ${PROJECT_NAME}
|
|
|
|
EXPORT ${PROJECT_NAME}_export
|
|
|
|
LIBRARY DESTINATION lib
|
|
|
|
ARCHIVE DESTINATION lib
|
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
INCLUDES DESTINATION include
|
|
|
|
)
|
|
|
|
|
|
|
|
ament_export_include_directories(include)
|
2020-02-28 17:45:57 -05:00
|
|
|
if(TRACETOOLS_LTTNG_ENABLED)
|
2019-05-16 12:55:31 +02:00
|
|
|
ament_export_libraries(${PROJECT_NAME} ${LTTNG_LIBRARIES})
|
2020-03-08 23:08:25 -04:00
|
|
|
# Export -rdynamic for downtream packages to use when calling
|
|
|
|
# ament_target_dependencies()
|
|
|
|
# which is needed to resolve function addresses to symbols when
|
|
|
|
# using function pointers directly/without std::bind()
|
|
|
|
# (the flag should not be used on Windows, but TRACETOOLS_LTTNG_ENABLED
|
|
|
|
# should never be true on Windows anyway, so there is no need to check)
|
|
|
|
ament_export_link_flags("-rdynamic")
|
2019-05-16 12:55:31 +02:00
|
|
|
else()
|
|
|
|
ament_export_libraries(${PROJECT_NAME})
|
|
|
|
endif()
|
|
|
|
|
2019-06-04 13:53:05 +02:00
|
|
|
if(BUILD_TESTING)
|
2020-02-28 17:10:40 +00:00
|
|
|
set(ament_cmake_cppcheck_ADDITIONAL_INCLUDE_DIRS ${LTTNG_INCLUDE_DIRS})
|
|
|
|
|
2019-07-02 14:35:24 +02:00
|
|
|
find_package(ament_cmake_gtest REQUIRED)
|
2019-06-04 13:53:05 +02:00
|
|
|
find_package(ament_lint_auto REQUIRED)
|
|
|
|
ament_lint_auto_find_test_dependencies()
|
2019-07-02 14:35:24 +02:00
|
|
|
|
2019-07-12 10:06:52 +02:00
|
|
|
# Only build tracetools utils tests if LTTng is enabled and found
|
2020-02-28 17:45:57 -05:00
|
|
|
if(TRACETOOLS_LTTNG_ENABLED)
|
2019-07-12 10:06:52 +02:00
|
|
|
ament_add_gtest(test_utils test/test_utils.cpp)
|
|
|
|
if(TARGET test_utils)
|
2020-03-08 23:08:25 -04:00
|
|
|
# Since we cannot use ament_target_dependencies(... tracetools) in the same file
|
2019-07-12 10:06:52 +02:00
|
|
|
target_link_libraries(test_utils ${PROJECT_NAME} -rdynamic)
|
|
|
|
endif()
|
2019-07-02 14:35:24 +02:00
|
|
|
endif()
|
2019-06-04 13:53:05 +02:00
|
|
|
endif()
|
|
|
|
|
2019-05-16 12:55:31 +02:00
|
|
|
ament_package()
|
2019-06-17 11:15:57 +02:00
|
|
|
|
2020-03-03 14:32:20 -08:00
|
|
|
target_compile_definitions(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_VERSION="${${PROJECT_NAME}_VERSION}")
|