You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cmake/cmake_bindings.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,4 +16,4 @@ See [Output](output.md) for details on the generated files.
16
16
17
17
## Filtering
18
18
19
-
See [Filtering](filtering.md) for how to exclude files from the generated CMake build.
19
+
See [Filtering](filtering.md) for how to exclude files from the generated CMake build and how to conditionally include generated sources and directories with `guards`.
Copy file name to clipboardExpand all lines: docs/cmake/filtering.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,3 +3,24 @@
3
3
## Skipping Files
4
4
5
5
The CMake config supports a `skip` option to exclude specific `*-rb.cpp` files from the generated `CMakeLists.txt`. However, in most cases it's better to add skip patterns to your Rice config instead — that way the problematic files are never generated, and CMake won't find them to include. The CMake `skip` is useful as a quick fix when you have stale generated files on disk that you don't want to recompile.
6
+
7
+
## Guarding Files And Directories
8
+
9
+
Use `guards` when generated paths should remain on disk but only be compiled when a CMake condition is true.
10
+
11
+
```yaml
12
+
guards:
13
+
OpenCV_HAS_CUDA:
14
+
- opencv2/cuda*-rb.cpp
15
+
TARGET OpenCV::dnn:
16
+
- opencv2/dnn
17
+
```
18
+
19
+
Guard keys are emitted as raw `if(...)` conditions. Guard values may be exact paths or globs and may match generated directories and `*-rb.cpp` files.
20
+
21
+
- Matching directories are emitted inside guarded `add_subdirectory(...)` blocks.
22
+
- Matching `*-rb.cpp` files are emitted inside guarded `target_sources(...)` blocks.
23
+
- A guard pattern that matches nothing emits a warning.
24
+
- If the same path matches multiple guards, generation fails with an error.
25
+
26
+
Use `skip` for permanent exclusion. Use `guards` for conditional inclusion.
Copy file name to clipboardExpand all lines: docs/cmake/getting_started.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,11 @@ project: my_extension
15
15
output: ./ext/generated
16
16
format: CMake
17
17
18
+
guards:
19
+
TARGET MyLib::gpu:
20
+
- gpu
21
+
- gpu/**/*-rb.cpp
22
+
18
23
include_dirs:
19
24
- "${CMAKE_CURRENT_SOURCE_DIR}/../include"
20
25
```
@@ -23,6 +28,7 @@ Key options:
23
28
24
29
- `project` — name used in the CMake `project()` command and build target. When omitted, only subdirectory `CMakeLists.txt` files are generated — useful when you manage the root project files yourself.
25
30
- `output`— directory containing the Rice `*-rb.cpp` files. `input` defaults to `output` for CMake.
31
+
- `guards`— raw CMake conditions mapped to generated path patterns. Use this when a generated subdirectory or `*-rb.cpp` file should only be compiled when a module or feature is available.
26
32
- `include_dirs`— include directories added via `target_include_directories`. These are CMake expressions written directly into the generated `CMakeLists.txt`.
27
33
28
34
See [Configuration](../configuration.md) for all options.
Copy file name to clipboardExpand all lines: docs/configuration.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,7 @@ These options apply to all formats.
53
53
|----------------|---------|-------------|
54
54
|`project`| none | Project name used in the CMake `project()` command and build target name. When provided, generates the root `CMakeLists.txt` (with project setup, Rice fetch, Ruby detection) and `CMakePresets.json`. When omitted, only subdirectory `CMakeLists.txt` files are generated — useful when you manage the root project files yourself. |
55
55
|`include_dirs`|`[]`| List of include directory expressions added via `target_include_directories`. These are CMake expressions written directly into `CMakeLists.txt` (e.g., `${CMAKE_CURRENT_SOURCE_DIR}/../headers`). |
56
+
|`guards`|`{}`| Map of raw CMake condition expressions to arrays of generated path patterns. Matching directories are emitted inside guarded `add_subdirectory(...)` blocks; matching `*-rb.cpp` files are emitted inside guarded `target_sources(...)` blocks. Exact paths and globs are both supported. |
0 commit comments