Browse Source

add more examples

ruki 1 week ago
parent
commit
e1cbe5b1f6

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


+ 14 - 0
docs/codes/examples/cpp/packages/boost/src/main.cpp

@@ -0,0 +1,14 @@
+#include <boost/algorithm/string.hpp>
+#include <iostream>
+#include <string>
+#include <vector>
+
+int main() {
+    std::string s = "Hello,World";
+    std::vector<std::string> strs;
+    boost::split(strs, s, boost::is_any_of(","));
+    for (const auto& str : strs) {
+        std::cout << str << std::endl;
+    }
+    return 0;
+}

+ 8 - 0
docs/codes/examples/cpp/packages/boost/xmake.lua

@@ -0,0 +1,8 @@
+add_rules("mode.debug", "mode.release")
+
+add_requires("boost")
+
+target("test")
+    set_kind("binary")
+    add_files("src/*.cpp")
+    add_packages("boost")

+ 6 - 0
docs/codes/examples/cpp/packages/fmt/src/main.cpp

@@ -0,0 +1,6 @@
+#include <fmt/core.h>
+
+int main() {
+    fmt::print("Hello, world!\n");
+    return 0;
+}

+ 8 - 0
docs/codes/examples/cpp/packages/fmt/xmake.lua

@@ -0,0 +1,8 @@
+add_rules("mode.debug", "mode.release")
+
+add_requires("fmt")
+
+target("test")
+    set_kind("binary")
+    add_files("src/*.cpp")
+    add_packages("fmt")

+ 12 - 0
docs/codes/examples/cpp/packages/gflags/src/main.cpp

@@ -0,0 +1,12 @@
+#include <iostream>
+#include <gflags/gflags.h>
+
+DEFINE_bool(big_menu, true, "Include 'advanced' options in the menu listing");
+
+int main(int argc, char** argv) {
+    gflags::ParseCommandLineFlags(&argc, &argv, true);
+    if (FLAGS_big_menu) {
+        std::cout << "big menu is enabled" << std::endl;
+    }
+    return 0;
+}

+ 8 - 0
docs/codes/examples/cpp/packages/gflags/xmake.lua

@@ -0,0 +1,8 @@
+add_rules("mode.debug", "mode.release")
+
+add_requires("gflags", {configs = {shared = true}})
+
+target("test")
+    set_kind("binary")
+    add_files("src/*.cpp")
+    add_packages("gflags")

+ 7 - 0
docs/codes/examples/cpp/packages/openssl/src/main.c

@@ -0,0 +1,7 @@
+#include <openssl/ssl.h>
+#include <stdio.h>
+
+int main() {
+    printf("OpenSSL Version: %s\n", SSLeay_version(SSLEAY_VERSION));
+    return 0;
+}

+ 8 - 0
docs/codes/examples/cpp/packages/openssl/xmake.lua

@@ -0,0 +1,8 @@
+add_rules("mode.debug", "mode.release")
+
+add_requires("openssl")
+
+target("test")
+    set_kind("binary")
+    add_files("src/*.c")
+    add_packages("openssl")

+ 7 - 0
docs/codes/examples/cpp/packages/zlib/src/main.c

@@ -0,0 +1,7 @@
+#include <stdio.h>
+#include <zlib.h>
+
+int main(int argc, char** argv) {
+    printf("zlib version: %s\n", zlibVersion());
+    return 0;
+}

+ 8 - 0
docs/codes/examples/cpp/packages/zlib/xmake.lua

@@ -0,0 +1,8 @@
+add_rules("mode.debug", "mode.release")
+
+add_requires("zlib 1.3.1")
+
+target("test")
+    set_kind("binary")
+    add_files("src/*.c")
+    add_packages("zlib")

+ 1 - 0
docs/config.ts

@@ -332,6 +332,7 @@ function examplesSidebar(): DefaultTheme.SidebarItem[] {
         { text: 'Android Native App', link: 'cpp/android-native-app' },
         { text: 'Bin2c/Bin2obj', link: 'cpp/bin2c-obj' },
         { text: 'GLSL/HLSL to SPIR-V', link: 'cpp/glsl2spv' },
+        { text: 'Package Management', link: 'cpp/packages' },
         { text: 'XPack Packaging', link: 'cpp/xpack' },
       ]
     },

+ 33 - 0
docs/examples/cpp/packages.md

@@ -0,0 +1,33 @@
+---
+outline: deep
+---
+
+# Package Management
+
+Xmake provides a powerful package management system that allows you to easily install and use third-party libraries.
+
+For more detailed documentation, please refer to [Add Packages](/guide/project-configuration/add-packages).
+
+## Use Fmt
+
+<FileExplorer rootFilesDir="examples/cpp/packages/fmt" />
+
+## Use Boost
+
+<FileExplorer rootFilesDir="examples/cpp/packages/boost" />
+
+## Use OpenSSL
+
+<FileExplorer rootFilesDir="examples/cpp/packages/openssl" />
+
+## Specify Version
+
+We can also specify the version of the package we want to use. By default, xmake uses the latest available version of a package. You can specify a semantic version constraint to require a specific version.
+
+<FileExplorer rootFilesDir="examples/cpp/packages/zlib" />
+
+## Use Shared Library
+
+We can also configure the package to use shared libraries. Some packages support building as shared libraries. You can enable this by passing `{configs = {shared = true}}` to `add_requires`.
+
+<FileExplorer rootFilesDir="examples/cpp/packages/gflags" />

+ 1 - 0
docs/zh/config.ts

@@ -413,6 +413,7 @@ function examplesSidebar(): DefaultTheme.SidebarItem[] {
         { text: 'Android Native App', link: 'cpp/android-native-app' },
         { text: 'Bin2c/Bin2obj 程序', link: 'cpp/bin2c-obj' },
         { text: 'GLSL/HLSL 转 SPIR-V', link: 'cpp/glsl2spv' },
+        { text: '包管理', link: 'cpp/packages' },
         { text: 'XPack 打包程序', link: 'cpp/xpack' },
       ]
     },

+ 33 - 0
docs/zh/examples/cpp/packages.md

@@ -0,0 +1,33 @@
+---
+outline: deep
+---
+
+# 包管理
+
+Xmake 提供了一个强大的包管理系统,允许你轻松安装和使用第三方库。
+
+更多详细文档,请参考 [添加依赖包](/zh/guide/project-configuration/add-packages)。
+
+## 使用 Fmt
+
+<FileExplorer rootFilesDir="examples/cpp/packages/fmt" />
+
+## 使用 Boost
+
+<FileExplorer rootFilesDir="examples/cpp/packages/boost" />
+
+## 使用 OpenSSL
+
+<FileExplorer rootFilesDir="examples/cpp/packages/openssl" />
+
+## 指定版本
+
+我们也可以指定我们想要使用的包的版本。默认情况下,xmake 使用包的最新可用版本。你可以指定语义版本约束来请求特定版本。
+
+<FileExplorer rootFilesDir="examples/cpp/packages/zlib" />
+
+## 使用动态库
+
+我们还可以配置包以使用动态库。一些包支持编译为动态库。你可以通过向 `add_requires` 传递 `{configs = {shared = true}}` 来启用此功能。
+
+<FileExplorer rootFilesDir="examples/cpp/packages/gflags" />

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