azadkuh / sqlite-amalgamation

The SQLite amalgamation mirror with cmake
http://www.sqlite.org/amalgamation.html
BSD 3-Clause "New" or "Revised" License
92 stars 63 forks source link

"Could NOT find SQLite3" error when building project depending on sqlite #2

Closed tetsuhaut closed 4 years ago

tetsuhaut commented 5 years ago

Hi Amir,

First of all thank you for your project, it's great to be able to use sqlite as a regular CMake project.

However, I had problems using it. I hope you are able to answer my few questions, as it could be useful for others.

I have built and installed the sqlite-amalgamation project.
To integrate the sqlite3 library to my project, I have used the way recommended in https://github.com/azadkuh/sqlite-amalgamation/blob/master/README.md:

find_package(Sqlite3) target_link_libraries(myProjectName sqlite3::sqlite3)

Unfortunately, I have an error message when trying to build my project with cmake:

-- Could NOT find SQLite3 (missing: SQLite3_INCLUDE_DIR SQLite3_LIBRARY)

I am using CMake 3.15.4. I have seen that it contains a share\cmake-3.15\Modules\FindSQLite3.cmake file.
Is your project intended to be found with it?
I supposed those two variables SQLite3_INCLUDE_DIR and SQLite3_LIBRARY are hints for CMake's find_package to find the include dir and library file. If so, it should be mentionned in the README.md that the user needs to pass those to cmake.
Another question, why do I have to provide the sqlite library file path ? Wouldn't I have to provide the library directory instead?
Last question, once I have provided both, I have to do #include sqlite3.h instead of #include sqlite3/sqlite3.h. Is it normal?

azadkuh commented 5 years ago

@tetsuhaut

to make the story short, we've better to separate this repository from system sqlite (which is already available on linux, android, macOS, ...).

so you can use any sqlite version you want along with any build option you need without messing up with system sqlite and system apps.

this is the main reason for using different include/link path.

azadkuh commented 5 years ago

@tetsuhaut

cmake by default finds the system sqlite library which is a different library.

depending on where you've installed this repository by make (or ninja) install, your application needs to know the location of installation, to be able to find this library, its include-path and build options.

for example if you've installed this repository into /opt/usr (please check CMAKE_INSTALL_PREFIX), then in your application build dir:

app_build_dir$> cmake app_source_dir -DCMAKE_PREFIX_PATH=/opt/usr [...other options...]

ref:

azadkuh commented 4 years ago

please check new commits on master branch