0

I'm working on a robot that consists of an ARM based SBC with an AVR based control board and would like to use CMake to manage the builds.

My desire is to just run CMake once and have the build process go through and compile each binary, then embed the AVR firmware into the image for the ARM SBC so that the ARM software can check and update the MCU as needed and without having to manually run 3 independent build process.

From what I'm reading, CMake doesn't like working with more than a single toolchain and thus is not capable of doing what I want it to, which would make sense given the CMAKE_*_COMPILER variables. However, with CMake being such a complex and featureful system, I get the impression that the issue lies more in that it requires some more legwork to actually get it working, but I'm not sure where to start with this. I have clobbered together a handful of CMakeLists in the past, but they have generally not been very complex, so I am not well-versed in everything CMake has to offer when it comes to things that extend beyond basic build needs.

As a bonus, I want this to be something that I can use from VS Code/Codium, and at a glance, the CMake extension doesn't seem to particularly like having multiple, unrelated CMakeLists in the workspace.

To try and summarize, I want CMake to:

  1. Build the MCU firmware using Toolchain A.
  2. Build the software for the ARM SBC using Toolchain B.
  3. Build a Linux-based image containing both that will be written to an SD card.

Are there any existing resources that cover this scenario? Where do I start with this? Do I just have to bite the bullet and stick with Make?

0

1 Answer 1

0

CMake does not naturally supports different C/CXX compilers in CMake Project. However, it does support "subdirs". Which means CMake understand that different project have completely different toolchains.

Just make an independent CMake for the MCU firmware and independent one for the SBC.
The third CMake will be your root CMake, it should add the others as subdirs and make the joint.

https://cmake.org/cmake/help/latest/command/add_subdirectory.html

I want to add correction:

Yes. it seems that toolchain is inherited but you can use set(CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc") magic and others to overcome this.

I think the solution here is just some build script

Sign up to request clarification or add additional context in comments.

4 Comments

"However, it does support "subdirs". Which means CMake understand that different project have completely different toolchains." - No, this is wrong. Different subdirectories still cannot use different toolchains.
If a child CMake calls set(CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc") for example. This will not overwrite the parent CMake. This make sense because subdir is about adding another completely different projects onto your own. If values will overwrite then this feature will be completely broken. It is not just compiler command but also the compiler flags and so on
Compiler language support in CMake is more than just setting (normal) variables. Enabling language in CMake sets many CACHE variables: those variables are global. BTW, the compiler is set as a CACHE variable too. You may have many project() calls in a CMake project, but for every language a compiler is detected only once, during the first call. Every other project() call (including one in the other subdirectory) will use the same compiler.
See that my answer about what happens when one changes a compiler after the first project() call.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.