Skip to content
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
36 changes: 34 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,28 @@ 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"

- 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:
Expand Down Expand Up @@ -213,4 +234,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"
71 changes: 14 additions & 57 deletions cmake/cpp-remote-profiler-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,38 @@

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
# ----------------------------------------------------------------------------

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()

# ----------------------------------------------------------------------------
Expand All @@ -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
Expand Down
53 changes: 0 additions & 53 deletions cmake/examples/CMakeLists.txt

This file was deleted.

53 changes: 0 additions & 53 deletions cmake/examples/FetchContent_example.cmake

This file was deleted.

43 changes: 0 additions & 43 deletions cmake/examples/FetchContent_integration_example.cpp

This file was deleted.

53 changes: 53 additions & 0 deletions cmake/examples/test_fetch_content/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 "")

# ============================================================================
# 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()

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()
9 changes: 9 additions & 0 deletions cmake/examples/test_fetch_content/main.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
21 changes: 21 additions & 0 deletions cmake/examples/test_find_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Loading
Loading