Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for external sqlite3 #234

Merged

Conversation

emmenlau
Copy link
Contributor

This PR adds support for an externally compiled SQLite3. There are two main changes:

  1. Detect and use SQLite3 via cmake if requested by the user, and
  2. Always link SQLiteCpp against cmake detected Threads::Threads and DL-libs.

The second change is a simplification and cleanup. SQLite3 always requires threads and DL-libraries. Therefore it seems not sensible to specify them individually for each target.

This PR also uses cmake standard functionality to detect the actual threads-implementation and DL-libraries for the current platform. This should improve portability to other (less common) platforms that may not use the name pthreads but another threading library name.

@SRombauts
Copy link
Owner

Hello @emmenlau

Thank you for all your pull requests!
I am don't know if you have noticed, but all CI tests failed on this one?

In the meantime, I believe that I have merged another pull request similar to this one.

Cheers!
Sébastien

@SRombauts SRombauts closed this Dec 26, 2019
@SRombauts SRombauts reopened this Jan 9, 2020
@SRombauts SRombauts self-assigned this Jan 10, 2020
@SRombauts
Copy link
Owner

Hello @emmenlau, looking back at this one, I see that there are still very valuable bits here!

Would you have the time to rebase it onto the new master branch?
If not, I will hopefully find some time to do it at a later time.

Cheers!

@emmenlau emmenlau force-pushed the emmenlau_support_external_sqlite branch from 07a0c0a to 09ef77b Compare January 10, 2020 13:30
@emmenlau
Copy link
Contributor Author

Dear @SRombauts , I've just reviewed the upstream changes and I think that some relevant parts have not been answered by the previous MR. I've therefore updated my PR accordingly.

This PR changes/improves multiple things:

  • It transitively links SQLiteCpp against either the included sqlite3 or the system sqlite3
  • It generalizes the linking against dl and thread libraries on Linux/Unix/Mac, so that this works for all targets and also is passed transitively to downstream projects
  • Due to the transitive linking of sqlite3, dl and threads, the CMakeLists.txt can be simplified and cleaned a bit, and downstream projects work more comfortably

@emmenlau
Copy link
Contributor Author

But one question: SQLiteCpp can be built against an internal sqlite3. However this internal sqlite3 is never installed. Is this intentional? It seems not sensible to allow building required dependencies but then leaving it to the user to resolve them for downstream projects?

Would it not be better if the internal sqlite3, if built, is installed alongside SQLiteCpp?

@SRombauts
Copy link
Owner

Oh yes, for sure, the thing is I never use this kind of "install" workflow

@emmenlau
Copy link
Contributor Author

Ok I'll give it a shot!

@emmenlau emmenlau force-pushed the emmenlau_support_external_sqlite branch from 09ef77b to 8554155 Compare January 13, 2020 14:06
@emmenlau
Copy link
Contributor Author

Ok I've implemented installation instructions for the internal sqlite3. To add a cmake export for the internal sqlite, I've followed the guidelines given in https://stackoverflow.com/questions/36103012/cmake-dependency-management-in-a-multi-library-package-export. I've tested the solution with and without internal sqlite3 and it works for me. However I must admit that the size of the change is big enough that I can not 100% guarantee it covers all cases. I'm curious about the result from your CI testing.

@emmenlau
Copy link
Contributor Author

emmenlau commented Jan 13, 2020

Please ignore this comment, it is deprecated with the latest version.

@emmenlau emmenlau force-pushed the emmenlau_support_external_sqlite branch 3 times, most recently from e0bda1f to 608ef2d Compare January 13, 2020 15:03
@coveralls
Copy link

coveralls commented Jan 13, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling a166062 on BioDataAnalysis:emmenlau_support_external_sqlite into 8485bb7 on SRombauts:master.

@emmenlau
Copy link
Contributor Author

Dear @SRombauts , I've continued to improve the cmake instructions in this PR. In order to support internal or external sqlite3 very cleanly, I've removed the generic line

include_directories("${PROJECT_SOURCE_DIR}/include")

and instead used specific includes with target_include_directories(PRIVATE for every target. This does not add much more code, but its the recommended clean code for "modern cmake". It can help in the future to discover targets dependencies and wrong/incorrect includes, because every target only has their minimal includes set.

Is this ok with you?

@emmenlau emmenlau force-pushed the emmenlau_support_external_sqlite branch 2 times, most recently from a9cfc40 to 980e313 Compare January 13, 2020 19:52
@SRombauts
Copy link
Owner

Hello, fun fact, I have already removed the line "include_directories("${PROJECT_SOURCE_DIR}/include")" yesterday evening on master ;)

@emmenlau emmenlau force-pushed the emmenlau_support_external_sqlite branch from 980e313 to a166062 Compare January 13, 2020 20:14
@emmenlau
Copy link
Contributor Author

Haha ok! I think all builds should now show green lights. If nothing else comes up, can this be merged?

@SRombauts
Copy link
Owner

Yes, it looks good too me... even though we don't actually test the installation itself, nor the use of it by a test project.

Adding an installation step and checking the result should be fairly easy I guess.
Testing the use of the installed library might be a bit more involving: I do have a separate SQLiteCpp_Example project, but perhaps could we even do that directly in here

@emmenlau
Copy link
Contributor Author

For what its worth, I've checked the installation in our CI on the three major platforms Win, Lin and Mac, and could use the installed sqlite3 in downstream projects. And this PR also makes SQLiteCpp usable with a completely external sqlite3 for me, which previously caused some issues...

@SRombauts SRombauts merged commit 91fe2d7 into SRombauts:master Jan 13, 2020
@SRombauts
Copy link
Owner

Very good, thank you for your contribution!

I'll see if I can automate some tests to avoid any regressions around these kind of sensitive features.

Cheers!

@emmenlau
Copy link
Contributor Author

Great, thanks!

@emmenlau emmenlau deleted the emmenlau_support_external_sqlite branch January 17, 2020 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants