From 90c86e72bdcf1d3c4f0d1e7ac126e6dabf7b68c4 Mon Sep 17 00:00:00 2001 From: marcelb Date: Mon, 20 Jan 2025 22:12:28 +0100 Subject: [PATCH] Switch to CMake --- .gitignore | 4 +- .vscode/settings.json | 61 ----------------------------- CMakeLists.txt | 69 +++++++++++++++++++++++++++++++++ README.md | 5 +++ cmake/sqlitecppConfig.cmake.in | 3 ++ example/example.db | Bin 24576 -> 0 bytes test/CMakeLists.txt | 6 +++ test/compile.sh | 1 - test/main.cpp | 35 +++++++++++++++++ test/test.cpp | 28 ------------- 10 files changed, 121 insertions(+), 91 deletions(-) delete mode 100644 .vscode/settings.json create mode 100644 CMakeLists.txt create mode 100644 cmake/sqlitecppConfig.cmake.in delete mode 100644 example/example.db create mode 100644 test/CMakeLists.txt delete mode 100644 test/compile.sh create mode 100644 test/main.cpp delete mode 100644 test/test.cpp diff --git a/.gitignore b/.gitignore index 1530978..1478632 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -*.o \ No newline at end of file +build +.vscode +example diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index de7e3a3..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "files.associations": { - "string": "cpp", - "vector": "cpp", - "*.tcc": "cpp", - "deque": "cpp", - "unordered_map": "cpp", - "system_error": "cpp", - "iostream": "cpp", - "type_traits": "cpp", - "tuple": "cpp", - "array": "cpp", - "utility": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "atomic": "cpp", - "bit": "cpp", - "chrono": "cpp", - "compare": "cpp", - "concepts": "cpp", - "condition_variable": "cpp", - "cstdint": "cpp", - "map": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "ratio": "cpp", - "string_view": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iosfwd": "cpp", - "istream": "cpp", - "limits": "cpp", - "mutex": "cpp", - "new": "cpp", - "numbers": "cpp", - "ostream": "cpp", - "semaphore": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "stop_token": "cpp", - "streambuf": "cpp", - "thread": "cpp", - "cinttypes": "cpp", - "typeinfo": "cpp" - } -} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..de46055 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,69 @@ +cmake_minimum_required(VERSION 3.15) +project(SqliteCppWrapper LANGUAGES CXX) + +# Postavi standard za C++ +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Dodaj glavnu biblioteku +add_library(sqlitecpp STATIC + src/sqlite3.cpp +) + +# Uključi zaglavlja +target_include_directories(sqlitecpp + PUBLIC + $ + $ +) + +# Poveži sa SQLite3 +find_package(SQLite3 REQUIRED) +target_link_libraries(sqlitecpp PRIVATE SQLite::SQLite3) + +# Generiši export fajl za lokalnu upotrebu +export(TARGETS sqlitecpp + FILE ${CMAKE_CURRENT_BINARY_DIR}/sqlitecppTargets.cmake + NAMESPACE sqlitecpp:: +) + +# Generiši sqlitecppConfig.cmake +include(CMakePackageConfigHelpers) + +configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sqlitecppConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/sqlitecppConfig.cmake + INSTALL_DESTINATION lib/cmake/sqlitecpp +) + +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/sqlitecppConfigVersion.cmake + VERSION 1.0.0 + COMPATIBILITY SameMajorVersion +) + +# Instalacija za lokalnu upotrebu +install(TARGETS sqlitecpp + EXPORT sqlitecppTargets + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin +) + +install(EXPORT sqlitecppTargets + FILE sqlitecppTargets.cmake + NAMESPACE sqlitecpp:: + DESTINATION lib/cmake/sqlitecpp +) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/sqlitecppConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/sqlitecppConfigVersion.cmake + DESTINATION lib/cmake/sqlitecpp +) + +# Opcionalno dodaj testove +# enable_testing() +# add_subdirectory(test) + +add_subdirectory(test) diff --git a/README.md b/README.md index 5ed7350..c745e65 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,11 @@ And compile your code ```bash g++ test.cpp ../src/* -o test.o -l sqlite3 + + +add_subdirectory(external/sqlitecpp) +target_link_libraries(my_project PRIVATE sqlitecpp) + ``` ## License diff --git a/cmake/sqlitecppConfig.cmake.in b/cmake/sqlitecppConfig.cmake.in new file mode 100644 index 0000000..a8a8ac5 --- /dev/null +++ b/cmake/sqlitecppConfig.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/sqlitecppTargets.cmake") diff --git a/example/example.db b/example/example.db deleted file mode 100644 index d674c75111a3d1791366ac08a4931ab42d6c0b4f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 24576 zcmeI)Piq=M7{~G1b+u@Sn~NBsCCi>HiXg#zOtJ)94QaCU&nb*Dfh4<1)Ix3{x4x3L zM_)!>M_xqEeMV`UrVx4wDe@h8+!@_x*Wc$huz2*Ydpb42$!MJFX|So*l;fzaAW%xJ zNadtFsm#5(Oy|S-IeFx`q8cCGtop8Ui!)W6`QM98`+B5eBgI!hC(kK>v8__t_WaQpvgY=fPv$Z`#WJ5iztMg+aBD4?DYIzOx@kd(mNCmiz5q z6z1dTV{BKwcBi{o6>NG20tg_000IagfB*srAb3Xd{`SZ~009ILKmY**5I_I{1Q0*~fh7}IwRzT*^6!=`7;z9l009ILKmY** z5I_I{1Q0+#slo!m?*Bdii}G*%8~>Y37ziMM00IagfB*srAb diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..a95c5bb --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(sqlitecpp_test main.cpp) + +target_link_libraries(sqlitecpp_test PRIVATE sqlitecpp SQLite::SQLite3) + +# Dodaj direktorijum za zaglavlja +target_include_directories(sqlitecpp_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib) diff --git a/test/compile.sh b/test/compile.sh deleted file mode 100644 index d78b604..0000000 --- a/test/compile.sh +++ /dev/null @@ -1 +0,0 @@ -g++ test.cpp ../src/* -o test.o -l sqlite3 \ No newline at end of file diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 0000000..0bddfa0 --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,35 @@ +#include "sqlite3.hpp" +#include + +int main() { + try { + // Kreiraj instancu SQLite wrapper klase + marcelb::SQlite3::SQLite3 db("test.db"); // test.db je naziv baze podataka + + // Izvrši SQL upit za kreiranje tabele + db.query("CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, name TEXT);"); + + // Ubaci podatke u tabelu + db.query("INSERT INTO test (name) VALUES ('John Doe');"); + + // Izvrši SELECT upit i pročitaj podatke + auto results = db.query("SELECT id, name FROM test;"); + + // Prikaži rezultate + for (const auto& row : results) { + std::string id = row.first; + std::string name = row.second[0]; + std::cout << "ID: " << id << ", Name: " << name << std::endl; + } + } catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + return 1; + } + + return 0; +} + + +// cmake .. -DCMAKE_BUILD_TYPE=Release +// cmake --build . --target sqlitecpp_test +// ./test/sqlitecpp_test \ No newline at end of file diff --git a/test/test.cpp b/test/test.cpp deleted file mode 100644 index 9e059bd..0000000 --- a/test/test.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -using namespace std; - -#include "../lib/sqlite3.hpp" -using namespace marcelb::SQlite3; - -int main() { - try { - - SQLite3 mydb("../example/example.db", false); - - auto res = mydb.query("Select * from Tab1"); - // cout << endl << res["NAME"][1]; - - // cout << endl << res["MAIL"][1]; - - for (auto i : res) { - for (auto j: i.second) { - cout << i.first << " : " << j << endl; - } - } - - } catch (const string err) { - cout << err << endl; - } - - return 0; -} \ No newline at end of file