Skip to content

Commit 1ac871c

Browse files
authored
Merge pull request #145 from cactusdynamics/cmake-update
Prefixed cmake option names where used
2 parents fafe57d + 65572dd commit 1ac871c

File tree

10 files changed

+53
-37
lines changed

10 files changed

+53
-37
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
runs-on: [self-hosted, noble, real-time]
3939
env:
4040
CACTUS_RT_BUILD_DIR: build
41-
ENABLE_TRACING: "OFF"
41+
CACTUS_RT_ENABLE_TRACING: "OFF"
4242
steps:
4343
- uses: actions/checkout@v3
4444

CMakeLists.txt

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@ project(cactus_rt)
33

44
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
55

6+
#################
7+
# Setup options #
8+
#################
9+
10+
# Used for building cactus-rt when all dependencies are vendored
11+
option(CACTUS_RT_ENABLE_FETCH_DEPENDENCIES "Fetch dependencies during build" ON)
12+
13+
# Used to disable tracing in some builds where the overhead of tracing is unwanted.
14+
option(CACTUS_RT_ENABLE_TRACING "Enable runtime tracing support" ON)
15+
16+
# Below are internal options
617
option(ENABLE_CLANG_TIDY "Run clang-tidy" OFF)
718
option(ENABLE_EXAMPLES "Build example programs" ON)
8-
option(ENABLE_TRACING "Enable runtime tracing support" ON)
919
option(ENABLE_ROS2 "Enables ROS2 support" OFF)
1020
option(BUILD_DOCS "Build documentations" OFF)
1121

12-
# Used for building cactus-rt when all dependencies are vendored
13-
option(CACTUS_RT_ENABLE_FETCH_DEPENDENCIES "Fetch dependencies during build" ON)
1422

1523
# https://stackoverflow.com/questions/5395309/how-do-i-force-cmake-to-include-pthread-option-during-compilation
1624
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
@@ -105,10 +113,8 @@ endfunction()
105113
# Cactus RT library #
106114
#####################
107115

108-
if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
109-
if (ENABLE_TRACING)
110-
add_subdirectory(protos)
111-
endif()
116+
if (CACTUS_RT_ENABLE_TRACING)
117+
add_subdirectory(protos)
112118
endif()
113119

