2023-07-30 15:59:38 +00:00
|
|
|
|
#[=======================================================================[.rst:
|
|
|
|
|
myx_download_content
|
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
|
|
Функция для загрузки дополнительных репозиториев::
|
|
|
|
|
|
|
|
|
|
myx_download_content(NAME
|
|
|
|
|
[ DOWNLOAD_DIR dir ] |
|
|
|
|
|
[ GIT_REPOSITORY url ] |
|
2023-08-04 07:16:31 +00:00
|
|
|
|
[ GIT_TAG tag ] |
|
|
|
|
|
[ AUTOFETCH ] | [ AUTOPULL ] )
|
2023-07-30 15:59:38 +00:00
|
|
|
|
|
|
|
|
|
Обязательный параметр: `NAME` - имя целевого каталога.
|
|
|
|
|
Параметр `DOWNLOAD_DIR` содержит имя каталога, в который будет загружаться
|
2023-08-03 13:54:23 +00:00
|
|
|
|
содержимое (по умолчанию `_downloads`).
|
2023-07-30 15:59:38 +00:00
|
|
|
|
Параметр `GIT_REPOSITORY` содержит адрес внешнего проекта, который нужно
|
|
|
|
|
загрузить с помощью git.
|
|
|
|
|
Параметр `GIT_TAG` содержит используемые метку, идентификатор коммита или
|
|
|
|
|
ветку в загружаемом репозитории.
|
2023-08-04 07:16:31 +00:00
|
|
|
|
Если указана опция `AUTOFETCH`, то на этапе конфигурирования для загруженного
|
|
|
|
|
репозитория будут скачиваться изменения.
|
|
|
|
|
Если указана опция `AUTOPULL`, то на этапе конфигурирования из загруженного
|
|
|
|
|
репозитория будет изменяться рабочий каталог.
|
2023-07-30 15:59:38 +00:00
|
|
|
|
|
|
|
|
|
#]=======================================================================]
|
|
|
|
|
|
|
|
|
|
find_package(Git QUIET)
|
|
|
|
|
|
2023-07-31 09:18:19 +00:00
|
|
|
|
option(ENABLE_DOWNLOAD_CONTENT "Enable download content" ON)
|
2023-07-30 15:59:38 +00:00
|
|
|
|
|
2023-08-28 10:53:42 +00:00
|
|
|
|
if(CMAKE_SCRIPT_MODE_FILE)
|
|
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/ProjectIsTopLevel.cmake)
|
|
|
|
|
endif()
|
2023-08-28 10:40:57 +00:00
|
|
|
|
|
2023-07-30 15:59:38 +00:00
|
|
|
|
function(myx_download_content NAME)
|
2023-08-04 07:16:31 +00:00
|
|
|
|
set(options AUTOFETCH AUTOPULL)
|
2023-07-30 15:59:38 +00:00
|
|
|
|
set(oneValueArgs)
|
|
|
|
|
set(multiValueArgs DOWNLOAD_DIR GIT_REPOSITORY GIT_TAG)
|
|
|
|
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
|
|
|
|
2023-08-28 10:53:42 +00:00
|
|
|
|
if(NOT CMAKE_SCRIPT_MODE_FILE)
|
2023-07-30 15:59:38 +00:00
|
|
|
|
if(TARGET myx-download-${NAME})
|
|
|
|
|
return()
|
|
|
|
|
else()
|
|
|
|
|
add_custom_target(myx-download-${NAME})
|
|
|
|
|
endif()
|
|
|
|
|
if(NOT TARGET myx-download-content)
|
|
|
|
|
add_custom_target(myx-download-content)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2023-08-28 10:40:57 +00:00
|
|
|
|
if(NOT PROJECT_IS_TOP_LEVEL)
|
|
|
|
|
return()
|
|
|
|
|
endif()
|
|
|
|
|
|
2023-07-30 15:59:38 +00:00
|
|
|
|
if(NOT ARG_DOWNLOAD_DIR)
|
2023-07-31 09:18:19 +00:00
|
|
|
|
set(ARG_DOWNLOAD_DIR "_downloads")
|
2023-07-30 15:59:38 +00:00
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(CMAKE_SCRIPT_MODE_FILE)
|
|
|
|
|
set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
|
|
|
|
|
endif()
|
|
|
|
|
set(ARG_DOWNLOAD_DIR ${PROJECT_SOURCE_DIR}/${ARG_DOWNLOAD_DIR})
|
|
|
|
|
|
|
|
|
|
if(NOT IS_DIRECTORY ${ARG_DOWNLOAD_DIR})
|
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ARG_DOWNLOAD_DIR})
|
|
|
|
|
endif()
|
|
|
|
|
|
2023-08-03 13:54:23 +00:00
|
|
|
|
set(WORK_DIR "${ARG_DOWNLOAD_DIR}/${NAME}")
|
2023-07-30 15:59:38 +00:00
|
|
|
|
if(ENABLE_DOWNLOAD_CONTENT AND GIT_EXECUTABLE AND ARG_GIT_REPOSITORY)
|
2023-08-03 13:54:23 +00:00
|
|
|
|
if(NOT IS_DIRECTORY ${WORK_DIR})
|
2023-07-30 15:59:38 +00:00
|
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} clone ${ARG_GIT_REPOSITORY} ${NAME}
|
|
|
|
|
WORKING_DIRECTORY ${ARG_DOWNLOAD_DIR})
|
|
|
|
|
else()
|
2023-08-04 07:16:31 +00:00
|
|
|
|
if(ARG_AUTOFETCH)
|
|
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} fetch
|
|
|
|
|
WORKING_DIRECTORY ${WORK_DIR})
|
|
|
|
|
endif()
|
2023-07-30 15:59:38 +00:00
|
|
|
|
endif()
|
2023-08-01 08:46:51 +00:00
|
|
|
|
if(ARG_GIT_TAG)
|
|
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} checkout ${ARG_GIT_TAG}
|
2023-08-03 13:54:23 +00:00
|
|
|
|
WORKING_DIRECTORY ${WORK_DIR})
|
2023-08-01 08:46:51 +00:00
|
|
|
|
else()
|
2023-08-02 11:31:48 +00:00
|
|
|
|
if(ARG_AUTOPULL)
|
|
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} pull
|
2023-08-03 13:54:23 +00:00
|
|
|
|
WORKING_DIRECTORY ${WORK_DIR})
|
2023-08-02 11:31:48 +00:00
|
|
|
|
endif()
|
2023-08-01 08:46:51 +00:00
|
|
|
|
endif()
|
2023-07-30 15:59:38 +00:00
|
|
|
|
endif()
|
|
|
|
|
|
2023-08-03 13:54:23 +00:00
|
|
|
|
if(NOT CMAKE_SCRIPT_MODE_FILE AND EXISTS "${WORK_DIR}/CMakeLists.txt")
|
|
|
|
|
add_subdirectory(${WORK_DIR} EXCLUDE_FROM_ALL)
|
2023-07-30 15:59:38 +00:00
|
|
|
|
endif()
|
|
|
|
|
endfunction()
|
|
|
|
|
|