Correct usage of FindSQLite3 module in Windows

Hi all,

I’ve been using module FindSQLite3.cmake that comes bundled into CMake’s installation for finding SQLite3’s include dir and library under Linux and macOS. Recently, I’m working on porting one of those projects to Windows and ran into the issue that the module is not able to find SQLite3. So, my question is:

Can this module be used in Windows?

and if so

What additional configuration is required?

I’m wondering if the issue is related to where I installed SQLite’s binaries and sources. This is how my installation looks:

  • C:\sdk\sqlite-3.30.1
    • include\
      • shell.c
      • sqlite3.c
      • sqlite3.h
      • sqlite3ext.h
    • lib\
      • sqlite3.def
      • sqlite3.dll

I noticed that if in my CMakeList.txt file I set variables SQLite3_INCLUDE_DIR and SQLite3_LIBRARY to the corresponding paths matching my SQLite3 installation, the module executes with no errors but if I have to explicitly set those paths then to use the module makes no sense anymore. Nonetheless, I’m still calling the modules in order to keep my build cross-platform. This is the relevant part:

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

if(WIN32)
  set(SQLite3_INCLUDE_DIR C:\\sdk\\sqlite-3.30.1\\include)
  set(SQLite3_LIBRARY_DIR C:\\sdk\\sqlite-3.30.1\\lib)
  set(SQLite3_LIBRARY sqlite3.dll)
endif()

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

Thanks in advance!

1 Like