Tools to run Python commands from CMake

Note

we will make sure to always use Python2, which is already a dependency of the qibuild command line

If you are using the qibuild command line, you will be able to run python command that imports qibuild


             
              qi_run_py_script(script [ARGUMENTS <arguments> ...]
)

             
            
Arguments:
  • script – The path to the script
  • ARGUMENTS – The arguments of the script ( sys.argv )

Run a Python script

Will call qi_error if the return code of the script is not zero. If you need to get the output of the script as a CMake variable, use


             
              qi_run_py_script(/path/to/my_script.py
  OUTPUT_VARIABLE _out
  OUTPUT_STRIP_TRAILING_WHITESPACE # optional, but may be handy
)
# do something with ``${_out}``

             
            

             
              qi_run_py_cmd(cmd)

             
            
Arguments:
  • cmd – : The Python code to run, as a string

Run a Python program passed in as a string Behaves the same as qi_run_py_script


             
              qi_create_python_ext()

             
            

Create a python extension