cmake-plugin: 插件框架的基础模式固化,并提供框架开发者计划方案 dev.cmake

This commit is contained in:
zinface 2024-03-23 16:20:48 +08:00
parent 199f57b975
commit f232da29c7
6 changed files with 173 additions and 102 deletions

3
.gitignore vendored
View File

@ -526,4 +526,5 @@ _deps
# If you copy here and customize the build form, its changes will be ignored.
# Windows cmd or powershell supported files..
/windows-msvc-ninja.bat
/windows-msvc-ninja.bat
/3rd_plugins_cache

View File

@ -0,0 +1,8 @@
# 3rd_plugins_cache
> 此处存储由框架构建自动缓存引用的项目,为了提供更好的引用间维护
如插件间开发,引用间调试,资源引用构建,插件代码调整等操作可在此处集中配置。
开发者请在src/plugin/dev.cmake 中编写插件

View File

@ -5,7 +5,7 @@ option(USE_NOTEPAD_PLUGIN_BASE "构建 Notepad-- 内部的插件基础模板" OF
if(USE_NOTEPAD_PLUGIN)
if(USE_NOTEPAD_PLUGIN_BASE)
if(USE_NOTEPAD_PLUGIN_BASE) #
#
add_subdirectory(test)
# cmake-plugins-dev helloworld
@ -19,17 +19,25 @@ if(USE_NOTEPAD_PLUGIN)
add_subdirectory(template-plugins/base-secondary-menu-ui-plugin-v1)
endif(USE_NOTEPAD_PLUGIN_BASE)
# framwork framework-helloworld
# [][]
include(framework/framework.cmake)
# add_framework_plugin [<dir>...] [<file>...]
# framework
include(framework/framework-include.cmake)
# [] CMakeLists.txt
# dev.cmake 线
# CMakeLists.txt
include(dev.cmake)
## []
# add_framework_plugin <target> [<dir>...] [<file>...]
# 1. framework
#
add_framework_plugin(framework-helloworld
framework-plugins/helloworld
)
# framework-hello
# 2. framework-hello
#
add_framework_plugin(framework-hello-simple
${PROJECT_SOURCE_DIR}/src/utils
framework-plugins/hello-simple
@ -37,19 +45,46 @@ if(USE_NOTEPAD_PLUGIN)
framework-plugins/hello-simple/template
framework-plugins/hello-simple/buildin.qrc)
# 使
## []
# include(path/to/plugin.cmake)
# 1. 使 plugin.cmake 引用构建(示例)
# plantuml 预览插件(使用 with_git 引用的在线构建)
## [ with_git - 线]
# add_framework_plugin_with_git <git> [args...]
# []
# framework_plugin_include <target> <git>
# framework_plugin_include_with_git <target> <git> [args...]
# 1. git 线 helloworld
# add_framework_plugin_with_git(
# https://gitee.com/zinface/notepad--plugin.helloworld
# --branch=cmake-plugins-dev)
# 2. plantuml
# (使 with_git 线)
# add_framework_plugin_with_git(
# https://gitee.com/ndd-community/notepad--plugin.plantuml-preview
# --branch=cmake-plugins-dev)
# svg 预览插件(使用 with_git 引用的在线构建,它使用了 plantuml 共享的资源定义)
# 3. svg
# (使 with_git 线)
# (使 plantuml )
# add_framework_plugin_with_git(
# https://gitee.com/ndd-community/notepad--plugin.svg-preview
# --branch=cmake-plugins-dev)
# 4. 使 plantumlexamples
# (使 with_git 线)
# (使 plantuml )
# (使 framework-plugin-component-library )
# add_framework_plugin_with_git(
# https://gitee.com/zinface/notepad--plugin.plantuml-examples
# --branch=cmake-plugins-dev)
##
# opencc 项目(基于 git)
# add_subdirectory(opencc-demo-plugin)
# #

15
src/plugin/dev.cmake Normal file
View File

@ -0,0 +1,15 @@
# DO NOT COMMIT THIS FILE!
# [](Developer plan)
# CMakeLists.txt 的情况下开发自己的插件(Develop your own plugin without changing CMakeLists.txt)
# [I] : copy the provided examples. like this:
# 1. git 线 helloworld 插件(Build the helloworld plug-in online based on the git repository.)
# add_framework_plugin_with_git(
# https://gitee.com/zinface/notepad--plugin.helloworld
# --branch=cmake-plugins-dev)
# Now, develop your new plugin:

View File

@ -0,0 +1,89 @@
# framework-extension.cmake
# framework_plugin_include <target> <plugin.cmake>
#
# framework_plugin_include_with_git <target> <git> [arg...]
# with_git
# framework_plugin_include <target> <plugin.cmake>
# plugin.cmake
# FRAMEWORK_WANT_INCLUDE ON include(plugin.cmake)
# FRAMEWORK_INCLUDE_EXPORTS 以便干净的引用资源(头文件目录)
# FRAMEWORK_SOURCES_EXPORTS 以便干净的引用资源(源文件声明)
# 使
# 使 spark_file_glob
macro(framework_plugin_include _target _plug_cmake)
if(EXISTS ${_plug_cmake})
message("-- [FRAMEWORK WANT]: ${_target}")
set(FRAMEWORK_WANT_INCLUDE TRUE)
set(FRAMEWORK_INCLUDE_EXPORTS)
set(FRAMEWORK_SOURCES_EXPORTS)
include(${_plug_cmake})
spark_file_glob(_want_files ${FRAMEWORK_SOURCES_EXPORTS})
message("-- [FRAMEWORK ANALYZE]: ${_target} Want Dirs: ")
message(" ${FRAMEWORK_INCLUDE_EXPORTS}")
message("-- [FRAMEWORK ANALYZE]: ${_target} Want Files: ")
message(" ${_want_files}")
target_include_directories(${_target} PUBLIC ${FRAMEWORK_INCLUDE_EXPORTS})
target_sources(${_target} PUBLIC ${_want_files})
set(FRAMEWORK_WANT_INCLUDE FALSE)
endif(EXISTS ${_plug_cmake})
endmacro(framework_plugin_include _target _plug_cmake)
# framework_plugin_include_with_git <target> <git_repo_url> [git_args...]
# git plugin.cmake
macro(framework_plugin_include_with_git _target 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_SOURCE_DIR}/3rd_plugins_cache/${URL_USER}_${URL_REPO}_git)
execute_process(COMMAND git clone ${GIT_REPO_URL} ${URL_USER}_${URL_REPO}_git ${GIT_ARGS}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/3rd_plugins_cache)
else()
execute_process(COMMAND git pull
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/3rd_plugins_cache/${URL_USER}_${URL_REPO}_git)
endif(NOT EXISTS ${CMAKE_SOURCE_DIR}/3rd_plugins_cache/${URL_USER}_${URL_REPO}_git)
if(EXISTS ${CMAKE_SOURCE_DIR}/3rd_plugins_cache/${URL_USER}_${URL_REPO}_git/plugin.cmake)
# message("-- [WANT_GIT_PLUGIN] Found new plugin with git: ${CMAKE_SOURCE_DIR}/3rd_plugins_cache/${URL_USER}_${URL_REPO}_git/plugin.cmake")
message("-- [WANT_GIT_PLUGIN] Found new plugin with git: ")
message(" ${CMAKE_SOURCE_DIR}/3rd_plugins_cache/${URL_USER}_${URL_REPO}_git/plugin.cmake")
# set(WITH_GIT ON)
framework_plugin_include(${_target}
${CMAKE_SOURCE_DIR}/3rd_plugins_cache/${URL_USER}_${URL_REPO}_git/plugin.cmake)
else()
message("-- [WANT_GIT_PLUGIN] Not Found plugin.cmake with git: ${GIT_REPO_URL}")
return()
endif(EXISTS ${CMAKE_SOURCE_DIR}/3rd_plugins_cache/${URL_USER}_${URL_REPO}_git/plugin.cmake)
endmacro(framework_plugin_include_with_git _target GIT_REPO_URL)
# add_framework_plugin_with_git(https://gitee.com/ndd-community/notepad--plugin.plantuml-preview --branch=cmake-plugins-dev)

