I am trying to figure out the correct (or perhaps least convoluted) way to create the setup I need.
I am building C++17 software for an embedded device using Visual studio 2022. The target device is a custom OS, but it is linux based and I have a cross compilation SDK. It is an ARM cpu. The compiler for it is based on gcc/g++ (version 9.1 if I am not mistaken). This cross compiler requires a linux system to run on. The target device has most linux tools, but is limited in power. Too limited to do the compilation.
My laptop and preferred system is a windows 11 computer. I use modern CMake as build tool.
What I (think I) want: I think I should configure my setup to build on WSL locally on my laptop from VS. Then I should deploy the application to my target embedded device. Then when debugging I should connect my VS to the gdb on the target.
The problem I have is that I am getting quite confused in which path to start following for setting this up. Using the documentation from microsoft learn (https://learn.microsoft.com/en-us/cpp/build/get-started-linux-cmake?view=msvc-170) I can set up to build on WSL using CMakeSettings.json. That is easy and works, but it is very visual studio specific and I have to keep in mind that later this all needs to run on Azure devops pipelines as well. So usually I try to use CMakePresets.json instead, which is more portable, but the overlap between both is not exactly the same.
Reading the information on cmake (https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html), it suggest to use a toolchain file to contain the information about the cross compiler to use. So that points to the SDK I installed on WSL. But those paths have my user name involved, so again, not portable to Azure devops or other developers.
But cross compiling as explained in the learn.microsoft link is about using windows to compile and run on linux. I also found this manual: https://devblogs.microsoft.com/cppblog/arm-gcc-cross-compilation-in-visual-studio/ which seems to be closer to what I need, but there they start to define tasks in a tasks.vs.json file. Which suggests that there is no build-in support for what I desire to do?
So, all in all, I am struggling to understand which path will lead me to a solution (or the best?):
- Can I set this up with cmake files (CMakePresets and CMakeUserPresets) in combination with a tool chain file? Will visual studio then be able to interpret this and correctly execute it (knowing that I will need to point it towards 2 different machines/platforms: one to build and one to deploy)?
- Or is it so that I can use CMake only to do the cross compilation part and that I have to add a manual launch.vs.json (or is it task.vs.json) to get the deployment/debugging running on the target device?
- Or do I have to stick to CMakeSettings.json?
If anybody can give me guidance on how Visual studio supports this setup (which I can only imaging to be pretty common), or point me to some tutorials on this topic, I would be very happy.
Preferably keeping in mind that I will need to also run my project on Azure devops for automatic unit testing and acceptance testing.
Thank you in advance.
PS: I am including the Q&A AI assist solution. It seems to go in the direction I think I need to go, which is the combination of the 'cmake-way' for the cross compilation, and then the 'VS-openFolder-Launch' way to get the deployment/debug part working. But it would be nice to get this confirmed by somebody who has experience in this.