[CMake] Building a main.cpp containing a QObject subclass
Laszlo Papp
lpapp at kde.org
Mon Oct 31 06:15:23 EDT 2011
Hi,
I would like to achieve something like this by using cmake:
http://doc.qt.nokia.com/4.8/activeqt-comapp.html
I would like to have a QObject subclass in my main.cpp file since it
has just one method for instance, and thus it would be a convenient
approach for me.
This is my current CMakeLists.txt file:
[code]
cmake_minimum_required(VERSION 2.8)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
find_package(Qt4)
#set(CMAKE_AUTOMOC ON)
set(test_SRCS
main.cpp
)
qt4_automoc(${test_SRCS})
add_executable(test ${test_SRCS})
[/code]
This is my current main.cpp file:
[code]
#include <QtCore/QObject>
class MyClass : public QObject
{
Q_OBJECT
}
#include "main.moc"
int main( int argc, char** argv )
{
return 0;
}
[/code]
I have tried the following changes to this code in separate steps:
1) #include "moc_main.cpp", comment set(CMAKE_AUTOMOC ON), and
uncomment qt4_automoc and vica versa
2) set(CMAKE_AUTOMOC ON) without a comment character, and comment qt4_automoc
I am getting similar errors, like:
1) make[2]: *** No rule to make target `../main.h', needed by `main.moc'. Stop.
2) /home/lpapp/Projects/kde/test/main.cpp:8:24: fatal error:
moc_main.cpp: No such file or directory
.. and so on
I was just reading about the qt4_wrapp_cpp as well, but I am really
unsure since I have no header file, just one cpp as in the official Qt
example. I would not like to change this construction, if possible. I
cannot use KDE macros since it is a pure Qt application.
Thank you for your help in advance!
Best Regards,
Laszlo Papp
More information about the CMake
mailing list