2024-09-23 16:01:31 +08:00
|
|
|
# Copyright (c) 2023, AgiBot Inc.
|
|
|
|
# All rights reserved.
|
|
|
|
|
|
|
|
include(FetchContent)
|
|
|
|
|
|
|
|
message(STATUS "get sqlite ...")
|
|
|
|
|
|
|
|
# sqlite version: https://www.sqlite.org/chronology.html
|
|
|
|
set(sqlite_DOWNLOAD_URL
|
|
|
|
"https://www.sqlite.org/2023/sqlite-amalgamation-3420000.zip"
|
|
|
|
CACHE STRING "")
|
|
|
|
|
|
|
|
if(sqlite_LOCAL_SOURCE)
|
|
|
|
FetchContent_Declare(
|
|
|
|
sqlite
|
|
|
|
SOURCE_DIR ${sqlite_LOCAL_SOURCE}
|
|
|
|
OVERRIDE_FIND_PACKAGE)
|
|
|
|
else()
|
|
|
|
FetchContent_Declare(
|
|
|
|
sqlite
|
|
|
|
URL ${sqlite_DOWNLOAD_URL}
|
|
|
|
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
|
|
|
|
OVERRIDE_FIND_PACKAGE)
|
|
|
|
endif()
|
|
|
|
|
2024-11-07 21:17:34 +08:00
|
|
|
# Wrap it in a function to restrict the scope of the variables
|
|
|
|
function(get_sqlite)
|
|
|
|
FetchContent_GetProperties(sqlite)
|
|
|
|
if(NOT sqlite_POPULATED)
|
|
|
|
FetchContent_Populate(sqlite)
|
2024-09-23 16:01:31 +08:00
|
|
|
|
2024-11-07 21:17:34 +08:00
|
|
|
# sqlite lib
|
|
|
|
add_library(libsqlite)
|
|
|
|
add_library(sqlite::libsqlite ALIAS libsqlite)
|
2024-09-23 16:01:31 +08:00
|
|
|
|
2024-11-07 21:17:34 +08:00
|
|
|
file(GLOB head_files ${sqlite_SOURCE_DIR}/*.h)
|
2024-09-23 16:01:31 +08:00
|
|
|
|
2024-11-07 21:17:34 +08:00
|
|
|
target_sources(libsqlite PRIVATE ${sqlite_SOURCE_DIR}/sqlite3.c)
|
|
|
|
target_include_directories(libsqlite PUBLIC $<BUILD_INTERFACE:${sqlite_SOURCE_DIR}>)
|
|
|
|
target_sources(libsqlite INTERFACE FILE_SET HEADERS BASE_DIRS ${sqlite_SOURCE_DIR} FILES ${head_files})
|
2024-09-23 16:01:31 +08:00
|
|
|
|
2024-11-07 21:17:34 +08:00
|
|
|
if(UNIX)
|
|
|
|
target_link_libraries(libsqlite PUBLIC pthread dl)
|
|
|
|
endif()
|
2024-09-23 16:01:31 +08:00
|
|
|
endif()
|
2024-11-07 21:17:34 +08:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
get_sqlite()
|
2024-09-23 16:01:31 +08:00
|
|
|
|
|
|
|
# import targets:
|
|
|
|
# sqlite::libsqlite
|