Skip to content

Prevent dependency mappings from leaking between projects #44

Closed

Description

@sean-parent

Problem

cpp_library_map_dependency() stores each mapping in a global property keyed only by the dependency target. During package-config generation, the mapping takes precedence over the dependency version tracked for the library being exported. A nested project's mapping can therefore silently change a parent library's generated find_dependency() requirement.

With cpp-library 6.0.2, cel-std 1.0.3 maps cel::parser to cel-parser 1.0.2 CONFIG. A parent that directly requires parser 1.1.0 can consequently export a 1.0.2 minimum after adding cel-std, unless the parent repeats its own mapping. For cel-euclid, parser 1.0.2 lacks the record-registration APIs it uses.

The global storage and lookup are in cpp-library-install.cmake and the dependency generator.

Reproduction

The following configure-only reproduction simulates a tracked CPM parser 1.1.0; it uses the internal generator to inspect what a package config would contain without installing anything. Pass -DCPP_LIBRARY_ROOT=/path/to/cpp-library when configuring.

# CMakeLists.txt
cmake_minimum_required(VERSION 3.24)
project(repro LANGUAGES CXX)
include("${CPP_LIBRARY_ROOT}/cmake/cpp-library-install.cmake")
add_library(parser INTERFACE)
add_library(cel::parser ALIAS parser)
add_library(euclid INTERFACE)
target_link_libraries(euclid INTERFACE cel::parser)
set(CPM_PACKAGES cel-parser)
set(CPM_PACKAGE_cel-parser_VERSION 1.1.0)
_cpp_library_generate_dependencies(before euclid cel)
message(STATUS "before: ${before}")
add_subdirectory(child)
_cpp_library_generate_dependencies(after euclid cel)
message(STATUS "after: ${after}")
# child/CMakeLists.txt
cpp_library_map_dependency("cel::parser" "cel-parser 1.0.2 CONFIG")

Observed output:

before: find_dependency(cel-parser 1.1.0)
after: find_dependency(cel-parser 1.0.2 CONFIG)

Expected behavior

A library's exported dependency requirements should not be overwritten by an unrelated nested project's mapping. Provide an appropriately scoped mapping mechanism and cover nested projects in cpp-library's existing dependency-mapping tests.

stlab/cel-std#2 removes the particular 1.0.2 mapping as part of a dependency update; the global collision remains possible for other projects that need explicit mappings. Discovered while updating stlab/cel-euclid#1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions