Skip to content

Commit

Permalink
独立 Fetch 宏到单独文件
Browse files Browse the repository at this point in the history
  • Loading branch information
lanthora committed Jul 15, 2024
1 parent 310d498 commit cf48d85
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
28 changes: 3 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,6 @@ if (${CANDY_STATIC})
set(CANDY_STATIC_POCO 1)
endif()

macro(Fetch NAME GIT_REPOSITORY GIT_TAG)
include(FetchContent)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.28")
FetchContent_Declare(
${NAME}
GIT_REPOSITORY ${GIT_REPOSITORY}
GIT_TAG ${GIT_TAG}
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(${NAME})
else()
FetchContent_Declare(
${NAME}
GIT_REPOSITORY ${GIT_REPOSITORY}
GIT_TAG ${GIT_TAG}
)
FetchContent_GetProperties(${NAME})
if(NOT ${NAME}_POPULATED)
FetchContent_Populate(${NAME})
add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
endif()
endmacro()


if (${CANDY_STATIC_OPENSSL})
execute_process(
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/openssl
Expand Down Expand Up @@ -86,10 +61,12 @@ if (${CANDY_STATIC_OPENSSL})
endif()

if (${CANDY_STATIC_FMT})
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Fetch.cmake)
Fetch(fmt "https://github.com/fmtlib/fmt.git" "10.2.1")
endif()

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

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

Expand Down
23 changes: 23 additions & 0 deletions cmake/Fetch.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
macro(Fetch NAME GIT_REPOSITORY GIT_TAG)
include(FetchContent)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.28")
FetchContent_Declare(
${NAME}
GIT_REPOSITORY ${GIT_REPOSITORY}
GIT_TAG ${GIT_TAG}
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(${NAME})
else()
FetchContent_Declare(
${NAME}
GIT_REPOSITORY ${GIT_REPOSITORY}
GIT_TAG ${GIT_TAG}
)
FetchContent_GetProperties(${NAME})
if(NOT ${NAME}_POPULATED)
FetchContent_Populate(${NAME})
add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
endif()
endmacro()

0 comments on commit cf48d85

Please sign in to comment.