Skip to content

Commit 31f77ab

Browse files
committed
Address latest custom command review feedback
1 parent 6d41c92 commit 31f77ab

6 files changed

Lines changed: 27 additions & 9 deletions

File tree

docs/cmake-toml.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ comment = "Run custom target"
273273
job-pool = "pool"
274274
job-server-aware = true
275275
verbatim = true
276-
uses-terminal = true
276+
uses-terminal = false # incompatible with job-pool when true
277277
command-expand-lists = true
278278

279279
cmake-before = """
@@ -314,7 +314,7 @@ implicit-depends = [["CXX", "src/input.idl"]]
314314
working-directory = "${CMAKE_CURRENT_BINARY_DIR}"
315315
comment = "Generate source"
316316
depfile = "${CMAKE_CURRENT_BINARY_DIR}/generated.d"
317-
job-pool = "pool"
317+
job-pool = "pool" # incompatible with uses-terminal when uses-terminal = true
318318
job-server-aware = true
319319
verbatim = true
320320
append = false
@@ -335,7 +335,7 @@ command-expand-lists = false
335335
uses-terminal = false
336336
```
337337

338-
For each custom command entry, exactly one of `outputs` or `build-event` is required. Relative `outputs`/`byproducts` paths follow CMake and are interpreted from the current binary directory. `build-event` is only valid for non-`interface` targets, and `pre-link` is not supported for `type = "custom"`.
338+
For each custom command entry, exactly one of `outputs` or `build-event` is required. Relative `outputs`/`byproducts` paths follow CMake and are interpreted from the current binary directory. `build-event` is only valid for non-`interface` targets, and `pre-link` is not supported for `type = "custom"`. In both `add_custom_command(OUTPUT ...)` and `add_custom_target(...)`, `job-pool` cannot be combined with `uses-terminal = true`.
339339

340340
A table mapping the cmkr features to the relevant CMake construct and the relevant documentation pages:
341341

docs/examples/generator-executable.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ type = "executable"
4848
sources = ["src/main.cpp"]
4949
include-directories = ["${CMAKE_CURRENT_BINARY_DIR}/generated"]
5050

51+
# Create the generated directory before the generator runs.
52+
cmake-before = """
53+
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/generated")
54+
"""
55+
5156
# Output form custom command: runs the generate_numbers executable to generate sources.
5257
# The outputs are automatically added as sources to this target.
5358
# The DEPENDS on "generate_numbers" ensures the generator is built before this runs.

src/cmake_generator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,11 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
13311331
}
13321332
custom_commands.insert(custom_commands.end(), target.custom_commands.begin(), target.custom_commands.end());
13331333

1334+
if (resolved_target_type == parser::target_custom && custom_target.has_job_pool && custom_target.has_uses_terminal &&
1335+
custom_target.uses_terminal) {
1336+
throw_target_error("job-pool cannot be used with uses-terminal");
1337+
}
1338+
13341339
auto normalize_generated_output_source = [](const std::string &output) {
13351340
auto starts_with = [](const std::string &value, const std::string &prefix) {
13361341
return value.rfind(prefix, 0) == 0;

src/project_parser.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,9 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
10161016
if (custom_command.has_depfile && !custom_command.implicit_depends.empty()) {
10171017
throw_key_error("depfile cannot be used with implicit-depends", "depfile", custom.find("depfile"));
10181018
}
1019+
if (custom_command.has_job_pool && custom_command.has_uses_terminal && custom_command.uses_terminal) {
1020+
throw_key_error("job-pool cannot be used with uses-terminal", "job-pool", custom.find("job-pool"));
1021+
}
10191022
if (custom_command.append &&
10201023
(custom_command.has_depfile || custom_command.has_job_pool || custom_command.has_job_server_aware ||
10211024
custom_command.has_codegen || custom_command.has_command_expand_lists || custom_command.has_uses_terminal ||
@@ -1034,6 +1037,11 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
10341037
}
10351038
}
10361039

1040+
if (resolved_target_type == target_custom && target.custom_target.has_job_pool && target.custom_target.has_uses_terminal &&
1041+
target.custom_target.uses_terminal) {
1042+
throw_key_error("job-pool cannot be used with uses-terminal", "job-pool", t.find("job-pool"));
1043+
}
1044+
10371045
if (resolved_target_type != target_custom && !target.custom_target.empty()) {
10381046
const char *custom_key = "all";
10391047
if (target.custom_target.has_command) {

tests/generator-executable/cmake.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ type = "executable"
3333
sources = ["src/main.cpp"]
3434
include-directories = ["${CMAKE_CURRENT_BINARY_DIR}/generated"]
3535

36+
# Create the generated directory before the generator runs.
37+
cmake-before = """
38+
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/generated")
39+
"""
40+
3641
# Output form custom command: runs the generate_numbers executable to generate sources.
3742
# The outputs are automatically added as sources to this target.
3843
# The DEPENDS on "generate_numbers" ensures the generator is built before this runs.

tests/generator-executable/src/generate_numbers.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ int main(int argc, char *argv[]) {
1313

1414
std::string output_path = argv[1];
1515

16-
// Create output directory if needed
17-
auto last_slash = output_path.find_last_of("/\\");
18-
if (last_slash != std::string::npos) {
19-
// Note: In a real generator, you'd create the directory
20-
// CMake creates it for us when using add_custom_command
21-
}
16+
// The example ensures the output directory exists before invoking the generator.
2217

2318
std::ofstream out(output_path);
2419
if (!out) {

0 commit comments

Comments
 (0)