diff options
author | Cristian Adam <cristian.adam@gmail.com> | 2020-02-27 19:20:22 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-03-03 13:42:13 (GMT) |
commit | 598b676b5e77540b366b01b3c10154c2a633d23c (patch) | |
tree | eb3aaea48e3c1743835a74be111ca64ee4a9a4e5 /Help/command/cmake_command.rst | |
parent | c58b9c5ab94d674c76a17e6154f05e0e8c5c37d1 (diff) | |
download | CMake-598b676b5e77540b366b01b3c10154c2a633d23c.zip CMake-598b676b5e77540b366b01b3c10154c2a633d23c.tar.gz CMake-598b676b5e77540b366b01b3c10154c2a633d23c.tar.bz2 |
cmake_command: Add command to EVAL a CMake script as a string
Diffstat (limited to 'Help/command/cmake_command.rst')
-rw-r--r-- | Help/command/cmake_command.rst | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/Help/command/cmake_command.rst b/Help/command/cmake_command.rst index 9281647..08b7832 100644 --- a/Help/command/cmake_command.rst +++ b/Help/command/cmake_command.rst @@ -9,6 +9,7 @@ Synopsis .. parsed-literal:: cmake_command(`INVOKE`_ <command> [<args>...]) + cmake_command(`EVAL`_ CODE <code>...) Introduction ^^^^^^^^^^^^ @@ -16,8 +17,10 @@ Introduction This command will call meta-operations on built-in CMake commands or those created via the :command:`macro` or :command:`function` commands. -Invoking -^^^^^^^^ +``cmake_command`` does not introduce a new variable or policy scope. + +Invoking Commands +^^^^^^^^^^^^^^^^^ .. _INVOKE: @@ -38,3 +41,50 @@ is equivalent to .. code-block:: cmake message(STATUS "Hello World!") + +Evaluating Code +^^^^^^^^^^^^^^^ + +.. _EVAL: + +.. code-block:: cmake + + cmake_command(EVAL CODE <code>...) + +Evaluates the ``<code>...`` as CMake code. + +For example, the code: + +.. code-block:: cmake + + set(A TRUE) + set(B TRUE) + set(C TRUE) + set(condition "(A AND B) OR C") + + cmake_command(EVAL CODE " + if (${condition}) + message(STATUS TRUE) + else() + message(STATUS FALSE) + endif()" + ) + +is equivalent to + +.. code-block:: cmake + + set(A TRUE) + set(B TRUE) + set(C TRUE) + set(condition "(A AND B) OR C") + + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/eval.cmake " + if (${condition}) + message(STATUS TRUE) + else() + message(STATUS FALSE) + endif()" + ) + + include(${CMAKE_CURRENT_BINARY_DIR}/eval.cmake) |