Skip to content
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

[package] cnats/*: CMake target name differs based on config and shared option #26056

Open
har-bw opened this issue Nov 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@har-bw
Copy link

har-bw commented Nov 28, 2024

Description

The cnats package behaves a bit different than the most Conan packages when using the CMake generators, because it changes the name of the CMake target depending on the build_type setting and shared option. While one can work around this in a single configuration environment, this totally breaks the generated CMake find modules in a multi configuration environment.

Locally I fixed this by simply removing the line self.cpp_info.set_property("cmake_target_name", f"cnats::{self._nats_library_name}") from the recipe. However, this would break the package for other consumers. Therefore my question is, whether it would be possible to introduce an option to toggle this behaviour? Maybe it could be solved using components as well, but I am not sure about that.

Package and Environment Details

  • Package Name/Version: cnats/*
  • Operating System+version: Windows 11
  • Compiler+version: MSVC 1940
  • Conan version: conan 2.9.3
  • Python version: Python 3.12.4

Conan profile

Profile vs17_debug:
[settings]
arch=x86_64
build_type=Debug
compiler=msvc
compiler.cppstd=20
compiler.runtime=dynamic
compiler.runtime_type=Debug
compiler.version=194
os=Windows

Profile vs17_release:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=20
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows

Steps to reproduce

conan install -r conancenter --generator CMakeDeps --requires cnats/3.9.1@ -pr=vs17_release
conan install -r conancenter --generator CMakeDeps --requires cnats/3.9.1@ -pr=vs17_debug

Now the last executed command decides which cnats:: target wins in cnatsTargets.cmake, in this case, it is cnats::nats_staticd. However, find_package(cnats) now fails, because cnats-Target-release.cmake expects the common target to be called cnats::nats_static.

Logs

Click to expand log
conan install -r conancenter --requires cnats/3.9.1@ --generator CMakeDeps -pr=vs17_release

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=20
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=20
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows


======== Computing dependency graph ========
Graph root
    cli
Requirements
    cnats/3.9.1#fc22ec0bf017a28878da6415953ddd35 - Cache
    openssl/3.3.2#9f9f130d58e7c13e76bb8a559f0a6a8b - Cache
    zlib/1.3.1#f52e03ae3d251dec704634230cd806a2 - Cache
Build requirements
    nasm/2.16.01#d0aebbd20ccbb6ad9c9c753ab708098c - Cache
    strawberryperl/5.32.1.1#707032463aa0620fa17ec0d887f5fe41 - Cache
Resolved version ranges
    openssl/[>=1.1 <4]: openssl/3.3.2
    zlib/[>=1.2.11 <2]: zlib/1.3.1

======== Computing necessary packages ========
zlib/1.3.1: Main binary package '0d6dd492a7d31822b2f2686ec67bbaef586416a3' missing
zlib/1.3.1: Checking 1 compatible configurations
zlib/1.3.1: Found compatible package '7bfde258ff4f62f75668d0896dbddedaa7480a0f': compiler.version=193
Requirements
    cnats/3.9.1#fc22ec0bf017a28878da6415953ddd35:84b020effb8eb0d2cb4603e3ecd301b0478db25f#3cfca7e184517d8b121e904010cf10c8 - Cache
    openssl/3.3.2#9f9f130d58e7c13e76bb8a559f0a6a8b:cd39cca4b275b2d92a30579fb1bb7f729cb6a6c5#c657cc0f25ec946d2d214815cf098600 - Cache
Build requirements
Skipped binaries
    zlib/1.3.1, nasm/2.16.01, strawberryperl/5.32.1.1

======== Installing packages ========
openssl/3.3.2: Already installed! (1 of 2)
cnats/3.9.1: Already installed! (2 of 2)
WARN: deprecated: Usage of deprecated Conan 1.X features that will be removed in Conan 2.X:
WARN: deprecated:     'cpp_info.names' used in: openssl/3.3.2
WARN: deprecated:     'cpp_info.build_modules' used in: openssl/3.3.2
WARN: deprecated:     'env_info' used in: openssl/3.3.2

======== Finalizing install (deploy, generators) ========
cli: Writing generators to F:\source\test-nats
cli: Generator 'CMakeDeps' calling 'generate()'
cli: CMakeDeps necessary find_package() and targets for your CMakeLists.txt
    find_package(cnats)
    target_link_libraries(... cnats::nats_static)
cli: Generating aggregated env files
cli: Generated aggregated env files: ['conanbuild.bat', 'conanrun.bat']
Install finished successfully

conan install -r conancenter --requires cnats/3.9.1@ --generator CMakeDeps -pr=vs17_debug

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Debug
compiler=msvc
compiler.cppstd=20
compiler.runtime=dynamic
compiler.runtime_type=Debug
compiler.version=194
os=Windows

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=20
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows


======== Computing dependency graph ========
Graph root
    cli
Requirements
    cnats/3.9.1#fc22ec0bf017a28878da6415953ddd35 - Cache
    openssl/3.3.2#9f9f130d58e7c13e76bb8a559f0a6a8b - Cache
    zlib/1.3.1#f52e03ae3d251dec704634230cd806a2 - Cache
Build requirements
    nasm/2.16.01#d0aebbd20ccbb6ad9c9c753ab708098c - Cache
    strawberryperl/5.32.1.1#707032463aa0620fa17ec0d887f5fe41 - Cache
Resolved version ranges
    openssl/[>=1.1 <4]: openssl/3.3.2
    zlib/[>=1.2.11 <2]: zlib/1.3.1

======== Computing necessary packages ========
Requirements
    cnats/3.9.1#fc22ec0bf017a28878da6415953ddd35:344e7f956828c0e624644acf36d7c7be077c7ace#f24aaeb2660c859d6fdccd3ad9724952 - Cache
    openssl/3.3.2#9f9f130d58e7c13e76bb8a559f0a6a8b:53065fe27a47749d08f63fb61d7b88b1bbdc5cc4#c1500469d4ee96781299ed6d8e96e275 - Cache
Build requirements
Skipped binaries
    zlib/1.3.1, nasm/2.16.01, strawberryperl/5.32.1.1

======== Installing packages ========
openssl/3.3.2: Already installed! (1 of 2)
cnats/3.9.1: Already installed! (2 of 2)
WARN: deprecated: Usage of deprecated Conan 1.X features that will be removed in Conan 2.X:
WARN: deprecated:     'cpp_info.names' used in: openssl/3.3.2
WARN: deprecated:     'cpp_info.build_modules' used in: openssl/3.3.2
WARN: deprecated:     'env_info' used in: openssl/3.3.2

======== Finalizing install (deploy, generators) ========
cli: Writing generators to F:\source\test-nats
cli: Generator 'CMakeDeps' calling 'generate()'
cli: CMakeDeps necessary find_package() and targets for your CMakeLists.txt
    find_package(cnats)
    target_link_libraries(... cnats::nats_staticd)
cli: Generating aggregated env files
cli: Generated aggregated env files: ['conanbuild.bat', 'conanrun.bat']
Install finished successfully

CMake error:

CMake Error at test-nats/cnats-Target-release.cmake:66 (set_property):
[cmake]   set_property could not find TARGET cnats::nats_static.  Perhaps it has not
[cmake]   yet been created.

@har-bw har-bw added the bug Something isn't working label Nov 28, 2024
@jcar87
Copy link
Contributor

jcar87 commented Nov 28, 2024

Thanks @har-bw for reporting this!

because it changes the name of the CMake target depending on the build_type

I think this is a bug in the recipe

setting and shared option.

But this is likely intentional - we merely transcribe the target names used by upstream
https://github.com/nats-io/nats.c/blob/2c59da4e8835d6fecf75cbd1841fca372c1e1866/src/CMakeLists.txt#L38-L54
where the static library has a different target name

While I'm no particular fan of this pattern - the intention is such that somebody already using CMake doesn't have to make invasive changes to their build scripts to support Conan or to use Conan Center recipes.

I suspect the issue you are facing is because of the "debug" configuration
cnats::nats_staticd this is not what the target should be called - will try to reproduce and fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants