First up, if setting your minimum CMake version to 3.14 is an option, a much simpler path is to make use of the SQLite3 find module:
cmake_minimum_required(VERSION 3.14)
project(My_SQLiteCpp_Example)
# Augment the search path before calling find_package(), but you'd typically leave this
# for the user to do rather than hard-code it directly in the project like this. You might
# also need to do some extra work to account for the architecture subdir below lib.
list(APPEND CMAKE_PREFIX_PATH /home/llist/kdedev)
find_package(SQLite3)
add_executable(My_SQLiteCpp_Example src/main.cpp)
target_link_libraries(My_SQLiteCpp_Example PRIVATE SQLite::SQLite3)
If you can’t make 3.14 your minimum CMake version, then I guess we’re stuck with having to do it manually like your original method.
This will leave finding the sqlite3 library to the linker instead of using the library you found earlier in the call to find_library().You need to replace sqlite3 with EXTLIB and the way the imported library is defined is also incorrect. It should look more like this (untested):
Thanks for the quick reply. If I understand your answer correctly I realized that I didn’t provide enough info.
I using an external product (SQLiteCpp) that wraps sqlite calls for c++. The product has its own cmake file and has been built and tested ok.
For the time being, there is no intention to (re)build SQLiteCpp as part of my small test project. All I need right now is the libSQLiteCpp.a which is currently in a non standard folder /home/llist/kdedev/lib/x86_64-linux-gnu and the .h files, currently in /home/llist/kdedev/include.
The sqlite development files are installed as part of my Ubuntu install.
Thanks
Note that BEFORE is being added as a header search path. This is because BEFORE has to be placed before the PUBLIC keyword in the call to target_include_directories(), not after it. This won’t have caused any build errors though.
Note the -lsqlite3 here. As I mentioned earlier, that is asking the linker to find a sqlite3 library somewhere on its library search path. There is also nothing on this link line asking the linker to link in the libSQLiteCpp.a library. If you want that on your link line, you need to call target_link_libraries() to tell it to do that. If I’m understanding your situation correctly now, you need this:
Assuming the external libraries are in a standard place, the following does what I need.
++++++++++++++++++++++++++++
cmake_minimum_required(VERSION 3.10)