Hello,
parts of our codebase is constructed to have config files which define class members in a specific header file for each variant.
E.g. in Class.cpp:
#if defined(VARIANT_1)
#include "Config_Variant_1.h"
#elif defined(VARIANT_2)
#include "Config_Variant_2.h"
#endif
In Config_Variant_1.h
#ifndef CONF_VAR_1
#define CONF_VAR_1
#if defined(VARIANT_1)
uint8_t Class::MemberVar = 1
// ... More config ...
#endif // VARIANT_1
#endif // CONF_VAR_1
Config_Variant_2.h looks very but has some variables / array entries changed. SonarQube not detects a lot of code duplications since we have multiple Variants who have a lot of configuration in common. Putting everything in one file and only separating changes behind defines is no option.
What can I do to get rid of all the code duplication code smells? I already tried checking for global define with preprocessor twice (when including file and in config file itself). And why is it in first place allowed to scan files that are locked by a define that is never set in first place?
We build with scons build wrapper in Azure pipeline and scons has properly defined variants and global defines.
Thank you
Marius