Skip to content

Commit d317261

Browse files
committed
support FetchContent (#561)
add FetchContent
1 parent 08ee461 commit d317261

File tree

6 files changed

+72
-22
lines changed

6 files changed

+72
-22
lines changed

CMakeLists.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.

DOC/C-CPP/Readme.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,46 @@ Dependency|Version
1010
cmake| 3.2+
1111
GCC| GCC `4.7+`
1212

13-
### Build
13+
#### Build
1414

15+
>@obsoleted
1516
Use CMake `add_subdirectory`;
16-
[CMakeLists.txt example](../../CMakeLists.txt)
17+
[CMakeLists.txt example](../../src/CPP/CMakeLists.txt)
1718

1819
```
1920
$ mkdir build
2021
$ cd build
2122
$ cmake .. && make
2223
```
24+
#### Integrate in your own project
25+
26+
> Use cmake FetchContent
27+
28+
[CMakeLists.txt example](../../src/CPP/CMakeLists.txt)
29+
30+
```shell
31+
include(FetchContent)
32+
FetchContent_Declare(
33+
pinpoint
34+
GIT_REPOSITORY https://github.com/pinpoint-c-agent/pinpoint-c-agent.git
35+
# GIT_TAG 74bc39d813d664cb56b78b1506d91932c8131396
36+
# not recommended, please use hash key like `74bc39d813d664cb56b78b1506d91932c8131396`
37+
GIT_TAG origin/dev
38+
)
39+
40+
FetchContent_GetProperties(pinpoint)
41+
if (NOT pinpoint_POPULATED)
42+
FetchContent_Populate(pinpoint)
43+
add_subdirectory(${pinpoint_SOURCE_DIR}/common ${pinpoint_BINARY_DIR})
44+
endif ()
45+
46+
FetchContent_MakeAvailable(pinpoint)
47+
48+
add_executable(app test_pinpoint.cpp)
49+
target_link_libraries(app PRIVATE pinpoint_common_static rt)
50+
```
51+
52+
2353
### Run
2454
2555
```

common/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.13)
2-
project(common VERSION 0.4.24 DESCRIPTION "pinpoint common library")
2+
project(pinpoint VERSION 0.4.24 DESCRIPTION "pinpoint common library")
33

44
set(CMAKE_CXX_STANDARD 11)
55

@@ -45,18 +45,26 @@ link_directories(${CMAKE_BINARY_DIR}/lib)
4545
add_subdirectory(jsoncpp)
4646
add_subdirectory(src)
4747

48+
add_library(pinpoint_common_static STATIC $<TARGET_OBJECTS:pinpoint_common_obj> $<TARGET_OBJECTS:jsoncppObj>)
49+
50+
target_include_directories(pinpoint_common_static PUBLIC
51+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
52+
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
53+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
54+
)
55+
4856
if(UNIX AND NOT APPLE)
4957
include(GNUInstallDirs)
5058
add_library(pinpoint_common_shared SHARED $<TARGET_OBJECTS:pinpoint_common_obj> $<TARGET_OBJECTS:jsoncppObj>)
5159
install(DIRECTORY include/ DESTINATION include/pinpoint_common
5260
FILES_MATCHING PATTERN "*.h")
5361

54-
set_target_properties(pinpoint_common_shared pinpoint_common PROPERTIES
62+
set_target_properties(pinpoint_common_shared pinpoint_common_static PROPERTIES
5563
VERSION ${PROJECT_VERSION}
5664
SOVERSION 1
5765
PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/include/common.h")
5866

59-
install(TARGETS pinpoint_common_shared pinpoint_common ${INSTALL_EXPORT}
67+
install(TARGETS pinpoint_common_shared pinpoint_common_static ${INSTALL_EXPORT}
6068
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
6169
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
6270
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}

common/src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ foreach(dir ${src_dir})
44
endforeach()
55

66
add_library(pinpoint_common_obj OBJECT ${SRC_FILES})
7-
add_library(pinpoint_common STATIC $<TARGET_OBJECTS:pinpoint_common_obj> $<TARGET_OBJECTS:jsoncppObj>)
7+
# add_library(pinpoint_common STATIC $<TARGET_OBJECTS:pinpoint_common_obj> $<TARGET_OBJECTS:jsoncppObj>)

common/test/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ target_compile_definitions(TestCommon PRIVATE "-DUTEST -DCOMMON_DEBUG")
66
# message("${CMAKE_BINARY_DIR}/lib")
77
if (WITH_CODECOVERAGE AND LINUX_)
88
# message("enable -lgcov")
9-
target_link_libraries(TestCommon pinpoint_common gtest_main rt gcov )
9+
target_link_libraries(TestCommon pinpoint_common_static gtest_main rt gcov )
1010
elseif(APPLE)
11-
target_link_libraries(TestCommon pinpoint_common gtest_main)
11+
target_link_libraries(TestCommon pinpoint_common_static gtest_main)
1212
elseif(MSVC)
1313
message( FATAL_ERROR "pinpoint-c-agent not support windows, if you need create an issue https://github.com/pinpoint-apm/pinpoint-c-agent/issues" )
1414
else()
1515
message("------------------------------")
16-
target_link_libraries(TestCommon pinpoint_common gtest_main rt)
16+
target_link_libraries(TestCommon pinpoint_common_static gtest_main rt)
1717
endif()
1818

1919
add_test(TestCommon TestCommon)

src/CPP/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
project(common)
3+
set(CMAKE_CXX_STANDARD 11)
4+
5+
include(FetchContent)
6+
FetchContent_Declare(
7+
pinpoint
8+
GIT_REPOSITORY https://github.com/pinpoint-c-agent/pinpoint-c-agent.git
9+
# GIT_TAG 74bc39d813d664cb56b78b1506d91932c8131396
10+
# not recommended, please use hash key like `74bc39d813d664cb56b78b1506d91932c8131396`
11+
GIT_TAG origin/dev
12+
)
13+
14+
FetchContent_GetProperties(pinpoint)
15+
if (NOT pinpoint_POPULATED)
16+
FetchContent_Populate(pinpoint)
17+
add_subdirectory(${pinpoint_SOURCE_DIR}/common ${pinpoint_BINARY_DIR})
18+
endif ()
19+
20+
FetchContent_MakeAvailable(pinpoint)
21+
22+
add_executable(test_pinpoint_cpp test_pinpoint.cpp)
23+
add_executable(test_pinpoint_c test_pinpoint.c)
24+
target_link_libraries(test_pinpoint_cpp PRIVATE pinpoint_common_static rt)
25+
target_link_libraries(test_pinpoint_c pinpoint_common_static rt)

0 commit comments

Comments
 (0)