I use CMake+ninjabuild as the top level build system
- there is a C++ static library called
foowhich is built by CMake
- There is a C++ executable called
- There is a Rust execuable called
example-rs, which is built inside CMake by
add_custom_command(COMMAND cargo build -p example-rs)
This executable need to link
What is the best way to specify that
example-rs needs to build after
cmake --build . --target all to build all of
Currently it is done by
add_custom_command(COMMAND cargo build -p example-rs DEPENDS foo)
But this makes
cargo test be unware of the dependency, so I have to manually rebuild
cargo test during development
The alternative solution would be using
cmake crate in
but I do not know how to solve the diamond problem.
The top level cmake and the cmake called within
build.rs uses the same CMAKE_BINARY_DIR,
The top level cmake and build.rs cmake may both compile
foo in parallel,
so this may cause a conflict in disk file.
The problem above may be solved by using both
but what if there are two Rust executables within CMake project, which both needs to link
cargo test, if both of them rebuilding
build.rs, there is also a conflict.
NOTE: Creating multiple cmake build directory (CMAKE_BINARY_DIR) is not preferred.
The project is big and CMake configuration takes several minutes.