cps-org / cps-org/cps

Support for name mapping

Open
#111 15 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
191
Forks
14
PR merge metrics
No merged PRs in 30d

Description

Hi,

first of all kudos to your efforts around CPS. This really helps a lot to connect tools without duplicating information. However, I came across one critical feature gap: name mapping.

Example:
CMakeLists.txt

```
cmake_minimum_required(VERSION 3.31)

# needed for CPS support
set(CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_INFO "b80be207-778e-46ba-8080-b23bba22639e")

project(FwdBoost LANGUAGES CXX)

# find Boost
find_package(Boost REQUIRED)

# empty interface library
add_library(FwdHeaders INTERFACE)

# forward Boost::headers as part of this library
target_link_libraries(FwdHeaders
INTERFACE
Boost::headers
)

# install the library target
install(
TARGETS FwdHeaders
EXPORT fwd_boost
)

# export CPS file
install(
PACKAGE_INFO fwd_boost
EXPORT fwd_boost
DESTINATION cps
)
```

conanfile.py
```
from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout, CMakeDeps
from conan.cps import CPS

class FwdBoost(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeToolchain", "CMakeDeps"
package_type = "shared-library"
name = "fwd_boost"
version = "0.0.1"
exports_sources = "*"

def layout(self):
cmake_layout(self)

# can also be any other version of boost
def requirements(self):
self.requires("boost/1.84.0", transitive_headers=True)

def build(self):
cmake = CMake(self)
cmake.configure(cli_args=["-Wno-dev"])
cmake.build()

def package(self):
cmake = CMake(self)
cmake.install()

def package_info(self):
cps = CPS.load("cps/" + self.name + ".cps")

# Temporary work-around:
# copy first component into second __dummy__ component
# as conan has problems with CPS files with just one CMake component
# should be fixed in https://github.com/conan-io/conan/pull/19584
if len(cps.components) == 1:
comp_0 = list(cps.components.values())[0]
cps.components["__dummy__"] = comp_0

self.cpp_info = cps.to_conan()

```

When calling `conan create . ` execution fails with `There are '(cpp_info/components).requires' that includes package 'Boost::', but such package is not a a direct requirement of the recipe`.

Reason for this problem is a library name mismatch: in conan the providing package is called `boost` while the CMake find scripts use `Boost`.

From a tooling perspective both tools are right:
- conan relies on lowercase package names
- In CMake deviations between package name and library name are accepted/needed for common use cases (e.g. alternative implementations of the same library by different providers, drop-in replacement of an old existing library by a new implementation).

With that a CPS extension supporting name mapping would be desirable to avoid hacks like post-install text replacements of `Boost` with `boost` in CMake.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.