Kevin Lannen
Kevin Lannen

Reputation: 89

Using conan to package multiple configurations of preexisting binaries

I have a set of third-party binaries that I am trying to put into a conan package. The binaries are in folders for the build configuration: Linux32, Win32, Win64, Win32.

I have been able to produce a conan package for the Win64 configuration using the following conanfile.py:

from conans import ConanFile

class LibNameConan(ConanFile):
    name = "LibName"
    version = "1.1.1"
    settings = "os", "compiler", "build_type", "arch"
    description = "Package for LibName"
    url = "None"
    license = "None"

    def package(self):
        self.copy("*", dst="lib", src="lib")
        self.copy("*.c", dst="include", src="include", keep_path=False)

    def package_info(self):
        self.cpp_info.libs = self.collect_libs()

I run the following commands in powershell:

conan install
mkdir pkg
cd pkg
conan package .. --build_folder=../
cd ..
conan export name/testing
conan package_files libname/1.1.1@name/testing

For the Win64 this works as expected. When I repeat the steps with Win32 binaries I do not get a different hash for the package.

I have tried running:

conan install -s arch=x86

However, this still results in the package having the same hash as the x86_64 configuration.

How is the configuration supposed to be set for generating a package from preexisting binaries?

Upvotes: 3

Views: 2639

Answers (1)

drodri
drodri

Reputation: 5972

If you are just packaging pre-built binaries, you are fine without the package() method, that is only relevant when building from the recipe:

from conans import ConanFile

class LibNameConan(ConanFile):
    name = "LibName"
    version = "1.1.1"
    settings = "os", "compiler", "build_type", "arch"
    description = "Package for LibName"
    url = "None"
    license = "None"

    def package_info(self):
        self.cpp_info.libs = self.collect_libs()

Unless there is some important reason you want to package the sources too, do you want them to be able to debug your dependencies too? In that case, please condition it to the build_type.

However this could be mostly irrelevant for your question. As your package doesn't have dependencies and you are not using any generator either, you don't need a conan install, and the settings you use there, have no effect.

You have to specify the settings for your binary configuration when you package_files:

$ conan package_files libname/1.1.1@name/testing # using your default config
$ conan package_files libname/1.1.1@name/testing -s arch=x86  # 32 bits instead of 64
...

Probably the recommended way is to use profiles:

$ conan package_files libname/1.1.1@name/testing # using your default profile
$ conan package_files libname/1.1.1@name/testing -pr=myprofile2

The documentation got recently a re-write, you might want to check: https://docs.conan.io/en/latest/creating_packages/existing_binaries.html

Upvotes: 5

Related Questions