Пока не билдится

This commit is contained in:
2025-02-02 11:58:56 +05:00
parent 9751db9617
commit 11ea3a8cd8
5 changed files with 94 additions and 4 deletions

View File

@@ -1,16 +1,58 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.16)
project(cpp-opds)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(ODB_INCLUDE_DIRS /usr/include)
set(ODB_LIBRARY_DIRS /usr/lib/x86_64-linux-gnu)
include_directories(${ODB_INCLUDE_DIRS})
link_directories(${ODB_LIBRARY_DIRS})
find_package(Qt6 REQUIRED COMPONENTS Core Sql Network)
# find_package(ODB REQUIRED)
# find_package(SQLite3 REQUIRED)
find_library(ODB_LIBRARIES NAMES odb HINTS ${ODB_LIBRARY_DIRS})
find_library(ODB_SQLITE_LIBRARIES NAMES odb-sqlite HINTS ${ODB_LIBRARY_DIRS})
set(CMAKE_AUTOMOC ON) # <-- Включаем автоматическую генерацию MOC-файлов
add_executable(cpp-opds
# include_directories(${ODB_INCLUDE_DIRS} ${SQLite3_INCLUDE_DIRS})
# link_directories(${ODB_LIBRARY_DIRS} ${SQLite3_LIBRARY_DIRS})
# add_executable(cpp-opds
# src/main.cpp
# include/backend.cpp
# )
set(SOURCE_FILES
src/main.cpp
include/backend.cpp
# src/database.cpp
# src/book.cpp
# src/author.hpp
)
set(ODB_SOURCES
src/book
src/author
)
# Генерация ODB файлов
foreach(file ${ODB_SOURCES})
add_custom_command(
OUTPUT ${file}.odb.cpp ${file}.odb.hpp
COMMAND odb --generate-query --generate-schema --database sqlite ${file}.hpp
DEPENDS ${file}.hpp
COMMENT "Running ODB on ${file}.hpp"
)
list(APPEND SOURCE_FILES ${file}.odb.cpp)
endforeach()
add_executable(cpp-opds ${SOURCE_FILES})
target_include_directories(cpp-opds PRIVATE include)
target_link_libraries(cpp-opds Qt6::Core Qt6::Sql Qt6::Network)
# target_link_libraries(cpp-opds Qt6::Core Qt6::Sql Qt6::Network ${ODB_LIBRARIES} ${SQLite3_LIBRARIES})
target_link_libraries(cpp-opds Qt6::Core Qt6::Sql Qt6::Network ${ODB_LIBRARIES} ${ODB_SQLITE_LIBRARIES})

13
src/author.hpp Normal file
View File

@@ -0,0 +1,13 @@
#pragma db object
class Author {
public:
Author() = default;
Author(const std::string& name) : name(name) {}
const std::string& getName() const { return name; }
private:
#pragma db id auto
int id;
std::string name;
};

22
src/book.hpp Normal file
View File

@@ -0,0 +1,22 @@
#pragma db object
class Book {
public:
Book() = default;
Book(const std::string& title, const std::string& author, const std::string& filePath,
int fileSize, const std::string& format);
const std::string& getTitle() const { return title; }
const std::string& getAuthor() const { return author; }
const std::string& getFilePath() const { return filePath; }
int getFileSize() const { return fileSize; }
const std::string& getFormat() const { return format; }
private:
#pragma db id auto
int id;
std::string title;
std::string author;
std::string filePath;
int fileSize;
std::string format;
};

13
src/database.cpp Normal file
View File

@@ -0,0 +1,13 @@
#include "database.h"
#include <odb/sqlite/database.hxx>
#include <odb/schema-catalog.hxx>
#include "book-odb.hxx"
#include "author-odb.hxx"
std::unique_ptr<odb::sqlite::database> initializeDatabase(const std::string& dbPath) {
auto db = std::make_unique<odb::sqlite::database>(dbPath, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
odb::transaction t(db->begin());
odb::schema_catalog::create_schema(*db);
t.commit();
return db;
}

0
src/database.h Normal file
View File