Browse Source

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

zinface 1 năm trước cách đây
mục cha
commit
f232da29c7

+ 2 - 1
.gitignore

@@ -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

+ 8 - 0
3rd_plugins_cache/README.md

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

+ 44 - 9
src/plugin/CMakeLists.txt

@@ -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 引用构建(示例)
+
+
+    ## [框架:插件 with_git 的引用构建 - 与在线]
+    # add_framework_plugin_with_git <git> [args...]
+        # [框架引用:插件扩展处的资源引用构建]
+            # framework_plugin_include <target> <git>
+            # framework_plugin_include_with_git <target> <git> [args...]
 
-    # 一个 plantuml 预览插件(使用 with_git 引用的在线构建)
+    # 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 - 0
src/plugin/dev.cmake

@@ -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:
+
+
+

+ 89 - 0
src/plugin/framework/framework-include.cmake

@@ -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)

+ 15 - 92
src/plugin/framework/framework.cmake

@@ -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)