We're writing an application for an embedded ARM/Linux device. Development is performed on a Windows PC, using a crosscompiler, Eclipse and Ninja. CMake currently can create the build scripts that work well for the intended purpose.
We have unit tests that run on the embedded device attached to the net, once the project is pushed (over Git) to the server.
We're trying to implement unit tests, that would run on the PC, before we try them on the device. That means building natively, using MinGW GCC - of course we can't launch the ARM Linux executables on the PC.
Even if we switch the toolchain, launching CMake to rebuild the ruleset for Ninja, or create two build directories, one for PC, one for ARM, the problem remains that CMake will try to run a test executable, and later during build, unit tests will be attempted on the ARM build.
How can we configure the builds (through CMake) to create both - and not attempt to run the crosscompiled ones on the PC?
CMAKE_CROSSCOMPILING. See e.g. How to instruct CMake to use the build architecture compiler?.add_custom_command(TARGET ... POST_BUILD ...)and/or withadd_test()? I think in both case just putting aif (NOT CMAKE_CROSSCOMPILING)|endif()around this particular command should do the trick.ADD_SUBDIRECTORY(UnitTests). Then in the directory there'sExternalProject_Add(GMockDownload GIT_REPOSITORY "https://github.com/google/googletest.git" ...which does the rest of the work. Yes,if (NOT CMAKE_CROSSCOMPILING)helps here. It seems two separate build dirs and launching cmake twice is the way. Not optimal, because I'm getting two Eclipse projects instead of merely two Build Configurations.