How to do it

We have already shown the use of execute_process when trying to find the NumPy Python module in Chapter 3, Detecting External Libraries and Programs, Recipe 3, Detecting Python modules and packages. In this example, we will use the execute_process command to find out whether a particular Python module (in this case, Python CFFI) is present, and if it is, we will discover its version:

  1. For this simple example, we will not require any language support:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)  project(recipe-02 LANGUAGES NONE)
  1. We will require the Python interpreter to execute a short Python snippet, and for this we discover the interpreter using find_package:
find_package(PythonInterp REQUIRED)
  1. We then invoke execute_process ...

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.