Building uRPC¶
This page describes how to build urpc, control logging, CLI, examples and tests.
Requirements¶
- CMake ≥ 3.27
- C++23 compiler (GCC / Clang / MSVC with C++23)
- OpenSSL (Crypto + SSL)
- Git (for
FetchContentdependencies)
uRPC uses:
All of them are pulled via FetchContent by default.
FetchContent (recommended for embedding)¶
If you want to embed uRPC directly into your project without installation, use CMake’s FetchContent.
Minimal example¶
include(FetchContent)
FetchContent_Declare(
urpc
GIT_REPOSITORY https://github.com/Usub-development/urpc.git
GIT_TAG main
)
FetchContent_MakeAvailable(urpc)
add_executable(my_app main.cpp)
target_link_libraries(my_app
PRIVATE
usub::urpc
)
With logging disabled¶
FetchContent_Declare(
urpc
GIT_REPOSITORY https://github.com/Usub-development/urpc.git
GIT_TAG main
)
set(URPC_LOGS OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(urpc)
add_executable(my_app main.cpp)
target_link_libraries(my_app PRIVATE urpc)
With CLI disabled / examples disabled¶
set(URPC_BUILD_CLI OFF CACHE BOOL "" FORCE)
set(URPC_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
urpc
GIT_REPOSITORY https://github.com/Usub-development/urpc.git
GIT_TAG main
)
FetchContent_MakeAvailable(urpc)
Notes¶
- All transitive dependencies (
uvent,ureflect,ulogif enabled) are fetched automatically. - No system installation is required.
- Works well for monorepos and statically linked backend binaries.
Basic build¶
git clone https://github.com/Usub-development/urpc.git
cd urpc
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Debug
cmake --build build
Install:
CMake options¶
| Option | Default | Description |
|---|---|---|
URPC_LOGS |
OFF |
Enable internal logging via ulog |
URPC_BUILD_CLI |
ON |
Build urpc_cli command-line tool |
URPC_BUILD_EXAMPLES |
ON |
Build example servers/clients |
URPC_BUILD_TESTS |
ON |
Build tests (if BUILD_TESTING=ON) |
Example: minimal build (no logs, no CLI, no examples, no tests)¶
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Release \
-DURPC_LOGS=OFF \
-DURPC_BUILD_CLI=OFF \
-DURPC_BUILD_EXAMPLES=OFF \
-DURPC_BUILD_TESTS=OFF
cmake --build build
Logging (URPC_LOGS)¶
option(URPC_LOGS "Use URPC_LOGS" ON)
if (URPC_LOGS)
# ulog is fetched and linked only if logs are enabled
FetchContent_Declare(
ulog
GIT_REPOSITORY https://github.com/Usub-development/ulog.git
GIT_TAG main
)
FetchContent_MakeAvailable(ulog)
target_link_libraries(urpc PUBLIC usub::ulog)
endif ()
target_compile_definitions(urpc PUBLIC
$<$<BOOL:${URPC_LOGS}>:URPC_LOGS>
)
URPC_LOGS=ON:urpclinks againstulog- all
#if URPC_LOGSlog statements are compiled in
URPC_LOGS=OFF:- no dependency on
ulog - all logging branches compiled out
- no dependency on
Build with logs disabled:
CLI tool (URPC_BUILD_CLI)¶
When URPC_BUILD_CLI=ON:
ulogis fetched (if not already)urpc_cliis built and installed to${CMAKE_INSTALL_BINDIR}
Relevant CMake:
option(URPC_BUILD_CLI "Build urpc_cli command-line tool" ON)
if (URPC_BUILD_CLI)
FetchContent_Declare(
ulog
GIT_REPOSITORY https://github.com/Usub-development/ulog.git
GIT_TAG main
)
FetchContent_MakeAvailable(ulog)
target_link_libraries(urpc PUBLIC usub::ulog)
add_executable(urpc_cli bin/urpc_cli.cpp)
target_link_libraries(urpc_cli PRIVATE urpc usub::ulog)
target_compile_definitions(urpc_cli PRIVATE DEV_STAGE=${DEV_STAGE})
install(TARGETS urpc_cli
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif ()
Disable CLI:
Examples (URPC_BUILD_EXAMPLES)¶
When URPC_BUILD_EXAMPLES=ON, the following binaries are built:
urpc_exampleurpc_example_server_mtlsurpc_example_clienturpc_stress_clienturpc_example_multiurpc_example_client_multiurpc_stress_client_multi
Each example is linked with urpc and compiled with DEV_STAGE=${DEV_STAGE}.
Disable examples:
Tests (URPC_BUILD_TESTS)¶
Tests are guarded by:
option(URPC_BUILD_TESTS "Build urpc tests" ON)
if (BUILD_TESTING AND URPC_BUILD_TESTS)
# Fetch / find GoogleTest etc...
endif ()
To enable tests:
(Currently test targets are commented out in CMakeLists.txt; they can be re-enabled later.)
DEV_STAGE define¶
Several executables are compiled with:
target_compile_definitions(urpc_cli PRIVATE DEV_STAGE=${DEV_STAGE})
target_compile_definitions(urpc_example PRIVATE DEV_STAGE=${DEV_STAGE})
# ... same for other examples
If you want to control DEV_STAGE, pass it via CMake:
(Your code can use #if DEV_STAGE == ... or ULOG formatting based on this define.)
Using installed urpc¶
After cmake --install:
find_package(urpc REQUIRED)
add_executable(my_app main.cpp)
target_link_libraries(my_app
PRIVATE
urpc::urpc
)
Include headers as:
#include <urpc/client/RPCClient.h>
#include <urpc/server/RPCServer.h>
#include <urpc/datatypes/Frame.h>
That’s enough to:
- toggle logs,
- toggle CLI,
- toggle examples/tests