[odb-users] cmake and odt

Michal Snoch kontakt at msnoch.pl
Sun Sep 11 17:06:49 EDT 2011


Hi Johann,

I had same problem few days before :) I'm not sure if it's the one or the  
best option to solve
the problem but that works for me fine.

First of all, you have to have var with headers which you want to parse  
with odb i.e.

set(core_odb_src header1.h header2.h ... headerN.h)

secondy you have to add something like this (I probably found solution on  
this group but im not sure ;) )

foreach(_file ${core_odb_src})
   string(REPLACE ".h" "-odb.cpp" gencppfile ${_file})
   add_custom_command(
     OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${gencppfile}
     COMMAND /usr/local/odb/bin/odb --database pgsql --profile qt  
--hxx-suffix .hpp --ixx-suffix .ipp --cxx-suffix .cpp
     --output-dir ${CMAKE_CURRENT_SOURCE_DIR}
     --generate-query --generate-schema --schema-format embedded
     ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
     -I${QT_INCLUDE_DIR}/QtCore
     -I${QT_INCLUDE_DIR}
     DEPENDS ${_file}
     COMMENT "Building odb for ${_file}"
     )
   list(APPEND core_lib_src ${gencppfile})
endforeach()

As you see I need to add some options to odb, but it's not necessary if  
you not use boost or qt. Im wondering
if I can set some runtime option in cmake (ie -odb=pathtoodb) so i can do  
it more flexible?

The last thing is adding the libraries

target_link_libraries(core odb odb-pgsql odb-qt)

Complete cmake file looks like this

set(core_lib_src core.cpp line.cpp)

set(core_lib_headers core.h)
set(core_odb_src line.h)

INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})

foreach(_file ${core_odb_src})
   string(REPLACE ".h" "-odb.cpp" gencppfile ${_file})
   add_custom_command(
     OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${gencppfile}
     COMMAND /usr/local/odb/bin/odb --database pgsql --profile qt  
--hxx-suffix .hpp --ixx-suffix .ipp --cxx-suffix .cpp
     --output-dir ${CMAKE_CURRENT_SOURCE_DIR}
     --generate-query --generate-schema --schema-format embedded
     ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
     -I${QT_INCLUDE_DIR}/QtCore
     -I${QT_INCLUDE_DIR}
     DEPENDS ${_file}
     COMMENT "Building odb for ${_file}"
     )
   list(APPEND core_lib_src ${gencppfile})
endforeach()

add_library(core SHARED ${core_lib_src})

target_link_libraries(core odb odb-pgsql odb-qt)
target_link_libraries(core ${QT_LIBRARIES} plugins)

I hope that help :)

Michal

Dnia 11-09-2011 o 19:40:09 Johannes Lochmann  
<johannes.lochmann at googlemail.com> napisał(a):

> Hello,
>
> is anybody using odb in a cmake environment and can give me some hints  
> on how to handle the call to the odb compiler?
>
> Thank you
>
> Johannes



More information about the odb-users mailing list