## Overview
Comprehensive guide for building DAP SDK from source code across all supported platforms. This guide covers prerequisites, source acquisition, configuration options, compilation, testing, and installation procedures for all DAP SDK modules including Core, Crypto, I/O, Net (with its submodules), Global DB, Plugin, and Test modules.
## Quick Build
### Essential Commands
**Linux/macOS:**
```bash
# Clone and build (standard configuration)
git clone https://gitlab.demlabs.net/dap/dap-sdk.git
cd dap-sdk
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
sudo make install
```
**Windows (with Visual Studio):**
```powershell
# Clone and build
git clone https://gitlab.demlabs.net/dap/dap-sdk.git
cd dap-sdk
mkdir build
cd build
cmake .. -G "Visual Studio 16 2019" -A x64
cmake --build . --config Release
cmake --install . --config Release
```
## Prerequisites
### System Requirements
**Minimum Requirements:**
- **CPU:** x86_64 or ARM64 architecture
- **RAM:** 2GB available memory (4GB recommended for compilation)
- **Storage:** 1GB free space for source and build artifacts
- **Network:** Internet connection for dependency downloads
**Supported Operating Systems:**
- **Linux:** Ubuntu 20.04+, Debian 11+, CentOS 8+, RHEL 8+, Fedora 34+
- **macOS:** macOS 11.0+ (Big Sur and later)
- **Windows:** Windows 10/11 with Visual Studio 2019+ or MinGW-w64
### Build Tools
#### Linux (Ubuntu/Debian)
```bash
# Essential build tools
sudo apt update
sudo apt install -y build-essential cmake git pkg-config
# Additional development libraries
sudo apt install -y \
libssl-dev \
libsqlite3-dev \
libjson-c-dev \
libpcap-dev \
libmagic-dev \
libcurl4-openssl-dev \
zlib1g-dev
```
#### Linux (CentOS/RHEL/Fedora)
```bash
# CentOS/RHEL 8+
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y cmake git pkg-config
# Additional libraries
sudo dnf install -y \
openssl-devel \
sqlite-devel \
json-c-devel \
libpcap-devel \
file-devel \
libcurl-devel \
zlib-devel
# Fedora (similar but with newer package names)
sudo dnf install -y gcc gcc-c++ cmake git pkg-config \
openssl-devel sqlite-devel json-c-devel \
libpcap-devel file-devel libcurl-devel zlib-devel
```
#### macOS
```bash
# Install Xcode Command Line Tools
xcode-select --install
# Install Homebrew (if not already installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install build dependencies
brew install cmake git pkg-config openssl sqlite json-c libpcap zlib curl
```
#### Windows
**Option 1: Visual Studio (Recommended)**
1. Install Visual Studio 2019 or 2022 Community Edition
2. Include "C++ CMake tools" and "Git for Windows" components
3. Install vcpkg for dependency management:
```powershell
# Install vcpkg
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg integrate install
# Install DAP SDK dependencies
.\vcpkg install openssl:x64-windows sqlite3:x64-windows curl:x64-windows zlib:x64-windows
```
**Option 2: MinGW-w64**
1. Install MSYS2 from https://www.msys2.org/
2. Install build tools:
```bash
# In MSYS2 terminal
pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake \
mingw-w64-x86_64-openssl mingw-w64-x86_64-sqlite3 \
mingw-w64-x86_64-curl mingw-w64-x86_64-zlib git
```
## Source Code Acquisition
### Git Repository
**Primary Repository:**
```bash
# Clone from GitLab (primary)
git clone https://gitlab.demlabs.net/dap/dap-sdk.git
cd dap-sdk
# Check available branches and tags
git branch -a
git tag --list
# Use specific version (recommended for production)
git checkout v1.0.0 # Replace with desired version
```
**Repository Information:**
- **URL:** https://gitlab.demlabs.net/dap/dap-sdk
- **Commits:** 2,475+ commits across 154 branches
- **License:** GNU General Public License v3.0
- **Created:** May 2020
### Source Verification
```bash
# Verify repository integrity
git fsck --full
# Check commit signatures (if available)
git log --show-signature -5
# Verify against known checksums (when available)
# sha256sum -c checksums.txt
```
## CMake Configuration
### Basic Configuration
```bash
# Create build directory
mkdir build && cd build
# Basic configuration
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local
```
### Configuration Options
#### Core Build Options
| Option | Default | Description |
|--------|---------|-------------|
| `CMAKE_BUILD_TYPE` | `Release` | Build type: Debug, Release, RelWithDebInfo, MinSizeRel |
| `CMAKE_INSTALL_PREFIX` | `/usr/local` | Installation directory prefix |
| `DAP_DEBUG` | `OFF` | Enable debug logging and assertions |
| `DAP_MEMSAN` | `OFF` | Enable memory sanitizer (debug builds) |
| `DAP_ASAN` | `OFF` | Enable address sanitizer (debug builds) |
#### Module Options
| Option | Default | Description |
|--------|---------|-------------|
| `DAP_MODULES_CRYPTO` | `ON` | Build cryptographic modules |
| `DAP_MODULES_NET` | `ON` | Build networking modules |
| `DAP_MODULES_IO` | `ON` | Build I/O and event modules |
| `DAP_MODULES_STREAM` | `ON` | Build stream processing modules |
| `DAP_MODULES_DB` | `ON` | Build database modules |
| `DAP_MODULES_PLUGIN` | `ON` | Build plugin system |
#### Platform-Specific Options
| Option | Default | Description |
|--------|---------|-------------|
| `DAP_OS_LINUX` | Auto-detect | Enable Linux-specific features |
| `DAP_OS_MACOS` | Auto-detect | Enable macOS-specific features |
| `DAP_OS_WINDOWS` | Auto-detect | Enable Windows-specific features |
| `DAP_NET_CLIENT` | `ON` | Build client networking support |
| `DAP_NET_SERVER` | `ON` | Build server networking support |
### Example Configurations
#### Debug Build with Sanitizers
```bash
cmake .. \
-DCMAKE_BUILD_TYPE=Debug \
-DDAP_DEBUG=ON \
-DDAP_ASAN=ON \
-DDAP_MEMSAN=ON \
-DCMAKE_INSTALL_PREFIX=$HOME/dap-sdk-debug
```
#### Minimal Build (Core Only)
```bash
cmake .. \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DDAP_MODULES_NET=OFF \
-DDAP_MODULES_STREAM=OFF \
-DDAP_MODULES_DB=OFF \
-DDAP_MODULES_PLUGIN=OFF
```
#### Production Build with Optimizations
```bash
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/opt/dap-sdk \
-DCMAKE_C_FLAGS="-O3 -march=native" \
-DDAP_DEBUG=OFF
```
## Platform-Specific Compilation
### Linux
#### Standard Build
```bash
# Configure and build
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
# Install system-wide
sudo make install
# Or install to custom location
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/dap-sdk
make -j$(nproc) install
```
#### Cross-Compilation
```bash
# For ARM64 (example)
cmake .. \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=aarch64 \
-DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \
-DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++
```
### macOS
#### Universal Binary (Intel + Apple Silicon)
```bash
# Build universal binary
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0
make -j$(sysctl -n hw.ncpu)
sudo make install
```
#### Intel-Only Build
```bash
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_OSX_ARCHITECTURES=x86_64 \
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15
```
### Windows
#### Visual Studio Build
```powershell
# Configure for Visual Studio 2019
cmake .. -G "Visual Studio 16 2019" -A x64 `
-DCMAKE_BUILD_TYPE=Release `
-DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake
# Build (from build directory)
cmake --build . --config Release --parallel
# Install
cmake --install . --config Release --prefix C:\dap-sdk
```
#### MinGW Build
```bash
# In MSYS2 MinGW64 terminal
cmake .. \
-G "MinGW Makefiles" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/mingw64
make -j$(nproc)
make install
```
## Build Process
### Compilation
```bash
# Parallel build (recommended)
make -j$(nproc) # Linux/macOS
make -j%NUMBER_OF_PROCESSORS% # Windows MinGW
# Single-threaded build (for debugging)
make VERBOSE=1
# Specific target
make dap-core
make dap-crypto
```
### Build Output
The build process creates:
```
build/
├── lib/ # Static and shared libraries
│ ├── libdap-core.a
│ ├── libdap-crypto.a
│ ├── libdap-io.a
│ └── ...
├── bin/ # Executables and tools
│ ├── dap-tool
│ └── test-runner
├── include/ # Header files
│ ├── dap_common.h
│ ├── dap_crypto.h
│ └── ...
└── test/ # Test executables
├── test-core
├── test-crypto
└── ...
```
## Testing
### Running Tests
```bash
# Run all tests
make test
# Or use ctest directly
ctest --parallel $(nproc) --output-on-failure
# Run specific test categories
ctest -R "crypto" --verbose
ctest -R "network" --parallel 4
# Run tests with memory checking (if available)
ctest -T memcheck
```
### Test Categories
- **Unit Tests** - Individual function and module testing
- **Integration Tests** - Multi-module interaction testing
- **Performance Tests** - Benchmarking and performance validation
- **Memory Tests** - Memory leak and corruption detection
- **Network Tests** - Network protocol and communication testing
### Test Output
```bash
# Example test output
Running tests...
Test project /path/to/dap-sdk/build
Start 1: test-core-basic
1/25 Test #1: test-core-basic .................. Passed 0.12 sec
Start 2: test-crypto-hash
2/25 Test #2: test-crypto-hash ................. Passed 0.08 sec
Start 3: test-io-events
3/25 Test #3: test-io-events ................... Passed 0.15 sec
...
100% tests passed, 0 tests failed out of 25
Total Test time (real) = 3.45 sec
```
## Installation
### System Installation
```bash
# Install to system directories (requires root)
sudo make install
# Verify installation
pkg-config --cflags dap-sdk
pkg-config --libs dap-sdk
# Check installed files
ldconfig -p | grep dap # Linux
```
### Custom Installation
```bash
# Install to custom prefix
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/local/dap-sdk
make install
# Set up environment
export PKG_CONFIG_PATH=$HOME/local/dap-sdk/lib/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=$HOME/local/dap-sdk/lib:$LD_LIBRARY_PATH
```
### Package Creation
#### DEB Package (Ubuntu/Debian)
```bash
# Install packaging tools
sudo apt install -y debhelper devscripts
# Create package
cpack -G DEB
# Install created package
sudo dpkg -i dap-sdk-*.deb
```
#### RPM Package (CentOS/RHEL/Fedora)
```bash
# Install packaging tools
sudo dnf install -y rpm-build rpmlint
# Create package
cpack -G RPM
# Install created package
sudo rpm -i dap-sdk-*.rpm
```
## Verification
### Build Verification
```bash
# Verify libraries are built correctly
ldd build/lib/libdap-core.so # Linux
otool -L build/lib/libdap-core.dylib # macOS
# Check symbols
nm build/lib/libdap-core.a | grep dap_common_init
objdump -t build/lib/libdap-core.a | grep dap_ # Linux
```
### Installation Verification
```bash
# Create test program
cat > test_install.c << 'EOF'
#include <dap_common.h>
#include <stdio.h>
int main() {
if (dap_common_init("test", NULL) == 0) {
printf("DAP SDK installation verified successfully!\n");
dap_common_deinit();
return 0;
} else {
printf("DAP SDK installation verification failed!\n");
return 1;
}
}
EOF
# Compile and run test
gcc test_install.c $(pkg-config --cflags --libs dap-sdk) -o test_install
./test_install
# Expected output: "DAP SDK installation verified successfully!"
```
## Troubleshooting
### Common Build Issues
#### Missing Dependencies
**Problem:** `Could not find required package`
```bash
# Solution: Install missing dependencies
sudo apt install libssl-dev # Ubuntu/Debian
sudo dnf install openssl-devel # CentOS/RHEL/Fedora
brew install openssl # macOS
```
#### CMake Version Too Old
**Problem:** `CMake 3.16 or higher is required`
```bash
# Ubuntu 18.04 or older - install newer CMake
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc | sudo apt-key add -
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'
sudo apt update && sudo apt install cmake
```
#### Compiler Issues
**Problem:** `error: 'for' loop initial declarations are only allowed in C99 mode`
```bash
# Solution: Use C99 or newer standard
export CFLAGS="-std=c99"
cmake .. -DCMAKE_C_STANDARD=99
```
#### Memory Issues During Build
**Problem:** `g++: internal compiler error: Killed`
```bash
# Solution: Reduce parallel jobs or add swap
make -j1 # Single-threaded build
# Or add swap space for memory-constrained systems
```
### Build Performance
#### Faster Builds
```bash
# Use ccache for faster rebuilds
sudo apt install ccache # Ubuntu/Debian
export CC="ccache gcc"
export CXX="ccache g++"
# Use Ninja generator (faster than Make)
cmake .. -G Ninja
ninja -j$(nproc)
# Use gold linker (faster linking)
export LDFLAGS="-fuse-ld=gold"
```
#### Clean Builds
```bash
# Clean build artifacts
make clean
# Complete clean (remove build directory)
cd .. && rm -rf build && mkdir build && cd build
# Clean and reconfigure
cmake --build . --target clean
cmake ..
```
## Advanced Configuration
### Custom Build Features
```bash
# Enable all debugging features
cmake .. \
-DCMAKE_BUILD_TYPE=Debug \
-DDAP_DEBUG=ON \
-DDAP_EXTENSIVE_LOGGING=ON \
-DDAP_MEMORY_DEBUG=ON \
-DDAP_STACK_PROTECTION=ON
# Performance-optimized build
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS="-O3 -flto -march=native" \
-DCMAKE_CXX_FLAGS="-O3 -flto -march=native" \
-DDAP_OPTIMIZE_SIZE=OFF \
-DDAP_OPTIMIZE_SPEED=ON
```
### Development Setup
```bash
# Development build with IDE support
cmake .. \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DDAP_BUILD_TESTS=ON \
-DDAP_BUILD_EXAMPLES=ON
# Generate IDE project files
cmake .. -G "Eclipse CDT4 - Unix Makefiles" # Eclipse
cmake .. -G "CodeBlocks - Unix Makefiles" # Code::Blocks
```
---
## Next Steps
After successful build and installation:
1. **[[First Application|First Application]]** - Create your first DAP SDK application
2. **[[Architecture Overview|Architecture Overview]]** - Understand the system architecture
3. **[[Module Overview|Module Overview]]** - Explore available modules and APIs
4. **[[Development Guide|Development Guide]]** - Learn development best practices
5. **[[Troubleshooting|Troubleshooting]]** - Solutions for common issues
For questions or issues:
- Check **[[Troubleshooting|Troubleshooting]]** documentation
- Review [GitLab Issues](https://gitlab.demlabs.net/dap/dap-sdk/-/issues)
- Examine build logs for specific error messages
---
*Last updated: December 2024 | Build guide version: 1.0 | Supports DAP SDK v1.0+*