cmake_command.rst 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. cmake_command
  2. -------------
  3. Call meta-operations on CMake commands.
  4. Synopsis
  5. ^^^^^^^^
  6. .. parsed-literal::
  7. cmake_command(`INVOKE`_ <command> [<args>...])
  8. cmake_command(`EVAL`_ CODE <code>...)
  9. Introduction
  10. ^^^^^^^^^^^^
  11. This command will call meta-operations on built-in CMake commands or
  12. those created via the :command:`macro` or :command:`function` commands.
  13. ``cmake_command`` does not introduce a new variable or policy scope.
  14. Invoking Commands
  15. ^^^^^^^^^^^^^^^^^
  16. .. _INVOKE:
  17. .. code-block:: cmake
  18. cmake_command(INVOKE <command> [<args>...])
  19. Invokes the named ``<command>`` with the given arguments (if any).
  20. For example, the code:
  21. .. code-block:: cmake
  22. set(message_command "message")
  23. cmake_command(INVOKE ${message_command} STATUS "Hello World!")
  24. is equivalent to
  25. .. code-block:: cmake
  26. message(STATUS "Hello World!")
  27. Evaluating Code
  28. ^^^^^^^^^^^^^^^
  29. .. _EVAL:
  30. .. code-block:: cmake
  31. cmake_command(EVAL CODE <code>...)
  32. Evaluates the ``<code>...`` as CMake code.
  33. For example, the code:
  34. .. code-block:: cmake
  35. set(A TRUE)
  36. set(B TRUE)
  37. set(C TRUE)
  38. set(condition "(A AND B) OR C")
  39. cmake_command(EVAL CODE "
  40. if (${condition})
  41. message(STATUS TRUE)
  42. else()
  43. message(STATUS FALSE)
  44. endif()"
  45. )
  46. is equivalent to
  47. .. code-block:: cmake
  48. set(A TRUE)
  49. set(B TRUE)
  50. set(C TRUE)
  51. set(condition "(A AND B) OR C")
  52. file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/eval.cmake "
  53. if (${condition})
  54. message(STATUS TRUE)
  55. else()
  56. message(STATUS FALSE)
  57. endif()"
  58. )
  59. include(${CMAKE_CURRENT_BINARY_DIR}/eval.cmake)