Skip to content

Commit

Permalink
Prefixed cmake option names where used
Browse files Browse the repository at this point in the history
ENABLE_TRACING is designed to be used by other projects, so we prefix
it.
  • Loading branch information
shuhaowu committed Oct 14, 2024
1 parent fafe57d commit 7d328e6
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 37 deletions.
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: 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

0 comments on commit 7d328e6

Please sign in to comment.