I'm testing out CMake 3.12, and I very much like the new
FindPython.cmake. Being able to use targets for the Python libraries
means I can much easier package my own library without hardcoded paths.
The only thing is that I want to be compatible with older CMakes >=
3.0. Therefore I came up with following approach: write a
FindPythonCompat.cmake that forwards to FindPython.cmake if CMake >=
3.12, and uses FindPythonInterp.cmake and FindPythonLibs.cmake to mimic
the new FindPython.cmake if CMake < 3.12.
The resulting targets and variables are the same as the ones from
Another approached I consider is a bit more cunning: add a
PythonConfig.cmake and PythonConfigVersion.cmake to CMAKE_PREFIX_PATH.
PythonConfig.cmake would not contain the forward to FindPython.cmake,
but it would instead rely on the fallback from MODULE to CONFIG mode
when FindPython.cmake cannot be found in CMake < 3.12. I would then
still be calling find_package(Python) but I extend CMAKE_PREFIX_PATH:
In both cases it is of course required that I install this
FindPythonCompat.cmake or PythonConfig.cmake next to my own library's
Also, in the compatibility mode, it's not my goal to get a 1-on-1 match
with FindPython.cmake. For my needs, I only require what
FindInterp.cmake and FindLibs.cmake can deliver.
Now my questions to you are:
- What do you think of these approaches?
- What's the most CMake-esque approach?
- How can I improve this?
- Any better names for FindPythonCompat.cmake? FindPythonShim.cmake?