From 30209d6781948bdf3198da337786f391ecb7b15e Mon Sep 17 00:00:00 2001 From: IronsDu Date: Thu, 9 Apr 2026 09:52:17 +0800 Subject: [PATCH 1/3] fix: update cmake config file and add find_package integration test After the Drogon decoupling refactoring, cpp-remote-profiler-config.cmake.in was still referencing the old `profiler_lib` target and finding PRIVATE deps (Backward, absl) that consumers don't need. This commit fixes the config file to match the new target structure (profiler_core/profiler_web) and adds a CI integration test to verify find_package correctness. Co-Authored-By: Claude Opus 4.6 --- .github/workflows/ci.yml | 26 ++++++- cmake/cpp-remote-profiler-config.cmake.in | 71 ++++--------------- .../examples/test_find_package/CMakeLists.txt | 21 ++++++ cmake/examples/test_find_package/main.cpp | 10 +++ plan.md | 51 ++++++++++++- 5 files changed, 118 insertions(+), 61 deletions(-) create mode 100644 cmake/examples/test_find_package/CMakeLists.txt create mode 100644 cmake/examples/test_find_package/main.cpp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b25f934..99adbf1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,7 +73,18 @@ jobs: working-directory: build/release run: | ldd profiler_example - ldd libprofiler_lib.so + ldd libprofiler_core.so + + - name: Test find_package integration + run: | + INSTALL_DIR=$(mktemp -d) + cmake --install build/release --prefix "$INSTALL_DIR" + cd cmake/examples/test_find_package + cmake -B build \ + -Dcpp-remote-profiler_DIR="$INSTALL_DIR/lib/cmake/cpp-remote-profiler" \ + -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" + cmake --build build + echo "find_package integration test PASSED" # Code Coverage coverage: @@ -213,4 +224,15 @@ jobs: working-directory: build/clang-release run: | ldd profiler_example - ldd libprofiler_lib.so + ldd libprofiler_core.so + + - name: Test find_package integration + run: | + INSTALL_DIR=$(mktemp -d) + cmake --install build/clang-release --prefix "$INSTALL_DIR" + cd cmake/examples/test_find_package + cmake -B build \ + -Dcpp-remote-profiler_DIR="$INSTALL_DIR/lib/cmake/cpp-remote-profiler" \ + -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" + cmake --build build + echo "find_package integration test PASSED" diff --git a/cmake/cpp-remote-profiler-config.cmake.in b/cmake/cpp-remote-profiler-config.cmake.in index 5bcfe39..59391c5 100644 --- a/cmake/cpp-remote-profiler-config.cmake.in +++ b/cmake/cpp-remote-profiler-config.cmake.in @@ -6,57 +6,16 @@ include(CMakeFindDependencyMacro) -# Find required dependencies -# Note: gperftools and backward-cpp should be found by pkg-config or system paths +# Find PUBLIC dependencies of profiler_core +# gperftools is the only PUBLIC dependency find_dependency(PkgConfig REQUIRED) - -# Try to find gperftools pkg_check_modules(GPERFTOOLS REQUIRED libprofiler libtcmalloc) -# Try to find Backward (optional, for symbolization) -find_package(Backward QUIET) -if(NOT Backward_FOUND) - message(STATUS "cpp-remote-profiler: Backward not found, symbolization may be limited") -endif() - -# Try to find abseil (optional, for symbolization) -# Try multiple methods to find abseil -find_package(absl QUIET) - -if(NOT absl_FOUND) - # Try to find via PkgConfig - pkg_check_modules(absl QUIET abseil-cpp absl_base absl_symbolize) - if(NOT absl_FOUND) - message(STATUS "cpp-remote-profiler: abseil not found, trying to find system libraries") - endif() -endif() - -# If still not found, it's OK - the library may still work if symbols are in the binary -if(NOT absl_FOUND) - message(STATUS "cpp-remote-profiler: abseil CMake package not found, assuming symbols are linked") -endif() - # ---------------------------------------------------------------------------- -# Include targets +# Include exported targets # ---------------------------------------------------------------------------- -# Check if we're building as part of the same build tree -if(CMAKE_CURRENT_LIST_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - # Not building as part of this project - include("${CMAKE_CURRENT_LIST_DIR}/cpp-remote-profiler-targets.cmake") -else() - # Building as part of this project - include("${CMAKE_CURRENT_LIST_DIR}/cpp-remote-profiler-targets.cmake") -endif() - -# ---------------------------------------------------------------------------- -# Set up imported targets -# ---------------------------------------------------------------------------- - -# Add alias for backward compatibility -if(NOT TARGET cpp-remote-profiler::profiler_lib AND TARGET profiler_lib) - add_library(cpp-remote-profiler::profiler_lib ALIAS profiler_lib) -endif() +include("${CMAKE_CURRENT_LIST_DIR}/cpp-remote-profiler-targets.cmake") # ---------------------------------------------------------------------------- # Set variables for compatibility @@ -64,21 +23,21 @@ endif() set(CPP_REMOTE_PROFILER_VERSION @PROJECT_VERSION@) set(CPP_REMOTE_PROFILER_FOUND TRUE) -set(CPP_REMOTE_PROFILER_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@") -# Get the installation prefix -if(NOT CMAKE_INSTALL_PREFIX) - set(CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@") +# Check if profiler_web was installed (optional component) +if(TARGET cpp-remote-profiler::profiler_web) + set(CPP_REMOTE_PROFILER_WEB_AVAILABLE TRUE) +else() + set(CPP_REMOTE_PROFILER_WEB_AVAILABLE FALSE) endif() # ---------------------------------------------------------------------------- # Check required components # ---------------------------------------------------------------------------- -# Validate that all required dependencies are available -if(NOT GPERFTOOLS_FOUND) +if(NOT TARGET cpp-remote-profiler::profiler_core) set(CPP_REMOTE_PROFILER_FOUND FALSE) - set(CPP_REMOTE_PROFILER_NOT_FOUND_MESSAGE "gperftools is required but not found") + set(CPP_REMOTE_PROFILER_NOT_FOUND_MESSAGE "profiler_core target not found") endif() # ---------------------------------------------------------------------------- @@ -87,16 +46,14 @@ endif() if(NOT cpp-remote-profiler_FIND_QUIETLY) message(STATUS "Found cpp-remote-profiler: ${CPP_REMOTE_PROFILER_VERSION}") - message(STATUS " Install prefix: ${CMAKE_INSTALL_PREFIX}") - message(STATUS " Include directories: ${CMAKE_INSTALL_PREFIX}/include/cpp-remote-profiler") - message(STATUS " Library directories: ${CMAKE_INSTALL_PREFIX}/lib") + message(STATUS " profiler_core: available") + message(STATUS " profiler_web: ${CPP_REMOTE_PROFILER_WEB_AVAILABLE}") endif() # ---------------------------------------------------------------------------- -# Compatibility check +# Version compatibility check # ---------------------------------------------------------------------------- -# Check if requested version is compatible if(@PROJECT_VERSION@ VERSION_LESS cpp-remote-profiler_FIND_VERSION) set(CPP_REMOTE_PROFILER_FOUND FALSE) set(CPP_REMOTE_PROFILER_NOT_FOUND_MESSAGE diff --git a/cmake/examples/test_find_package/CMakeLists.txt b/cmake/examples/test_find_package/CMakeLists.txt new file mode 100644 index 0000000..d8802a5 --- /dev/null +++ b/cmake/examples/test_find_package/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.15) +project(test_find_package VERSION 1.0.0 LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Find the installed cpp-remote-profiler package +find_package(cpp-remote-profiler REQUIRED) + +# Test 1: Link against profiler_core (always available) +add_executable(test_core main.cpp) +target_link_libraries(test_core cpp-remote-profiler::profiler_core) + +# Test 2: If profiler_web is available, test linking against it +if(TARGET cpp-remote-profiler::profiler_web) + add_executable(test_web main.cpp) + target_link_libraries(test_web cpp-remote-profiler::profiler_web) + message(STATUS "test_find_package: profiler_web available, building test_web") +else() + message(STATUS "test_find_package: profiler_web not available, skipping test_web") +endif() diff --git a/cmake/examples/test_find_package/main.cpp b/cmake/examples/test_find_package/main.cpp new file mode 100644 index 0000000..413a184 --- /dev/null +++ b/cmake/examples/test_find_package/main.cpp @@ -0,0 +1,10 @@ +#include "profiler_manager.h" +#include "profiler/log_sink.h" + +int main() { + profiler::ProfilerManager profiler; + // Verify the library can be constructed and basic API is accessible + // Verify the library links correctly — just construct and destroy + (void)profiler; + return 0; +} diff --git a/plan.md b/plan.md index 44de90c..d203227 100644 --- a/plan.md +++ b/plan.md @@ -1638,6 +1638,53 @@ yourFrameworkResponse.setBody(resp.body); --- -**文档版本**: 1.3 -**最后更新**: 2026-04-07 +### 修复 cmake config 文件 & 添加 find_package 集成测试 (2026-04-09) + +#### 背景 + +Drogon 解耦重构后,`cpp-remote-profiler-config.cmake.in` 未同步更新: +1. 仍然引用旧目标名 `profiler_lib`(已改为 `profiler_core`/`profiler_web`) +2. 尝试查找 Backward、absl 等 PRIVATE 依赖(消费者不需要) +3. 没有处理可选的 `profiler_web` target +4. 没有任何测试验证 `find_package` 的正确性 + +CI 中 `ldd` 步骤也引用了旧的 `libprofiler_lib.so`(应为 `libprofiler_core.so`)。 + +#### 变更内容 + +1. **修复 `cmake/cpp-remote-profiler-config.cmake.in`**: + - 移除 Backward、absl 的查找(PRIVATE 依赖,不暴露给消费者) + - 只保留 gperftools(profiler_core 唯一的 PUBLIC 依赖) + - 添加可选 `profiler_web` target 检测(`CPP_REMOTE_PROFILER_WEB_AVAILABLE` 变量) + - 正确检查 `cpp-remote-profiler::profiler_core` target 是否存在 + +2. **添加 `cmake/examples/test_find_package/`**: + - `CMakeLists.txt` — `find_package(cpp-remote-profiler REQUIRED)` + 链接 `profiler_core` + - 如果 `profiler_web` 可用,额外构建 `test_web` 目标 + - `main.cpp` — 最小验证程序 + +3. **更新 `.github/workflows/ci.yml`**: + - GCC 和 Clang job 各增加 `find_package` 集成测试步骤 + - 修复 `ldd` 步骤:`libprofiler_lib.so` → `libprofiler_core.so` + +#### 测试验证 + +- ✅ `find_package(cpp-remote-profiler)` 配置成功 +- ✅ `test_core`(链接 profiler_core)编译链接运行成功 +- ✅ `test_web`(链接 profiler_web)编译链接运行成功 +- ✅ 生成的 config 文件不再查找 Backward/absl + +#### 文件变更清单 + +| 操作 | 文件 | 说明 | +|------|------|------| +| 修改 | `cmake/cpp-remote-profiler-config.cmake.in` | 修复目标名、移除 PRIVATE 依赖、添加 profiler_web 支持 | +| 新增 | `cmake/examples/test_find_package/CMakeLists.txt` | find_package 集成测试 CMake 配置 | +| 新增 | `cmake/examples/test_find_package/main.cpp` | 最小验证程序 | +| 修改 | `.github/workflows/ci.yml` | 添加集成测试步骤、修复 ldd 目标名 | + +--- + +**文档版本**: 1.4 +**最后更新**: 2026-04-09 **维护者**: Claude Code From d9f60b76d3a9e3def09de02dc59512dabb4f3914 Mon Sep 17 00:00:00 2001 From: IronsDu Date: Thu, 9 Apr 2026 13:48:58 +0800 Subject: [PATCH 2/3] ci: add add_subdirectory integration test and fix format - Add cmake/examples/test_fetch_content/ to test add_subdirectory usage (simulates FetchContent consumption pattern) - Fix clang-format issue in test_find_package/main.cpp (include order) - Add add_subdirectory integration test step to GCC CI job - Document discovered issue: profiler_version.h include path broken with add_subdirectory due to global include_directories() usage Co-Authored-By: Claude Opus 4.6 --- .github/workflows/ci.yml | 10 ++++++ .../test_fetch_content/CMakeLists.txt | 35 +++++++++++++++++++ cmake/examples/test_fetch_content/main.cpp | 9 +++++ cmake/examples/test_find_package/main.cpp | 3 +- plan.md | 8 ++++- 5 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 cmake/examples/test_fetch_content/CMakeLists.txt create mode 100644 cmake/examples/test_fetch_content/main.cpp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99adbf1..61fd16f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,6 +86,16 @@ jobs: cmake --build build echo "find_package integration test PASSED" + - name: Test add_subdirectory integration + run: | + cd cmake/examples/test_fetch_content + cmake -B build \ + -DPROFILER_SOURCE_DIR="$GITHUB_WORKSPACE" \ + -DVCPKG_INSTALLED_DIR="$GITHUB_WORKSPACE/build/release/vcpkg_installed" \ + -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" + cmake --build build + echo "add_subdirectory integration test PASSED" + # Code Coverage coverage: name: Code Coverage diff --git a/cmake/examples/test_fetch_content/CMakeLists.txt b/cmake/examples/test_fetch_content/CMakeLists.txt new file mode 100644 index 0000000..3d4a209 --- /dev/null +++ b/cmake/examples/test_fetch_content/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.15) +project(test_fetch_content VERSION 1.0.0 LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Disable cpp-remote-profiler's own examples/tests/install to avoid conflicts +set(REMOTE_PROFILER_BUILD_EXAMPLES OFF CACHE BOOL "") +set(REMOTE_PROFILER_BUILD_TESTS OFF CACHE BOOL "") +set(REMOTE_PROFILER_INSTALL OFF CACHE BOOL "") + +# Use add_subdirectory to bring in cpp-remote-profiler +# This simulates what FetchContent does at configure time +# SOURCE_DIR is passed by the CI test step +if(NOT DEFINED PROFILER_SOURCE_DIR) + message(FATAL_ERROR "PROFILER_SOURCE_DIR must be set to the cpp-remote-profiler source directory") +endif() + +add_subdirectory(${PROFILER_SOURCE_DIR} ${CMAKE_BINARY_DIR}/cpp-remote-profiler) + +# Test: link against profiler_core +add_executable(test_core main.cpp) +target_link_libraries(test_core profiler_core) +# Include generated profiler_version.h from the subproject's binary dir +target_include_directories(test_core PRIVATE ${CMAKE_BINARY_DIR}/cpp-remote-profiler) + +# Test: link against profiler_web (if available) +if(TARGET profiler_web) + add_executable(test_web main.cpp) + target_link_libraries(test_web profiler_web) + target_include_directories(test_web PRIVATE ${CMAKE_BINARY_DIR}/cpp-remote-profiler) + message(STATUS "test_fetch_content: profiler_web available, building test_web") +else() + message(STATUS "test_fetch_content: profiler_web not available, skipping test_web") +endif() diff --git a/cmake/examples/test_fetch_content/main.cpp b/cmake/examples/test_fetch_content/main.cpp new file mode 100644 index 0000000..a26e6f4 --- /dev/null +++ b/cmake/examples/test_fetch_content/main.cpp @@ -0,0 +1,9 @@ +#include "profiler/log_sink.h" +#include "profiler_manager.h" + +int main() { + profiler::ProfilerManager profiler; + // Verify the library links correctly — just construct and destroy + (void)profiler; + return 0; +} diff --git a/cmake/examples/test_find_package/main.cpp b/cmake/examples/test_find_package/main.cpp index 413a184..a26e6f4 100644 --- a/cmake/examples/test_find_package/main.cpp +++ b/cmake/examples/test_find_package/main.cpp @@ -1,9 +1,8 @@ -#include "profiler_manager.h" #include "profiler/log_sink.h" +#include "profiler_manager.h" int main() { profiler::ProfilerManager profiler; - // Verify the library can be constructed and basic API is accessible // Verify the library links correctly — just construct and destroy (void)profiler; return 0; diff --git a/plan.md b/plan.md index d203227..28be971 100644 --- a/plan.md +++ b/plan.md @@ -1681,7 +1681,13 @@ CI 中 `ldd` 步骤也引用了旧的 `libprofiler_lib.so`(应为 `libprofiler | 修改 | `cmake/cpp-remote-profiler-config.cmake.in` | 修复目标名、移除 PRIVATE 依赖、添加 profiler_web 支持 | | 新增 | `cmake/examples/test_find_package/CMakeLists.txt` | find_package 集成测试 CMake 配置 | | 新增 | `cmake/examples/test_find_package/main.cpp` | 最小验证程序 | -| 修改 | `.github/workflows/ci.yml` | 添加集成测试步骤、修复 ldd 目标名 | +| 新增 | `cmake/examples/test_fetch_content/CMakeLists.txt` | add_subdirectory 集成测试(模拟 FetchContent) | +| 新增 | `cmake/examples/test_fetch_content/main.cpp` | 最小验证程序 | +| 修改 | `.github/workflows/ci.yml` | 添加 find_package + add_subdirectory 集成测试、修复 ldd 目标名 | + +#### 发现的问题 + +`add_subdirectory` 使用时 `profiler_version.h` 的 include 路径缺失。原因是主 CMakeLists.txt 使用全局 `include_directories(${CMAKE_CURRENT_BINARY_DIR})` 而非 target-specific 的 `target_include_directories`。后续需要修复。 --- From 8bd4c25d117a111c18e405b3d73c99c95e93b7f4 Mon Sep 17 00:00:00 2001 From: IronsDu Date: Thu, 9 Apr 2026 14:00:02 +0800 Subject: [PATCH 3/3] refactor: replace outdated FetchContent examples with in-file docs - Delete cmake/examples/{CMakeLists.txt,FetchContent_example.cmake, FetchContent_integration_example.cpp} which used placeholder URLs and deprecated singleton API (getInstance) - Add FetchContent_Declare usage example as comments in test_fetch_content/CMakeLists.txt so users can see both add_subdirectory and FetchContent approaches in one place Co-Authored-By: Claude Opus 4.6 --- cmake/examples/CMakeLists.txt | 53 ------------------- cmake/examples/FetchContent_example.cmake | 53 ------------------- .../FetchContent_integration_example.cpp | 43 --------------- .../test_fetch_content/CMakeLists.txt | 24 +++++++-- 4 files changed, 21 insertions(+), 152 deletions(-) delete mode 100644 cmake/examples/CMakeLists.txt delete mode 100644 cmake/examples/FetchContent_example.cmake delete mode 100644 cmake/examples/FetchContent_integration_example.cpp diff --git a/cmake/examples/CMakeLists.txt b/cmake/examples/CMakeLists.txt deleted file mode 100644 index 5eae46f..0000000 --- a/cmake/examples/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(FetchContentExample VERSION 1.0.0 LANGUAGES CXX) - -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -# ============================================================================ -# Option 1: FetchContent from GitHub -# ============================================================================ - -include(FetchContent) - -FetchContent_Declare( - cpp-remote-profiler - GIT_REPOSITORY https://github.com/your-org/cpp-remote-profiler.git - GIT_TAG v0.1.0 - GIT_SHALLOW TRUE -) - -# Configure cpp-remote-profiler options -set(REMOTE_PROFILER_BUILD_EXAMPLES OFF CACHE BOOL "") -set(REMOTE_PROFILER_BUILD_TESTS OFF CACHE BOOL "") -set(REMOTE_PROFILER_INSTALL OFF CACHE BOOL "") - -# Fetch and make available -FetchContent_MakeAvailable(cpp-remote-profiler) - -# Find dependencies (manual - since we're not using vcpkg here) -find_package(PkgConfig REQUIRED) -pkg_check_modules(GPERFTOOLS REQUIRED libprofiler libtcmalloc) -# Drogon is pulled in automatically by profiler_web target - -# ============================================================================ -# Build example executable -# ============================================================================ - -add_executable(fetch_content_example FetchContent_integration_example.cpp) - -target_link_libraries(fetch_content_example - cpp-remote-profiler::profiler_web - ${GPERFTOOLS_LIBRARIES} -) - -# ============================================================================ -# Alternative: Option 2 - Using local path -# ============================================================================ - -# If you have cpp-remote-profiler locally: -# add_subdirectory(/path/to/cpp-remote-profiler) - -# Then link: -# target_link_libraries(your_app cpp-remote-profiler::profiler_core) diff --git a/cmake/examples/FetchContent_example.cmake b/cmake/examples/FetchContent_example.cmake deleted file mode 100644 index 136805f..0000000 --- a/cmake/examples/FetchContent_example.cmake +++ /dev/null @@ -1,53 +0,0 @@ -# ============================================================================ -# FetchContent Integration Example for cpp-remote-profiler -# ============================================================================ -# -# This file demonstrates how to use FetchContent to include -# cpp-remote-profiler in your project without installing it. -# -# Usage: -# In your project's CMakeLists.txt, add: -# include(cmake/FetchContent_example.cmake) -# -# Or copy the content to your CMakeLists.txt directly. -# ============================================================================ - -include(FetchContent) - -# Method 1: From GitHub (release) -FetchContent_Declare( - cpp-remote-profiler - GIT_REPOSITORY https://github.com/your-org/cpp-remote-profiler.git - GIT_TAG v0.1.0 - GIT_SHALLOW TRUE -) - -# Method 2: From GitHub (branch) -# FetchContent_Declare( -# cpp-remote-profiler -# GIT_REPOSITORY https://github.com/your-org/cpp-remote-profiler.git -# GIT_TAG main -# GIT_SHALLOW TRUE -# ) - -# Method 3: From URL (archive) -# FetchContent_Declare( -# cpp-remote-profiler -# URL https://github.com/your-org/cpp-remote-profiler/archive/refs/tags/v0.1.0.tar.gz -# URL_HASH SHA256= -# ) - -# Set options for cpp-remote-profiler -set(REMOTE_PROFILER_BUILD_EXAMPLES OFF CACHE BOOL "") -set(REMOTE_PROFILER_BUILD_TESTS OFF CACHE BOOL "") -set(REMOTE_PROFILER_INSTALL OFF CACHE BOOL "") -set(BUILD_SHARED_LIBS ON CACHE BOOL "") - -# Make available -FetchContent_MakeAvailable(cpp-remote-profiler) - -# Link to your target -# target_link_libraries(your_target -# cpp-remote-profiler::profiler_web -# Drogon::Drogon # Required if using web features -# ) diff --git a/cmake/examples/FetchContent_integration_example.cpp b/cmake/examples/FetchContent_integration_example.cpp deleted file mode 100644 index f7e4eb3..0000000 --- a/cmake/examples/FetchContent_integration_example.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Example: Using cpp-remote-profiler via FetchContent - * - * This example demonstrates how to integrate cpp-remote-profiler - * into your project using CMake FetchContent. - */ - -#include "profiler_manager.h" -#include -#include -#include - -void doWork() { - double result = 0; - for (int i = 0; i < 1000000; i++) { - result += std::sqrt(i); - } -} - -int main() { - std::cout << "=== FetchContent Integration Example ===" << std::endl; - - // Get profiler instance - auto& profiler = profiler::ProfilerManager::getInstance(); - - std::cout << "Profiler version: " << REMOTE_PROFILER_VERSION << std::endl; - - // Start CPU profiling - std::cout << "Starting CPU profiling..." << std::endl; - profiler.startCPUProfiler("fetch_content_profile.prof"); - - // Do some work - for (int i = 0; i < 10; i++) { - doWork(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - - // Stop profiling - profiler.stopCPUProfiler(); - std::cout << "Profiling complete!" << std::endl; - - return 0; -} diff --git a/cmake/examples/test_fetch_content/CMakeLists.txt b/cmake/examples/test_fetch_content/CMakeLists.txt index 3d4a209..0d07202 100644 --- a/cmake/examples/test_fetch_content/CMakeLists.txt +++ b/cmake/examples/test_fetch_content/CMakeLists.txt @@ -9,9 +9,27 @@ set(REMOTE_PROFILER_BUILD_EXAMPLES OFF CACHE BOOL "") set(REMOTE_PROFILER_BUILD_TESTS OFF CACHE BOOL "") set(REMOTE_PROFILER_INSTALL OFF CACHE BOOL "") -# Use add_subdirectory to bring in cpp-remote-profiler -# This simulates what FetchContent does at configure time -# SOURCE_DIR is passed by the CI test step +# ============================================================================ +# Option A: FetchContent (recommended for real projects) +# ============================================================================ +# +# include(FetchContent) +# FetchContent_Declare( +# cpp-remote-profiler +# GIT_REPOSITORY https://github.com/IronsDu/cpp-remote-profiler.git +# GIT_TAG v0.1.0 +# GIT_SHALLOW TRUE +# ) +# FetchContent_MakeAvailable(cpp-remote-profiler) +# +# Then link: +# target_link_libraries(your_app profiler_core) # core only +# target_link_libraries(your_app profiler_web) # with Drogon web UI +# +# ============================================================================ +# Option B: add_subdirectory (used below for CI testing) +# ============================================================================ + if(NOT DEFINED PROFILER_SOURCE_DIR) message(FATAL_ERROR "PROFILER_SOURCE_DIR must be set to the cpp-remote-profiler source directory") endif()