Project with Native & Cross-compile Targets

My C++ VS Code project has multiple native executables & multiple cross-compiled executables. Some of the executables are compiled native and cross-compiled. All executables use the same library.

Is it possible to do this with one project? I would like to do it in one project because I don’t want the same source code in two places. Also, all of the executables are part of the same physical product.

I’d like to end up with something like:

  • foo - compiled with native compiler
  • foo - compiled with PowerPC compiler
  • bar - native
  • baz - PowerPC

I’d like to be able to edit a cpp file and just compile the specified target and then run it, for a quick debug cycle.

I’m using Ubuntu 20.04, Visual Studio Code, make. I would consider using Ninja if that would help.

Is this possible??? Can you give me any pointers?

Thanks!

CMake doesn’t support targeting multiple platforms in the same build (with the exception of the Xcode generator for Apple platforms). You can however use ExternalProject to coordinate sub-builds where you compile for the native platform in one sub-build and the PowerPC platform in another. Each sub-build will effectively act like its own isolated sub-build, unaware of the other. The top level project would just be a relatively lean co-ordination layer. This is typically referred to as a superbuild and is generally the recommended approach for your scenario.