Skip to content

Commit

Permalink
support FetchContent (#561)
Browse files Browse the repository at this point in the history
add FetchContent
  • Loading branch information
eeliu committed Mar 28, 2024
1 parent e699274 commit 23bc3a8
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 22 deletions.
13 changes: 0 additions & 13 deletions CMakeLists.txt

This file was deleted.

34 changes: 32 additions & 2 deletions DOC/C-CPP/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,46 @@ Dependency|Version
cmake| 3.2+
GCC| GCC `4.7+`

### Build
#### Build

>@obsoleted
Use CMake `add_subdirectory`;
[CMakeLists.txt example](../../CMakeLists.txt)
[CMakeLists.txt example](../../src/CPP/CMakeLists.txt)

```
$ mkdir build
$ cd build
$ cmake .. && make
```
#### Integrate in your own project

> Use cmake FetchContent
[CMakeLists.txt example](../../src/CPP/CMakeLists.txt)

```shell
include(FetchContent)
FetchContent_Declare(
pinpoint
GIT_REPOSITORY https://github.com/pinpoint-c-agent/pinpoint-c-agent.git
# GIT_TAG 74bc39d813d664cb56b78b1506d91932c8131396
# not recommended, please use hash key like `74bc39d813d664cb56b78b1506d91932c8131396`
GIT_TAG origin/dev
)

FetchContent_GetProperties(pinpoint)
if (NOT pinpoint_POPULATED)
FetchContent_Populate(pinpoint)
add_subdirectory(${pinpoint_SOURCE_DIR}/common ${pinpoint_BINARY_DIR})
endif ()

FetchContent_MakeAvailable(pinpoint)

add_executable(app test_pinpoint.cpp)
target_link_libraries(app PRIVATE pinpoint_common_static rt)
```
### Run
```
Expand Down
14 changes: 11 additions & 3 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13)
project(common VERSION 0.4.24 DESCRIPTION "pinpoint common library")
project(pinpoint VERSION 0.4.24 DESCRIPTION "pinpoint common library")

set(CMAKE_CXX_STANDARD 11)

Expand Down Expand Up @@ -45,18 +45,26 @@ link_directories(${CMAKE_BINARY_DIR}/lib)
add_subdirectory(jsoncpp)
add_subdirectory(src)

add_library(pinpoint_common_static STATIC $<TARGET_OBJECTS:pinpoint_common_obj> $<TARGET_OBJECTS:jsoncppObj>)

target_include_directories(pinpoint_common_static PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
)

if(UNIX AND NOT APPLE)
include(GNUInstallDirs)
add_library(pinpoint_common_shared SHARED $<TARGET_OBJECTS:pinpoint_common_obj> $<TARGET_OBJECTS:jsoncppObj>)
install(DIRECTORY include/ DESTINATION include/pinpoint_common
FILES_MATCHING PATTERN "*.h")

set_target_properties(pinpoint_common_shared pinpoint_common PROPERTIES
set_target_properties(pinpoint_common_shared pinpoint_common_static PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/include/common.h")

install(TARGETS pinpoint_common_shared pinpoint_common ${INSTALL_EXPORT}
install(TARGETS pinpoint_common_shared pinpoint_common_static ${INSTALL_EXPORT}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
2 changes: 1 addition & 1 deletion common/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ foreach(dir ${src_dir})
endforeach()

add_library(pinpoint_common_obj OBJECT ${SRC_FILES})
add_library(pinpoint_common STATIC $<TARGET_OBJECTS:pinpoint_common_obj> $<TARGET_OBJECTS:jsoncppObj>)
# add_library(pinpoint_common STATIC $<TARGET_OBJECTS:pinpoint_common_obj> $<TARGET_OBJECTS:jsoncppObj>)
6 changes: 3 additions & 3 deletions common/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ target_compile_definitions(TestCommon PRIVATE "-DUTEST -DCOMMON_DEBUG")
# message("${CMAKE_BINARY_DIR}/lib")
if (WITH_CODECOVERAGE AND LINUX_)
# message("enable -lgcov")
target_link_libraries(TestCommon pinpoint_common gtest_main rt gcov )
target_link_libraries(TestCommon pinpoint_common_static gtest_main rt gcov )
elseif(APPLE)
target_link_libraries(TestCommon pinpoint_common gtest_main)
target_link_libraries(TestCommon pinpoint_common_static gtest_main)
elseif(MSVC)
message( FATAL_ERROR "pinpoint-c-agent not support windows, if you need create an issue https://github.com/pinpoint-apm/pinpoint-c-agent/issues" )
else()
message("------------------------------")
target_link_libraries(TestCommon pinpoint_common gtest_main rt)
target_link_libraries(TestCommon pinpoint_common_static gtest_main rt)
endif()

add_test(TestCommon TestCommon)
25 changes: 25 additions & 0 deletions src/CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.13)
project(common)
set(CMAKE_CXX_STANDARD 11)

include(FetchContent)
FetchContent_Declare(
pinpoint
GIT_REPOSITORY https://github.com/pinpoint-c-agent/pinpoint-c-agent.git
# GIT_TAG 74bc39d813d664cb56b78b1506d91932c8131396
# not recommended, please use hash key like `74bc39d813d664cb56b78b1506d91932c8131396`
GIT_TAG origin/dev
)

FetchContent_GetProperties(pinpoint)
if (NOT pinpoint_POPULATED)
FetchContent_Populate(pinpoint)
add_subdirectory(${pinpoint_SOURCE_DIR}/common ${pinpoint_BINARY_DIR})
endif ()

FetchContent_MakeAvailable(pinpoint)

add_executable(test_pinpoint_cpp test_pinpoint.cpp)
add_executable(test_pinpoint_c test_pinpoint.c)
target_link_libraries(test_pinpoint_cpp PRIVATE pinpoint_common_static rt)
target_link_libraries(test_pinpoint_c pinpoint_common_static rt)

0 comments on commit 23bc3a8

Please sign in to comment.