3

I have to deal with a cross-platform application which needs an additional 3rd party library on Windows but not on Linux (and that library doesn't support Linux anyway). I have packed the library into a Conan package, supporting only `os=Windows complier="Visual Studio". Now if I put this library as

[requires]
Library/1.2.3@foo/bar

in my conanfile.txt, conan install will logically fail with the Error Missing prebuilt package on Linux.

So is there a way to specify required packages conditionally in conanfile.txt? Something like Library/1.2.3@foo/bar [os="Windows"]. I read through the Conan docs but found nothing.

Or to tell conan install ignore the error?

Or my only luck is to use two different conanfile.txt on two platforms?

I can not use a conanfile.py, since the build process is not managed by Conan, only the dependencies.

Metaphox
  • 2,085
  • 2
  • 21
  • 34
  • 1
    If the build process is managed by CMake, you can [check for OS there](https://stackoverflow.com/questions/9160335/os-specific-instructions-in-cmake-how-to) and use two different conanfile.txts. – nada Jul 30 '19 at 14:38
  • @nada thanks for the comment, I am just wondering if I can somehow avoid using two conanfiles (with a one-line difference). – Metaphox Jul 30 '19 at 14:46
  • I'd write a script for that in CMake or so ^^, there is a more elegant solution for sure – nada Jul 30 '19 at 14:54
  • 1
    You should still be able to use conanfile.py for just dependencies. Using the python file does not require it to control the building. – John Dec 11 '20 at 13:00
  • @John thanks for the advice. It was a pilot project for other C++ projects to migrate to use Conan as a dependency manager. I ended up with suggesting two txt files for each platform, and encourage the developers who are willing to learn python to write their own conanfile.py. – Metaphox Dec 12 '20 at 14:11

1 Answers1

2

I would say the best option in your case is conanfile.py, but as you are not able to use it, you will need to keep two conanfile.txt, one per platform.

It's not possible adding condition in conanfile.txt, because it would cost a big effort of development, and conafile.py is able to deal with conditions since is a python script.

@nada solution is good, you can use CMake to call conan according your OS, but also you can try cmake-conan, which sounds better for your specific scenario.

uilianries
  • 3,363
  • 15
  • 28