In a project I’m involved with, we need to check if certain Python packages are available to the interpreter. To do this, I have written a basic macro find_Python3_package
.
This is used in a CMake block like this:
find_package(Python3 COMPONENTS Interpreter)
if(Python3_FOUND)
find_Python3_package("pyyaml" HAS_PYYAML)
find_Python3_package("ruamel.yaml" HAS_RUAMEL_YAML)
endif()
with a possible CMake configure output:
...
-- Found Python3: /usr/bin/python3.10 (found version "3.10.12") found components: Interpreter
-- Looking for pyyaml
-- Looking for pyyaml - not found
-- Looking for ruamel.yaml
-- Looking for ruamel.yaml - found version "0.17.16"
...
I think this type of functionality could be potentially useful for others, and I don’t believe it exists anywhere else. Is it within scope to refine and contribute to the CMake source? I can push this effort, but I might need some guidance.