|
PackageBuilder
Tools to assist with CMake/C++ package development
|
Tired of writing hundreds of lines of CMake boilerplate just to create a properly installable library? Build sleek, professional C++ libraries and executables with a few simple function calls. Installation and package config generation—all handled automatically.
If your project uses cmake-conan (the tnt-coders fork), this is the recommended way to consume PackageBuilder. Dependencies are resolved automatically with no manual installation.
Add the following to your conanfile.py:
Or in conanfile.txt:
The #recipe: tag tells cmake-conan where to find the source for the package. If the package is not already present in your local Conan cache or any configured remote, cmake-conan will automatically clone the tagged version from the provided git URL and run conan create to build it locally. No manual recipe hosting or remote setup needed.
Then in your CMakeLists.txt:
For full details on how cmake-conan and the recipe tag work, see the tnt-coders fork of the cmake-conan repository.
The simplest way to get started. No installation or package manager required.
This allows you to immediately hit the ground running with professional quality install/package creation logic for your own project.
Build and install PackageBuilder to your system, then find it like any other CMake package.
Install:
Consume:
Required. Must be called before any other PackageBuilder functions.
This function performs essential validation before any targets are defined:
PROJECT_VERSION is set and fails with a fatal error if it is not. PROJECT_VERSION is typically set by specifying the version in the project() command.PROJECT_DESCRIPTION is set and fails with a fatal error if it is not. Set via the DESCRIPTION argument in the project() command.LICENSE file exists at the project root. This is required for CPack packaging.Libraries created with package_add_library are automatically given a namespaced alias of <PROJECT_NAME>::<target>. This is the same alias that downstream consumers will use after find_package().
This single call handles everything:
package_add_library and package_add_executableinclude/cmake/<ProjectName>Config.cmake and <ProjectName>ConfigVersion.cmakeDownstream projects can then consume your package:
package_install() configures CPack to generate platform-native installers:
| Platform | Generators |
|---|---|
| Windows | ZIP, NSIS |
| macOS | ZIP, DragNDrop |
| Linux | ZIP, DEB |
By default, generated installers include only Runtime components (executables and shared libraries). Development files such as static libraries, headers, and CMake package config are excluded from installers because Conan is the preferred method for consuming packages as libraries during development.
If your project needs installers that also ship development files, set PACKAGE_BUILDER_CPACK_COMPONENTS before calling package_install():
PackageBuilder is designed to work with the following project layout:
include/ are exposed publicly to consumers of your library.src/ are private to your project and are not installed..cmake files in cmake/ are installed alongside the generated package config, making them available to consumers via CMAKE_MODULE_PATH.