[odb-users] Custom ODB compiler build rule on OSX

Alexandre Pretyman alexandre.pretyman at gmail.com
Fri Aug 26 09:22:10 EDT 2016


Hi Andrew (and Boris!)

If you don't mind using CMake on your project, as it could generate Xcode
project files, I've contributed the unix friendly odb libraries to the
hunter package manager [ https://github.com/ruslo/hunter ]. CMake will
manage the build rule for you.

hunter is a kick-ass-CMake-based package manager for C++/C run by Ruslan
Baratov. It will download the sources for odb-* and compile them - only
once per toolchain (except for odb-compiler, where it downloads the
binaries directly).

The odb compiler CMake integration is based on the work of Timo
Rothenpieler and Per Edin except for the crucial change that the
odb_compile(...) function has to be called AFTER defining the CMake target
for your executable/library:

list(APPEND headers-to-run-the-odb-compiler-on header1.hpp header2.hpp ...)

add_executable(MyGreatestApp ...)

odb_compile(
    MyGreatestApp
    FILES
      ${headers-to-run-the-odb-compiler-on}
    DB
      mysql
    GENERATE_QUERY
    GENERATE_SESSION
    GENERATE_SCHEMA
)

To use hunter you will add
https://github.com/hunter-packages/gate/blob/master/cmake/HunterGate.cmake
to the cmake directory next to the CMakeLists.txt file, and before your
project(MyGreatesProject) you will put:

include("cmake/HunterGate.cmake")

HunterGate(
    URL "https://github.com/ruslo/hunter/archive/v0.15.20.tar.gz"
    SHA1 "1771b5509cf8645bdb1c7ac12bc5d29a35465d12"
)

project(MyGreatesProject)

...

hunter_add_package(odb-compiler)
hunter_add_package(odb-mysql)
find_package(odb COMPONENTS compiler mysql)

... [repeated from above for clarity]

list(APPEND headers-to-run-the-odb-compiler-on header1.hpp header2.hpp ...)

add_executable(MyGreatestApp ...)

odb_compile(
    MyGreatestApp
    FILES
      ${headers-to-run-the-odb-compiler-on}
    DB
      mysql
    GENERATE_QUERY
    GENERATE_SESSION
    GENERATE_SCHEMA
)

target_link_libraries(MyGreatestApp odb::mysql)

This is from an example at:
https://github.com/ruslo/hunter/blob/master/examples/odb-mysql

Arguments to the odb_compile function can be found at:
https://github.com/ruslo/hunter/blob/master/cmake/find/Findodb-compiler.cmake
(I has not yet updated the hunter wiki for the odb library, sorry!)

At the moment hunter has version 2.4.0 of odb, which I don't know if will
suite you.

iOS integration was working with a few manual hacks, but there is an issue
open to fix it, which I will do *soon*.

Hope you find this useful,
Alexandre Pretyman


On 26 August 2016 at 01:06, Andrew Cunningham <odb at a-cunningham.com> wrote:

> I am trying to create a custom build rule for the header files in my Xcode
> project to call the odb compiler.
> I know how to create custom build rule for a target - but it seems creating
> one to actually process a subset of the headers is somehow eluding me.
> As a test, I created a build rule for a specific header, but this build
> rule is never call on "Build".
> ideas?
>



-- 
Alexandre Pretyman


More information about the odb-users mailing list