Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
314 changes: 314 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
# OpenWheel Build System

This document describes the build system, testing infrastructure, and installation targets for the OpenWheel project.

## Build System Overview

OpenWheel uses CMake as its build system with support for:
- **Multi-component builds**: Daemon and gadget can be built independently
- **Flexible configuration**: Build options to customize what gets built
- **Testing infrastructure**: CTest integration for automated testing
- **Comprehensive installation**: Install targets for binaries, data, and development files

## Prerequisites

### Required
- CMake 3.16 or newer
- C11 compiler (for openwheel-daemon)
- C++20 compiler (for openwheel-gadget)
- pkg-config
- DBus development libraries

### For Gadget Component
- Qt5 (5.15+) or Qt6
- Qt modules: Core, Gui, Widgets, Qml, Quick, DBus

### Optional
- KDE Frameworks 6 (for enhanced features)
- X11 with XTest (for keyboard/mouse simulation)

## Build Options

The following CMake options control the build:

| Option | Default | Description |
|--------|---------|-------------|
| `BUILD_DAEMON` | ON | Build the openwheel-daemon component |
| `BUILD_GADGET` | ON | Build the openwheel-gadget component |
| `BUILD_TESTS` | ON | Build and enable tests |
| `ENABLE_INSTALL` | ON | Enable installation targets |
| `CMAKE_BUILD_TYPE` | Release | Build type (Debug, Release, RelWithDebInfo, MinSizeRel) |

## Building

### Standard Build

```bash
# Create build directory
mkdir build
cd build

# Configure
cmake ..

# Build
make -j$(nproc)
```

### Build with Custom Options

```bash
# Build only the daemon
cmake -DBUILD_GADGET=OFF ..
make

# Build with debug symbols
cmake -DCMAKE_BUILD_TYPE=Debug ..
make

# Build without tests
cmake -DBUILD_TESTS=OFF ..
make

# Custom install prefix
cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..
make
```

### Out-of-source Build (Recommended)

```bash
# From project root
mkdir -p build/release
cd build/release
cmake ../..
make -j$(nproc)
```

## Testing

The project uses CTest for testing infrastructure.

### Running Tests

```bash
# From build directory
ctest

# Verbose output
ctest -V

# Run specific test
ctest -R daemon_executable_exists

# Run tests in parallel
ctest -j$(nproc)
```

### Available Tests

- `check_build_outputs` - Verifies build completed successfully
- `daemon_executable_exists` - Checks daemon binary exists (if built)
- `gadget_executable_exists` - Checks gadget binary exists (if built)
- `version_test` - Validates project version
- `config_summary` - Displays build configuration

## Installation

### Installation Targets

The project provides component-based installation:

| Component | Description | Files |
|-----------|-------------|-------|
| `daemon` | Daemon executable | `asus_wheel` binary |
| `daemon-dev` | Daemon headers | Development headers |
| `gadget` | Gadget executable | `openwheel-gadget` binary |
| `gadget-dev` | Gadget headers | Development headers |
| `data` | Data files | Profiles, desktop files, icons |

### Install Commands

```bash
# Install everything
sudo make install

# Install specific component
sudo cmake --install . --component daemon
sudo cmake --install . --component gadget
sudo cmake --install . --component data

# Install to custom prefix
cmake -DCMAKE_INSTALL_PREFIX=$HOME/.local ..
make install # No sudo needed
```

### Installation Paths

Default installation paths (with `/usr/local` prefix):

- **Binaries**: `/usr/local/bin/`
- `asus_wheel` (daemon)
- `openwheel-gadget` (gadget)
- **Headers**: `/usr/local/include/openwheel/`
- **Data files**: `/usr/local/share/openwheel/`
- **Desktop files**: `/usr/local/share/applications/`
- **Icons**: `/usr/local/share/icons/hicolor/128x128/apps/`

## Build Artifacts

Build outputs are organized in the build directory:

```
build/
├── bin/ # Executables
│ ├── asus_wheel
│ └── openwheel-gadget
├── lib/ # Libraries (if any)
└── Testing/ # CTest output
```

## Common Build Tasks

### Clean Build

```bash
# Remove build directory
rm -rf build

# Recreate and build
mkdir build && cd build
cmake ..
make -j$(nproc)
```

### Rebuild After Changes

