Skip to content

Commit cf48d85

Browse files
committed
独立 Fetch 宏到单独文件
1 parent 310d498 commit cf48d85

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

CMakeLists.txt

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,6 @@ if (${CANDY_STATIC})
1717
set(CANDY_STATIC_POCO 1)
1818
endif()
1919

20-
macro(Fetch NAME GIT_REPOSITORY GIT_TAG)
21-
include(FetchContent)
22-
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.28")
23-
FetchContent_Declare(
24-
${NAME}
25-
GIT_REPOSITORY ${GIT_REPOSITORY}
26-
GIT_TAG ${GIT_TAG}
27-
EXCLUDE_FROM_ALL
28-
)
29-
FetchContent_MakeAvailable(${NAME})
30-
else()
31-
FetchContent_Declare(
32-
${NAME}
33-
GIT_REPOSITORY ${GIT_REPOSITORY}
34-
GIT_TAG ${GIT_TAG}
35-
)
36-
FetchContent_GetProperties(${NAME})
37-
if(NOT ${NAME}_POPULATED)
38-
FetchContent_Populate(${NAME})
39-
add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR} EXCLUDE_FROM_ALL)
40-
endif()
41-
endif()
42-
endmacro()
43-
44-
4520
if (${CANDY_STATIC_OPENSSL})
4621
execute_process(
4722
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/openssl
@@ -86,10 +61,12 @@ if (${CANDY_STATIC_OPENSSL})
8661
endif()
8762

8863
if (${CANDY_STATIC_FMT})
64+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Fetch.cmake)
8965
Fetch(fmt "https://github.com/fmtlib/fmt.git" "10.2.1")
9066
endif()
9167

9268
if (${CANDY_STATIC_SPDLOG})
69+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Fetch.cmake)
9370
Fetch(spdlog "https://github.com/gabime/spdlog.git" "v1.14.1")
9471
endif()
9572

@@ -109,6 +86,7 @@ if (${CANDY_STATIC_POCO})
10986
set(ENABLE_ACTIVERECORD_COMPILER OFF CACHE BOOL "" FORCE)
11087
set(ENABLE_ZIP OFF CACHE BOOL "" FORCE)
11188
set(ENABLE_JWT OFF CACHE BOOL "" FORCE)
89+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Fetch.cmake)
11290
Fetch(poco "https://github.com/pocoproject/poco.git" "poco-1.13.3-release")
11391
endif()
11492

cmake/Fetch.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
macro(Fetch NAME GIT_REPOSITORY GIT_TAG)
2+
include(FetchContent)
3+
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.28")
4+
FetchContent_Declare(
5+
${NAME}
6+
GIT_REPOSITORY ${GIT_REPOSITORY}
7+
GIT_TAG ${GIT_TAG}
8+
EXCLUDE_FROM_ALL
9+
)
10+
FetchContent_MakeAvailable(${NAME})
11+
else()
12+
FetchContent_Declare(
13+
${NAME}
14+
GIT_REPOSITORY ${GIT_REPOSITORY}
15+
GIT_TAG ${GIT_TAG}
16+
)
17+
FetchContent_GetProperties(${NAME})
18+
if(NOT ${NAME}_POPULATED)
19+
FetchContent_Populate(${NAME})
20+
add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR} EXCLUDE_FROM_ALL)
21+
endif()
22+
endif()
23+
endmacro()

0 commit comments

Comments
 (0)