diff options
author | Brad King <brad.king@kitware.com> | 2020-03-03 14:19:31 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-03-03 14:19:39 (GMT) |
commit | 38ac070eada4abb9786968b2f88f7d0d8874770c (patch) | |
tree | 9442acbf5aef60f6dc8105fc64d95c0138dacf7f /Help | |
parent | cabde33ed87a127416ac40278d4c4ead21767c6e (diff) | |
parent | 598b676b5e77540b366b01b3c10154c2a633d23c (diff) | |
download | CMake-38ac070eada4abb9786968b2f88f7d0d8874770c.zip CMake-38ac070eada4abb9786968b2f88f7d0d8874770c.tar.gz CMake-38ac070eada4abb9786968b2f88f7d0d8874770c.tar.bz2 |
Merge topic 'cmake_command-eval'
598b676b5e cmake_command: Add command to EVAL a CMake script as a string
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4408
Diffstat (limited to 'Help')
-rw-r--r-- | Help/command/cmake_command.rst | 54 | ||||
-rw-r--r-- | Help/release/dev/cmake_command-command.rst | 2 |
2 files changed, 53 insertions, 3 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) diff --git a/Help/release/dev/cmake_command-command.rst b/Help/release/dev/cmake_command-command.rst index ebe75b1..6200ae2 100644 --- a/Help/release/dev/cmake_command-command.rst +++ b/Help/release/dev/cmake_command-command.rst @@ -3,4 +3,4 @@ cmake_command * The :command:`cmake_command()` command was added for meta-operations on scripted or built-in commands, starting with a mode to ``INVOKE`` other - commands. + commands, and ``EVAL CODE`` to inplace evaluate a CMake script. |