cmake-plugin: 为引用型生成插件的构建支持在线构建

This commit is contained in:
zinface 2024-03-21 15:36:26 +08:00
parent f2862392ee
commit 8c68f8b8dc
2 changed files with 58 additions and 8 deletions

View File

@ -41,14 +41,8 @@ if(USE_NOTEPAD_PLUGIN)
# include(path/to/plugin.cmake)
# # plantuml
# add_framework_plugin(framework-plantuml-preview
# framework-plugins/plantuml-preview
# framework-plugins/plantuml-preview/nplugin.qrc
# )
# if(framework-plantuml-preview_ENABLE)
# find_package(Qt5Svg)
# target_link_libraries(framework-plantuml-preview Qt5::Svg)
# endif(framework-plantuml-preview_ENABLE)
# add_framework_plugin_with_git(https://gitee.com/ndd-community/notepad--plugin.plantuml-preview --branch=cmake-plugins-dev)
# # svg
# add_framework_plugin(framework-svg-preview

View File

@ -87,3 +87,59 @@ if(${${_target}_ENABLE})
endif(${${_target}_ENABLE})
endmacro(add_framework_plugin _target)
# support git plugin
# add_framework_plugin_with_git <git_repo_url> [git_args...]
# git
macro(add_framework_plugin_with_git GIT_REPO_URL)
# string(REGEX MATCHALL "(?<=:\/\/)[^\/]+\/([^\/]+)\/([^\/]+)(?=\/)" GIT_VAR "${GIT_REPO_URL}")
set(GIT_ARGS ${ARGN})
# 1.
string(REGEX MATCHALL "^http://" HTTP_VAR "${GIT_REPO_URL}")
string(REGEX MATCHALL "^https://" HTTPS_VAR "${GIT_REPO_URL}")
# 2.
if(HTTP_VAR STREQUAL "http://")
string(REPLACE "${HTTP_VAR}" "" REPO_URL "${GIT_REPO_URL}")
elseif(HTTPS_VAR STREQUAL "https://")
string(REPLACE "${HTTPS_VAR}" "" REPO_URL "${GIT_REPO_URL}")
else()
return()
endif(HTTP_VAR STREQUAL "http://")
# 3. cmake LIST
string(REPLACE "/" ";" URLSEGS ${REPO_URL})
list(LENGTH URLSEGS URLSEGS_LENGTH)
# 4.
if(URLSEGS_LENGTH GREATER_EQUAL 3)
list(GET URLSEGS 1 URL_USER)
list(GET URLSEGS 2 URL_REPO)
else()
return()
endif(URLSEGS_LENGTH GREATER_EQUAL 3)
message("HTTP_VAR: ${HTTP_VAR}")
message("HTTPS_VAR: ${HTTPS_VAR}")
message("URL_USER: ${URL_USER}")
message("URL_REPO: ${URL_REPO}")
# 4. git clone
if(NOT EXISTS ${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git)
execute_process(COMMAND git clone ${GIT_REPO_URL} ${URL_USER}_${URL_REPO}_git ${GIT_ARGS}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif(NOT EXISTS ${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git)
# 6. plugin.cmake
if(EXISTS ${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git/plugin.cmake)
message("-- [GIT_PLUGIN] Found new plugin with git: ${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git/plugin.cmake")
include(${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git/plugin.cmake)
else()
return()
endif(EXISTS ${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git/plugin.cmake)
endmacro(add_framework_plugin_with_git GIT_REPO_URL)
# add_framework_plugin_with_git(https://gitee.com/ndd-community/notepad--plugin.plantuml-preview --branch=cmake-plugins-dev)