find_package
lets you specify a version range:
find_package(<PackageName> major.minor...<major.minor REQUIRED)
The first match wins over consecutive find_package
calls. This means that you have to add this call further up your project (somewhere to make sure it is the first find_package
used). You seem to be interested in a single Python version for your entire CMake project, in which case this function should be in the top level CMake list.
If your Python installation is not in the default path you’d also need to manually set the root dir:
cmake -DPython3_ROOT_DIR=$HOME/python/versions/3.9.0 ..