Conditionally including packages with Conan

1 minute read

Conan for consumers

I wanted to add curses support to a cross-platform console project I’ve been working on on and off for a couple years. The standard implmentation of ncurses for macOS and Linux was relatively easy to add via Conan, however there is no “ncurses for Windows” implementation. Instead there is PDCurses which is a port of ncurses to Windows.

So how could I resolve this in my conanfile.txt file? From what I could tell there was no way to tell the configuration “if we’re on Windows then include this, but if we’re on macOS then include that. I was right! There is no way to do it in conanfile.txt but conanfile.txt is not my only option!

When doing conan install, Conan will look for either conanfile.txt or (note: I have not experimented to see which one takes priority if they’re both present).

I created a like so:

class MyConanFile(ConanFile):
    settings = "os", "compiler", "build_type", "arch"

    requires = (

    generators = "cmake"

    default_options = {
        "boost:shared": False,

    def requirements(self):
        if self.settings.os == "Windows":

The important part here being def requirements. Once I did this I was able to conditionally include files with Conan and my existing build jobs worked without a problem.