|
| 1 | +# PHP/AddCustomCommand |
| 2 | + |
| 3 | +See: [AddCustomCommand.cmake](https://github.com/petk/php-build-system/tree/master/cmake/cmake/modules/PHP/AddCustomCommand.cmake) |
| 4 | + |
| 5 | +Add custom command. |
| 6 | + |
| 7 | +This module is built on top of the CMake |
| 8 | +[`add_custom_command`](https://cmake.org/cmake/help/latest/command/add_custom_command.html) |
| 9 | +and [`add_custom_target()`](https://cmake.org/cmake/help/latest/command/add_custom_target.html) |
| 10 | +commands. |
| 11 | + |
| 12 | +A common issue in build systems is the generation of files with the project |
| 13 | +program itself. Here are two main cases: |
| 14 | +* PHP is found on the system: this is the most simple and developer-friendly to |
| 15 | + use as some files can be generated during the build phase. |
| 16 | +* When PHP is not found on the system, ideally the files could be generated |
| 17 | + after the PHP CLI binary is built in the current project itself. However, this |
| 18 | + can quickly bring cyclic dependencies between the target at hand, PHP CLI and |
| 19 | + the generated files. In such case, inconvenience is that two build steps might |
| 20 | + need to be done in order to generate the entire project once the file has been |
| 21 | + regenerated. |
| 22 | + |
| 23 | +This module exposes the following function: |
| 24 | + |
| 25 | +```cmake |
| 26 | +php_add_custom_command( |
| 27 | + <unique-symbolic-target-name> |
| 28 | + OUTPUT ... |
| 29 | + DEPENDS ... |
| 30 | + PHP_COMMAND ... |
| 31 | + [COMMENT <comment>] |
| 32 | + [VERBATIM] |
| 33 | +) |
| 34 | +``` |
| 35 | + |
| 36 | +It acts similar to `add_custom_command()` and `add_custom_target()`, except that |
| 37 | +the DEPENDS argument doesn't add dependencies among targets but instead checks |
| 38 | +their timestamps manually and executes the PHP_COMMAND only when needed. |
| 39 | + |
| 40 | +```cmake |
| 41 | +php_add_custom_command( |
| 42 | + php_generate_something |
| 43 | + OUTPUTS |
| 44 | + list of generated files |
| 45 | + DEPENDS |
| 46 | + list of files or targets that this generation depends on |
| 47 | + PHP_COMMAND |
| 48 | + ${CMAKE_CURRENT_SOURCE_DIR}/generate-something.php |
| 49 | + COMMENT "Generate something" |
| 50 | + VERBATIM |
| 51 | +) |
| 52 | +``` |
0 commit comments