Ignore targets incompatible with given system processor?
Hi!
I want to ask if there's any neat solution to the following use case in CMake. I have a project that contains:
- x86-only code (e.g. google tests)
- arm-only code (e.g. low-level device drivers)
- generic code that is hardware agnostic and should be built for any platform.
Now, I'm aware that with CMake it's only possible to built for one platform at a time, and this is selected via the toolchain file. What I'm interested in knowing is how to skip building targets that are not compatible with the platform at hand. I normally build with just make
, so I guess what I'm after is connected to EXCLUDE_FROM_ALL
.
For example, if I want to build for arm, I want to skip building the unit tests that only work on x86. Currently my solution is not very clean:
if CMAKE_SYSTEM_PROCESSOR == "x86_64"
add_executable(unit_test)
endif()
My CMakeLists.txt
s are full of those if
branches and I'm looking for a cleaner solution. Preferably this information should propagate transitively (INTERFACE
), i.e. if I set a low-level library to only be compatible with arm
, then any other target depending on it should also only be compatible with arm
.
Thanks!