Skip to content

Commit b1ea0ed

Browse files
committed
add corrosion_add_target_generated_headers for code generators
This sets the GENERATED_HEADER_DIR environment variable when calling cargo and adds that path to the target's include paths. Cargo build scripts can read this to determine where to output generated C/C++ headers. Depends on dtolnay/cxx#1120 for cxx-build Fixes corrosion-rs#204
1 parent 23603e8 commit b1ea0ed

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ Some configuration options can be specified individually for each target. You ca
216216
the environment variable will only be set for direct builds of the target via cmake, and not for any
217217
build where cargo built the crate in question as a dependency for another target.
218218
The environment variables may contain generator expressions.
219+
- `corrosion_add_target_generated_headers(<target_name>)`: Use this for crates whose build scripts generate C/C++
220+
headers to add the headers to the target's include paths. Currently cxx-build and cxx-qt-build support this.
221+
The build script must output the generated headers to the path specified by the GENERATED_HEADER_DIR environment
222+
variable for this to work.
219223
- `corrosion_add_target_rustflags(<target_name> <rustflag> [... <rustflagN>])`: When building the target,
220224
the `RUSTFLAGS` environment variable will contain the flags added via this function. Please note that any
221225
dependencies (built by cargo) will also see these flags. In the future corrosion may offer a second function

cmake/Corrosion.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,12 @@ function(corrosion_set_hostbuild target_name)
11421142
)
11431143
endfunction()
11441144

1145+
function(corrosion_add_target_generated_headers target_name)
1146+
set(generated_header_dir "${CMAKE_CURRENT_BINARY_DIR}/generated-code")
1147+
target_include_directories("${target_name}" INTERFACE "${generated_header_dir}")
1148+
corrosion_set_env_vars("${target_name}" "GENERATED_HEADER_DIR=${generated_header_dir}")
1149+
endfunction()
1150+
11451151
# Add flags for rustc (RUSTFLAGS) which affect the target and all of it's Rust dependencies
11461152
#
11471153
# Additional rustflags may be passed as optional parameters after rustflag.

0 commit comments

Comments
 (0)