Skip to content

Commit

Permalink
使用 CMake 3.28 简化 CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
lanthora committed Jul 15, 2024
1 parent 6a9cb40 commit 310d498
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 34 deletions.
1 change: 1 addition & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:

linux:
strategy:
fail-fast: false
matrix:
image:
- "debian:12"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ jobs:

deb:
strategy:
fail-fast: false
matrix:
image:
- "debian:12"
Expand Down
63 changes: 29 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.18.4)

project(candy LANGUAGES C CXX VERSION 5.10.0)
project(candy LANGUAGES C CXX VERSION 5.10.1)

option(CANDY_NOEXE "Don't build executable")
option(CANDY_DEVEL "Build development library")
Expand All @@ -17,6 +17,31 @@ 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 @@ -61,31 +86,11 @@ if (${CANDY_STATIC_OPENSSL})
endif()

if (${CANDY_STATIC_FMT})
include(FetchContent)
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 10.2.1
)
FetchContent_GetProperties(fmt)
if(NOT fmt_POPULATED)
FetchContent_Populate(fmt)
add_subdirectory(${fmt_SOURCE_DIR} ${fmt_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
Fetch(fmt "https://github.com/fmtlib/fmt.git" "10.2.1")
endif()

if (${CANDY_STATIC_SPDLOG})
include(FetchContent)
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.14.1
)
FetchContent_GetProperties(spdlog)
if(NOT spdlog_POPULATED)
FetchContent_Populate(spdlog)
add_subdirectory(${spdlog_SOURCE_DIR} ${spdlog_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
Fetch(spdlog "https://github.com/gabime/spdlog.git" "v1.14.1")
endif()

if (${CANDY_STATIC_POCO})
Expand All @@ -104,17 +109,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(FetchContent)
FetchContent_Declare(
poco
GIT_REPOSITORY "https://github.com/pocoproject/poco.git"
GIT_TAG "poco-1.13.3-release"
)
FetchContent_GetProperties(poco)
if(NOT poco_POPULATED)
FetchContent_Populate(poco)
add_subdirectory(${poco_SOURCE_DIR} ${poco_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
Fetch(poco "https://github.com/pocoproject/poco.git" "poco-1.13.3-release")
endif()

set(CANDY_EXECUTE_NAME "candy")
Expand Down

0 comments on commit 310d498

Please sign in to comment.