Installation - liuli-neko/NekoProtoTools GitHub Wiki
NekoProtoTools uses xmake as its build system and package manager. Integrating it into your own xmake-based project is straightforward.
Prerequisites
- You need to have xmake installed on your system. If you haven't already, please follow the installation instructions on the official xmake website.
Adding NekoProtoTools as a Dependency
To use NekoProtoTools in your project, you need to add it as a requirement in your project's xmake.lua
file using add_requires
.
-- In your xmake.lua
-- 1. Declare the requirement
add_requires("neko-proto-tools", { /* options can go here */ })
-- Note: If the package isn't found in the default xmake repositories,
-- you might need to specify the Git repository source, especially during
-- early development or if using a specific branch/fork.
-- add_requires("neko-proto-tools", {git = "https://github.com/liuli-neko/NekoProtoTools.git", branch = "main"})
-- Or add the Btk-Project repository to your project or global xmake config:
-- add_repositories("btk-repo https://github.com/Btk-Project/xmake-repo.git")
-- 2. Link your target against the package
target("your_project_name")
set_kind("binary") -- Or "shared", "static"
add_files("src/*.cpp")
-- Add the package to your target
add_packages("neko-proto-tools")
Configuring Optional Features
NekoProtoTools is designed to be modular. You can enable or disable specific features based on your needs, which helps keep the library footprint small and manages external dependencies. Configuration is done via the configs
table within add_requires
.
Here's an example showing how to enable several common features:
-- In your xmake.lua
add_requires("neko-proto-tools", {
-- The 'configs' table holds the feature flags
configs = {
-- === JSON Backend Selection (Choose one or none) ===
enable_rapidjson = true, -- Enable RapidJSON for JSON serialization/deserialization.
-- Adds a dependency on the RapidJSON library.
enable_simdjson = false, -- Enable SIMDJson for potentially faster JSON serialization/deserialization.
-- Adds a dependency on the SIMDJson library.
-- Note: serialization is implemented by my self
-- === Logging Backend Selection (Choose one or none) ===
-- enable_std_format = true, -- (Automatic detection) Use std::format for logging.
-- Requires a C++20 compliant compiler/STL.
enable_fmt = false, -- Enable fmtlib for logging output.
-- Adds a dependency on the fmt library. Useful if std::format isn't available/desired.
enable_spdlog = false, -- Enable spdlog as the logging backend.
-- Adds a dependency on the spdlog library.
-- === Feature Modules ===
enable_communication = true,-- Enable the network communication layer (ProtoStreamClient/ProtoDatagramClient).
-- Adds a dependency on the ilias library.
enable_jsonrpc = true, -- Enable the JSON-RPC 2.0 client/server implementation.
-- Requires a JSON backend (e.g., 'enable_rapidjson = true' or 'enable_simdjson = true')
-- Adds a dependency on the ilias library.
enable_xml = false -- Enable XML deserialization support.
-- Adds a dependency on the RapidXML library.
}
})
target("your_project_name")
set_kind("binary")
add_files("src/*.cpp")
add_packages("neko-proto-tools")
Explanation of Common Options:
enable_rapidjson
/enable_simdjson
: Control which JSON library backend is used. RapidJSON is generally good for both input and output. SIMDJson offers very high performance for JSON parsing (input). Choose based on your performance needs and existing dependencies. You typically only need one enabled for JSON support.enable_fmt
/enable_spdlog
/enable_std_format
: Selects the logging framework. If none are enabled, logging features might be disabled or use basicstd::cout
.enable_communication
: Required if you plan to use the built-in TCP/UDP message transport features (ProtoStreamClient
,ProtoDatagramClient
). Depends on Ilias.enable_jsonrpc
: Required for the JSON-RPC client/server functionality. Depends onenable_communication
and a JSON backend.enable_xml
: Required if you need to deserialize data from XML format. Depends on RapidXML.
Default Values: It's generally recommended to explicitly set the configs
you need. If omitted, features are typically disabled by default to minimize dependencies.
Fetching and Building
Once you have configured your xmake.lua
, xmake will automatically handle downloading NekoProtoTools and its required dependencies the next time you build your project:
# Configure the project (optional, usually needed only once or when changing configs)
xmake f -c
# Build the project
xmake build
Xmake will place the compiled NekoProtoTools library and headers in its cache or build directory, and your project will link against it automatically.
Next Steps
With NekoProtoTools added to your project, you're ready to start using it! Head over to the tutorials: