Calling conda from within CMake

I’m putting together a project with depends on pybind11, xtensor, and xtensor-python. The easiest way to download all these packages is with conda install xtensor-python. Would it be reasonable to call conda from cmake like this?

execute_process(COMMAND conda install -y xtensor-python)
find_package(pybind11 REQUIRED)
find_package(xtensor REQUIRED)
find_package(xtensor-python REQUIRED)

Is there a better way? I tried without success to use FetchContent. All packages but xtensor-python were happy with the FetchContent approach.

I think you’ll probably want to let the user specify a specific environment instead of dumping it into their global one, but knowing why FetchContent isn’t working is probably the better road long-term.

Cc: @craig.scott

Hard-coding a conda install command in your project would likely be an unpopular move if consumers of your project wanted to provide xtensor-python some other way. I agree with Ben in this case, let the user set up their environment such that xtensor-python will be found.

Note that the user could set up that environment in various ways. They could do it before calling cmake. They could also do it with a custom CMake script that gets executed with a project() command. This second scenario would be less command today, but something similar could become more prevalent if the proposal in issue 22685 is implemented.