We will build up the CMakeLists.txt file step by step:
- We start out by defining the minimum CMake version and project name. Note that for this example we will not need any language support:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(recipe-01 LANGUAGES NONE)
- Then, we use the find_package command to find the Python interpreter:
find_package(PythonInterp REQUIRED)
- Then, we execute a Python command and capture its output and return value:
execute_process( COMMAND ${PYTHON_EXECUTABLE} "-c" "print('Hello, world!')" RESULT_VARIABLE _status OUTPUT_VARIABLE _hello_world ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE )
- Finally, we print the return value and the output of the Python command:
message(STATUS "RESULT_VARIABLE ...