Skip to content

Commit 9ec7522

Browse files
committed
fix(build): Unify dependency installation with vcpkg
The previous installation process was unreliable on modern Linux distributions (e.g., Ubuntu 24.04) and had inconsistent instructions for vcpkg. This was caused by two key issues: 1. System package managers like `apt` no longer provide key dependencies (e.g., `libuwebsockets-dev`) on newer OS versions. 2. The `vcpkg` instructions were Windows-only, used an incorrect `unofficial-uwebsockets` package, and were not properly supported by the CMake configuration for Linux. This commit overhauls the build system and documentation to make vcpkg the standard, recommended method for dependency management across all platforms. - **CMakeLists.txt**: Now uses the official `uwebsockets` vcpkg package and correctly handles its integration on both Windows and Linux. The system library lookup is kept as a fallback. - **README.md**: Updated to provide a single, cross-platform `vcpkg` command as the primary installation method. Instructions for system package managers are now a secondary option, with a warning about potential issues on newer systems. This resolves installation failures on Ubuntu 24.04 and provides a more robust and maintainable build process for all users.
1 parent 1bcd3f7 commit 9ec7522

2 files changed

Lines changed: 35 additions & 25 deletions

File tree

CMakeLists.txt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if(WIN32)
2727
CACHE STRING "Vcpkg toolchain file")
2828
endif()
2929
include_directories("${VCPKG_ROOT}/installed/x64-windows/include")
30-
find_package(unofficial-uwebsockets CONFIG REQUIRED)
30+
find_package(uwebsockets CONFIG REQUIRED)
3131
find_package(ZLIB REQUIRED)
3232
find_package(Threads REQUIRED)
3333
find_package(jwt-cpp CONFIG REQUIRED)
@@ -39,14 +39,19 @@ if(WIN32)
3939
find_package(fmt CONFIG REQUIRED)
4040
else() # UNIX/Linux
4141
add_compile_options(-finput-charset=UTF-8 -fexec-charset=UTF-8)
42-
find_path(UWEBSOCKETS_INCLUDE_DIR uWebSockets/App.h PATHS /usr/include /usr/local/include)
43-
find_library(USOCKETS_LIBRARY usockets PATHS /usr/lib /usr/local/lib)
44-
if(NOT UWEBSOCKETS_INCLUDE_DIR)
45-
message(FATAL_ERROR "uWebSockets include directory not found!")
46-
endif()
47-
if(NOT USOCKETS_LIBRARY)
48-
message(FATAL_ERROR "uSockets library not found!")
42+
43+
# If not using vcpkg on Linux, find packages manually
44+
if(NOT CMAKE_TOOLCHAIN_FILE)
45+
find_path(UWEBSOCKETS_INCLUDE_DIR uWebSockets/App.h PATHS /usr/include /usr/local/include)
46+
find_library(USOCKETS_LIBRARY usockets PATHS /usr/lib /usr/local/lib)
47+
if(NOT UWEBSOCKETS_INCLUDE_DIR)
48+
message(FATAL_ERROR "uWebSockets include directory not found!")
49+
endif()
50+
if(NOT USOCKETS_LIBRARY)
51+
message(FATAL_ERROR "uSockets library not found!")
52+
endif()
4953
endif()
54+
5055
find_package(OpenSSL REQUIRED)
5156
find_package(ZLIB REQUIRED)
5257
find_package(Threads REQUIRED)
@@ -123,7 +128,7 @@ endif()
123128

