View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015608CMakeCMakepublic2015-06-11 02:142016-02-01 09:10
ReporterHendrik Sattler 
Assigned ToBrad King 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product VersionCMake 3.2.2 
Target VersionCMake 3.4Fixed in VersionCMake 3.4 
Summary0015608: automoc fails when enabling autorcc
DescriptionAutomoc does not work after initial cmake run when autorcc is enabled.

I created a small example that shows the problem. I created it from
scratch and it instantly fails for me. I get:
error C3861: 'onTst2': identifier not found (moc_main.cpp)

This file is auto-generated and thus was not updated. -> Should not
happen.

I also tried to manually run cmake, it won't help. However, commenting mainx.qrc helps! Or using qt4_add_resources() and disabling CMAKE_AUTORCC!

Suddenly, the bugtest_automoc target is gone in VS and it compiles
again, even after adding/removing Qt slot functions.
BTW, why is this target called bugtest_automoc and not bugtest_autogen?

The whole thing looks strange as bugtest target still has a
qrc_mainx.cpp.rule but bugtest_automoc also has such a rule.
The bugtest.automoc.rule file properties show no real command:
-----------------
setlocal
cd D:\bugtest\cmake-autogen\build
if %errorlevel% neq 0 goto :cmEnd
D:
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
-----------------
Is that supposed to actually do something?

I am using Visual Studio 2010. CMake is 3.2.2 but also I tried 3.3-rc1.

Steps To ReproduceYou need to create a foo.png to get the qrc to actually create the
source file (actually 2nd bug that CMake doesn't warn about a missing file).

First run, comment out the onTst2 slot function (both h and cpp file),
it should build.
Then comment it before 2nd run.
Additional InformationCMakeLists.txt:
----------------------------------------------
cmake_minimum_required ( VERSION 3.0.2 )
cmake_policy ( VERSION 3.0.2 )

project ( bugtest CXX )

find_package ( Qt4 )

set ( CMAKE_INCLUDE_CURRENT_DIR ON )
set ( CMAKE_AUTOMOC ON )
set ( CMAKE_AUTORCC ON )

add_executable ( bugtest
  main.cpp
  mainx.qrc
)
target_link_libraries ( bugtest Qt4::QtCore )
----------------------------------------------

main.h:
----------------------------------------------
#include <QObject>

class tst1 : public QObject
{
  Q_OBJECT

 public slots:
   void onTst1();
   //void onTst2();
};
----------------------------------------------

main.cpp:
----------------------------------------------
#include "main.h"

void tst1::onTst1()
{
}

// void tst1::onTst2()
// {
// }

int main( int argc, char **argv)
{
  return 0;
}
----------------------------------------------

mainx.qrc:
----------------------------------------------
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
  <file>foo.png</file>
</qresource>
</RCC>
----------------------------------------------
TagsNo tags attached.
Attached Files

 Relationships
related to 0015074closedStephen Kelly Qt 5: resources aren't being updated when CMAKE_AUTORCC is used 

  Notes
(0038935)
Brad King (manager)
2015-06-16 12:54

I cannot reproduce this. Here is a session:

$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.0.2)
project(Issue15608 CXX)

find_package(Qt4)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

add_executable(bugtest
  main.cpp
  mainx.qrc
  )
target_link_libraries(bugtest Qt4::QtCore)

$ cat main.h
#include <QObject>

class tst1 : public QObject
{
  Q_OBJECT

 public slots:
   void onTst1();
   void onTst2();
};

$ cat main.cpp
#include "main.h"

void tst1::onTst1()
{
}

void tst1::onTst2()
{
}

int main( int argc, char **argv)
{
  return 0;
}

$ cat mainx.qrc
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
  <file>foo.png</file>
</qresource>
</RCC>

$ test -f foo.png && echo exists
exists

$ cmake --version
cmake version 3.3.0-rc2

$ mkdir build
$ cd build

$ cmake .. -G "Visual Studio 10 2010" -DQT_QMAKE_EXECUTABLE=c:/.../bin/qmake
$ cmake --build . --config Debug
...
Build succeeded.
    0 Warning(s)
    0 Error(s)
(0038936)
Hendrik Sattler (reporter)
2015-06-16 15:41

Hi Brad,

you forgot the second part where the slot function onTst2() is delete from .h and .cpp file. Then try to recompile.

Additionally, I only tried with Visual Studio 2010 GUI, not command line build. The above will use MSBuild, the GUI uses devenv AFAIK.

I'll try again, tommorrow with 3.3-rc2 but I'm sure that it still breaks.
(0038937)
Brad King (manager)
2015-06-16 16:20
edited on: 2015-06-16 16:21

