1
0
Fork 0
forked from fun/fun

Added support for libSQL as an compatible alternative for SQLite. (0.33.0)

This commit is contained in:
Johannes Findeisen 2025-11-27 00:42:47 +01:00
commit 56712206d1
17 changed files with 418 additions and 5 deletions

View file

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.10)
project(fun VERSION 0.32.0 LANGUAGES C)
project(fun VERSION 0.33.0 LANGUAGES C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
@ -90,6 +90,40 @@ if(FUN_WITH_JSON)
endif()
endif()
# Optional libsql support (independent from SQLite)
option(FUN_WITH_LIBSQL "Enable libsql (Turso) client support" OFF)
set(LIBSQL_INCLUDE_DIRS "")
set(LIBSQL_LINK_LIBS "")
if(FUN_WITH_LIBSQL)
message(STATUS "Building with libsql support")
add_definitions(-DFUN_WITH_LIBSQL)
# Try pkg-config for libsql first; some systems expose libsql-client
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBSQL QUIET libsql)
if(NOT LIBSQL_FOUND)
pkg_check_modules(LIBSQL_CLIENT QUIET libsql-client)
if(LIBSQL_CLIENT_FOUND)
set(LIBSQL_FOUND TRUE)
set(LIBSQL_INCLUDE_DIRS ${LIBSQL_CLIENT_INCLUDE_DIRS})
set(LIBSQL_LINK_LIBS ${LIBSQL_CLIENT_LIBRARIES})
endif()
endif()
endif()
if(LIBSQL_FOUND)
include_directories(${LIBSQL_INCLUDE_DIRS})
else()
# Fallback: many libsql deployments provide a sqlite3-compatible client lib
# so try linking against sqlite3 as a compatibility layer.
find_library(LIBSQL_LIB sqlite3)
if(LIBSQL_LIB)
list(APPEND LIBSQL_LINK_LIBS ${LIBSQL_LIB})
else()
message(FATAL_ERROR "libsql not found. Install libsql (or compatible sqlite3 client) or disable FUN_WITH_LIBSQL.")
endif()
endif()
endif()
# Optional PCRE2 support
option(FUN_WITH_PCRE2 "Enable PCRE2 (Perl Compatible Regular Expressions) support" OFF)
set(PCRE2_INCLUDE_DIRS "")
@ -201,6 +235,14 @@ if(SQLITE3_LINK_LIBS)
target_link_libraries(fun_core PUBLIC ${SQLITE3_LINK_LIBS})
endif()
# libsql include and link (if enabled)
if(LIBSQL_INCLUDE_DIRS)
target_include_directories(fun_core PRIVATE ${LIBSQL_INCLUDE_DIRS})
endif()
if(LIBSQL_LINK_LIBS)
target_link_libraries(fun_core PUBLIC ${LIBSQL_LINK_LIBS})
endif()
# Link threads if available on UNIX
if(Threads_FOUND)
target_link_libraries(fun_core PUBLIC Threads::Threads)