I have a C++ repository for a header-only library (built via CMake, although that's not critical). Its structure is roughly:
include/
mylib.hpp
mylib/
foo.hpp
bar.hpp
Now, I know some popular C++ libraries are maintained as single-header files. I don't like dumping everything into a kitchen-sink file; but at the same time I can well appreciate the convenience of being able to utilize a library by just downloading a single file.
So, I was thinking - maybe I can just generate the single header file as part of the installation process?
Supposedly this is a "simple matter of prerocessing"; but - it's not actually quite that simple:
- I don't want to fully preprocess the C++ files, just
#includedirectives. - Not all include files are relevant - only the files under a certain source tree.
- During actual compilation, the same file is included multiple times (ignoring potential compiler optimizations against doing so), with the second-and-later copies typically removed later using include guards or
#pragma once; in my case one would need to watch out and prevent double includes.
So, my question: How do I go about doing this?
Note:
- A CMake-based method would be nice, but anything reasonable goes.