Skip to content

Commit

Permalink
cxxbridge: Add target to regenerate bridge files
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonMatthesKDAB committed Nov 13, 2024
1 parent 1c6974c commit 3cb5e82
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions cmake/Corrosion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,7 @@ ANCHOR: corrosion_add_cxxbridge
```cmake
corrosion_add_cxxbridge(cxx_target
CRATE <imported_target_name>
REGEN_TARGET <regen_target_name>
[FILES <file1.rs> <file2.rs>]
)
```
Expand All @@ -1533,6 +1534,7 @@ Adds build-rules to create C++ bindings using the [cxx] crate.
* `cxxtarget`: Name of the C++ library target for the bindings, which corrosion will create.
* **FILES**: Input Rust source file containing #[cxx::bridge].
* **CRATE**: Name of an imported Rust target. Note: Parameter may be renamed before release
* **REGEN_TARGET**: Name of a custom target that will regenerate the cxx bindings **without** recompiling. Note: Parameter may be renamed before release
#### Currently missing arguments
Expand Down Expand Up @@ -1570,7 +1572,7 @@ ANCHOR_END: corrosion_add_cxxbridge
#]=======================================================================]
function(corrosion_add_cxxbridge cxx_target)
set(OPTIONS)
set(ONE_VALUE_KEYWORDS CRATE)
set(ONE_VALUE_KEYWORDS CRATE REGEN_TARGET)
set(MULTI_VALUE_KEYWORDS FILES)
cmake_parse_arguments(PARSE_ARGV 1 _arg "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}")

Expand Down Expand Up @@ -1690,6 +1692,9 @@ function(corrosion_add_cxxbridge cxx_target)
$<INSTALL_INTERFACE:include>
)

if(DEFINED _arg_REGEN_TARGET)
endif()

# cxx generated code is using c++11 features in headers, so propagate c++11 as minimal requirement
target_compile_features(${cxx_target} PUBLIC cxx_std_11)

Expand All @@ -1712,6 +1717,8 @@ function(corrosion_add_cxxbridge cxx_target)
COMMENT "Generating rust/cxx.h header"
)

set(GENERATED_FILES "${generated_dir}/include/rust/cxx.h")

foreach(filepath ${_arg_FILES})
get_filename_component(filename ${filepath} NAME_WE)
get_filename_component(directory ${filepath} DIRECTORY)
Expand Down Expand Up @@ -1739,16 +1746,22 @@ function(corrosion_add_cxxbridge cxx_target)
--output "${source_placement_dir}/${cxx_source}"
--include "${cxx_target}/${cxx_header}"
DEPENDS "cxxbridge_v${cxx_required_version}" "${rust_source_path}"
COMMENT "Generating cxx bindings for crate ${_arg_CRATE}"
COMMENT "Generating cxx bindings for crate ${_arg_CRATE} and file src/${filepath}"
)

target_sources(${cxx_target}
PRIVATE
"${header_placement_dir}/${cxx_header}"
"${generated_dir}/include/rust/cxx.h"
"${source_placement_dir}/${cxx_source}"
)
list(APPEND GENERATED_FILES
"${header_placement_dir}/${cxx_header}"
"${generated_dir}/include/rust/cxx.h"
"${source_placement_dir}/${cxx_source}")
endforeach()
target_sources(${cxx_target} PRIVATE ${GENERATED_FILES})

if(DEFINED _arg_REGEN_TARGET)
add_custom_target(${_arg_REGEN_TARGET}
DEPENDS ${GENERATED_FILES}
COMMENT "Generated cxx bindings for crate ${_arg_CRATE}")
endif()

endfunction()

#[=======================================================================[.md:
Expand Down

0 comments on commit 3cb5e82

Please sign in to comment.