From e8a0a5b5560719cd8d6cb846b4fd6e4c12559dc0 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Fri, 17 Feb 2023 12:28:05 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D0=B0=20my?= =?UTF-8?q?x=5Fadd=5Fexternal=5Ftarget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MyxCMake/MyxCMakeConfig.cmake | 1 + MyxCMake/MyxCMakeConfigVersion.cmake | 2 +- MyxCMake/lib/AddExternalTarget.cmake | 79 ++++++++++++++++++++++++++++ README.md | 2 +- VERSION | 2 +- debian/CMakeLists.txt | 2 +- debian/changelog | 2 +- myx_setup.cmake | 4 +- 8 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 MyxCMake/lib/AddExternalTarget.cmake diff --git a/MyxCMake/MyxCMakeConfig.cmake b/MyxCMake/MyxCMakeConfig.cmake index 164bd2a..43c3934 100644 --- a/MyxCMake/MyxCMakeConfig.cmake +++ b/MyxCMake/MyxCMakeConfig.cmake @@ -50,6 +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) set(MYX_CMAKE_TOOLCHAINS_DIR "${MYX_CMAKE_LIB_DIR}/toolchains") diff --git a/MyxCMake/MyxCMakeConfigVersion.cmake b/MyxCMake/MyxCMakeConfigVersion.cmake index c95f0be..e440a06 100644 --- a/MyxCMake/MyxCMakeConfigVersion.cmake +++ b/MyxCMake/MyxCMakeConfigVersion.cmake @@ -1,4 +1,4 @@ -set(MYX_CMAKE_PACKAGE_VERSION "2.2.7") +set(MYX_CMAKE_PACKAGE_VERSION "2.3.0") if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) set(PACKAGE_VERSION_COMPATIBLE FALSE) else() diff --git a/MyxCMake/lib/AddExternalTarget.cmake b/MyxCMake/lib/AddExternalTarget.cmake new file mode 100644 index 0000000..9148a53 --- /dev/null +++ b/MyxCMake/lib/AddExternalTarget.cmake @@ -0,0 +1,79 @@ +#[=======================================================================[.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/README.md b/README.md index 70139ec..4419682 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## Установка В корневом каталоге проекта создать каталог `cmake` и распаковать в него -[архив](../../../releases/download/2.2.7/myx-cmake-local-2.2.7.tar.xz ). +[архив](../../../releases/download/2.3.0/myx-cmake-local-2.3.0.tar.xz ). ## Использование diff --git a/VERSION b/VERSION index 5bc1cc4..276cbf9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.7 +2.3.0 diff --git a/debian/CMakeLists.txt b/debian/CMakeLists.txt index f05fb11..26ecf99 100644 --- a/debian/CMakeLists.txt +++ b/debian/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.6 FATAL_ERROR) -project(myx-cmake VERSION 2.2.7 LANGUAGES) +project(myx-cmake VERSION 2.3.0 LANGUAGES) include(GNUInstallDirs) file(WRITE ${CMAKE_SOURCE_DIR}/MyxCMake/MyxCMakeConfigVersion.cmake diff --git a/debian/changelog b/debian/changelog index 99afa87..879bd5a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -myx-cmake (2.2.7) unstable; urgency=medium +myx-cmake (2.3.0) unstable; urgency=medium * New version. diff --git a/myx_setup.cmake b/myx_setup.cmake index 3322185..2b9ee9c 100644 --- a/myx_setup.cmake +++ b/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.2.7 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH) + find_package(MyxCMake 2.3.0 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.2.7 REQUIRED) + find_package(MyxCMake 2.3.0 REQUIRED) myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===") else() include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)