Re 0015608:0038936: Thanks. I was confused by "comment out" in "First run, comment out the onTst2 slot function".

I now continued the session in 0015608:0038935 by removing onTst2 from the .h and .cpp files and then could see the error:

$ cmake --build . --config Debug
...\build\moc_main.cpp(50): error C2039: 'onTst2' : is not a member of 'tst1'


(0038938)
Brad King (manager)
2015-06-16 16:32

One must set the AUTOGEN_TARGET_DEPENDS target property for this case. See property documentation for why:

  http://www.cmake.org/cmake/help/v3.3/prop_tgt/AUTOGEN_TARGET_DEPENDS.html [^]

I added the line

  set_property(TARGET bugtest PROPERTY AUTOGEN_TARGET_DEPENDS main.cpp mainx.qrc)

to the end of the example CMakeLists.txt file and now it works.
(0038939)
Brad King (manager)
2015-06-16 16:36

Re 0015608:0038938: This is documented in the cmake-qt(7) manual:

 http://www.cmake.org/cmake/help/v3.3/manual/cmake-qt.7.html#qt-build-tools [^]
 "The tools are executed as part of a synthesized custom target generated by
  CMake. Target dependencies may be added to that custom target by adding
  them to the AUTOGEN_TARGET_DEPENDS target property."
(0038940)
Hendrik Sattler (reporter)
2015-06-16 16:50

Then why does automoc work without that line when not using autorcc?
So everyone needs to add all files that potentially need moc or rcc? For most projects this will be all source and all header files. That's really strange...
(0038942)
Hendrik Sattler (reporter)
2015-06-17 08:21

After looking into it, I don't think that AUTOGET_TARGET_DEPENDS is the right solution here.

Why?
Because when _NOT_ using AUTORCC, it is not needed!
Enabling both is what causes the wrong behaviour for AUTOMOC.

The solution cannot be adding all sources of a target AUTOGEN_TARGET_DEPENDS.
I always understood that as dependencies needed when moc runs (e.g. generated header files included into the moc'd sources) but not the sources for moc to run on.

Aditionally, the first build should also fail, not just after the first incompatible mofification.
(0038943)
Brad King (manager)
2015-06-18 08:35

Steve, Clinton?
(0038955)
Brad King (manager)
2015-06-19 09:51

I think the change made for issue 0015074 broke this by causing automoc to not always rerun when autorcc is enabled.
(0038956)
Brad King (manager)
2015-06-19 10:36

Here is a fix and a test case:

 QtAutogen: Always run autogen step even when rcc is enabled
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0e346427 [^]

It also allows this simplification:

 QtAutogen: Use PRE_BUILD in Visual Studio generators even with rcc
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=12c3fcde [^]
(0040403)
Robert Maynard (manager)
2016-02-01 09:10

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2015-06-11 02:14 Hendrik Sattler New Issue
2015-06-16 12:54 Brad King Note Added: 0038935
2015-06-16 15:41 Hendrik Sattler Note Added: 0038936
2015-06-16 16:20 Brad King Note Added: 0038937
2015-06-16 16:21 Brad King Note Edited: 0038937
2015-06-16 16:32 Brad King Note Added: 0038938
2015-06-16 16:36 Brad King Note Added: 0038939
2015-06-16 16:37 Brad King Status new => resolved
2015-06-16 16:37 Brad King Resolution open => no change required
2015-06-16 16:50 Hendrik Sattler Note Added: 0038940
2015-06-17 08:21 Hendrik Sattler Note Added: 0038942
2015-06-17 08:21 Hendrik Sattler Status resolved => feedback
2015-06-17 08:21 Hendrik Sattler Resolution no change required => reopened
2015-06-18 08:33 Brad King Status feedback => backlog
2015-06-18 08:33 Brad King Resolution reopened => open
2015-06-18 08:35 Brad King Note Added: 0038943
2015-06-19 09:50 Brad King Relationship added related to 0015074
2015-06-19 09:51 Brad King Note Added: 0038955
2015-06-19 10:36 Brad King Note Added: 0038956
2015-06-19 10:36 Brad King Assigned To => Brad King
2015-06-19 10:36 Brad King Status backlog => resolved
2015-06-19 10:36 Brad King Resolution open => fixed
2015-06-19 10:36 Brad King Fixed in Version => CMake 3.4
2015-06-19 10:36 Brad King Target Version => CMake 3.4
2016-02-01 09:10 Robert Maynard Note Added: 0040403
2016-02-01 09:10 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team