```bash
# From build directory
make clean
make -j$(nproc)
```

### Update CMake Configuration

```bash
# From build directory
cmake ..
make -j$(nproc)
```

## Troubleshooting

### Missing Dependencies

If CMake reports missing dependencies:

```bash
# Ubuntu/Debian
sudo apt-get install cmake build-essential pkg-config libdbus-1-dev
sudo apt-get install qt6-base-dev qt6-declarative-dev # For Qt6
sudo apt-get install libx11-dev libxtst-dev # For X11 support

# Fedora
sudo dnf install cmake gcc-c++ pkg-config dbus-devel
sudo dnf install qt6-qtbase-devel qt6-qtdeclarative-devel
sudo dnf install libX11-devel libXtst-devel

# Arch
sudo pacman -S cmake base-devel pkg-config dbus
sudo pacman -S qt6-base qt6-declarative
sudo pacman -S libx11 libxtst
```

### Qt Version Issues

If both Qt5 and Qt6 are installed and you want to use a specific version:

```bash
# Force Qt6
cmake -DQT_VERSION_MAJOR=6 ..

# Force Qt5
cmake -DQT_VERSION_MAJOR=5 ..
```

### Build Warnings

To enable additional compiler warnings:

```bash
cmake -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic" ..
make
```

## Development Workflow

### Making Changes

1. Make code changes
2. Rebuild: `make -j$(nproc)`
3. Run tests: `ctest`
4. Install locally: `make install DESTDIR=/tmp/openwheel-test`

### Adding Tests

1. Add test to `tests/CMakeLists.txt`
2. Reconfigure: `cmake ..`
3. Build and test: `make && ctest`

## Build System Maintenance

### Updating Version

Edit `CMakeLists.txt` and update the version:

```cmake
project(openwheel VERSION 0.2.0 LANGUAGES C CXX)
```

### Adding Build Options

Add to root `CMakeLists.txt`:

```cmake
option(NEW_FEATURE "Enable new feature" OFF)
```

### Adding Dependencies

Add to component's `CMakeLists.txt`:

```cmake
find_package(NewLib REQUIRED)
target_link_libraries(target_name PRIVATE NewLib::NewLib)
```

## Performance Considerations

- Use parallel builds: `make -j$(nproc)`
- Use Ninja for faster builds: `cmake -G Ninja ..`
- Enable ccache: `cmake -DCMAKE_CXX_COMPILER_LAUNCHER=ccache ..`
- Use LTO for smaller binaries: `cmake -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON ..`

## Continuous Integration

For CI/CD pipelines:

```bash
# Configure with all checks
cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON ..

# Build with verbose output
make VERBOSE=1

# Run tests with output
ctest --output-on-failure

# Install to staging directory
make install DESTDIR=staging
```

---

For more information, see the main [README.md](README.md) or visit the [project repository](https://github.com/fredaime/openwheel).
52 changes: 49 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
cmake_minimum_required(VERSION 3.0)
project(openwheel C)
cmake_minimum_required(VERSION 3.16)
project(openwheel VERSION 0.1.0 LANGUAGES C CXX)

include_directories(${CMAKE_SOURCE_DIR}/openwheel-daemon ${CMAKE_SOURCE_DIR}/openwheel-gadget)
# Set default build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()

# Project-wide options
option(BUILD_DAEMON "Build openwheel-daemon" ON)
option(BUILD_GADGET "Build openwheel-gadget" ON)
option(BUILD_TESTS "Build tests" ON)
option(ENABLE_INSTALL "Enable installation targets" ON)

# Set output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# Include standard CMake modules
include(GNUInstallDirs)
include(CTest)

# Add subdirectories
if(BUILD_DAEMON)
message(STATUS "Building openwheel-daemon")
add_subdirectory(openwheel-daemon)
endif()

if(BUILD_GADGET)
message(STATUS "Building openwheel-gadget")
add_subdirectory(openwheel-gadget)
endif()

# Enable testing
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
message(STATUS "Testing enabled")
endif()

# Installation summary
message(STATUS "")
message(STATUS "Build Configuration Summary:")
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS " Build daemon: ${BUILD_DAEMON}")
message(STATUS " Build gadget: ${BUILD_GADGET}")
message(STATUS " Build tests: ${BUILD_TESTS}")
message(STATUS " Install prefix: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "")
Loading