Building the Apollo Server
Using vcpkg (recommended)
1. Install vcpkg
bash
# Clone vcpkg
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
# Linux/macOS
./bootstrap-vcpkg.sh
# Windows
.\bootstrap-vcpkg.bat2. Build the project
bash
# Return to the project root
cd ..
# Configure CMake
cmake -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake \
-DVCPKG_TARGET_TRIPLET=x64-linux # Linux
# Build
cmake --build build --config ReleaseUsing System Package Managers
Ubuntu/Debian
bash
# Install dependencies
sudo apt-get install nlohmann-json3-dev libprotobuf-dev protobuf-compiler libgtest-dev libssl-dev libcurl4-openssl-dev libpugixml-dev libreadline-dev
# Build
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build buildmacOS
bash
# Using Homebrew
brew install nlohmann-json protobuf gtest openssl curl pugixml readline
# Build
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build buildWindows
bash
# Using vcpkg (recommended)
vcpkg install nlohmann-json protobuf gtest openssl curl pugixml readline crashpad:x64-windows
# Build
cmake -B build `
-DCMAKE_BUILD_TYPE=Release `
-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake `
-DVCPKG_TARGET_TRIPLET=x64-windows
cmake --build build --config ReleaseBuild Options
CMake options
APOLLO_BUILD_TESTS=ON- build unit tests (default: ON)APOLLO_BUILD_EXAMPLES=ON- build example programs (default: OFF; legacy aliasBUILD_EXAMPLES=ONforces it on)APOLLO_ENABLE_COVERAGE=ON- enable code coverage (requires gcov/lcov)APOLLO_ENABLE_DOXYGEN=ON- generate API documentation (requires Doxygen)APOLLO_ENABLE_CLANG_TIDY=ON- enable clang-tidy static analysis
vcpkg dependencies
The vcpkg.json manifest mode installs the following dependencies automatically (no manual vcpkg install needed):
| Dependency | Purpose |
|---|---|
| openssl | TLS/encryption |
| protobuf | Serialization (golden .proto) |
| gtest | Unit tests |
| curl | HTTP client |
| nlohmann-json | JSON parsing |
| pugixml | XML parsing (contracts) |
| readline | Interactive command line |
| crashpad | Crash capture |
Running Tests
bash
cd build
ctest --output-on-failure -C ReleaseGenerating Documentation
bash
cmake -B build -DAPOLLO_ENABLE_DOXYGEN=ON
cd build
make doc
# Documentation will be generated in build/docs/html/Developer Guide
Adding a New Dependency
- Edit
vcpkg.jsonto add the dependency:
json
{
"dependencies": [
"nlohmann-json",
"your-new-dependency"
]
}- Update
CMakeLists.txt:
cmake
find_package(your-dependency CONFIG REQUIRED)
target_link_libraries(apollo PRIVATE your-dependency::your-dependency)- Install the new dependency:
bash
cd vcpkg
./vcpkg install your-dependencyWindows Development Tips
- Use Visual Studio 2019 or later
- Install the CMake tools
- Use the x64 Native Tools Command Prompt
- Consider using CLion for development
Linux Development Tips
- CLion or VSCode + the CMake plugin recommended
- Install clang-tidy for static analysis
- Use valgrind for memory checking
Troubleshooting
Dependencies Not Found
If CMake cannot find a dependency, ensure:
- vcpkg has installed the dependencies correctly
- The
CMAKE_TOOLCHAIN_FILEpath is correct - The correct
VCPKG_TARGET_TRIPLETis used
Windows-Specific Issues
- Ensure Python is installed (vcpkg needs it)
- Use the x64 toolchain
- You may need to install Visual Studio Build Tools
macOS-Specific Issues
- Update Xcode to the latest version
- Install the Xcode Command Line Tools
Performance Optimization Tips
- Use the Release build for performance testing
- Enable compiler optimizations:
-O3 -march=native - Use LTO (link-time optimization):
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON - Use static linking to reduce dependencies:
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
