I have a configuration class that I would like to use for a variety of builds. The class itself changes between builds, but the class name remains the same, as does the header file name.
The separate versions of this class are held in separate subfolders.
ex.
-
main/config.h
-
main/config.cpp
-
secondary/config.h
-
secondary/config.cpp
Is there a good way to, through a compile-time flag or command line option, have the build determine which header/cpp to use? I have quite a few configurations already, and expect to have many more in the future. I would like to avoid a long list of #ifdef/#elif/#elif/etc..
edit: I would like to avoid having separate builds, and would like to avoid using #defines throughout the code. I’m sorry if I didn’t make that clear before! >_<
Depending on what build system you are using you would create a variable that points to the main or secondary path. This variable is then used to append to the
INCLUDEpath so all of your sources can just#include "config.h"when they need access to config. In your Makefile (or equivalent) you will need to add the$CONFIGPATH/config.cppto your sources to build.MSBuild
Update source file paths:
And the include path:
Then call
msbuild build.xml /p:ConfigToUse=PathToConfig