-
Notifications
You must be signed in to change notification settings - Fork 0
Using a dependency provider to generate install dependencies #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Added cleaned up installation support, along with an overhauled readme.
This CI test added complexity without adding value. Testing find_package() is sufficient to ensure the package installs correctly.
To simplify the ci logic, I'm changing the ci.yml file to a template.
Adds conditional execution for environment setup and CMake configuration steps based on the presence of matrix.cc.
…brary into sean-parent/install
The _cpp_library_setup_install function now requires a PACKAGE_NAME argument, ensuring correct package naming in generated CMake config files and install locations. Version detection in _cpp_library_get_git_version now prefers PROJECT_VERSION if set, improving compatibility with package managers and source archives.
Added logic to introspect INTERFACE_LINK_LIBRARIES and generate appropriate find_dependency() calls in installed CMake package config files. Updated documentation to explain dependency handling, added a helper function in cpp-library-install.cmake, and modified the config template to include generated dependencies. This ensures downstream users automatically find and link required dependencies.
Replaces usage of a 'clean' name with PACKAGE_NAME for library target aliases and CI workflow templates. Ensures consistent naming between CMake targets and package discovery, improving clarity and reducing potential mismatches.
Introduces the cpp_library_map_dependency() function to allow custom find_dependency() calls for specific targets, such as Qt components requiring COMPONENTS syntax. Updates documentation and dependency generation logic to prioritize custom mappings, improving flexibility for complex dependencies in installed CMake package config files.
Updated internal CMake functions to require PACKAGE_NAME as a parameter instead of relying on PROJECT_NAME. This clarifies the preconditions for template and CI workflow generation, ensuring correct substitution and improving maintainability.
The install-test job was removed from the GitHub Actions workflow because it duplicated functionality already provided by the main test job. This simplifies the workflow and reduces unnecessary runs across multiple operating systems. Also fixed a quoting issue with the install prefix on Windows.
Updated dependency mapping logic to distinguish between internal cpp-library and external dependencies, ensuring package names are collision-safe and consistent. Added support for overriding the version using the CPP_LIBRARY_VERSION variable, which is useful for package managers and CI systems without git history. Improved documentation in README.md to clarify dependency handling, target naming patterns, and version management. Refactored CMake scripts to align with these changes and updated comments for clarity.
Adds conditional steps in the CI workflow to set CC and CXX environment variables only when matrix.cc is defined. Ensures builds use the correct compiler configuration based on the matrix setup.
Clarifies that GitHub repository names must match package names, including namespace prefixes, for CPM compatibility. Updates usage examples, instructions, and project links to reflect this requirement and prevent issues with CPM's local package finding and source fetching. Repository naming requirements may be backed out if [this CPM PR](cpm-cmake/CPM.cmake#682) lands.
Introduces setup.cmake, an interactive script for initializing new C++ library projects using the cpp-library template. The README is updated with detailed quick start instructions for using the script in both interactive and non-interactive modes, as well as guidance for manual setup.
Updated README and setup.cmake to clarify template file generation steps and improve user prompts for input. Project directory is now created in the current working directory, and setup messages better reflect the workflow for generating and regenerating template files.
Introduces a GitHub Actions CI workflow for unit, integration, and documentation tests. Expands the README with detailed documentation on dependency mapping, version detection, and custom mappings. Refactors and enhances `cpp-library-install.cmake` to support automatic version detection, component merging, and improved error messages for dependency handling. Adds a full unit test suite in `tests/install` with 18 cases covering system packages, external dependencies, component merging, custom mappings, and edge cases. Minor cleanup in `.vscode/extensions.json` and removal of unused symlink logic in `cpp-library.cmake`.
Expanded the README with a troubleshooting section and clarified documentation deployment instructions. Updated comments and logic in cpp-library-install.cmake to centralize system package handling for dependency mapping. Generalized cpp-library.cmake to support both header-only and compiled C++ libraries.
The CI workflow now runs unit tests only on ubuntu-latest instead of a matrix of OSes. Test project and header names were updated from 'test' to 'mylib' for consistency, and related CMake and file references were adjusted accordingly.
This commit introduces a CMake dependency provider (3.24+) to capture exact
find_package() and CPMAddPackage() calls, enabling accurate find_dependency()
generation in installed package config files.
Key Features:
- New cpp_library_enable_dependency_tracking() function to enable provider
- Tracks all dependency requests with exact syntax (version, COMPONENTS, etc.)
- Automatic component merging for multi-component packages (Qt, Boost, etc.)
- Fallback to introspection method for CMake < 3.24
- Custom mapping support via cpp_library_map_dependency() for overrides
Implementation:
- Added cmake/cpp-library-dependency-provider.cmake with provider logic
- Enhanced cpp-library.cmake with tracking enablement function
- Refactored _cpp_library_generate_dependencies() to use tracked data
- Provider-based resolution with introspection fallback
- Handles conditional dependencies correctly
Testing:
- All 18 existing tests pass (introspection method)
- Added 8 new tests for provider tracking (26 total, all passing)
- Added integration example documentation
Benefits:
- Perfect accuracy - captures exact find_package() syntax
- No manual version tracking needed in most cases
- Works seamlessly with CPM_USE_LOCAL_PACKAGES
- Handles complex multi-component dependencies correctly
- Backward compatible with CMake 3.20+
Usage:
cmake_minimum_required(VERSION 3.24)
include(cmake/CPM.cmake)
CPMAddPackage("gh:stlab/cpp-library@5.0.0")
include(${cpp-library_SOURCE_DIR}/cpp-library.cmake)
cpp_library_enable_dependency_tracking()
project(my-library)
# Dependencies are now tracked automatically
… of COMPONENTS in CMake dependency management. This file is no longer needed as the regex logic has been improved and integrated into the main functionality.
…m/stlab/cpp-library into sean-parent/install-with-provider
- Updated regex handling in cpp_library_setup to correctly escape namespace prefixes when calculating clean names. - Refined version extraction logic in dependency provider to enforce semantic versioning format. - Improved error messages in dependency resolution to clarify common issues and provide guidance on correct usage. - Expanded unit test documentation to reflect the interaction between dependency tracking and custom mappings. These changes enhance the clarity and robustness of the CMake configuration for the cpp-library.
…traction - Simplified the clean name calculation in cpp_library_setup by removing unnecessary regex escaping. - Updated the version extraction logic in _cpp_library_add_dependency to ensure proper semantic versioning format. These changes enhance the clarity and efficiency of the CMake configuration for the cpp-library.
- Updated the _cpp_library_dependency_provider function to clarify the fallback behavior of CMake when dependencies are not satisfied. - Improved regex escaping in _cpp_library_add_dependency to ensure safe handling of special characters in component names. - Changed the delimiter for package keys from '|' to '<|>' to avoid potential conflicts and enhance parsing reliability. These changes improve the robustness and clarity of the CMake configuration for the cpp-library.
… OPTIONAL_COMPONENTS - Updated the _cpp_library_track_find_package function to ensure the CONFIG flag is preserved when merging calls without COMPONENTS. - Enhanced handling of OPTIONAL_COMPONENTS to avoid duplication and ensure they are correctly merged from both old and new calls. - Added tests to verify the preservation of the CONFIG flag and the correct merging of dependencies. These changes improve the reliability and correctness of the CMake dependency management for the cpp-library.
Moved inclusion of cpp-library-install.cmake and related modules to after project() is called to avoid requiring language/architecture information too early. Updated documentation and comments to clarify this behavior. Improved CPM cache setup logic in README and setup.cmake. Removed the 'install' preset from CMakePresets.json.
The 'install' CMake preset entry has been removed from the list in the README.
Replaces direct inclusion of CTest with a deferred call to enable_testing() at the directory scope using cmake_language(DEFER). This ensures enable_testing() is executed after the function returns, allowing add_test() to work correctly when cpp_library_setup is used. Also updates comments for clarity.
Updated _cpp_library_track_find_package to strip CONFIG, NO_MODULE, and REQUIRED keywords from component lists, preventing them from being treated as components. Added a test to verify CONFIG is not merged as a component.
Moved CPM_SOURCE_CACHE configuration from CMakeLists.txt to CMakePresets.json for all presets, ensuring consistent and automatic cache setup. Updated README to document this behavior and removed redundant cache setup code from setup.cmake and README.
Replaced hardcoded version numbers with a placeholder (X.Y.Z) in documentation, templates, and CMake scripts to encourage users to check for the latest release. Added logic in setup.cmake to auto-detect the current version from git tags, falling back to a placeholder if unavailable. Centralized example usage generation for consistent error messages and updated CI workflows to use actions/checkout@v6.
Improves the cpp-library dependency provider to correctly filter out dependencies from find_package() calls with the QUIET flag if the package was not found, preventing phantom dependencies in generated Config files. Adds a verification function for QUIET dependencies, updates tests to cover these cases, and documents the behavior and best practices in the integration example.
Revises the usage instructions in cpp-library-dependency-provider.cmake to recommend calling cpp_library_enable_dependency_tracking() before project(), instead of modifying CMAKE_PROJECT_TOP_LEVEL_INCLUDES.
Replaces cmake_language(DEFER DIRECTORY ...) with cmake_language(EVAL CODE ...) to execute enable_testing() immediately at the parent directory scope. This ensures enable_testing() is called before any add_test() calls, improving compatibility with CTest and test setup.
Update documentation and code to clarify the required order for enabling dependency tracking, declaring the project, and setting up the library. Require explicit include(CTest) for tests/examples, update error messages and install logic to reflect new best practices, and defer Config.cmake generation to ensure all dependencies are captured. Update examples and tests to match the improved workflow.
Added a workaround in cpp-library.cmake to automatically append --extra-arg=/EHsc to CMAKE_CXX_CLANG_TIDY when using MSVC, addressing a known clang-tidy issue with exception handling flags. Updated README with documentation about this issue and the applied solution. Also simplified test executable handling logic in _cpp_library_setup_executables.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Trying a different approach to install dependencies using a dependency provider.
Note
Adds a CMake dependency provider to auto-track dependencies and generate accurate find_dependency() in installed Config.cmake, with comprehensive tests, CI, docs, and a project setup script.
cpp_library_enable_dependency_tracking()and dependency provider (cmake/cpp-library-dependency-provider.cmake) to trackfind_package/FetchContent(incl. QUIET handling and component merging).cmake/cpp-library-install.cmake) to generateConfig.cmakewith mergedfind_dependency(...)and deferred generation; support system packages and custom mappings viacpp_library_map_dependency.cmake/cpp-library-ci.cmake).templates/Config.cmake.in: inject@PACKAGE_DEPENDENCIES@and correct targets file.templates/CMakePresets.json: addCPM_SOURCE_CACHEto presets.templates/.github/workflows/ci.yml.in(modernized matrix and install verification)..github/workflows/ci.yml) running unit tests, provider merge tests, integration install/find_package verification, and docs checks.tests/install/*for dependency mapping, provider behavior, component merging, QUIET filtering, and docs.setup.cmakeinteractive scaffolding script for creating projects using cpp-library.Written by Cursor Bugbot for commit 5d0565f. This will update automatically on new commits. Configure here.