-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
153 lines (135 loc) · 4.29 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
cmake_minimum_required(VERSION 3.5)
project(tracetools_acceleration)
# 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")
add_compile_options(-Wall -Wextra -Wpedantic)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/W4)
endif()
find_package(ament_cmake_ros REQUIRED)
if(WIN32)
set(DISABLED_DEFAULT ON)
else()
set(DISABLED_DEFAULT OFF)
endif()
option(TRACETOOLS_DISABLED "Explicitly disable support for tracing" ${DISABLED_DEFAULT})
option(TRACETOOLS_NO_RDYNAMIC "Disable export of -rdynamic link flag" OFF)
option(TRACETOOLS_STATUS_CHECKING_TOOL "Enable the status checking tool" ON)
if(NOT TRACETOOLS_DISABLED)
# Set TRACETOOLS_LTTNG_ENABLED if we can find lttng-ust
find_package(PkgConfig)
if(PkgConfig_FOUND)
pkg_check_modules(LTTNG lttng-ust)
if(LTTNG_FOUND)
set(TRACETOOLS_LTTNG_ENABLED TRUE)
message("LTTng found: tracing enabled")
endif()
endif()
endif()
# Store configuration variables for runtime use
# TRACETOOLS_DISABLED
# TRACETOOLS_LTTNG_ENABLED
configure_file(include/${PROJECT_NAME}/config.h.in include/${PROJECT_NAME}/config.h)
# tracetools_acceleration lib
set(SOURCES
src/tracetools.c
src/utils.cpp
)
set(HEADERS
include/${PROJECT_NAME}/tracetools.h
include/${PROJECT_NAME}/utils.hpp
include/${PROJECT_NAME}/visibility_control.hpp
)
if(TRACETOOLS_LTTNG_ENABLED)
# We only need these if we're using LTTng
list(APPEND SOURCES
src/tp_call.c
)
list(APPEND HEADERS
include/${PROJECT_NAME}/tp_call.h
)
endif()
# 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()
add_library(${PROJECT_NAME} ${SOURCES})
if(TRACETOOLS_LTTNG_ENABLED)
target_link_libraries(${PROJECT_NAME} ${LTTNG_LIBRARIES})
# 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)
if(NOT TRACETOOLS_NO_RDYNAMIC)
target_link_libraries(${PROJECT_NAME} "-rdynamic")
endif()
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()
# Only use output/binary include directory
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
"$<INSTALL_INTERFACE:include>"
)
ament_export_targets(${PROJECT_NAME}_export HAS_LIBRARY_TARGET)
if(TRACETOOLS_STATUS_CHECKING_TOOL)
# Status checking tool
add_executable(status
src/status.c
)
target_link_libraries(status
${PROJECT_NAME}
)
install(TARGETS
status
DESTINATION lib/${PROJECT_NAME}
)
endif()
install(
DIRECTORY ${PROJECT_BINARY_DIR}/include/
DESTINATION include
)
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)
if(TRACETOOLS_LTTNG_ENABLED)
ament_export_libraries(${PROJECT_NAME} ${LTTNG_LIBRARIES})
# Export -rdynamic for downstream packages using classic CMake variables
if(NOT TRACETOOLS_NO_RDYNAMIC)
ament_export_link_flags("-rdynamic")
endif()
else()
ament_export_libraries(${PROJECT_NAME})
endif()
if(BUILD_TESTING)
set(ament_cmake_cppcheck_ADDITIONAL_INCLUDE_DIRS ${LTTNG_INCLUDE_DIRS})
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
if(TRACETOOLS_STATUS_CHECKING_TOOL)
# Run status tool executable as test and set pass/fail expectation appropriately
add_test(test_status_tool status)
if(NOT TRACETOOLS_LTTNG_ENABLED)
set_tests_properties(test_status_tool PROPERTIES WILL_FAIL TRUE)
endif()
endif()
endif()
ament_package()
target_compile_definitions(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_VERSION="${${PROJECT_NAME}_VERSION}")