124129
if(WIN32)
125130
target_link_libraries(binaryrpc_core PUBLIC
126-
unofficial::uwebsockets::uwebsockets
131+
uwebsockets::uwebsockets
127132
ZLIB::ZLIB
128133
Threads::Threads
129134
# jwt-cpp::jwt-cpp is only needed if ENABLE_JWT is ON
@@ -136,7 +141,8 @@ if(WIN32)
136141
)
137142
else()
138143
target_link_libraries(binaryrpc_core PUBLIC
139-
${USOCKETS_LIBRARY}
144+
$<$<TARGET_EXISTS:uwebsockets::uwebsockets>:uwebsockets::uwebsockets>
145+
$<$<NOT:$<TARGET_EXISTS:uwebsockets::uwebsockets>>:${USOCKETS_LIBRARY}>
140146
pthread
141147
ZLIB::ZLIB
142148
Threads::Threads

README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ This project is a modern C++ RPC framework with several external dependencies. T
5757
> **Note:**
5858
> Starting from version 0.1.0, BinaryRPC expects you to set the `VCPKG_ROOT` environment variable to your vcpkg installation path **on Windows**. This makes the build process portable and avoids hardcoding paths. If you do not set this variable on Windows, CMake will stop with an error.
5959
>
60-
> **Linux/macOS users:** You don't need to set VCPKG_ROOT as the project uses system package managers on these platforms.
60+
> **Linux/macOS users:** You can use your system package manager (like `apt` or `pacman`), but using `vcpkg` is recommended for better consistency, especially on newer distributions like Ubuntu 24.04 where some packages may not be available in the default repositories.
6161
>
6262
> **How to set VCPKG_ROOT (Windows only):**
6363
> - **Windows (PowerShell):**
@@ -71,34 +71,34 @@ This project is a modern C++ RPC framework with several external dependencies. T
7171
>
7272
> Replace `/path/to/vcpkg` with the actual path where you cloned vcpkg.
7373
74-
#### Step 2.1: Install Dependencies with vcpkg
74+
#### Step 2.1: Install Dependencies
7575
76-
First, ensure you have [vcpkg](https://github.com/microsoft/vcpkg) installed and bootstrapped. Then, install all required dependencies:
76+
You can install dependencies using **vcpkg** (recommended for all platforms) or your system's package manager (Linux-only alternative).
7777
78-
# Install all dependencies for binaryrpc
78+
### Option 1: Install with vcpkg (Recommended)
7979
80-
## Core Dependencies
80+
First, ensure you have [vcpkg](https://github.com/microsoft/vcpkg) installed and bootstrapped. Then, run the following command to install all required dependencies. This command works for Windows, Linux, and macOS.
8181
82-
These are required for building and running the core framework:
83-
84-
### Windows (vcpkg)
8582
```bash
86-
./vcpkg install unofficial-uwebsockets zlib folly glog gflags fmt double-conversion --triplet x64-windows
83+
./vcpkg install uwebsockets zlib folly glog gflags fmt double-conversion
8784
```
8885
89-
### Linux (Arch/pacman)
86+
### Option 2: Install with System Package Manager (Linux)
87+
88+
#### Linux (Arch/pacman)
9089
```bash
9190
sudo pacman -S uwebsockets zlib folly glog gflags fmt double-conversion openssl usockets
9291
```
9392

94-
### Linux (Ubuntu/Debian)
93+
#### Linux (Ubuntu/Debian)
94+
These packages might not be available on newer versions like Ubuntu 24.04. If you encounter errors, please use `vcpkg`.
9595
```bash
9696
sudo apt update
9797
sudo apt install libuwebsockets-dev zlib1g-dev libfolly-dev libgoogle-glog-dev libgflags-dev libfmt-dev libdouble-conversion-dev libssl-dev libusockets-dev
9898
```
9999

100100
> **Note on folly and glog:**
101-
> - On some distributions, the package names may differ or the packages may not be available in the default repositories. In that case, you may need to build [folly](https://github.com/facebook/folly) and [glog](https://github.com/google/glog) from source. Please refer to their official documentation for build instructions.
101+
> - On some distributions, the package names may differ or the packages may not be available in the default repositories. In that case, you may need to build [folly](https://github.com/facebook/folly) and [glog](https://github.com/google/glog) from source or use vcpkg.
102102
> - **Folly and glog can sometimes be incompatible on certain Linux systems.** If you encounter build errors related to glog, you can try disabling glog or ensure you are using compatible versions. On Linux, BinaryRPC disables glog logging by default if there is a known incompatibility.
103103
> - If you see an error like `folly library not found!`, make sure folly is installed and the library path is visible to the linker (e.g., `/usr/lib` or `/usr/local/lib`).
104104
> - If you see an error like `glog library not found!`, make sure glog is installed and the library path is visible to the linker.
@@ -130,8 +130,8 @@ cmake -E make_directory build
130130
cd build
131131

132132
# 3. Configure the project with the vcpkg toolchain
133-
# Use the VCPKG_ROOT environment variable for portability
134-
cmake .. -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
133+
# This step is required if you used vcpkg for dependencies.
134+
cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake
135135

136136
# 4. Build the library
137137
cmake --build . --config Release
@@ -152,7 +152,11 @@ cd binaryrpc
152152
cmake -E make_directory build
153153
cd build
154154

155-
# 3. Configure the project (no toolchain file needed on Linux/macOS)
155+
# 3. Configure the project
156+
# If using vcpkg, add the toolchain file:
157+
# cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake
158+
#
159+
# If using system libraries:
156160
cmake ..
157161

158162
# 4. Build the library

0 commit comments

Comments
 (0)