Example project demonstrating CMake's find_package config mode for building and consuming libraries with different build types.
Package Example is a demonstration project that shows how to properly use CMake's `find_package` command in config mode. It provides working examples of creating installable libraries with Debug and Release variants, generating CMake package configuration files, and consuming those libraries in downstream projects. The project solves the problem of understanding how to structure CMake projects for proper package distribution and consumption.
CMake users and C++ developers who need to create reusable libraries or consume third-party libraries with proper build variant support. This is particularly useful for developers working on multi-configuration build systems or distributing libraries to other teams.
Developers choose this project because it provides clear, working examples of complex CMake package management concepts that are often poorly documented. It demonstrates best practices for handling build variants, version compatibility, and package discovery in real-world scenarios.
CMake: config mode of find_package command (examples)
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Demonstrates precise installation of Debug and Release libraries with proper naming conventions (e.g., libbar.a vs libbard.a) and configuration files, as shown in the step-by-step commands.
Shows how find_package automatically sets include directories, defines (like FOO_BAR_DEBUG), and links the correct library based on build type, reducing manual CMake scripting.
Includes examples of version validation via FooConfigVersion.cmake, which rejects incompatible requests (e.g., version 2.0 when 1.2.3 is installed), ensuring package integrity.
Illustrates multiple ways to locate packages using CMAKE_INSTALL_PREFIX, CMAKE_PREFIX_PATH, or Foo_DIR, providing adaptability for different development environments.
As a demonstration project, it focuses on basic scenarios and omits advanced topics like cross-compilation, shared libraries beyond monolithic builds, or integration with CI/CD pipelines beyond simple scripts.
The README lacks explanations for CMake novices, assuming familiarity with command-line flags (e.g., -H, -B) and concepts, which can be a barrier for learners.
It doesn't provide a packaged solution or ecosystem support; users must adapt the examples manually, which can be time-consuming for complex projects compared to using dedicated package managers.