SQLiteCpp icon indicating copy to clipboard operation
SQLiteCpp copied to clipboard

Make the library header only

Open DraTeots opened this issue 8 years ago • 7 comments

Is there anything, that prevents converting this library into a header only library?

I believe it would be very convenient in many aspects.

DraTeots avatar Jul 21 '17 20:07 DraTeots

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)

SRombauts avatar Jul 24 '17 07:07 SRombauts

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.

DraTeots avatar Jul 24 '17 18:07 DraTeots

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>;    

DraTeots avatar Jul 25 '17 19:07 DraTeots

Yes sure, also such namespace comments are already enforced by the Python cpplint script :)

SRombauts avatar Jul 26 '17 08:07 SRombauts

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:

  1. Is single_header/SQLiteCpp.h OK?

    Or single_header/SQLiteCpp/SQLiteCpp.h?

    Better naming? Ideas?

  2. 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_HEADER and make all tests like:

    #ifndef TEST_SINGLE_HEADER
    #include <SQLiteCpp/Backup.h>
    #include <SQLiteCpp/Database.h>
    #else
    #include <SQLiteCpp.h>
    #endif   // TEST_SINGLE_HEADER
    

    TEST_SINGLE_HEADER?
    TEST_HEADER_ONLY? - better naming?

  3. Add one more target with TEST_SINGLE_HEADER definition 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?

  4. One has to add -std=c++11 to compile with the single header.

  5. This single include definitely shell not pass cpplint. I think this is OK.

DraTeots avatar Aug 16 '17 22:08 DraTeots

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 avatar Aug 21 '17 14:08 SRombauts

@SRombauts check out amalgamate

pratikpc avatar Feb 02 '19 20:02 pratikpc