CMake Cookbook
上QQ阅读APP看书,第一时间看更新

There is more

How do we make sure that the Python header and libraries are correctly located even when they are not in a standard installation directory? For the Python interpreter, it is possible to force CMake to look in specific directories by passing the PYTHON_LIBRARY and PYTHON_INCLUDE_DIR options via the -D option to the CLI. These options specify the following:

  • PYTHON_LIBRARY, the path to the Python library
  • PYTHON_INCLUDE_DIR, the path to where Python.h is located

This ensures that the desired version of Python will be picked up.

Sometimes it is necessary to pass -D PYTHON_EXECUTABLE, -D PYTHON_LIBRARY, and -D PYTHON_INCLUDE_DIR to the CMake CLI in order to locate all necessary components and pin them down to the exact same version.