conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.25k stars 980 forks source link

[question] Please help how to use NuGet Libraries with Conan and CMake for Builds. #16536

Closed leviskim17 closed 2 months ago

leviskim17 commented 4 months ago

What is your question?

conanfile - libpng.txt conandata.yml-libpng.txt conanfile - zlib.txt conandata.yml-zlib.txt

conan version: 2.2.3

Situation After downloading the zlib library through NuGet in Conan, I encountered an issue where CMake could not find zlib when building the libpng package in Conan

Attempts Made

  1. Downloading zlib as NuGet is not working:
  1. Building zlib from source is working well.
  1. Manual Modified CMakeList in libpng.
# Set CMP0091 policy to NEW
if(POLICY CMP0091)
    cmake_policy(SET CMP0091 NEW)
endif()

# Include the Conan toolchain using the absolute path
include("C:/Users/kimjas/.conan2/p/b/zlib0f59ff8bfa3fe/b/conan_toolchain.cmake")
  1. conan_toolchain.cmake in libpng When I checked conan_toolchain.cmake in C:\Users\kimjas.conan2\p\b**libpnb1f2c624ba939**\b\build\generators, I can see CMake configurations for zlib lib, include, bin locations related. However, why is it that the zlib downloaded as NuGet cannot be recognized by CMake in the libpng package?

Are there any further steps required, beyond the attached conanfile, to ensure the usage of the zlib package downloaded from NuGet? Any advice would be greatly appreciated.

Have you read the CONTRIBUTING guide?

memsharded commented 4 months ago

Hi @leviskim17

Thanks for your question.

After downloading the zlib library through NuGet in Conan,

Sorry, it is not very clear what you are trying to achieve. Why would you download it from Nuget?

Some important notes:

I would suggest just building from source the combinations that you need, it is going to be much faster and simpler than trying to fetch them as pre-built from other place. If you still need to go this way, I'd suggest to just do the downloads in the build() method as explained in the docs: https://docs.conan.io/2/tutorial/creating_packages/other_types_of_packages/package_prebuilt_binaries.html#downloading-and-packaging-pre-built-binaries. Do everything in the build() method, do not use source() or layout() for any of this logic.

leviskim17 commented 4 months ago

@memsharded Thanks for your comment. I think it was the issue of CMake of libpng. Maybe.

It is the compony policy to use prebuilt libraries through nuget. So I have implemented to use nuget from the company Artifactory.

After chaning of package_info to

    self.cpp_info.set_property("cmake_find_mode", "both")  # Enable both module and config mode
    self.cpp_info.set_property("cmake_file_name", "ZLIB")  # Set CMake file name
    self.cpp_info.set_property("cmake_target_name", "ZLIB::ZLIB")  # Set CMake target name

From lowercase to uppercase, it is working.

Thanks for your helps.

memsharded commented 4 months ago

It is the compony policy to use prebuilt libraries through nuget. So I have implemented to use nuget from the company Artifactory.

Conan integrates the full lifecycle of creating the packages from source and managing the binaries with less effort than having to have a separate build process that uploads the binaries to nuget first. Specially, when those libraries start to have their own dependencies (zlib is easy, as it doesn't have dependencies) then the process gets more and more complicated if having to download dependencies (via Conan?) build the binary, upload the binary to nuget, then have another recipe that downloads the binary from nuget? That would be terribly complicated for something that Conan can manage very easily. While I understand that there might be company policies, I suggest to propose simplifying that process when it starts getting complicated, you will waste more time, effort and money to make it work. And Conan packages are stored in Artifactory as well, it is not that they are not traceable and manageable.

From lowercase to uppercase, it is working.

Ok, so I guess the main issue is solved then? May we close the ticket as resolved? Thanks.

memsharded commented 2 months ago

Hi @leviskim17

Any further question or issue here? Can we close the ticket? Thanks for your feedback.

leviskim17 commented 2 months ago

Thanks so much for your support!