Description
Improve the cangen-cmake interface.
Currently we use the include
command to effectively "copy and paste" the contents of firmware/cmake/cangen.cmake into the project's CMakeLists.
# TMS/CMakeLists.txt
include("${CMAKE_SOURCE_DIR}/cmake/cangen.cmake")
target_sources(main PRIVATE main.cc)
This is a pretty rough interface. A better solution would wrap the existing cangen.cmake
logic inside a cmake function and call this function in each project. Thus the project's CMakelists would look something like
# updated TMS/CMakeLists.txt
cangen_generate()
target_sources(main PRIVATE main.cc)
Task
- Create a function as above.
- To bring the function into scope, include the
cmake/cangen.cmake
file in the top-level CMakeLists, as is done forfunctions.cmake
here/This does not call the function, it only makes it available for calling later.
- Add a comments at the top of the function's file describing how and where to use it (should just be a sentence or two).
Is there a standard CMake documentation / docstring format? Like something that would show your comment when you hover over it in the editor.
- Update each project's CMakeLists to replace the existing
include
with your function call
Considerations
The existing code defines a generated_can
target and links it to main
. It still must do this, but your function should clearly document the name of this target since some projects (namely Demo/TestCangen
) need to use it explicitly