[odb-users] Includes and CMake out-of-source builds

Per Edin info at peredin.com
Mon Aug 26 08:50:01 EDT 2013

Hi Boris,

CMake can accomplish this on its own by executing ODB one file at a
time. In fact, this how I do it in my CMake function for ODB to get
correct "Generating ..." messages, except when SLOC_LIMIT is
specified. In that case all input files are passed to ODB at once.
Having the output directory logic in ODB itself would allow
--sloc-limit / --show-sloc to work while fixing the directory/include

Personally I don't use --sloc-limit / --show-sloc, but someone else
might and my goal was to keep my ODB module for CMake as
feature-complete as possible.

By the way, the input headers always have a common prefix, in the
worst case it is /. CMake uses the project directory root as the base
and re-creates the project directory structure in the build directory.
So "project/gui/controls/text/richtext.cpp" would result in the .o
file being created in
"${build}/CMakeFiles/project.dir/gui/controls/text/richtext.o". Visual
Studio for instance creates all .o files in the same dir, which causes
severe problems if you have both foo/baz.cpp and bar/baz.cpp in the
same project resulting in 2 baz.o files being created in the same
directory. I think CMake "does the right thing" here. :)


On Mon, Aug 26, 2013 at 2:19 PM, Boris Kolpackov
<boris at codesynthesis.com> wrote:
> Hi Per,
> Per Edin <info at peredin.com> writes:
>> What do you think about this?
> Short version: bad idea.
> Longer version: This whole file/include/directory management is already
> way more complex than what I would have liked (don't believe me, take
> a look at the odb/odb.cxx file with all the gory details). Adding another
> set of "soft" rules like "if there is a common directory then strip it
> and re-create the remaining directories in the output-dir" will just
> complicate things even further. And, BTW, what is the logic if there
> is no common directory prefix? Do we re-create the whole directory
> sequence in output-dir? Or not? Maybe issue an error? Maybe add an
> option that specifies what to do in this case?
> And don't let me started on explaining all this convoluted logic in
> the documentation.
> At the same time, there is a very simple solution to this: compile
> one file a time. This way you can figure out the output-dir as
> you wish, make sure that it is created before running the ODB
> compiler, and also add the include prefix with --include-prefix
> option. Any half-decent build system should allow you to do all
> that.
> Boris

More information about the odb-users mailing list