Commit 9fb7610c authored by louiz’'s avatar louiz’

Introduce the database module, and write all CMake things to compile it

parent 35ba8ac5
......@@ -43,6 +43,7 @@ option(BUILD_CLIENT "build the server" ${BUILD_CLIENT})
find_package(Boost 1.48.0 COMPONENTS filesystem system iostreams locale serialization chrono REQUIRED)
find_package(Cryptopp REQUIRED)
find_package(Protobuf REQUIRED)
find_package(LITESQL REQUIRED)
if(BUILD_CLIENT)
find_package(SFML 2 REQUIRED system window graphics audio)
......@@ -142,6 +143,17 @@ target_link_libraries(
${Boost_LIBRARIES}
)
#
## Database
#
LITESQL_GENERATE_CPP("src/database/database.xml"
"batadb"
LITESQL_GENERATED_SOURCES)
add_library(database STATIC src/database/database.cpp
${LITESQL_GENERATED_SOURCES})
target_link_libraries(database ${LITESQL_LIBRARIES})
#
## Gui
#
......
# - Find LiteSQL
# Find the LiteSQL library, and more particularly the stringprep header.
#
# This module defines the following variables:
# LITESQL_FOUND - True if library and include directory are found
# If set to TRUE, the following are also defined:
# LITESQL_INCLUDE_DIRS - The directory where to find the header file
# LITESQL_LIBRARIES - Where to find the library file
#
# For conveniance, these variables are also set. They have the same values
# than the variables above. The user can thus choose his/her prefered way
# to write them.
# LITESQL_INCLUDE_DIR
# LITESQL_LIBRARY
#
# This file is in the public domain
find_path(LITESQL_INCLUDE_DIRS NAMES litesql.hpp
DOC "The LiteSQL include directory")
find_library(LITESQL_LIBRARIES NAMES litesql
DOC "The LiteSQL library")
foreach(DB_TYPE sqlite postgresql mysql ocilib)
string(TOUPPER ${DB_TYPE} DB_TYPE_UPPER)
find_library(LITESQL_${DB_TYPE_UPPER}_LIB_PATH NAMES litesql_${DB_TYPE}
DOC "The ${DB_TYPE} backend for LiteSQL")
if(LITESQL_${DB_TYPE_UPPER}_LIB_PATH)
list(APPEND LITESQL_LIBRARIES ${LITESQL_${DB_TYPE_UPPER}_LIB_PATH})
endif()
endforeach()
find_program(LITESQLGEN_EXECUTABLE NAMES litesql-gen
DOC "The utility that creates .h and .cpp files from a xml database description")
# Use some standard module to handle the QUIETLY and REQUIRED arguments, and
# set LITESQL_FOUND to TRUE if these two variables are set.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LITESQL REQUIRED_VARS LITESQL_LIBRARIES LITESQL_INCLUDE_DIRS
LITESQLGEN_EXECUTABLE)
# Compatibility for all the ways of writing these variables
if(LITESQL_FOUND)
set(LITESQL_INCLUDE_DIR ${LITESQL_INCLUDE_DIRS})
set(LITESQL_LIBRARY ${LITESQL_LIBRARIES})
endif()
mark_as_advanced(LITESQL_INCLUDE_DIRS LITESQL_LIBRARIES)
# LITESQL_GENERATE_CPP function
function(LITESQL_GENERATE_CPP
SOURCE_FILE OUTPUT_NAME OUTPUT_SOURCES)
set(${OUTPUT_SOURCES})
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}.hpp"
COMMAND ${LITESQLGEN_EXECUTABLE}
ARGS -t c++ --output-dir=${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE}
DEPENDS ${SOURCE_FILE}
COMMENT "Running litesql-gen on ${SOURCE_FILE}"
VERBATIM)
list(APPEND ${OUTPUT_SOURCES} "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}.cpp")
set_source_files_properties(${${OUTPUT_SOURCES}} PROPERTIES GENERATED TRUE)
set(${OUTPUT_SOURCES} ${${OUTPUT_SOURCES}} PARENT_SCOPE)
endfunction()
#include <database/database.hpp>
Database::Database()
{
}
#ifndef DATABASE_HPP_INCLUDED
#define DATABASE_HPP_INCLUDED
#include "batadb.hpp"
/**
* Unique class that handles all database access.
* It internally uses the litesql.
*/
class Database
{
public:
Database();
~Database() = default;
private:
Database(const Database&) = delete;
Database(Database&&) = delete;
Database& operator=(const Database&) = delete;
Database& operator=(Database&&) = delete;
};
#endif /* DATABASE_HPP_INCLUDED */
<?xml version="1.0"?>
<!DOCTYPE database SYSTEM "litesql.dtd">
<database name="BataDB" namespace="db">
<object name="User">
<field name="login" type="string" length="256"/>
<field name="password" type="string" lenght="256"/>
<index unique="true">
<indexfield name="login"/>
</index>
</object>
</database>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment