[odb-users] ODB + Cmake
Diego Fernando
lordvampyre at gmail.com
Thu May 14 23:07:38 EDT 2015
Hi,
I did the download of the source code from this
https://github.com/BtbN/OdbCmake and I put in person.h #include
<QtCore/QString>, when I will try to compile the project the compiler
showed a error saying that doesn't found the QtCore. If I compile without
qtcore or without odb, it works.
The only thing that I did was to change on the project was person.h
person.h
#ifndef PERSON_HXX
#define PERSON_HXX
#include <string>
#include <cstddef> // std::size_t
#include <odb/core.hxx>
#include <QtCore/QString>
#pragma db object
class person
{
public:
person (const std::string& first,
const std::string& last,
unsigned short age)
: first_ (first), last_ (last), age_ (age)
{
}
const std::string&
first () const
{
return first_;
}
const std::string&
last () const
{
return last_;
}
unsigned short
age () const
{
return age_;
}
void
age (unsigned short age)
{
age_ = age;
}
private:
friend class odb::access;
person () {}
#pragma db id auto
unsigned long id_;
std::string first_;
std::string last_;
unsigned short age_;
};
#pragma db view object(person)
struct person_stat
{
#pragma db column("count(" + person::id_ + ")")
std::size_t count;
#pragma db column("min(" + person::age_ + ")")
unsigned short min_age;
#pragma db column("max(" + person::age_ + ")")
unsigned short max_age;
};
#endif // PERSON_HXX
Cmakelist
cmake_minimum_required(VERSION 2.8.12)
project(OdbCMake)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
find_package(ODB REQUIRED COMPONENTS qt pgsql)
find_package(Qt5Core REQUIRED)
include(${ODB_USE_FILE})
set(OdbCMake_SOURCES
driver.cpp
database.h)
set(OdbCMake_ODB_HEADERS
person.h)
odb_compile(OdbCMake_SOURCES FILES ${OdbCMake_ODB_HEADERS} DB pgsql
GENERATE_QUERY GENERATE_SESSION)
add_executable(odbcmake
${OdbCMake_SOURCES}
${OdbCMake_ODB_HEADERS})
target_link_libraries(odbcmake
${ODB_LIBRARIES})
target_include_directories(odbcmake
PRIVATE
${ODB_INCLUDE_DIRS}
${ODB_COMPILE_OUTPUT_DIR})
target_compile_definitions(odbcmake
PRIVATE
DATABASE_PGSQL)
Thank you,
Diego Fernando
More information about the odb-users
mailing list