PackageProject.cmake
🏛️ Help other developers use your project. A CMake script for packaging C/C++ projects for simple project installation while employing best-practices for maximum compatibility.
Install / Use
/learn @TheLartians/PackageProject.cmakeREADME
PackageProject.cmake
Creating installable CMake scripts always requires a large amount of boilerplate code to get things working. This small script should simplify the CMake packaging process into a single, easy-to-use command.
PackageProject.cmake has been tested with CMake v3.18.4.
Usage
To create an installable target for your current project, add the following to your CMakeLists.txt. This example assumes the project to be versioned and the name to be identical to the library to export. Also the CPM.cmake script should be included. See here for an example usage.
CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.6.0")
packageProject(
# the name of the target to export
NAME ${PROJECT_NAME}
# the version of the target to export
VERSION ${PROJECT_VERSION}
# a temporary directory to create the config files
BINARY_DIR ${PROJECT_BINARY_DIR}
# location of the target's public headers
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
# should match the target's INSTALL_INTERFACE include directory
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
# (optional) option to install only header files with matching pattern
INCLUDE_HEADER_PATTERN "*.h"
# semicolon separated list of the project's dependencies
DEPENDENCIES "fmt 7.1.3;cxxopts 2.2.0"
# (optional) create a header containing the version info
# Note: that the path to headers should be lowercase
VERSION_HEADER "${PROJECT_NAME}/version.h"
# (optional) create a export header using GenerateExportHeader module
EXPORT_HEADER "${PROJECT_NAME}/export.h"
# (optional) install your library with a namespace (Note: do NOT add extra '::')
NAMESPACE ${PROJECT_NAMESPACE}
# (optional) define the project's version compatibility, defaults to `AnyNewerVersion`
# supported values: `AnyNewerVersion|SameMajorVersion|SameMinorVersion|ExactVersion`
COMPATIBILITY AnyNewerVersion
# (optional) option to disable the versioning of install destinations
DISABLE_VERSION_SUFFIX YES
# (optional) option to ignore target architecture for package resolution
# defaults to YES for header only (i.e. INTERFACE) libraries
ARCH_INDEPENDENT YES
# (optional) option to generate CPack variables
CPACK YES
# (optional) relative install directory for runtimes: bins, libs, archives
# by default libs will be installed to <...>/lib/<packagename-version>/
# / - means relative to <...>/lib, i.e. install libs to <...>/lib/, bins to <...>/bin/, etc
RUNTIME_DESTINATION /
)
CPack
We provide only the most basic variables for CPack generation, however this might not be enough for each and every generator.
For example, Debians' DEB generator needs additionally CPACK_DEBIAN_PACKAGE_MAINTAINER or a CPACK_PACKAGE_CONTACT:
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Foo Bar <foo@bar.local>")
If you need extra functionality feel free to open an issue or a PR.
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
