summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-10-20 14:28:53 (GMT)
committerBrad King <brad.king@kitware.com>2020-12-10 12:06:19 (GMT)
commitc523d1cc32f53a176ea485aa33e076e577db2d17 (patch)
tree7d4b740ae1532a9c991fbe0c5c7b6875a2a26f59
parent9109475bfb9371e74c6ddbf64a66054e5aaea795 (diff)
downloadCMake-c523d1cc32f53a176ea485aa33e076e577db2d17.zip
CMake-c523d1cc32f53a176ea485aa33e076e577db2d17.tar.gz
CMake-c523d1cc32f53a176ea485aa33e076e577db2d17.tar.bz2
Help: Add examples to add_custom_command reference documentation
-rw-r--r--Help/command/add_custom_command.rst38
1 files changed, 38 insertions, 0 deletions
diff --git a/Help/command/add_custom_command.rst b/Help/command/add_custom_command.rst
index 45e4e3e..85d56a3 100644
--- a/Help/command/add_custom_command.rst
+++ b/Help/command/add_custom_command.rst
@@ -259,6 +259,26 @@ The options are:
``DEPFILE`` should also be relative to :variable:`CMAKE_CURRENT_BINARY_DIR`
(see policy :policy:`CMP0116`.)
+Examples: Generating Files
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Custom commands may be used to generate source files.
+For example, the code:
+
+.. code-block:: cmake
+
+ add_custom_command(
+ OUTPUT out.c
+ COMMAND someTool -i ${CMAKE_CURRENT_SOURCE_DIR}/in.txt
+ -o out.c
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/in.txt
+ VERBATIM)
+ add_library(myLib out.c)
+
+adds a custom command to run ``someTool`` to generate ``out.c`` and then
+compile the generated source as part of a library. The generation rule
+will re-run whenever ``in.txt`` changes.
+
Build Events
^^^^^^^^^^^^
@@ -308,3 +328,21 @@ of the following is specified:
configuration and no "empty-string-command" will be added.
This allows to add individual build events for every configuration.
+
+Examples: Build Events
+^^^^^^^^^^^^^^^^^^^^^^
+
+A ``POST_BUILD`` event may be used to post-process a binary after linking.
+For example, the code:
+
+.. code-block:: cmake
+
+ add_executable(myExe myExe.c)
+ add_custom_command(
+ TARGET myExe POST_BUILD
+ COMMAND someHasher -i "$<TARGET_FILE:myExe>"
+ -o "$<TARGET_FILE:myExe>.hash"
+ VERBATIM)
+
+will run ``someHasher`` to produce a ``.hash`` file next to the executable
+after linking.