mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-24 07:08:38 -05:00
cmake_command: Add command to EVAL a CMake script as a string
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user