114120
add_library(cactus_rt
@@ -136,28 +142,28 @@ target_link_libraries(cactus_rt
136142
# Use a bounded queue
137143
target_compile_definitions(cactus_rt PUBLIC QUILL_USE_BOUNDED_QUEUE)
138144

139-
if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
140-
if (ENABLE_TRACING)
141-
target_sources(cactus_rt
142-
PRIVATE
143-
src/cactus_rt/tracing/sink.cc
144-
src/cactus_rt/tracing/thread_tracer.cc
145-
src/cactus_rt/tracing/trace_aggregator.cc
146-
src/cactus_rt/tracing/tracing_enabled.cc
147-
src/cactus_rt/tracing/utils/string_interner.cc
148-
)
145+
if (CACTUS_RT_ENABLE_TRACING)
146+
target_sources(cactus_rt
147+
PRIVATE
148+
src/cactus_rt/tracing/sink.cc
149+
src/cactus_rt/tracing/thread_tracer.cc
150+
src/cactus_rt/tracing/trace_aggregator.cc
151+
src/cactus_rt/tracing/tracing_enabled.cc
152+
src/cactus_rt/tracing/utils/string_interner.cc
153+
)
149154

150-
target_link_libraries(cactus_rt
151-
PUBLIC
152-
cactus_tracing_embedded_perfetto_protos
153-
)
155+
target_link_libraries(cactus_rt
156+
PUBLIC
157+
cactus_tracing_embedded_perfetto_protos
158+
)
154159

155-
target_compile_definitions(cactus_rt
156-
PUBLIC
157-
CACTUS_RT_TRACING_ENABLED=1
158-
)
159-
endif()
160+
target_compile_definitions(cactus_rt
161+
PUBLIC
162+
CACTUS_RT_TRACING_ENABLED=1
163+
)
164+
endif()
160165

166+
if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
161167
if (ENABLE_CLANG_TIDY)
162168
find_program(CLANG_TIDY clang-tidy clang-tidy-18 clang-tidy-17 clang-tidy-16 clang-tidy-15 clang-tidy-14)
163169
else()
@@ -191,7 +197,7 @@ if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
191197
add_subdirectory(examples/simple_example)
192198
add_subdirectory(examples/random_example)
193199

194-
if (ENABLE_TRACING)
200+
if (CACTUS_RT_ENABLE_TRACING)
195201
add_subdirectory(examples/tracing_protos_example)
196202
add_subdirectory(examples/tracing_example)
197203
add_subdirectory(examples/tracing_example_no_rt)

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
.PHONY: release debug build-test-debug test-debug test benchmark clean clean-all
22

3+
CACTUS_RT_ENABLE_TRACING ?= ON
34
ENABLE_CLANG_TIDY ?= OFF
4-
ENABLE_TRACING ?= ON
55
ENABLE_EXAMPLES ?= ON
66
BUILD_DOCS ?= OFF
77
BUILD_TESTING ?= OFF
8-
CMAKE_FLAGS := -DENABLE_CLANG_TIDY=$(ENABLE_CLANG_TIDY) -DENABLE_EXAMPLES=$(ENABLE_EXAMPLES) -DBUILD_DOCS=$(BUILD_DOCS) -DBUILD_TESTING=$(BUILD_TESTING) -DENABLE_TRACING=$(ENABLE_TRACING)
8+
CMAKE_FLAGS := -DENABLE_CLANG_TIDY=$(ENABLE_CLANG_TIDY) -DENABLE_EXAMPLES=$(ENABLE_EXAMPLES) -DBUILD_DOCS=$(BUILD_DOCS) -DBUILD_TESTING=$(BUILD_TESTING) -DCACTUS_RT_ENABLE_TRACING=$(CACTUS_RT_ENABLE_TRACING)
99

1010
debug:
1111
cmake -Bbuild/$@ -DCMAKE_BUILD_TYPE=Debug $(CMAKE_FLAGS)
@@ -16,7 +16,7 @@ release:
1616
cmake --build build/$@ -j $$(nproc)
1717

1818
build-test-debug:
19-
cmake -Bbuild/test -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=OFF -DBUILD_TESTING=ON -DENABLE_CLANG_TIDY=$(ENABLE_CLANG_TIDY) -DENABLE_TRACING=$(ENABLE_TRACING)
19+
cmake -Bbuild/test -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=OFF -DBUILD_TESTING=ON -DENABLE_CLANG_TIDY=$(ENABLE_CLANG_TIDY) -DCACTUS_RT_ENABLE_TRACING=$(CACTUS_RT_ENABLE_TRACING)
2020
cmake --build build/test -j $$(nproc)
2121

2222
test-debug: build-test-debug
@@ -25,7 +25,7 @@ test-debug: build-test-debug
2525
test: test-debug
2626

2727
build-test-release:
28-
cmake -Bbuild/benchmark -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_EXAMPLES=OFF -DBUILD_TESTING=ON -DENABLE_CLANG_TIDY=$(ENABLE_CLANG_TIDY) -DENABLE_TRACING=$(ENABLE_TRACING)
28+
cmake -Bbuild/benchmark -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_EXAMPLES=OFF -DBUILD_TESTING=ON -DENABLE_CLANG_TIDY=$(ENABLE_CLANG_TIDY) -DCACTUS_RT_ENABLE_TRACING=$(CACTUS_RT_ENABLE_TRACING)
2929
cmake --build build/benchmark -j $$(nproc)
3030

3131
benchmark: build-test-release

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ FetchContent_MakeAvailable(cactus_rt)
295295
target_link_libraries(myapp PRIVATE cactus_rt)
296296
```
297297

298+
See https://github.com/cactusdynamics/cactus-rt-sample-app for an example.
299+
298300
Note that if you compile your app in debug mode, cactus-rt will be compiled in
299301
debug mode due to how `FetchContent` works. To get cactus-rt in release mode,
300302
compile your app in release mode.

docker/scripts/01-build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ cmake -B${CACTUS_RT_BUILD_DIR} \
66
-DENABLE_CLANG_TIDY=ON \
77
-DBUILD_DOCS=ON \
88
-DBUILD_TESTING=ON \
9-
-DENABLE_TRACING=${ENABLE_TRACING:-ON} \
9+
-DCACTUS_RT_ENABLE_TRACING=${CACTUS_RT_ENABLE_TRACING:-ON} \
1010
-DCMAKE_BUILD_TYPE=RelWithDebInfo
1111
cmake --build ${CACTUS_RT_BUILD_DIR} -j $(nproc)

include/cactus_rt/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct AppConfig {
3434
quill::Config logger_config;
3535

3636
/**
37-
* @brief The config for the tracer if enabled (ENABLE_TRACING option in cmake)
37+
* @brief The config for the tracer if enabled (CACTUS_RT_ENABLE_TRACING option in cmake)
3838
*/
3939
TracerConfig tracer_config;
4040
};

include/cactus_rt/tracing/tracing_enabled.disabled.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ inline bool IsTracingEnabled() noexcept {
55
return false;
66
}
77

8+
inline bool IsTracingAvailable() noexcept {
9+
return false;
10+
}
11+
812
inline void EnableTracing() noexcept {}
913

1014
inline void DisableTracing() noexcept {}

include/cactus_rt/tracing/tracing_enabled.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ inline bool IsTracingEnabled() noexcept {
1919
return tracing_enabled.load(std::memory_order_relaxed);
2020
}
2121

22+
inline bool IsTracingAvailable() noexcept {
23+
return true;
24+
}
25+
2226
inline void EnableTracing() noexcept {
2327
tracing_enabled = true;
2428
}

scripts/test-in-docker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cd docker
66
docker build . -t cactus-rt-test
77
cd ..
88
docker run --rm \
9-
-e ENABLE_TRACING=${ENABLE_TRACING:-ON} \
9+
-e CACTUS_RT_ENABLE_TRACING=${CACTUS_RT_ENABLE_TRACING:-ON} \
1010
-it \
1111
--cap-add IPC_LOCK \
1212
-v $(pwd):/cactus-rt/source \

tests/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ target_compile_definitions(cactus_rt_tests
2929

3030
gtest_discover_tests(cactus_rt_tests)
3131

32-
if(ENABLE_TRACING)
32+
if(CACTUS_RT_ENABLE_TRACING)
3333
add_executable(cactus_rt_tracing_tests
3434

3535
tracing/single_threaded_test.cc
@@ -60,7 +60,7 @@ add_executable(cactus_rt_tracing_benchmark
6060
tracing/tracing_benchmark.cc
6161
)
6262

63-
if (ENABLE_TRACING)
63+
if (CACTUS_RT_ENABLE_TRACING)
6464
target_sources(cactus_rt_tracing_benchmark
6565
PRIVATE
6666
tracing/string_interner_benchmark.cc

0 commit comments

Comments
 (0)