How do you set up the appropriate compiler macros?
If the logic of definition of the compiler macro is done in CMake you can use the same logic
to add (or not add) source to a particular target.
Using https://cmake.org/cmake/help/latest/command/target_sources.html guarded by appropriate condition seems a good use case.
See: Enhanced source file handling with target_sources() - Crascit