How it works

The FindPythonLibs.cmake module will look in standard locations for the Python header and library. Since these are required dependencies of our project, configuration will stop with an error if these are not found.

Notice that we explicitly asked CMake to detect the installation of the Python executable. This is to ensure that executable, header, and library all have a matching version. This is paramount to ensure that there are no mismatches between versions that could cause crashes at runtime. We have achieved this by using PYTHON_VERSION_MAJOR and PYTHON_VERSION_MINOR, defined in FindPythonInterp.cmake:

find_package(PythonInterp REQUIRED)find_package(PythonLibs ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} EXACT REQUIRED) ...

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.