I'm looking for a system to be able to configure my C++ project to compile some sections of codes and not others depending on what target hardware I'm compiling for. The area of development is software for computers onboard unmanned vehicles (e.g. drones, small fixed-wings, rovers). So, for example, if I'm building for a drone that has a certain set of sensors, and certain kinematics, I want only the code for the sensors that will be onboard that vehicle to compile. I know I can create feature flags with macros, such as something like:
#define ULTRASONIC_SENSOR_AVAILABLE 1 #define TARGET_VEHICLE_TYPE_DRONE 1 #define TARGET_VEHICLE_TYPE_ROVER 0 #define TARGET_VEHICLE_TYPE_PLANE 0
But this seems clunky and very error prone. There's also no way to store a certain "loadout" -- the exact set of flags that should be turned on or off for a specific, frequently built target.
Do any solutions exist that help with this problem?