[CMake] cmake automoc fails when enabling autorcc

Hendrik Sattler post at hendrik-sattler.de
Mon Jun 8 15:29:51 EDT 2015


Hi,

can someone explain to me what goes wrong?

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

I created a small example that shows the problem. I created it from
scratch and it instantly fails for me.
You need to create a foo.png to get the qrc to actually create the
source file (actually 2nd bug that CMake doesn't warn here).

First run, comment out the onTst2 slot function (both h and cpp file),
it should build.
Then comment it before 2nd run.
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?

Can someone point me to a possible solution?
I'm back to qt4_add_resources() for now.

Regards,

HS


CMakeLists.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>
----------------------------------------------



More information about the CMake mailing list