Has anyone used CMake/CPack to package compiled Rust applications, and if so, how did you obtain the locations of the compiled executables?
I have a simple standalone Rust project that I’d like to package into an installer with CPack. I can build the application just fine with cargo
or via Corrosion (GitHub - AndrewGaspar/corrosion: Marrying Rust and CMake - Easy Rust and C/C++ Integration!)-- the problem is locating the compiled artifacts (i.e. the executable) to pass to install()
. See How to identify compiled artifacts for packaging with CPack? · Issue #117 · AndrewGaspar/corrosion · GitHub and Building Rust binaries in CMake project(?) · Issue #5 · micahsnyder/cmake-rust-demo · GitHub for details.
With C/C++/Fortran code I typically have a compilation target name that I can pass to install(TARGETS)
, otherwise I use install(FILES)
or install(DIRECTORY)
when I can reliably predict where the compiled results are located. CPack handles the rest. CMake is not strictly necessary here since cargo
handles all the build tasks I currently need. I use a simple CMake recipe as a driver for CPack (standalone CPack configuration makes no sense to me).
Corrosion (formerly cmake-cargo
) works well enough as a driver for cargo
but doesn’t seem to expose the location of the generated binaries or target names that CMake could use with install(TARGETS)
Since I’m building a single executable and since Corrosion seems to hard-code the build type as Debug
, I’ve worked around the issue just by hard-coding the expected location of the executable in CMakeLists.txt
and modifying the file extension if WIN32
is set. It’s brittle and I don’t like it; hopefully someone else has successfully packaged Rust applications in a more elegant manner.