This document describes how to build, install, and distribute cmcpp packages.
cmcpp uses CMake's built-in packaging capabilities:
- CMake Config Files: For integration with other CMake projects
- CPack: For creating distribution packages (tar.gz, DEB, RPM, ZIP, NSIS)
Install cmcpp to a local prefix (default: build/stage/Debug for Debug preset):
cmake --preset linux-ninja-Debug
cmake --build --preset linux-ninja-Debug
cmake --install build --prefix build/stage/DebugOr use the default install directory configured by the preset:
cmake --preset linux-ninja-Debug
cmake --build --preset linux-ninja-Debug
cmake --build build --target installThe installation includes:
- Headers: All C++20 header files in
include/ - CMake Config: Package config files for
find_package(cmcpp) - Tools:
wit-codegenexecutable (ifBUILD_GRAMMAR=ON)
cmake --preset linux-ninja-Debug -DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build --preset linux-ninja-Debug
cmake --build build --target installOn Windows with Visual Studio preset:
cmake --preset vcpkg-VS-17 -DCMAKE_INSTALL_PREFIX=C:/Program\ Files/cmcpp
cmake --build --preset VS-17-Debug
cmake --build build --config Debug --target installOnce installed, other CMake projects can find and use cmcpp:
cmake_minimum_required(VERSION 3.10)
project(MyProject)
# Find cmcpp
find_package(cmcpp REQUIRED)
# Create your executable
add_executable(my_app main.cpp)
# Link against cmcpp
target_link_libraries(my_app PRIVATE cmcpp::cmcpp)
# Optional: Use wit-codegen tool if available
if(DEFINED CMCPP_WIT_CODEGEN_EXECUTABLE)
message(STATUS "wit-codegen found: ${CMCPP_WIT_CODEGEN_EXECUTABLE}")
endif()Build your project with:
cmake . -DCMAKE_PREFIX_PATH=/path/to/cmcpp/install
cmake --build .cmcpp supports multiple package formats via CPack:
- Linux: TGZ, DEB, RPM
- Windows: ZIP, NSIS
- macOS: TGZ, ZIP
cd build
cpackThis generates packages for all default generators on your platform:
- Windows: ZIP and NSIS installer
- Linux: TGZ, DEB, and RPM
- macOS: TGZ and ZIP
cd build
cpack -G TGZOutput: cmcpp-<version>-<platform>.tar.gz
cd build
cpack -G DEBOutput: cmcpp_<version>_<arch>.deb
Install on Ubuntu/Debian:
sudo dpkg -i cmcpp_0.1.0_amd64.debcd build
cpack -G RPMOutput: cmcpp-<version>-<release>.<arch>.rpm
Install on Red Hat/Fedora:
sudo rpm -i cmcpp-0.1.0-1.x86_64.rpmcd build
cpack -G ZIPcd build
cpack -G NSISRequires NSIS to be installed on Windows.
All packages include:
-
Headers: Complete C++20 header-only library
- Location:
include/cmcpp/ - Main header:
include/cmcpp.hpp - Runtime integration:
include/wamr.hpp - Boost.PFR headers:
include/boost/pfr/
- Location:
-
CMake Integration Files:
lib/cmake/cmcpp/cmcppConfig.cmake- Package configurationlib/cmake/cmcpp/cmcppConfigVersion.cmake- Version compatibilitylib/cmake/cmcpp/cmcppTargets.cmake- Target exports
-
Tools (if
BUILD_GRAMMAR=ON):bin/wit-codegen- WIT code generator (orwit-codegen.exeon Windows)- Runtime dependencies (automatically included):
- Windows:
antlr4-runtime.dll - Linux:
libantlr4-runtime.so* - macOS:
libantlr4-runtime*.dylib
- Windows:
Packages are configured with the following metadata:
- Name: cmcpp
- Version: From
PROJECT_VERSIONin CMakeLists.txt (e.g., 0.1.0) - Description: C++20 WebAssembly Component Model implementation
- License: Apache-2.0 (from LICENSE file)
- Homepage: https://github.com/GordonSmith/component-model-cpp
- Components:
headers- C++ header fileslibraries- CMake library targetstools- wit-codegen command-line tool
cmcpp uses semantic versioning with the following compatibility rules:
- Pre-1.0 versions (0.x.y): Minor version must match exactly
find_package(cmcpp 0.1)only accepts 0.1.x versions
- Post-1.0 versions (1.x.y+): Major version must match
find_package(cmcpp 1.0)accepts any 1.x.y version
This ensures API compatibility according to Component Model stability guarantees.
Note: The version compatibility is implemented in cmcppConfigVersion.cmake.in with custom logic that overrides CMake's default SameMajorVersion compatibility to enforce stricter rules for pre-1.0 versions.
Packages are automatically generated via CI/CD and attached to GitHub releases.
A vcpkg port is planned for easier installation:
vcpkg install cmcppTo distribute cmcpp manually:
-
Build a release package:
cmake --preset linux-ninja-Release cmake --build --preset linux-ninja-Release cd build && cpack -G TGZ
-
Distribute the generated
cmcpp-<version>-<platform>.tar.gz -
Users extract and set
CMAKE_PREFIX_PATH:tar xzf cmcpp-0.1.0-Linux.tar.gz export CMAKE_PREFIX_PATH=$PWD/cmcpp-0.1.0-Linux
Or install system-wide:
sudo tar xzf cmcpp-0.1.0-Linux.tar.gz -C /usr/local # CMAKE_PREFIX_PATH=/usr/local is typically searched by default
CPack supports installing specific components:
# Install only headers (no tools)
cpack -G TGZ -D CPACK_COMPONENTS_ALL="headers;libraries"
# Install only tools
cpack -G TGZ -D CPACK_COMPONENTS_ALL="tools"Current Limitation: The headers and library target installations in CMakeLists.txt do not explicitly specify COMPONENT tags (lines 67-76), so they are included in all packages by default. Only the wit-codegen tool has an explicit COMPONENT tools tag. To properly separate components, the install commands would need to be updated to include:
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT headers
)
install(TARGETS cmcpp
EXPORT cmcppTargets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT libraries
)Ensure CMAKE_PREFIX_PATH includes the installation directory:
cmake . -DCMAKE_PREFIX_PATH=/path/to/cmcpp/installOr set the cmcpp_DIR variable directly:
cmake . -Dcmcpp_DIR=/path/to/cmcpp/install/lib/cmake/cmcppMake sure BUILD_GRAMMAR=ON when configuring:
cmake --preset linux-ninja-Debug -DBUILD_GRAMMAR=ONCheck CPack generators are available:
cpack --help | grep "Generators:"Install required tools:
- DEB:
dpkg-deb(usually pre-installed on Debian/Ubuntu) - RPM:
rpmbuild(sudo apt-get install rpmon Ubuntu) - NSIS: Download from https://nsis.sourceforge.io/ (Windows only)
- CMake Config File:
cmcppConfig.cmake.in - Version File:
cmcppConfigVersion.cmake.in - CPack Configuration: Bottom of root
CMakeLists.txt - Installation Rules: Root
CMakeLists.txt(lines 60+)