cmake-rs
cmake-rs copied to clipboard
return static libraries required for linking
After building a static library it would be great if we could get the required list of libraries that need to be passed to the rust linker. If the cmake files use targets this info will be available.
I had the same issue and what I ended up is:
- Use https://github.com/Interstellar-Network/cmake/blob/main/export_libs.cmake to generate
cmake_generated_libswhich contains a list of all STATIC and SHARED libs used by the given TARGET - Parse this file in build.rs to set the correct
cargo:rustc-link-searchandcargo:rustc-link-libcf https://github.com/Interstellar-Network/rust-cxx-cmake-bridge
It works, and is reasonably resilient (ie OK for both local and system libs, STATIC and SHARED) but it is a messy way to workaround the lack of communication between rust and CMake.
IMPORTANT: if you want to link with IMPORTED lib ie all those coming from find_package (eg Boost) you MUST set them GLOBAL eg set_target_properties(Boost::filesystem PROPERTIES IMPORTED_GLOBAL TRUE)
I would happily take a cleaner approach if there is one I have missed!