Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use bin types? #60

Closed
kjeremy opened this issue Oct 7, 2020 · 7 comments
Closed

Is it possible to use bin types? #60

kjeremy opened this issue Oct 7, 2020 · 7 comments

Comments

@kjeremy
Copy link
Contributor

kjeremy commented Oct 7, 2020

I'm looking into building some ROS nodes using a combination of corrosion and https://github.com/adnanademovic/rosrust

The examples show linking cpp and rust together but what I want to do is use corrosion to build my rust binary and then refer to it elsewhere in my cmake file (for instance in an install step).

@AndrewGaspar
Copy link
Collaborator

Yep, that's definitely supported! You're going to want to do something like this:

add_custom_command(
    OUTPUT my_output.txt
    COMMAND $<TARGET_PROPERTY:my-bin-crate,IMPORTED_LOCATION> -o my_output.txt
)

@AndrewGaspar
Copy link
Collaborator

You might not need the generator expression if you're just using it for install, though. The generator expression is mostly to make sure that my-bin-crate is built before trying to build my_output.txt (it sets up the dependencies correctly). To customize install, you'll need to write an install script, which can then use your bin crate after you've built: https://cmake.org/cmake/help/latest/command/install.html?highlight=install#script

@kjeremy
Copy link
Contributor Author

kjeremy commented Oct 7, 2020

I will have to read up on this (I am not a cmake expert). Typically for C++ projects using catkin this goes something like:

cmake_minimum_required(VERSION 3.0.2)
project(publisher_node)

find_package(catkin REQUIRED)

catkin_package()

add_executable(${PROJECT_NAME}_node src/ros_test_node.cpp)
install(TARGETS ${PROJECT_NAME}_node
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

I was hoping for a way to just refer to the crate output in install(TARGETS

@AndrewGaspar
Copy link
Collaborator

Oh, I misunderstood. I thought you were trying to use the bin as part of install. You just want to install the bin.

Yeah, unfortunately CMake doesn't let you refer to imported targets in install(TARGETS. However, I added a custom function that behaves basically like install(TARGETS specifically for Corrosion targets. You can see an example usage in Corrosion itself: https://github.com/AndrewGaspar/corrosion/blob/master/CMakeLists.txt#L55

The function "signature" for corrosion_install is here: https://github.com/AndrewGaspar/corrosion/blob/master/cmake/Corrosion.cmake#L327

@kjeremy
Copy link
Contributor Author

kjeremy commented Oct 8, 2020

Thanks for the advice. corrosion_install works perfectly when I do an install. I think I have one more issue that I need to solve. catkin_package sets a bunch of variables including CMAKE_RUNTIME_OUTPUT_DIRECTORY so that libraries via add_library and binaries via add_executable get put into a devel space. Is it possible to support that in corrosion_import_crate?

@AndrewGaspar
Copy link
Collaborator

It's not out of the question, but it's probably not priority for v0.1 - currently libs and bins aren't even copied out of the cargo build directories. I've filed an issue: #65

@jschwe
Copy link
Collaborator

jschwe commented Apr 11, 2022

Looks like the original issue was solved, and a separate issue was created for the documentation. Feel free to reopen if I'm missing something.

@jschwe jschwe closed this as completed Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants