Skip to content

Commit 8a69cc8

Browse files
committed
[doc] add FetchContent for CGraph
1 parent 6e6057a commit 8a69cc8

2 files changed

Lines changed: 35 additions & 23 deletions

File tree

CMakeLists.txt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ project(CGraph VERSION 3.1.1)
1515
# CGraph默认使用C++11版本,推荐使用C++17版本。暂不支持C++11以下版本
1616
set(CMAKE_CXX_STANDARD 11)
1717

18-
option(CGRAPH_BUILD_TUTORIAL "Enables builds of tutorials" ON)
19-
option(CGRAPH_BUILD_EXAMPLE "Enables builds of examples" ON)
20-
option(CGRAPH_BUILD_FUNCTIONAL_TESTS "Enables builds of functional tests" OFF)
21-
option(CGRAPH_BUILD_PERFORMANCE_TESTS "Enables builds of performance tests" OFF)
18+
option(CGRAPH_BUILD_TUTORIALS "Enable build tutorials" ON)
19+
option(CGRAPH_BUILD_EXAMPLES "Enable build examples" ON)
20+
option(CGRAPH_BUILD_FUNCTIONAL_TESTS "Enable build functional tests" OFF)
21+
option(CGRAPH_BUILD_PERFORMANCE_TESTS "Enable build performance tests" OFF)
2222

2323
# 如果开启此宏定义,则CGraph执行过程中,不会在控制台打印任何信息
2424
# add_definitions(-D_CGRAPH_SILENCE_)
@@ -40,12 +40,17 @@ option(CGRAPH_BUILD_PERFORMANCE_TESTS "Enables builds of performance tests" OFF)
4040
# add CGraph environment info
4141
include(cmake/CGraph-env-include.cmake)
4242

43-
if(CGRAPH_BUILD_TUTORIAL)
43+
# 教程相关内容
44+
if(CGRAPH_BUILD_TUTORIALS)
45+
message(STATUS "[CGraph] build tutorials")
4446
add_subdirectory(./tutorial)
45-
endif(CGRAPH_BUILD_TUTORIAL)
46-
if(CGRAPH_BUILD_EXAMPLE)
47+
endif(CGRAPH_BUILD_TUTORIALS)
48+
49+
# 样例相关内容
50+
if(CGRAPH_BUILD_EXAMPLES)
51+
message(STATUS "[CGraph] build examples")
4752
add_subdirectory(./example)
48-
endif(CGRAPH_BUILD_EXAMPLE)
53+
endif(CGRAPH_BUILD_EXAMPLES)
4954

5055
# 功能测试相关内容
5156
if(CGRAPH_BUILD_FUNCTIONAL_TESTS)

COMPILE.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,6 @@
3232
$ ./tutorial/T00-HelloCGraph # 运行 T00-HelloCGraph
3333
```
3434

35-
* 在项目中作为第三方库调用,使用FetchContent
36-
```cmake
37-
Include(FetchContent)
38-
FetchContent_Declare(
39-
CGraph
40-
GIT_REPOSITORY https://github.com/ChunelFeng/CGraph.git
41-
GIT_TAG main
42-
GIT_SHALLOW true
43-
)
44-
FetchContent_MakeAvailable(CGraph)
45-
46-
target_include_directories(${PROJECT_NAME} PRIVATE ${CGraph_SOURCE_DIR}/src)
47-
target_link_libraries(${PROJECT_NAME} PRIVATE CGraph)
48-
```
49-
5035
* Bazel编译方式(Linux/MacOS/Windows)
5136
```shell
5237
$ git clone https://github.com/ChunelFeng/CGraph.git
@@ -72,6 +57,28 @@
7257

7358
---
7459

60+
* 在其他使用 CMakeLists.txt 构建的项目中,通过 FetchContent 作为三方库引入
61+
```cmake
62+
set(CGRAPH_BUILD_TUTORIAL OFF CACHE BOOL "" FORCE)
63+
set(CGRAPH_BUILD_EXAMPLE OFF CACHE BOOL "" FORCE)
64+
set(CGRAPH_BUILD_FUNCTIONAL_TESTS OFF CACHE BOOL "" FORCE)
65+
set(CGRAPH_BUILD_PERFORMANCE_TESTS OFF CACHE BOOL "" FORCE)
66+
67+
Include(FetchContent)
68+
FetchContent_Declare(
69+
CGraph
70+
GIT_REPOSITORY https://github.com/ChunelFeng/CGraph.git
71+
GIT_TAG main
72+
GIT_SHALLOW true
73+
)
74+
75+
FetchContent_MakeAvailable(CGraph)
76+
target_include_directories(${PROJECT_NAME} PRIVATE ${CGraph_SOURCE_DIR}/src)
77+
target_link_libraries(${PROJECT_NAME} PRIVATE CGraph)
78+
```
79+
80+
---
81+
7582
### Python 版本
7683
* MacOS 和 Windows 用户可以通过命令安装(推荐)
7784
```shell

0 commit comments

Comments
 (0)