Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefixed cmake option names where used #145

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
runs-on: [self-hosted, noble, real-time]
env:
CACTUS_RT_BUILD_DIR: build
ENABLE_TRACING: "OFF"
CACTUS_RT_ENABLE_TRACING: "OFF"
steps:
- uses: actions/checkout@v3

Expand Down
60 changes: 33 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ project(cactus_rt)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

#################
# Setup options #
#################

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

# Used to disable tracing in some builds where the overhead of tracing is unwanted.
option(CACTUS_RT_ENABLE_TRACING "Enable runtime tracing support" ON)

# Below are internal options
option(ENABLE_CLANG_TIDY "Run clang-tidy" OFF)
option(ENABLE_EXAMPLES "Build example programs" ON)
option(ENABLE_TRACING "Enable runtime tracing support" ON)
option(ENABLE_ROS2 "Enables ROS2 support" OFF)
option(BUILD_DOCS "Build documentations" OFF)

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

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

if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
if (ENABLE_TRACING)
add_subdirectory(protos)
endif()
if (CACTUS_RT_ENABLE_TRACING)
add_subdirectory(protos)
endif()

add_library(cactus_rt
Expand Down Expand Up @@ -136,28 +142,28 @@ target_link_libraries(cactus_rt
# Use a bounded queue
target_compile_definitions(cactus_rt PUBLIC QUILL_USE_BOUNDED_QUEUE)

if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
if (ENABLE_TRACING)
target_sources(cactus_rt
PRIVATE
src/cactus_rt/tracing/sink.cc
src/cactus_rt/tracing/thread_tracer.cc
src/cactus_rt/tracing/trace_aggregator.cc
src/cactus_rt/tracing/tracing_enabled.cc
src/cactus_rt/tracing/utils/string_interner.cc
)
if (CACTUS_RT_ENABLE_TRACING)
target_sources(cactus_rt
PRIVATE
src/cactus_rt/tracing/sink.cc
src/cactus_rt/tracing/thread_tracer.cc
src/cactus_rt/tracing/trace_aggregator.cc
src/cactus_rt/tracing/tracing_enabled.cc
src/cactus_rt/tracing/utils/string_interner.cc
)

target_link_libraries(cactus_rt
PUBLIC
cactus_tracing_embedded_perfetto_protos
)
target_link_libraries(cactus_rt
PUBLIC
cactus_tracing_embedded_perfetto_protos
)

target_compile_definitions(cactus_rt
PUBLIC
CACTUS_RT_TRACING_ENABLED=1
)
endif()
target_compile_definitions(cactus_rt
PUBLIC
CACTUS_RT_TRACING_ENABLED=1
)
endif()

if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
if (ENABLE_CLANG_TIDY)
find_program(CLANG_TIDY clang-tidy clang-tidy-18 clang-tidy-17 clang-tidy-16 clang-tidy-15 clang-tidy-14)
else()
Expand Down Expand Up @@ -191,7 +197,7 @@ if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
add_subdirectory(examples/simple_example)
add_subdirectory(examples/random_example)

if (ENABLE_TRACING)
if (CACTUS_RT_ENABLE_TRACING)
add_subdirectory(examples/tracing_protos_example)
add_subdirectory(examples/tracing_example)
add_subdirectory(examples/tracing_example_no_rt)
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.PHONY: release debug build-test-debug test-debug test benchmark clean clean-all

CACTUS_RT_ENABLE_TRACING ?= ON
ENABLE_CLANG_TIDY ?= OFF
ENABLE_TRACING ?= ON
ENABLE_EXAMPLES ?= ON
BUILD_DOCS ?= OFF
BUILD_TESTING ?= OFF
CMAKE_FLAGS := -DENABLE_CLANG_TIDY=$(ENABLE_CLANG_TIDY) -DENABLE_EXAMPLES=$(ENABLE_EXAMPLES) -DBUILD_DOCS=$(BUILD_DOCS) -DBUILD_TESTING=$(BUILD_TESTING) -DENABLE_TRACING=$(ENABLE_TRACING)
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)

debug:
cmake -Bbuild/$@ -DCMAKE_BUILD_TYPE=Debug $(CMAKE_FLAGS)
Expand All @@ -16,7 +16,7 @@ release:
cmake --build build/$@ -j $$(nproc)

build-test-debug:
cmake -Bbuild/test -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=OFF -DBUILD_TESTING=ON -DENABLE_CLANG_TIDY=$(ENABLE_CLANG_TIDY) -DENABLE_TRACING=$(ENABLE_TRACING)
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)
cmake --build build/test -j $$(nproc)

