Skip to content

Commit d8e3a53

Browse files
committed
Simple post build test
1 parent 02e2b5a commit d8e3a53

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

tests/custom-command/cmake.toml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
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]
28
name = "custom-command"
39
description = "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]
631
type = "executable"
732
sources = ["src/main.cpp"]
833
include-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]]
1138
outputs = ["${CMAKE_CURRENT_BINARY_DIR}/generated/generated.cpp"]
1239
byproducts = ["${CMAKE_CURRENT_BINARY_DIR}/generated/generated.hpp"]
@@ -21,6 +48,7 @@ command = [
2148
comment = "Generate source files"
2249
verbatim = true
2350

51+
# Target form: This post-build command runs after 'custom-command' is built.
2452
[[target.custom-command.custom-command]]
2553
build-event = "post-build"
2654
command = [
@@ -33,6 +61,12 @@ byproducts = ["${CMAKE_CURRENT_BINARY_DIR}/custom-command-post-build.stamp"]
3361
comment = "Create a post-build stamp file"
3462
verbatim = 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]
3771
type = "custom"
3872
all = true

tests/custom-command/src/hello.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <iostream>
2+
3+
int main() {
4+
std::cout << "Hello, world!" << std::endl;
5+
return 0;
6+
}

0 commit comments

Comments
 (0)