Make the library header only
Is there anything, that prevents converting this library into a header only library?
I believe it would be very convenient in many aspects.
Yes, sure, this should be very convenient. I went for this at the very beginning, but then wanted to move to more traditional dev and reduce compile times inherent to headers only.
If one can make a Python script to generate a big header file out of the many sources files, I could upload the monolithic header with each release (somewhat like the sqlite Amalgation source file)
I could look into it. I saw something like this in the Catch unit test framework. While their script combines only headers, maybe It would be easy to adjust it.
Looked the code, python scripts and thought about the particular python script. I would prefer not to use full scale C++ parsing facilities.
So would it be acceptable to make some current code styling to be required. Like putting comments about closing name spaces?
} // namespace SQLite
Such comments are already there but only as a matter of better readability, while they will become required for the script to work. Same goes for some other formatting choices like putting extern const definitions in one line.
extern const .... <VeriableName>; // GOOD
extern const // BAD
.... <VeriableName>;
Yes sure, also such namespace comments are already enforced by the Python cpplint script :)
Ok! Suppose I have a python file that generates a single header (I actually do):
single_header/SQLiteCpp.h
It compiles, tests are passed. How to integrate it in CMake build, tests, CI etc? Need your opinion as a library author:
-
Is
single_header/SQLiteCpp.hOK?Or
single_header/SQLiteCpp/SQLiteCpp.h?Better naming? Ideas?
-
What I did now, I copied (bad!) tests to a separate directory and changed their includes to a single header version. What I would do is to introduce one more definition option like
TEST_SINGLE_HEADERand make all tests like:#ifndef TEST_SINGLE_HEADER #include <SQLiteCpp/Backup.h> #include <SQLiteCpp/Database.h> #else #include <SQLiteCpp.h> #endif // TEST_SINGLE_HEADERTEST_SINGLE_HEADER?
TEST_HEADER_ONLY? - better naming? -
Add one more target with
TEST_SINGLE_HEADERdefinition to CMake. Something like this:add_executable(SQLiteCpp_sh_tests ${SQLITECPP_TESTS}) target_compile_definitions(SQLiteCpp_sh_tests TEST_SINGLE_HEADER)And use it in CI Or is there a better way?
-
One has to add
-std=c++11to compile with the single header. -
This single include definitely shell not pass cpplint. I think this is OK.
Hi @DraTeots, I am sorry but I am very busy at the moment...
We should probably move one step by one step: if you can provide the scrip, I can run it manually to release the monolithic header as a downloadable file.
I am not too eager to complexify the CMake files nor do I need to automate testing on it.
Cheers!
@SRombauts check out amalgamate