test-debug: build-test-debug
Expand All @@ -25,7 +25,7 @@ test-debug: build-test-debug
test: test-debug

build-test-release:
cmake -Bbuild/benchmark -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_EXAMPLES=OFF -DBUILD_TESTING=ON -DENABLE_CLANG_TIDY=$(ENABLE_CLANG_TIDY) -DENABLE_TRACING=$(ENABLE_TRACING)
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)
cmake --build build/benchmark -j $$(nproc)

benchmark: build-test-release
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ FetchContent_MakeAvailable(cactus_rt)
target_link_libraries(myapp PRIVATE cactus_rt)
```

See https://github.com/cactusdynamics/cactus-rt-sample-app for an example.

Note that if you compile your app in debug mode, cactus-rt will be compiled in
debug mode due to how `FetchContent` works. To get cactus-rt in release mode,
compile your app in release mode.
Expand Down
2 changes: 1 addition & 1 deletion docker/scripts/01-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ cmake -B${CACTUS_RT_BUILD_DIR} \
-DENABLE_CLANG_TIDY=ON \
-DBUILD_DOCS=ON \
-DBUILD_TESTING=ON \
-DENABLE_TRACING=${ENABLE_TRACING:-ON} \
-DCACTUS_RT_ENABLE_TRACING=${CACTUS_RT_ENABLE_TRACING:-ON} \
-DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build ${CACTUS_RT_BUILD_DIR} -j $(nproc)
2 changes: 1 addition & 1 deletion include/cactus_rt/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct AppConfig {
quill::Config logger_config;

/**
* @brief The config for the tracer if enabled (ENABLE_TRACING option in cmake)
* @brief The config for the tracer if enabled (CACTUS_RT_ENABLE_TRACING option in cmake)
*/
TracerConfig tracer_config;
};
Expand Down
4 changes: 4 additions & 0 deletions include/cactus_rt/tracing/tracing_enabled.disabled.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inline bool IsTracingEnabled() noexcept {
return false;
}

inline bool IsTracingAvailable() noexcept {
return false;
}

inline void EnableTracing() noexcept {}

inline void DisableTracing() noexcept {}
Expand Down
4 changes: 4 additions & 0 deletions include/cactus_rt/tracing/tracing_enabled.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ inline bool IsTracingEnabled() noexcept {
return tracing_enabled.load(std::memory_order_relaxed);
}

inline bool IsTracingAvailable() noexcept {
return true;
}

inline void EnableTracing() noexcept {
tracing_enabled = true;
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-in-docker
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cd docker
docker build . -t cactus-rt-test
cd ..
docker run --rm \
-e ENABLE_TRACING=${ENABLE_TRACING:-ON} \
-e CACTUS_RT_ENABLE_TRACING=${CACTUS_RT_ENABLE_TRACING:-ON} \
-it \
--cap-add IPC_LOCK \
-v $(pwd):/cactus-rt/source \
Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ target_compile_definitions(cactus_rt_tests

gtest_discover_tests(cactus_rt_tests)

if(ENABLE_TRACING)
if(CACTUS_RT_ENABLE_TRACING)
add_executable(cactus_rt_tracing_tests

tracing/single_threaded_test.cc
Expand Down Expand Up @@ -60,7 +60,7 @@ add_executable(cactus_rt_tracing_benchmark
tracing/tracing_benchmark.cc
)

if (ENABLE_TRACING)
if (CACTUS_RT_ENABLE_TRACING)
target_sources(cactus_rt_tracing_benchmark
PRIVATE
tracing/string_interner_benchmark.cc
Expand Down
Loading