This example demonstrates how to use xcplite as an external library when you don't want to build it from source as part of your project. This is the typical workflow for:
- Production deployments where xcplite is pre-installed
- System-wide installations on Linux (e.g.,
/usr/local) - Package-based distributions (e.g.,
.deb,.rpm) - Development without modifying xcplite source code
Independent CMakeLists.txt - Self-contained project configuration
CMake find_package() - Standard way to locate installed libraries
No system installation required - Uses local staging directory for development
Cross-platform - Works on Linux, macOS, and Windows
external_example/
├── CMakeLists.txt # Independent build configuration
├── build.sh # Automated build script
├── src/
│ └── main.c # Simple XCP example application for C
│ └── main.cpp # Simple XCP example application for C++
├── CANape/ # CANape project files (optional)
└── README.md # This file
The easiest way to build and run this example:
cd examples/external_example
./build.shThis script will:
- Build xcplite in the main repository and install it to a local staging directory (
../../build/install) - Configure and build this external example against the installed library
If you prefer to understand each step:
From the repository root:
# Configure xcplite (installs to build/install by default)
./build.sh release lib installThis installs xcplite to build/install/ with the following structure:
build/install/
├── lib/
│ ├── libxcplite.a # Static library
│ └── cmake/xcplite/ # CMake package files
│ ├── xcpliteConfig.cmake
│ ├── xcpliteConfigVersion.cmake
│ └── xcpliteTargets.cmake
└── include/xcplite/ # Public headers
├── xcplite.h
├── xcplite.hpp
├── a2l.h
└── a2l.hpp
From this directory:
# Configure, pointing to the installed xcplite
cmake -B build -S . -DCMAKE_PREFIX_PATH=../../build/install
# Build
cmake --build build./build/external_exampleConnect with CANape:
- Protocol: XCP on Ethernet
- Address: localhost
- Port: 5555
- Transport: TCP
The key parts of this independent CMakeLists.txt:
# Find the installed xcplite package
find_package(xcplite REQUIRED)
# Create executable
add_executable(external_example src/main.c)
# Link against xcplite - this automatically provides:
# - Include directories
# - Library dependencies (Threads, math, atomic)
# - Compile definitions
target_link_libraries(external_example PRIVATE xcplite::xcplite)CMake can find xcplite in three ways (in order of precedence):
-
Via xcplite_DIR pointing to the cmake config directory:
cmake -Dxcplite_DIR=../../build/install/lib/cmake/xcplite -B build
-
Via CMAKE_PREFIX_PATH pointing to the install root (recommended):
cmake -DCMAKE_PREFIX_PATH=../../build/install -B build
-
System-wide installation (if installed to
/usr/localor similar):cmake -B build
For production use on Linux, install xcplite system-wide:
# Build and install to /usr/local (requires sudo)
cd /path/to/xcplite-source
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build build
sudo cmake --install buildThen your external project can find it automatically:
cd /path/to/your-project
cmake -B build -S .
cmake --build buildIf xcplite is installed via a package manager (e.g., apt install libxcplite-dev), it's typically in standard system locations and CMake will find it automatically:
cmake -B build -S .
cmake --build build- Building XCPlite - Detailed build instructions
- XCPlite API Reference - API documentation
- hello_xcp - Basic XCP example with source build
- XCPlite README - Project overview