Metaphox
Metaphox

Reputation: 2094

How to specify requirements conditionally in `conanfile.txt`?

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.

Upvotes: 3

Views: 2413

Answers (1)

uilianries
uilianries

Reputation: 3887

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.

Upvotes: 2

Related Questions