I am compiling 4 different programs, each using a lot of the same core functions and files. One of the programs requires access to a large third party library, the others do not.
I have created an "options" structure suitable for all 4 programs. The way the options structure is filled out however can differ depending on the program which is to be used. Most of it is trivial stuff... "do I write to stdout?", etc. However, one of the programs, in the options function, may attempt to access those functions calling the large third party libraries if some information is not available. Moreover, it must do this before the rest of the options can be processed, and its purpose is intricately tied to task of options processing.
How would you set up the source code in files suitable for this? Here are some choices as I see them:
1. Use one options.cpp file, and link everyone against the large library.
2. Use one options.cpp file, and move the offending line of code elsewhere.
3. Tie the options processing, usage statements, etc., into the same file containing the main() for each program.
4. Create different .cpp files for the filling out of options data (p1-options.cpp, p2-options.cpp, ...) where each program links only to the instructions for options filling that it needs.
5. Create one options.cpp file, with #ifdefs for each program. Use makefile trickery to compile different options object files (p1-options.o, p2-options.o, ...) all from the same one source file.
I like option 5 the best, which is to say I don't like it much, but I have yet to come up with a better thought as to how to do it. Hence the request for suggestions/comments. As per my thoughts on each:
1. Unnecessary Bloat
2. Not a reliable solution for the future
3. Creates too much code in the files containing main()
4. Not very elegant, and a larger traversal should an option need to be changed. Basically more clunky than (5).
5. Still clunky
Thanks!