Команда myx_add_external_target
This commit is contained in:
parent
d6b6cb39c7
commit
e8a0a5b556
@ -50,6 +50,7 @@ include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWarning.cmake)
|
|||||||
include(${MYX_CMAKE_LIB_DIR}/DirectoriesGuards.cmake)
|
include(${MYX_CMAKE_LIB_DIR}/DirectoriesGuards.cmake)
|
||||||
include(${MYX_CMAKE_LIB_DIR}/SemanticProjectVersion.cmake)
|
include(${MYX_CMAKE_LIB_DIR}/SemanticProjectVersion.cmake)
|
||||||
include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWrapper.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}/FetchContentAdd.cmake)
|
||||||
|
|
||||||
set(MYX_CMAKE_TOOLCHAINS_DIR "${MYX_CMAKE_LIB_DIR}/toolchains")
|
set(MYX_CMAKE_TOOLCHAINS_DIR "${MYX_CMAKE_LIB_DIR}/toolchains")
|
||||||
|
@ -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)
|
if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
|
||||||
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
||||||
else()
|
else()
|
||||||
|
79
MyxCMake/lib/AddExternalTarget.cmake
Normal file
79
MyxCMake/lib/AddExternalTarget.cmake
Normal file
@ -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)
|
||||||
|
|
@ -3,7 +3,7 @@
|
|||||||
## Установка
|
## Установка
|
||||||
|
|
||||||
В корневом каталоге проекта создать каталог `cmake` и распаковать в него
|
В корневом каталоге проекта создать каталог `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 ).
|
||||||
|
|
||||||
## Использование
|
## Использование
|
||||||
|
|
||||||
|
2
debian/CMakeLists.txt
vendored
2
debian/CMakeLists.txt
vendored
@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
|
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)
|
include(GNUInstallDirs)
|
||||||
file(WRITE ${CMAKE_SOURCE_DIR}/MyxCMake/MyxCMakeConfigVersion.cmake
|
file(WRITE ${CMAKE_SOURCE_DIR}/MyxCMake/MyxCMakeConfigVersion.cmake
|
||||||
|
2
debian/changelog
vendored
2
debian/changelog
vendored
@ -1,4 +1,4 @@
|
|||||||
myx-cmake (2.2.7) unstable; urgency=medium
|
myx-cmake (2.3.0) unstable; urgency=medium
|
||||||
|
|
||||||
* New version.
|
* New version.
|
||||||
|
|
||||||
|
@ -20,11 +20,11 @@ if(ENV{MYX_CMAKE_DIR})
|
|||||||
set(MYX_CMAKE_DIR $ENV{MYX_CMAKE_DIR})
|
set(MYX_CMAKE_DIR $ENV{MYX_CMAKE_DIR})
|
||||||
endif()
|
endif()
|
||||||
if(MYX_CMAKE_DIR)
|
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} ===")
|
myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===")
|
||||||
else()
|
else()
|
||||||
if(MYX_CMAKE_USE_SYSTEM)
|
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} ===")
|
myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===")
|
||||||
else()
|
else()
|
||||||
include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)
|
include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)
|
||||||
|
Loading…
Reference in New Issue
Block a user