Skip to content

Commit 77ba17d

Browse files
authored
[misc] split dependency preparation logic into individual dependency files for enhanced configuration flexibility (#597)
1 parent 79d502a commit 77ba17d

File tree

5 files changed

+91
-59
lines changed

5 files changed

+91
-59
lines changed

ucm/shared/vendor/CMakeLists.txt

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,3 @@
1-
function(EnableDept)
2-
cmake_parse_arguments(DEPT "" "NAME;TAG" "GIT_URLS" ${ARGN})
3-
find_program(GIT_EXECUTABLE git)
4-
if(NOT GIT_EXECUTABLE)
5-
message(FATAL_ERROR "git not found!")
6-
endif()
7-
foreach(GIT_URL IN LISTS DEPT_GIT_URLS)
8-
execute_process(
9-
COMMAND ${GIT_EXECUTABLE} ls-remote --heads "${GIT_URL}"
10-
RESULT_VARIABLE GIT_RESULT
11-
OUTPUT_QUIET
12-
ERROR_QUIET
13-
TIMEOUT 15
14-
)
15-
if(GIT_RESULT EQUAL 0)
16-
set(VALID_GIT_URL ${GIT_URL})
17-
break()
18-
endif()
19-
endforeach()
20-
if(NOT VALID_GIT_URL)
21-
message(FATAL_ERROR "all urls for ${DEPT_NAME} are not reachable!")
22-
endif()
23-
message(STATUS "Fetching ${DEPT_NAME}(${DEPT_TAG}) from ${VALID_GIT_URL}")
24-
FetchContent_Declare(${DEPT_NAME} GIT_REPOSITORY ${VALID_GIT_URL} GIT_TAG ${DEPT_TAG} GIT_SHALLOW TRUE)
25-
string(TOUPPER ${DEPT_NAME} NAME_UPPER)
26-
set(${NAME_UPPER}_INSTALL OFF CACHE INTERNAL "" FORCE)
27-
set(${NAME_UPPER}_BUILD_TESTS OFF CACHE INTERNAL "" FORCE)
28-
set(${NAME_UPPER}_BUILD_EXAMPLES OFF CACHE INTERNAL "" FORCE)
29-
FetchContent_MakeAvailable(${DEPT_NAME})
30-
endfunction()
31-
32-
if(DOWNLOAD_DEPENDENCE)
33-
include(FetchContent)
34-
EnableDept(
35-
NAME fmt
36-
TAG 11.2.0
37-
GIT_URLS
38-
https://github.com/fmtlib/fmt.git
39-
https://gitcode.com/GitHub_Trending/fm/fmt.git
40-
)
41-
EnableDept(
42-
NAME spdlog
43-
TAG v1.15.3
44-
GIT_URLS
45-
https://github.com/gabime/spdlog.git
46-
https://gitcode.com/GitHub_Trending/sp/spdlog.git
47-
)
48-
EnableDept(
49-
NAME pybind11
50-
TAG v3.0.1
51-
GIT_URLS
52-
https://github.com/pybind/pybind11.git
53-
https://gitcode.com/GitHub_Trending/py/pybind11.git
54-
)
55-
else()
56-
add_subdirectory(fmt)
57-
add_subdirectory(spdlog)
58-
add_subdirectory(pybind11)
59-
endif()
1+
include(dep-fmt.cmake)
2+
include(dep-spdlog.cmake)
3+
include(dep-pybind11.cmake)

ucm/shared/vendor/dep-fmt.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
set(FMT_INSTALL OFF CACHE INTERNAL "" FORCE)
2+
set(FMT_BUILD_TESTS OFF CACHE INTERNAL "" FORCE)
3+
set(FMT_BUILD_EXAMPLES OFF CACHE INTERNAL "" FORCE)
4+
5+
if(DOWNLOAD_DEPENDENCE)
6+
set(DEP_FMT_NAME fmt)
7+
set(DEP_FMT_TAG 11.2.0)
8+
set(DEP_FMT_GIT_URLS
9+
https://github.com/fmtlib/fmt.git
10+
https://gitcode.com/GitHub_Trending/fm/fmt.git
11+
)
12+
include(helper.cmake)
13+
find_reachable_git_url(REACHABLE_URL DEP_FMT_GIT_URLS)
14+
include(FetchContent)
15+
message(STATUS "Fetching ${DEP_FMT_NAME}(${DEP_FMT_TAG}) from ${REACHABLE_URL}")
16+
FetchContent_Declare(${DEP_FMT_NAME} GIT_REPOSITORY ${REACHABLE_URL} GIT_TAG ${DEP_FMT_TAG} GIT_SHALLOW TRUE)
17+
FetchContent_MakeAvailable(${DEP_FMT_NAME})
18+
else()
19+
add_subdirectory(fmt)
20+
endif()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
set(PYBIND11_INSTALL OFF CACHE INTERNAL "" FORCE)
2+
set(PYBIND11_BUILD_TESTS OFF CACHE INTERNAL "" FORCE)
3+
set(PYBIND11_BUILD_EXAMPLES OFF CACHE INTERNAL "" FORCE)
4+
5+
if(DOWNLOAD_DEPENDENCE)
6+
set(DEP_PYBIND11_NAME pybind11)
7+
set(DEP_PYBIND11_TAG v3.0.1)
8+
set(DEP_PYBIND11_GIT_URLS
9+
https://github.com/pybind/pybind11.git
10+
https://gitcode.com/GitHub_Trending/py/pybind11.git
11+
)
12+
include(helper.cmake)
13+
find_reachable_git_url(REACHABLE_URL DEP_PYBIND11_GIT_URLS)
14+
include(FetchContent)
15+
message(STATUS "Fetching ${DEP_PYBIND11_NAME}(${DEP_PYBIND11_TAG}) from ${REACHABLE_URL}")
16+
FetchContent_Declare(${DEP_PYBIND11_NAME} GIT_REPOSITORY ${REACHABLE_URL} GIT_TAG ${DEP_PYBIND11_TAG} GIT_SHALLOW TRUE)
17+
FetchContent_MakeAvailable(${DEP_PYBIND11_NAME})
18+
else()
19+
add_subdirectory(pybind11)
20+
endif()

ucm/shared/vendor/dep-spdlog.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
set(SPDLOG_INSTALL OFF CACHE INTERNAL "" FORCE)
2+
set(SPDLOG_BUILD_TESTS OFF CACHE INTERNAL "" FORCE)
3+
set(SPDLOG_BUILD_EXAMPLES OFF CACHE INTERNAL "" FORCE)
4+
set(SPDLOG_FMT_EXTERNAL ON CACHE INTERNAL "" FORCE)
5+
6+
if(DOWNLOAD_DEPENDENCE)
7+
set(DEP_SPDLOG_NAME spdlog)
8+
set(DEP_SPDLOG_TAG v1.15.3)
9+
set(DEP_SPDLOG_GIT_URLS
10+
https://github.com/gabime/spdlog.git
11+
https://gitcode.com/GitHub_Trending/sp/spdlog.git
12+
)
13+
include(helper.cmake)
14+
find_reachable_git_url(REACHABLE_URL DEP_SPDLOG_GIT_URLS)
15+
include(FetchContent)
16+
message(STATUS "Fetching ${DEP_SPDLOG_NAME}(${DEP_SPDLOG_TAG}) from ${REACHABLE_URL}")
17+
FetchContent_Declare(${DEP_SPDLOG_NAME} GIT_REPOSITORY ${REACHABLE_URL} GIT_TAG ${DEP_SPDLOG_TAG} GIT_SHALLOW TRUE)
18+
FetchContent_MakeAvailable(${DEP_SPDLOG_NAME})
19+
else()
20+
add_subdirectory(spdlog)
21+
endif()

ucm/shared/vendor/helper.cmake

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function(find_reachable_git_url OUT_REACHABLE_URL IN_URL_LIST)
2+
find_program(GIT_EXECUTABLE git)
3+
if(NOT GIT_EXECUTABLE)
4+
message(FATAL_ERROR "git not found!")
5+
endif()
6+
7+
if(DEFINED ${IN_URL_LIST})
8+
set(URL_LIST ${${IN_URL_LIST}})
9+
else()
10+
set(URL_LIST ${ARGN})
11+
endif()
12+
13+
foreach(GIT_URL IN LISTS URL_LIST)
14+
execute_process(
15+
COMMAND ${GIT_EXECUTABLE} ls-remote --heads "${GIT_URL}"
16+
RESULT_VARIABLE GIT_RESULT
17+
OUTPUT_QUIET ERROR_QUIET
18+
TIMEOUT 5
19+
)
20+
if(GIT_RESULT EQUAL 0)
21+
set(${OUT_REACHABLE_URL} ${GIT_URL} PARENT_SCOPE)
22+
return()
23+
endif()
24+
endforeach()
25+
26+
message(FATAL_ERROR "All git URLs are not reachable!")
27+
endfunction()

0 commit comments

Comments
 (0)