From 740598a21ff43c13cb362e5a74a6c7d36f6013a7 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Sun, 30 Jul 2023 19:02:06 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20MyxCMake?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/myx/MyxCMakeConfig.cmake | 3 +- cmake/myx/MyxCMakeConfigVersion.cmake | 2 +- cmake/myx/lib/AddExternalTarget.cmake | 79 -------------------------- cmake/myx/lib/DownloadContent.cmake | 72 +++++++++++++++++++++++ cmake/myx/lib/FetchContentAdd.cmake | 56 ------------------ cmake/myx/lib/doc/Doxygen.cmake | 2 +- cmake/myx/lib/generators/GitInfo.cmake | 2 +- cmake/myx_setup.cmake | 4 +- 8 files changed, 78 insertions(+), 142 deletions(-) delete mode 100644 cmake/myx/lib/AddExternalTarget.cmake create mode 100644 cmake/myx/lib/DownloadContent.cmake delete mode 100644 cmake/myx/lib/FetchContentAdd.cmake diff --git a/cmake/myx/MyxCMakeConfig.cmake b/cmake/myx/MyxCMakeConfig.cmake index e4ada74..707f411 100644 --- a/cmake/myx/MyxCMakeConfig.cmake +++ b/cmake/myx/MyxCMakeConfig.cmake @@ -50,8 +50,7 @@ include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWarning.cmake) include(${MYX_CMAKE_LIB_DIR}/DirectoriesGuards.cmake) include(${MYX_CMAKE_LIB_DIR}/SemanticProjectVersion.cmake) include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWrapper.cmake) -include(${MYX_CMAKE_LIB_DIR}/AddExternalTarget.cmake) -include(${MYX_CMAKE_LIB_DIR}/FetchContentAdd.cmake) +include(${MYX_CMAKE_LIB_DIR}/DownloadContent.cmake) set(MYX_CMAKE_TOOLCHAINS_DIR "${MYX_CMAKE_LIB_DIR}/toolchains") include(${MYX_CMAKE_LIB_DIR}/Toolchains.cmake) diff --git a/cmake/myx/MyxCMakeConfigVersion.cmake b/cmake/myx/MyxCMakeConfigVersion.cmake index 5eee7a2..c4ee4b1 100644 --- a/cmake/myx/MyxCMakeConfigVersion.cmake +++ b/cmake/myx/MyxCMakeConfigVersion.cmake @@ -1,4 +1,4 @@ -set(MYX_CMAKE_PACKAGE_VERSION "2.4.2") +set(MYX_CMAKE_PACKAGE_VERSION "2.4.3") if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) set(PACKAGE_VERSION_COMPATIBLE FALSE) else() diff --git a/cmake/myx/lib/AddExternalTarget.cmake b/cmake/myx/lib/AddExternalTarget.cmake deleted file mode 100644 index b1f562b..0000000 --- a/cmake/myx/lib/AddExternalTarget.cmake +++ /dev/null @@ -1,79 +0,0 @@ -#[=======================================================================[.rst: -myx_add_external_target ------------------------ - -Функция для подключения целей из внешних проектов:: - - myx_add_external_target(TARGET_NAME - [ MODULES_PATH modules_path ] | - [ GIT_REPOSITORY url ] | - [ GIT_TAG tag ] | - [ LOCAL_PATH local_path ] ) - -Обязательный параметр: `TARGET_NAME` - имя цели, содержащейся во внешнем проекте. -Параметр `MODULES_PATH` содержит имя каталога, в который будут загружаться -внешние проекты (по умолчанию `modules`). Параметр `GIT_REPOSITORY` содержит -адрес внешнего проекта, который нужно загрузить с помощью git. Параметр `GIT_TAG` -содержит используемые метку, идентификатор коммита или ветку в репозитории. -Параметр `LOCAL_PATH` используется для указания пути к подкаталогу, находящемуся -вне текущего проекта. Его следует указывать только при вызове функции из -вспомогательного файла `external_targets.cmake`. - -#]=======================================================================] - - -find_package(Git) - -function(myx_add_external_target TARGET_NAME) - set(options) - set(oneValueArgs) - set(multiValueArgs MODULES_PATH GIT_REPOSITORY GIT_TAG LOCAL_PATH) - cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - if(TARGET ${TARGET_NAME}) - return() - endif() - - if(ARG_LOCAL_PATH) - myx_message_notice("Using directory ${ARG_LOCAL_PATH} to build target ${TARGET_NAME}") - add_subdirectory(${ARG_LOCAL_PATH} ${CMAKE_BINARY_DIR}/${TARGET_NAME} EXCLUDE_FROM_ALL) - return() - endif() - - if(NOT ARG_MODULES_PATH) - set(ARG_MODULES_PATH modules) - endif() - - if(CMAKE_SCRIPT_MODE_FILE) - set(PROJECT_SOURCE_DIR ${CMAKE_SOURCE_DIR}) - endif() - set(ARG_MODULES_PATH ${PROJECT_SOURCE_DIR}/${ARG_MODULES_PATH}) - - if(NOT IS_DIRECTORY ${ARG_MODULES_PATH}) - execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ARG_MODULES_PATH}) - endif() - - if(GIT_EXECUTABLE) - if(NOT IS_DIRECTORY ${ARG_MODULES_PATH}/${TARGET_NAME}) - execute_process(COMMAND ${GIT_EXECUTABLE} clone ${ARG_GIT_REPOSITORY} ${TARGET_NAME} - WORKING_DIRECTORY ${ARG_MODULES_PATH}) - else() - execute_process(COMMAND ${GIT_EXECUTABLE} fetch - WORKING_DIRECTORY ${ARG_MODULES_PATH}/${TARGET_NAME}) - endif() - execute_process(COMMAND ${GIT_EXECUTABLE} checkout ${ARG_GIT_TAG} - WORKING_DIRECTORY ${ARG_MODULES_PATH}/${TARGET_NAME}) - endif() - - if(NOT CMAKE_SCRIPT_MODE_FILE) - add_subdirectory(${ARG_MODULES_PATH}/${TARGET_NAME} EXCLUDE_FROM_ALL) - endif() - - if(NOT TARGET ${TARGET_NAME}) - myx_message_fatal_error("Target ${TARGET_NAME} is not found.") - endif() - -endfunction(myx_add_external_target) - -include("${PROJECT_SOURCE_DIR}/external_targets.cmake" OPTIONAL) - diff --git a/cmake/myx/lib/DownloadContent.cmake b/cmake/myx/lib/DownloadContent.cmake new file mode 100644 index 0000000..4686d79 --- /dev/null +++ b/cmake/myx/lib/DownloadContent.cmake @@ -0,0 +1,72 @@ +#[=======================================================================[.rst: +myx_download_content +----------------------- + +Функция для загрузки дополнительных репозиториев:: + + myx_download_content(NAME + [ DOWNLOAD_DIR dir ] | + [ GIT_REPOSITORY url ] | + [ GIT_TAG tag ] ) + +Обязательный параметр: `NAME` - имя целевого каталога. +Параметр `DOWNLOAD_DIR` содержит имя каталога, в который будет загружаться +содержимое (по умолчанию `downloads`). +Параметр `GIT_REPOSITORY` содержит адрес внешнего проекта, который нужно +загрузить с помощью git. +Параметр `GIT_TAG` содержит используемые метку, идентификатор коммита или +ветку в загружаемом репозитории. + +#]=======================================================================] + +find_package(Git QUIET) + +option(ENABLE_DONWLOAD_CONTENT "Enable download content" ON) + +function(myx_download_content NAME) + set(options) + set(oneValueArgs) + set(multiValueArgs DOWNLOAD_DIR GIT_REPOSITORY GIT_TAG) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT CMAKE_SCRIPT_MODE_FILE) + 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() + + if(NOT ARG_DOWNLOAD_DIR) + set(ARG_DOWNLOAD_DIR downloads) + 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() + + if(ENABLE_DOWNLOAD_CONTENT AND GIT_EXECUTABLE AND ARG_GIT_REPOSITORY) + if(NOT IS_DIRECTORY ${ARG_DOWNLOAD_DIR}/${NAME}) + execute_process(COMMAND ${GIT_EXECUTABLE} clone ${ARG_GIT_REPOSITORY} ${NAME} + WORKING_DIRECTORY ${ARG_DOWNLOAD_DIR}) + else() + execute_process(COMMAND ${GIT_EXECUTABLE} fetch + WORKING_DIRECTORY ${ARG_DOWNLOAD_DIR}/${NAME}) + endif() + execute_process(COMMAND ${GIT_EXECUTABLE} checkout ${ARG_GIT_TAG} + WORKING_DIRECTORY ${ARG_DOWNLOAD_DIR}/${NAME}) + endif() + + if(NOT CMAKE_SCRIPT_MODE_FILE) + add_subdirectory(${ARG_DOWNLOAD_DIR}/${NAME} EXCLUDE_FROM_ALL) + endif() +endfunction() + diff --git a/cmake/myx/lib/FetchContentAdd.cmake b/cmake/myx/lib/FetchContentAdd.cmake deleted file mode 100644 index 4202c92..0000000 --- a/cmake/myx/lib/FetchContentAdd.cmake +++ /dev/null @@ -1,56 +0,0 @@ -#[=======================================================================[.rst: -FetchContent_Add ----------------- - -Вспомогательная функция для `FetchContent_Declare()`:: - - FetchContent_Add(NAME - [ GIT_REPOSITORY repo ] | - [ GIT_REMOTE remote ] | - [ GIT_PATH path ]) - -Обязательные параметры: `NAME` - идентификатор загружаемого ресурса. -Параметр `GIT_REPOSITORY` определяет имя репозитория по умолчанию. -Если указана пара параметров `GIT_REMOTE` и `GIT_PATH` и у git-репозитория -основного проекта указан удалённый репозиторий с именем, определяемым -переменной `GIT_REMOTE`, то адрес репозитория для получения проекта -изменяется. В этом случае загрузка будет производиться с сервера, -определяемого из адреса с меткой `GIT_REMOTE`, и по пути `GIT_PATH`. - -#]=======================================================================] - -include_guard(GLOBAL) - -# Обязательно в глобальной области -find_package(Git) - -function(FetchContent_Add TARGET_NAME) - set(options "") - set(oneValueArgs GIT_REPOSITORY GIT_REMOTE GIT_PATH) - set(multiValueArgs "") - - cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - if(GIT_FOUND AND ARG_GIT_REMOTE AND ARG_GIT_PATH) - execute_process(COMMAND ${GIT_EXECUTABLE} config --get remote.${ARG_GIT_REMOTE}.url OUTPUT_VARIABLE REMOTE_URL ERROR_QUIET) - if(REMOTE_URL) - string(REGEX REPLACE ":.*" "" SERVER ${REMOTE_URL}) - string(FIND ${SERVER} "http" POS) - if(NOT POS EQUAL 0) - if(NOT SERVER STREQUAL REMOTE_URL) - set(ARG_GIT_REPOSITORY "${SERVER}:${ARG_GIT_PATH}") - endif() - endif() - endif() - endif() - - FetchContent_Declare( - ${TARGET_NAME} - ${ARG_UNPARSED_ARGUMENTS} - GIT_REPOSITORY ${ARG_GIT_REPOSITORY} - GIT_SHALLOW 1 - ) - - set(FETCHCONTENT_QUIET off) - FetchContent_MakeAvailable(${TARGET_NAME}) -endfunction() diff --git a/cmake/myx/lib/doc/Doxygen.cmake b/cmake/myx/lib/doc/Doxygen.cmake index 6cb2fe0..abc3072 100644 --- a/cmake/myx/lib/doc/Doxygen.cmake +++ b/cmake/myx/lib/doc/Doxygen.cmake @@ -2,7 +2,7 @@ if(${CMAKE_VERSION} VERSION_LESS "3.17.0") set(MYX_CMAKE_LIB_DOC_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}") endif() -find_package(Doxygen) +find_package(Doxygen QUIET) function(myx_doc_doxygen TARGET_NAME) if(${CMAKE_VERSION} VERSION_LESS "3.17.0") diff --git a/cmake/myx/lib/generators/GitInfo.cmake b/cmake/myx/lib/generators/GitInfo.cmake index 5b9f2a7..455ce91 100644 --- a/cmake/myx/lib/generators/GitInfo.cmake +++ b/cmake/myx/lib/generators/GitInfo.cmake @@ -7,7 +7,7 @@ set(GIT_DIFF "") set(GIT_TAG "N/A") set(GIT_BRANCH "N/A") -find_package(Git) +find_package(Git QUIET) if(GIT_EXECUTABLE) execute_process(COMMAND ${GIT_EXECUTABLE} log --pretty=format:'%h' -n 1 OUTPUT_VARIABLE GIT_REV ERROR_QUIET) diff --git a/cmake/myx_setup.cmake b/cmake/myx_setup.cmake index cd2f5a2..2ccb1d4 100644 --- a/cmake/myx_setup.cmake +++ b/cmake/myx_setup.cmake @@ -20,11 +20,11 @@ if(ENV{MYX_CMAKE_DIR}) set(MYX_CMAKE_DIR $ENV{MYX_CMAKE_DIR}) endif() if(MYX_CMAKE_DIR) - find_package(MyxCMake 2.4.2 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH) + find_package(MyxCMake 2.4.3 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH) myx_message_notice("== MyxCMake directory: ${MyxCMake_CONFIG} ==") else() if(MYX_CMAKE_USE_SYSTEM) - find_package(MyxCMake 2.4.2 REQUIRED) + find_package(MyxCMake 2.4.3 REQUIRED) myx_message_notice("== MyxCMake directory: ${MyxCMake_CONFIG} ==") else() include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)