rtlabs-com / c-open

CANopen stack for embedded devices
http://www.rt-labs.com
Other
79 stars 40 forks source link

Fix CMake to be able to use c-open as a submodule #2

Closed nattgris closed 4 years ago

nattgris commented 4 years ago

Export the required include directories for use in a toplevel build which includes this repo as a submodule/subdir and uses it like this:

add_subdirectory (lib/c-open) target_link_libraries (slave PUBLIC canopen)

Remove the weird and now unnecessary coupling between the example slave/master and the platform cmake files.

nattgris commented 4 years ago

This is just random hacking until it built, while trying to learn as little CMake as possible.

hefloryd commented 4 years ago

Thanks for the patch. The osal lib and headers are not exported because they were considered internal implementation details. However, the osal layer is used in a few of our projects and seems useful on its own so we will probably move it to its own repo.

I'm not sure you wouid need it unless you use the osal layer in your own application (like the example does)?

Also note that with the update to "modern" cmake we export a CMake config file and you should do something like this in your CMakelist:

find_package(CanOpen) # Sets up includes/libs target_link_libraries(myprogram PUBLIC CanOpen)

(assuming you have built and installed the canopen files somewhere CMake can find them).

With that said we could consider exporting the osal files until we have created the separate repo.

nattgris commented 4 years ago

I just wanted to get a project structure up and running and the slave example seemed like a good minimal application to get started. The osal layer is perhaps not needed, but since my next project won't have any hardware for some time, I might be able to get something running on linux in the meantime so maybe the osal layer is a good solution anyway.

Still considering whether we should port our application over to this stack or not.

The find_package() method seems like unnecessary complication when you could just point out the subdir of the lib directly, without any "installation"?

nattgris commented 4 years ago

Removed the osal changes from this PR, now just fixes the CMake variable so c-open can be used in a subdir/submodule.

hefloryd commented 4 years ago

Merged, thanks!