Discussion:
[cmake-developers] Was AUTOMOC designed to run for each build?
Stephen Kelly
2014-09-23 07:58:58 UTC
Permalink
Hi (especially Alex),

I noticed that the automoc target is run each time, even for a trivial
project:

cmake_minimum_required(VERSION 2.8)
project(automoctest)

set(CMAKE_AUTOMOC ON)

find_package(Qt5Widgets REQUIRED)

add_executable(main main.cpp)
target_link_libraries(main Qt5::Widgets)

Each time I run make I get

[ 33%] Automatic moc for target main
/path/to/cmake -E cmake_autogen /path/to/build/CMakeFiles/main_automoc.dir/
""

I checked CMake 2.8.7 and it executes the target each time too.

In the implementation, makefile->AddUtilityCommand is called with 'true' to
set the excludeFromAll parameter.

I don't see why the target is executed each time, but is it that way by
design?

Thanks,

Steve.
Alexander Neundorf
2014-09-23 20:27:51 UTC
Permalink
Post by Stephen Kelly
Hi (especially Alex),
I noticed that the automoc target is run each time, even for a trivial
cmake_minimum_required(VERSION 2.8)
project(automoctest)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Widgets REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main Qt5::Widgets)
Each time I run make I get
[ 33%] Automatic moc for target main
/path/to/cmake -E cmake_autogen /path/to/build/CMakeFiles/main_automoc.dir/
"
I checked CMake 2.8.7 and it executes the target each time too.
In the implementation, makefile->AddUtilityCommand is called with 'true' to
set the excludeFromAll parameter.
I don't see why the target is executed each time, but is it that way by
design?
iirc, yes.
The moc files have to be generated before any of the source files is compiled,
so automoc is in a target the actual target depends on.
IIRC it is exclude_from_all so that it is only built when the actual target is
built.
Do you think it should only rerun if any of the source files has changed ?
There was some problem with this.
The headers are usually not part of the listed source files. I would have to
check to find out the details again.

Alex
Stephen Kelly
2014-09-25 23:53:35 UTC
Permalink
Post by Alexander Neundorf
Post by Stephen Kelly
I don't see why the target is executed each time, but is it that way by
design?
iirc, yes.
The moc files have to be generated before any of the source files is
compiled, so automoc is in a target the actual target depends on.
IIRC it is exclude_from_all so that it is only built when the actual
target is built.
Do you think it should only rerun if any of the source files has changed ?
There was some problem with this.
The headers are usually not part of the listed source files.
Hmm, well, we do know which header is relevant right? Because it's the one
(or many) we set up commands to run moc on. Maybe we only know the relevant
headers too late (at the time of running the -E cmake_autogen command, not
at cmake time)?

Something else I've wondered is why the parsing of the files is done
'delayed' with the -E cmake_autogen command. Is it just to avoid doing that
task during cmake time (because it's time consuming), and to allow
parallelization?

Thanks,

Steve.
Alexander Neundorf
2014-09-26 20:04:23 UTC
Permalink
Post by Stephen Kelly
Post by Alexander Neundorf
Post by Stephen Kelly
I don't see why the target is executed each time, but is it that way by
design?
iirc, yes.
The moc files have to be generated before any of the source files is
compiled, so automoc is in a target the actual target depends on.
IIRC it is exclude_from_all so that it is only built when the actual
target is built.
Do you think it should only rerun if any of the source files has changed ?
There was some problem with this.
The headers are usually not part of the listed source files.
Hmm, well, we do know which header is relevant right? Because it's the one
(or many) we set up commands to run moc on. Maybe we only know the relevant
headers too late (at the time of running the -E cmake_autogen command, not
at cmake time)?
Something else I've wondered is why the parsing of the files is done
'delayed' with the -E cmake_autogen command. Is it just to avoid doing that
task during cmake time (because it's time consuming), and to allow
parallelization?
it can't be done at cmake time, because editing a cpp file and inserting
#include "foo.moc" does not cause cmake to rerun, so the parsing must happen
during buildtime.

Alex

Loading...