Skip to content

Commit d9f60b7

Browse files
IronsDuclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 30209d6 commit d9f60b7

5 files changed

Lines changed: 62 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ jobs:
8686
cmake --build build
8787
echo "find_package integration test PASSED"
8888
89+
- name: Test add_subdirectory integration
90+
run: |
91+
cd cmake/examples/test_fetch_content
92+
cmake -B build \
93+
-DPROFILER_SOURCE_DIR="$GITHUB_WORKSPACE" \
94+
-DVCPKG_INSTALLED_DIR="$GITHUB_WORKSPACE/build/release/vcpkg_installed" \
95+
-DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake"
96+
cmake --build build
97+
echo "add_subdirectory integration test PASSED"
98+
8999
# Code Coverage
90100
coverage:
91101
name: Code Coverage
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(test_fetch_content VERSION 1.0.0 LANGUAGES CXX)
3+
4+
set(CMAKE_CXX_STANDARD 20)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
# Disable cpp-remote-profiler's own examples/tests/install to avoid conflicts
8+
set(REMOTE_PROFILER_BUILD_EXAMPLES OFF CACHE BOOL "")
9+
set(REMOTE_PROFILER_BUILD_TESTS OFF CACHE BOOL "")
10+
set(REMOTE_PROFILER_INSTALL OFF CACHE BOOL "")
11+
12+
# Use add_subdirectory to bring in cpp-remote-profiler
13+
# This simulates what FetchContent does at configure time
14+
# SOURCE_DIR is passed by the CI test step
15+
if(NOT DEFINED PROFILER_SOURCE_DIR)
16+
message(FATAL_ERROR "PROFILER_SOURCE_DIR must be set to the cpp-remote-profiler source directory")
17+
endif()
18+
19+
add_subdirectory(${PROFILER_SOURCE_DIR} ${CMAKE_BINARY_DIR}/cpp-remote-profiler)
20+
21+
# Test: link against profiler_core
22+
add_executable(test_core main.cpp)
23+
target_link_libraries(test_core profiler_core)
24+
# Include generated profiler_version.h from the subproject's binary dir
25+
target_include_directories(test_core PRIVATE ${CMAKE_BINARY_DIR}/cpp-remote-profiler)
26+
27+
# Test: link against profiler_web (if available)
28+
if(TARGET profiler_web)
29+
add_executable(test_web main.cpp)
30+
target_link_libraries(test_web profiler_web)
31+
target_include_directories(test_web PRIVATE ${CMAKE_BINARY_DIR}/cpp-remote-profiler)
32+
message(STATUS "test_fetch_content: profiler_web available, building test_web")
33+
else()
34+
message(STATUS "test_fetch_content: profiler_web not available, skipping test_web")
35+
endif()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "profiler/log_sink.h"
2+
#include "profiler_manager.h"
3+
4+
int main() {
5+
profiler::ProfilerManager profiler;
6+
// Verify the library links correctly — just construct and destroy
7+
(void)profiler;
8+
return 0;
9+
}

cmake/examples/test_find_package/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#include "profiler_manager.h"
21
#include "profiler/log_sink.h"
2+
#include "profiler_manager.h"
33

44
int main() {
55
profiler::ProfilerManager profiler;
6-
// Verify the library can be constructed and basic API is accessible
76
// Verify the library links correctly — just construct and destroy
87
(void)profiler;
98
return 0;

plan.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,13 @@ CI 中 `ldd` 步骤也引用了旧的 `libprofiler_lib.so`(应为 `libprofiler
16811681
| 修改 | `cmake/cpp-remote-profiler-config.cmake.in` | 修复目标名、移除 PRIVATE 依赖、添加 profiler_web 支持 |
16821682
| 新增 | `cmake/examples/test_find_package/CMakeLists.txt` | find_package 集成测试 CMake 配置 |
16831683
| 新增 | `cmake/examples/test_find_package/main.cpp` | 最小验证程序 |
1684-
| 修改 | `.github/workflows/ci.yml` | 添加集成测试步骤、修复 ldd 目标名 |
1684+
| 新增 | `cmake/examples/test_fetch_content/CMakeLists.txt` | add_subdirectory 集成测试(模拟 FetchContent) |
1685+
| 新增 | `cmake/examples/test_fetch_content/main.cpp` | 最小验证程序 |
1686+
| 修改 | `.github/workflows/ci.yml` | 添加 find_package + add_subdirectory 集成测试、修复 ldd 目标名 |
1687+
1688+
#### 发现的问题
1689+
1690+
`add_subdirectory` 使用时 `profiler_version.h` 的 include 路径缺失。原因是主 CMakeLists.txt 使用全局 `include_directories(${CMAKE_CURRENT_BINARY_DIR})` 而非 target-specific 的 `target_include_directories`。后续需要修复。
16851691
16861692
---
16871693

0 commit comments

Comments
 (0)