Bladeren bron

update examples

ruki 1 dag geleden
bovenliggende
commit
0df84b32da

File diff suppressed because it is too large
+ 0 - 5
docs/.vitepress/data/codes-data.js


+ 7 - 0
docs/codes/examples/configuration/add_configfiles/basic/config.h.in

@@ -0,0 +1,7 @@
+#ifndef CONFIG_H
+#define CONFIG_H
+
+#define HELLO "${FOO_STRING}"
+${define FOO_ENABLE}
+
+#endif

+ 11 - 0
docs/codes/examples/configuration/add_configfiles/basic/src/main.c

@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include "config.h"
+
+int main(int argc, char** argv)
+{
+    printf("%s\n", HELLO);
+#ifdef FOO_ENABLE
+    printf("foo enabled\n");
+#endif
+    return 0;
+}

+ 18 - 0
docs/codes/examples/configuration/add_configfiles/basic/xmake.lua

@@ -0,0 +1,18 @@
+add_rules("mode.debug", "mode.release")
+
+target("test")
+    set_kind("binary")
+    add_files("src/main.c")
+
+    -- set config variables
+    set_configvar("FOO_ENABLE", 1)
+    set_configvar("FOO_STRING", "hello xmake")
+
+    -- set config directory
+    set_configdir("$(builddir)/config")
+    
+    -- generate config header
+    add_configfiles("config.h.in")
+    
+    -- add include directory
+    add_includedirs("$(builddir)/config")

+ 8 - 0
docs/codes/examples/configuration/custom_scope_api/basic/src/main.cpp

@@ -0,0 +1,8 @@
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char **argv) {
+    cout << "hello world!" << endl;
+    return 0;
+}

+ 33 - 0
docs/codes/examples/configuration/custom_scope_api/basic/xmake.lua

@@ -0,0 +1,33 @@
+add_rules("mode.debug", "mode.release")
+
+-- register scope apis
+interp_add_scopeapis("myscope.set_name", "myscope.add_list", {kind = "values"})
+interp_add_scopeapis("myscope.on_script", {kind = "script"})
+
+-- use myscope
+myscope("hello")
+    set_name("foo")
+    add_list("value1", "value2")
+    on_script(function ()
+        print("hello")
+    end)
+
+target("test")
+    set_kind("binary")
+    add_files("src/*.cpp")
+    on_config(function (target)
+        import("core.project.project")
+        
+        -- get scope data
+        local myscope = project.scope("myscope")
+        for name, scope in pairs(myscope) do
+            print("myscope(%s)", name)
+            print("    name: %s", scope:get("name"))
+            print("    list: %s", table.concat(scope:get("list"), ", "))
+            print("    script:")
+            local script = scope:get("script")
+            if script then
+                script()
+            end
+        end
+    end)

+ 2 - 0
docs/config.ts

@@ -339,6 +339,8 @@ function examplesSidebar(): DefaultTheme.SidebarItem[] {
         { text: 'Custom Toolchain', link: 'configuration/custom_toolchain' },
         { text: 'Custom Rule', link: 'configuration/custom_rule' },
         { text: 'Custom Module', link: 'configuration/custom_module' },
+        { text: 'Custom Scope API', link: 'configuration/custom_scope_api' },
+        { text: 'Config Header Generation', link: 'configuration/add_configfiles' },
         { text: 'Autogen Programs', link: 'configuration/autogen' },
       ]
     },

+ 20 - 0
docs/examples/configuration/add_configfiles.md

@@ -0,0 +1,20 @@
+---
+outline: deep
+---
+
+# Generate Config Files
+
+For details on config header generation, see: [Config Header API](/api/description/project-target#add_configfiles).
+
+We can use `add_configfiles` to automatically generate configuration files such as `config.h`.
+
+## Basic Example
+
+<FileExplorer rootFilesDir="examples/configuration/add_configfiles/basic" />
+
+### Build and Run
+
+```bash
+$ xmake
+$ xmake run
+```

+ 18 - 0
docs/examples/configuration/custom_scope_api.md

@@ -0,0 +1,18 @@
+---
+outline: deep
+---
+
+# Custom Description Scope API
+
+We can use `interp_add_scopeapis` to register custom description scope APIs to support custom configuration domains and interfaces.
+
+## Basic Example
+
+<FileExplorer rootFilesDir="examples/configuration/custom_scope_api/basic" />
+
+### Build and Run
+
+```bash
+$ xmake
+$ xmake run
+```

+ 2 - 0
docs/zh/config.ts

@@ -420,6 +420,8 @@ function examplesSidebar(): DefaultTheme.SidebarItem[] {
         { text: '自定义工具链', link: 'configuration/custom_toolchain' },
         { text: '自定义规则', link: 'configuration/custom_rule' },
         { text: '自定义模块', link: 'configuration/custom_module' },
+        { text: '自定义描述域 API', link: 'configuration/custom_scope_api' },
+        { text: '配置文件生成', link: 'configuration/add_configfiles' },
         { text: '自动代码生成', link: 'configuration/autogen' },
       ]
     },

+ 20 - 0
docs/zh/examples/configuration/add_configfiles.md

@@ -0,0 +1,20 @@
+---
+outline: deep
+---
+
+# 配置文件生成
+
+关于配置文件生成的更多详情,请参考:[配置文件生成 API](/zh/api/description/project-target#add_configfiles)。
+
+我们可以使用 `add_configfiles` 自动生成 `config.h` 等配置文件。
+
+## 基础示例
+
+<FileExplorer rootFilesDir="examples/configuration/add_configfiles/basic" />
+
+### 编译运行
+
+```bash
+$ xmake
+$ xmake run
+```

+ 18 - 0
docs/zh/examples/configuration/custom_scope_api.md

@@ -0,0 +1,18 @@
+---
+outline: deep
+---
+
+# 自定义描述域 API
+
+我们可以使用 `interp_add_scopeapis` 注册自定义描述域 API,来支持自定义配置域和接口。
+
+## 基础示例
+
+<FileExplorer rootFilesDir="examples/configuration/custom_scope_api/basic" />
+
+### 编译运行
+
+```bash
+$ xmake
+$ xmake run
+```

Some files were not shown because too many files changed in this diff