Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add working sqlite example. #579

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions examples/sqlite/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

project(CPMSqliteExample)

# ---- Dependencies ----

include(../../cmake/CPM.cmake)

# sqlite - You know it, you love it!
CPMAddPackage(
NAME sqlite
URL https://www.sqlite.org/2024/sqlite-amalgamation-3460000.zip
URL_HASH SHA256=712a7d09d2a22652fb06a49af516e051979a3984adb067da86760e60ed51a7f5
PATCHES sqlite.patch
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the extra example, this is an interesting use of the patches command! I'm a bit torn if we should encourage the use of the patches like this as the command still seems to have some issues. Until the command is more mature I think we should still encourage the old way of adding the library without using patches:

Suggested change
if (sqlite_ADDDED)
add_library(
sqlite STATIC
${sqlite_SOURCE_DIR}/sqlite3.c
${sqlite_SOURCE_DIR}/sqlite3.h
${sqlite_SOURCE_DIR}/sqlite3ext.h
)
target_include_directories(sqlite PUBLIC SYSTEM "${sqlite_SOURCE_DIR}")
endif()

add_executable(CPMSqliteExample main.cpp)
target_link_libraries(CPMSqliteExample sqlite)
8 changes: 8 additions & 0 deletions examples/sqlite/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <sqlite3.h>

#include <iostream>

int main(int, char**) {
std::cout << sqlite3_libversion() << "\n";
return 0;
}
11 changes: 11 additions & 0 deletions examples/sqlite/sqlite.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff -uN a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt 1969-12-31 18:00:00.000000000 -0600
+++ b/CMakeLists.txt 2024-07-30 12:22:59.022590360 -0500
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.11)
+project(sqlite)
+
+add_library(sqlite STATIC sqlite3.c sqlite3.h sqlite3ext.h)
+target_include_directories(sqlite PUBLIC SYSTEM
+ "${CMAKE_CURRENT_SOURCE_DIR}"
+)
Loading