Correct usage of FindSQLite3 module in Windows

Hi Ben,

My understanding is that the .dll is required for both: linking and at runtime.

After looking closer at the FindSQLite3.cmake module’s source code and further investigating CMake commands find_path & find_library, which are used by the module to set variables SQLite3_INCLUDE_DIR & * SQLite3_LIBRARY* respectively, I came up with the following solution:

add_executable(sqlite-cache sqlite-cache/main.cpp)

if(WIN32)
  set(CMAKE_PREFIX_PATH C:\\sdk\\sqlite-3.30.1)
endif()

find_package(SQLite3 REQUIRED)
target_include_directories(sqlite-cache PRIVATE ${SQLite3_INCLUDE_DIRS})
target_link_libraries(sqlite-cache ${SQLite3_LIBRARIES})

According to the documentation of find_path and find_library commands, one of the steps of their search algorithm is to look inside paths specified in CMAKE_PREFIX_PATH; per these commands documentation will search for include paths as:

<prefix>/include/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and <prefix>/include for each <prefix> in CMAKE_PREFIX_PATH

and for libraries as:

<prefix>/lib/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and <prefix>/lib for each <prefix> in CMAKE_PREFIX_PATH

As you can see, the commands enforce that headers must be inside an include/ dir and libraries inside a lib/ dir and since my SQLite installation happens to have that format, then the solution above works. The search algorithm also looks in directories declared in system env vars like PATH and INCLUDE, but I prefer this approach since headers & libraries will be found faster.

2 Likes