User forums > Using Code::Blocks

How to handle generated files from header.

(1/1)

jarod42:
Working on premake-codeBlocks and premake-qt to generate Code::Blocks project with Qt, I encountered issues with generated source files.

I have 3 different source files type, expected generation is:

resources.qrc -> resources.cpp (-> resources.o) OK
foo.ui -> ui_foo.h (OK too)
foo.h -> moc_foo.cpp (-> moc_foo.o)

I used respectively (path simplified (tool options and complete path for bin&obj omitted)):


--- Code: ---<Option compile="1" />
<Option link="1" />
<Option weight="40" />
<Option compiler="gcc" use="1" buildCommand="qrc resource.qrc -o resource.cpp\n$compiler $options $includes -c resource.cpp -o $object" />
--- End code ---

--- Code: ---<Option compile="1" />
<Option weight="35" />
<Option compiler="gcc" use="1" buildCommand="uic foo.ui -o ui_foo.h" />
--- End code ---

--- Code: ---<Option compile="1" />
<Option link="1" />
<Option weight="40" />
<Option compiler="gcc" use="1" buildCommand="moc foo.h -o moc_foo.cpp\n$compiler $options $includes -c moc_foo.cpp -o $object" />

--- End code ---

Issue for the last one with `$object` which is `foo.h.gch` for `foo.h`whereas I expect `moc_foo.o` (or any unique .o, `foo.o` would also be problematic as foo.cpp also exists).
I tried to replace directly `$object` by `moc_foo.o`, but then the link fails.

Is there a way to specify object (it is shown in UI, but as read only) or fix the issue differently?

(I previously added generated file directly in project, but build failed as the file doesn't exist at the begining of the build).

sodev:
Instead of adding custom build commands to files it is better to define a compiler build command for the file extension. This allows to specify the outputs which will get added to the build automatically, without causing an error if they don't exist yet.

In your case, this would work for the first two cases, it won't work for the last one, because this file has a standard extension and the default build command creates a precompiled header with that .h.gch extension. Are foo.ui and foo.h related? Do always exist both of them? In that case, you could add the step for foo.h to the build command for .ui files.

jarod42:
> Are foo.ui and foo.h related?

Not necessary.

foo.h is a regular header, and generation should be done if a MACRO (QOBJECT) is present in the file.

sodev:
I'm not familiar with Qt so i don't know how its preprocessing works.

How to you know that you have to add foo.h to the project then? Do you scan the file yourself? Would be strange if Qt requires you to do this on your own, how do the Qt build tools do this?

jarod42:
We have to scan ourself (or provide list manually).

CMake has AUTOMOC

Not familiar with QMake (the build tool from Qt), but it seems also scanning/processing files given to HEADERS and SOURCES entries.

It is was for my project, as workaround, I might indeed change file extension to make it easier.
But it is for a project/solution builder...

It seems we cannot have a (linkable) *.o from a *.h

At worst , I will warn that moc is unsupported for Code::Blocks.

Thanks.

Navigation

[0] Message Index

Go to full version