Pass CMake configuration options to 'conan build' on the command line

Viewed 1238

I know CMake configuration options can be specified in conanfile.py in the build step. But is there a way to pass cmake configuration options to conan build directly via the command line?

A rough workaround for, say, build type could be something like:

def build(self):
    cmake = CMake(self)
    cmake.definitions["CMAKE_BUILD_TYPE"] = os.environ.get("CMAKE_BUILD_TYPE", "Debug")  # specify here
    cmake.configure()
    cmake.build()

which can then be called like this

CMAKE_BUILD_TYPE=Release conan build {BUILD_DIR}

But is there away to do this generally for any configuration option? I know it can be done at the conan install level via -s but that to my knowledge is only for dependencies and in any case I'm not interested necessarily in them being in Debug mode, I only want to configure it for the current project I'm building.

The conan build docs only allude to this being possible in conanfile.py::build and there doesn't seem to be a command line option that allows to you to directly pass CMake options.

I know I can just defer to calling cmake directly and call that instead but was wondering if it was possible at all to do via conan build.

0 Answers
Related