Interpreter¶
Helper functions for executing CMake code in Python.
- class cmake_parser.interpreter.Context(parent=None, var=<factory>, env=<factory>, cache=<factory>, functions=<factory>, macros=<factory>)¶
Execution context for CMake code.
- Parameters:
parent (
Optional
[Self
]) – the parent of a scoped context orNone
for the top-level context.var (
Dict
[str
,str
]) – defined CMake variablesenv (
Dict
[str
,str
]) – available environment variablescache (
Dict
[str
,str
]) – defined CMake cache variablesfunctions (
Dict
[str
,Function
]) – defined functionsmacros (
Dict
[str
,Macro
]) – defined macros
- exists(f)¶
Helper function to check if a file or directory exists
- Parameters:
f (
str
) – a path name- Return type:
bool
- Returns:
True
if the path name refers to an existing file or directory.
- class cmake_parser.interpreter.LookAheadIterator(iterable)¶
- cmake_parser.interpreter.eval_bool_expr(ctx, args)¶
Evaluate boolean expressions.
Some CMake command such as
if()
have a boolean expression as argument. This function will evaluate such expressions toFalse
orTrue
given the current execution context.Note
This function does not resolve variable references, so you need to pass the argument list through
resolve_args()
first.- Parameters:
- Return type:
bool
- Returns:
the boolean value of the expression
- Raise:
CMakeExprError
if the expression is malformed.
- cmake_parser.interpreter.eval_expr(ctx, args)¶
Evaluate boolean expressions.
Some CMake command such as
if()
have a boolean expression as argument. This function will evaluate such expressions toFalse
orTrue
given the current execution context.Note
This function does not resolve variable references, so you need to pass the argument list through
resolve_args()
first.- Parameters:
- Return type:
bool
- Returns:
the boolean value of the expression
- Raise:
CMakeExprError
if the expression is malformed.
- cmake_parser.interpreter.resolve_args(ctx, args)¶
Resolve variable references in argument lists.
Due to the semantics of unquoted variable references, this function may also change the number and type of arguments, which means that the returned argument list can have more or fewer items than the input, depending on the execution context.
The returned token list will have a proper 1:1 relation between function arguments and tokens. Boolean expressions are suitable input for
eval_bool_expr()
after they have been processed by this function.- Parameters:
ctx (
Context
) – the current execution contextargs (
List
[Token
]) – the argument tokens as they were parsed byparse_raw()
orparse_tree()
.
- Return type:
List
[Token
]- Returns:
a new argument list with all variable references resolved