View File

@ -1,4 +1,8 @@
# framework.cmake
# add_framework_plugin <target> [dir...|file...]
#
# add_framework_plugin_with_git <git> [arg...]
# with_git 线
# add_framework_plugin [<dir>...] [<file>...]
# framework
@ -136,103 +140,22 @@ macro(add_framework_plugin_with_git GIT_REPO_URL)
message("URL_REPO: ${URL_REPO}")
# 4. git clone
if(NOT EXISTS ${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git)
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/3rd_plugins_cache/${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)
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/3rd_plugins_cache)
else()
execute_process(COMMAND git pull
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/3rd_plugins_cache/${URL_USER}_${URL_REPO}_git)
endif(NOT EXISTS ${CMAKE_SOURCE_DIR}/3rd_plugins_cache/${URL_USER}_${URL_REPO}_git)
# 6. plugin.cmake
if(EXISTS ${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git/plugin.cmake)
if(EXISTS ${CMAKE_SOURCE_DIR}/3rd_plugins_cache/${URL_USER}_${URL_REPO}_git/plugin.cmake)
message("-- [GIT_PLUGIN] Found new plugin with git: ")
message(" ${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git/plugin.cmake")
message(" ${CMAKE_SOURCE_DIR}/3rd_plugins_cache/${URL_USER}_${URL_REPO}_git/plugin.cmake")
set(WITH_GIT ON)
include(${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git/plugin.cmake)
include(${CMAKE_SOURCE_DIR}/3rd_plugins_cache/${URL_USER}_${URL_REPO}_git/plugin.cmake)
else()
return()
endif(EXISTS ${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git/plugin.cmake)
endif(EXISTS ${CMAKE_SOURCE_DIR}/3rd_plugins_cache/${URL_USER}_${URL_REPO}_git/plugin.cmake)
endmacro(add_framework_plugin_with_git GIT_REPO_URL)
# framework_plugin_include <target> <git_repo_url> [git_args...]
# plugin.cmake
# FRAMEWORK_WANT_INCLUDE ON include(plugin.cmake)
# FRAMEWORK_INCLUDE_EXPORTS 以便干净的引用资源(头文件目录)
# FRAMEWORK_SOURCES_EXPORTS 以便干净的引用资源(源文件声明)
# 使
# 使 spark_file_glob
macro(framework_plugin_include _target _plug_cmake)
if(EXISTS ${_plug_cmake})
message("-- [FRAMEWORK WANT]: ${_target}")
set(FRAMEWORK_WANT_INCLUDE TRUE)
set(FRAMEWORK_INCLUDE_EXPORTS)
set(FRAMEWORK_SOURCES_EXPORTS)
include(${_plug_cmake})
spark_file_glob(_want_files ${FRAMEWORK_SOURCES_EXPORTS})
message("-- [FRAMEWORK ANALYZE]: ${_target} Want Dirs: ")
message(" ${FRAMEWORK_INCLUDE_EXPORTS}")
message("-- [FRAMEWORK ANALYZE]: ${_target} Want Files: ")
message(" ${_want_files}")
target_include_directories(${_target} PUBLIC ${FRAMEWORK_INCLUDE_EXPORTS})
target_sources(${_target} PUBLIC ${_want_files})
set(FRAMEWORK_WANT_INCLUDE FALSE)
endif(EXISTS ${_plug_cmake})
endmacro(framework_plugin_include _target _plug_cmake)
# framework_plugin_include_with_git <target> <git_repo_url> [git_args...]
# git plugin.cmake
macro(framework_plugin_include_with_git _target 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})
# else()
# execute_process(COMMAND git pull
# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git)
endif(NOT EXISTS ${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git)
if(EXISTS ${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git/plugin.cmake)
# message("-- [WANT_GIT_PLUGIN] Found new plugin with git: ${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git/plugin.cmake")
message("-- [WANT_GIT_PLUGIN] Found new plugin with git: ")
message(" ${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git/plugin.cmake")
# set(WITH_GIT ON)
framework_plugin_include(${_target}
${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git/plugin.cmake)
else()
message("-- [WANT_GIT_PLUGIN] Not Found plugin.cmake with git: ${GIT_REPO_URL}")
return()
endif(EXISTS ${CMAKE_BINARY_DIR}/${URL_USER}_${URL_REPO}_git/plugin.cmake)
endmacro(framework_plugin_include_with_git _target GIT_REPO_URL)
# add_framework_plugin_with_git(https://gitee.com/ndd-community/notepad--plugin.plantuml-preview --branch=cmake-plugins-dev)