From 65572dd2a305a959b64ef34978dbc1cb3e4135ba Mon Sep 17 00:00:00 2001 From: Shuhao Wu Date: Mon, 14 Oct 2024 12:20:39 -0400 Subject: [PATCH] Prefixed cmake option names where used ENABLE_TRACING is designed to be used by other projects, so we prefix it. --- .github/workflows/main.yml | 2 +- CMakeLists.txt | 60 ++++++++++--------- Makefile | 8 +-- README.md | 2 + docker/scripts/01-build.sh | 2 +- include/cactus_rt/config.h | 2 +- .../tracing/tracing_enabled.disabled.h | 4 ++ include/cactus_rt/tracing/tracing_enabled.h | 4 ++ scripts/test-in-docker | 2 +- tests/CMakeLists.txt | 4 +- 10 files changed, 53 insertions(+), 37 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e2a036e..f7d83d5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index dddf8c4..3c97011 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 @@ -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() @@ -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) diff --git a/Makefile b/Makefile index 3336393..0a17ce6 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -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 @@ -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 diff --git a/README.md b/README.md index ea6e780..9fee530 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/docker/scripts/01-build.sh b/docker/scripts/01-build.sh index beb74c4..4870b42 100755 --- a/docker/scripts/01-build.sh +++ b/docker/scripts/01-build.sh @@ -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) diff --git a/include/cactus_rt/config.h b/include/cactus_rt/config.h index 73d9e9a..d80b14d 100644 --- a/include/cactus_rt/config.h +++ b/include/cactus_rt/config.h @@ -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; }; diff --git a/include/cactus_rt/tracing/tracing_enabled.disabled.h b/include/cactus_rt/tracing/tracing_enabled.disabled.h index 2ebe241..bc4ae5f 100644 --- a/include/cactus_rt/tracing/tracing_enabled.disabled.h +++ b/include/cactus_rt/tracing/tracing_enabled.disabled.h @@ -5,6 +5,10 @@ inline bool IsTracingEnabled() noexcept { return false; } +inline bool IsTracingAvailable() noexcept { + return false; +} + inline void EnableTracing() noexcept {} inline void DisableTracing() noexcept {} diff --git a/include/cactus_rt/tracing/tracing_enabled.h b/include/cactus_rt/tracing/tracing_enabled.h index ff475e9..46c76e2 100644 --- a/include/cactus_rt/tracing/tracing_enabled.h +++ b/include/cactus_rt/tracing/tracing_enabled.h @@ -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; } diff --git a/scripts/test-in-docker b/scripts/test-in-docker index cbda3cf..f03c008 100755 --- a/scripts/test-in-docker +++ b/scripts/test-in-docker @@ -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 \ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e06e92c..a874d0b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 @@ -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