|
1 | | -function(EnableDept name url tag) |
2 | | - if(DOWNLOAD_DEPENDENCE) |
3 | | - FetchContent_Declare(${name} GIT_REPOSITORY ${url} GIT_TAG ${tag} GIT_SHALLOW TRUE) |
4 | | - FetchContent_MakeAvailable(${name}) |
5 | | - else() |
6 | | - add_subdirectory(${name}) |
| 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!") |
7 | 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 | + FetchContent_MakeAvailable(${DEPT_NAME}) |
8 | 26 | endfunction() |
9 | 27 |
|
10 | | -include(FetchContent) |
11 | | -EnableDept(fmt https://github.com/fmtlib/fmt.git 11.2.0) |
12 | | -EnableDept(spdlog https://github.com/gabime/spdlog.git v1.15.3) |
13 | | -EnableDept(pybind11 https://github.com/pybind/pybind11.git v3.0.1) |
| 28 | +if(DOWNLOAD_DEPENDENCE) |
| 29 | + include(FetchContent) |
| 30 | + EnableDept( |
| 31 | + NAME fmt |
| 32 | + TAG 11.2.0 |
| 33 | + GIT_URLS |
| 34 | + https://github.com/fmtlib/fmt.git |
| 35 | + https://gitcode.com/GitHub_Trending/fm/fmt.git |
| 36 | + ) |
| 37 | + EnableDept( |
| 38 | + NAME spdlog |
| 39 | + TAG v1.15.3 |
| 40 | + GIT_URLS |
| 41 | + https://github.com/gabime/spdlog.git |
| 42 | + https://gitcode.com/GitHub_Trending/sp/spdlog.git |
| 43 | + ) |
| 44 | + EnableDept( |
| 45 | + NAME pybind11 |
| 46 | + TAG v3.0.1 |
| 47 | + GIT_URLS |
| 48 | + https://github.com/pybind/pybind11.git |
| 49 | + https://gitcode.com/GitHub_Trending/py/pybind11.git |
| 50 | + ) |
| 51 | +else() |
| 52 | + add_subdirectory(fmt) |
| 53 | + add_subdirectory(spdlog) |
| 54 | + add_subdirectory(pybind11) |
| 55 | +endif() |
0 commit comments