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

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

Open
1 task done
leviskim17 opened this issue Jun 24, 2024 · 3 comments
Open
1 task done
Assignees

Comments

@leviskim17
Copy link

leviskim17 commented Jun 24, 2024

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:
  • Using conanfile.py, I downloaded the zlib library from NuGet via Conan.
  • When Conan tried to build libpng refering zlib, it returns an error can't find zlib.
  • To address the toolchain issue, I added CMakeToolchain and CMakeDeps in the generate() method. Please see attached conanfile.-.zlib.txt
  1. Building zlib from source is working well.
  • Building zlib from source allows the libpng build to succeed. However, due to existing components that depend on the NuGet zlib, it is necessary to use the NuGet version of zlib until a complete transition can be made.
  1. Manual Modified CMakeList in libpng.
  • When running the downloaded libpng source with CMake standalone, it similarly failed to locate zlib. However, forcibly adding the zlib toolchain to CMake as shown below allowed it to be found:
# 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?

  • I've read the CONTRIBUTING guide
@memsharded
Copy link
Member

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:

  • the source() method must be invariant. It should always download exactly the same sources, but this is not what you are doing. Conditionals in source() are explicitly forbidden, access to settings/options will fail, but you are avoiding that unpexectedly using self.info in a place that can be broken for some cases like the local flow.
  • The binary model is incorrect. You are hardcoding self.src_url = urllib.parse.urljoin(baseUrl, data["Windows"]["inc"]) in the recipe, so even if the setting -s os=Linux it will still download the Windows binary, not the Linux one.
  • Why using CMakeToolchain + CMakeDeps if you are trying to download pre-compiled binaries? Those are for building from source

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
Copy link
Author

@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
Copy link
Member

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.

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

No branches or pull requests

2 participants