1+ # This test demonstrates add_custom_command and add_custom_target support in cmkr.
2+ #
3+ # There are two forms of add_custom_command in CMake:
4+ # 1. Output form: generates files that can be consumed by other targets
5+ # 2. Target form: runs commands at build time for a specific target (pre-build, pre-link, post-build)
6+
17[project ]
28name = " custom-command"
39description = " Tests add_custom_command and add_custom_target support"
410
11+ # -----------------------------------------------------------------------------
12+ # Simple executable demonstrating post-build events
13+ # -----------------------------------------------------------------------------
14+
15+ [target .hello ]
16+ type = " executable"
17+ sources = [" src/hello.cpp" ]
18+
19+ # This post-build command runs after the 'hello' executable is built.
20+ # build-event can be: "pre-build", "pre-link", or "post-build"
21+ [[target .hello .custom-command ]]
22+ build-event = " post-build"
23+ command = [" ${CMAKE_COMMAND}" , " -E" , " echo" , " Built executable: $<TARGET_FILE_NAME:hello>" ]
24+ comment = " Print the built executable name"
25+
26+ # -----------------------------------------------------------------------------
27+ # Executable with code generation (output form custom command)
28+ # -----------------------------------------------------------------------------
29+
530[target .custom-command ]
631type = " executable"
732sources = [" src/main.cpp" ]
833include-directories = [" ${CMAKE_CURRENT_BINARY_DIR}/generated" ]
934
35+ # Output form: This custom command generates source files before building.
36+ # The outputs are automatically added as sources to the target.
1037[[target .custom-command .custom-command ]]
1138outputs = [" ${CMAKE_CURRENT_BINARY_DIR}/generated/generated.cpp" ]
1239byproducts = [" ${CMAKE_CURRENT_BINARY_DIR}/generated/generated.hpp" ]
@@ -21,6 +48,7 @@ command = [
2148comment = " Generate source files"
2249verbatim = true
2350
51+ # Target form: This post-build command runs after 'custom-command' is built.
2452[[target .custom-command .custom-command ]]
2553build-event = " post-build"
2654command = [
@@ -33,6 +61,12 @@ byproducts = ["${CMAKE_CURRENT_BINARY_DIR}/custom-command-post-build.stamp"]
3361comment = " Create a post-build stamp file"
3462verbatim = true
3563
64+ # -----------------------------------------------------------------------------
65+ # Custom target (add_custom_target)
66+ # -----------------------------------------------------------------------------
67+
68+ # A custom target runs commands independently of any executable/library.
69+ # Setting 'all = true' makes it run as part of the default build.
3670[target .custom-codegen ]
3771type = " custom"
3872all = true
0 commit comments