[CMake] How to write CMakeLists.txt for Qt4 when Q_OBJECT in xxx.cpp file
Michael Jackson
mike.jackson at bluequartz.net
Sat Jul 31 08:21:02 EDT 2010
PROJECT(mytest)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui REQUIRED)
INCLUDE(${QT_USE_FILE})
SET(pro_SOURCES main.cpp)
QT4_WRAP_CPP( Generated_MOC_SRCS main.cpp )
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
ADD_EXECUTABLE(mytest ${pro_SOURCES} ${Generated_MOC_SRCS} )
TARGET_LINK_LIBRARIES(mytest ${QT_LIBRARIES})
___________________________________________________________
Mike Jackson www.bluequartz.net
On Jul 31, 2010, at 7:38 AM, 1+1=2 wrote:
> Hi,everyone
>
> I am new to cmake. I don't know how to write a CMakeList.txt file if
> Q_OBJECT in a "xxx.cpp" source file.
>
> for example,
> A very simple qt4 program like this.
>
> // filename main.cpp
> #include <QtGui/QApplication>
> #include <QtGui/QWidget>
> class Widget:public QWidget
> {
> Q_OBJECT
> public:
> Widget(QWidget * parent=0):QWidget(parent) {}
> };
> #include "main.moc"
> int main(int argc, char** argv) {
> QApplication app(argc, argv);
> Widget w;
> w.show();
> return app.exec();
> }
>
>
> if i use qmake, i only needed a simple .pro file like this:
>
> TEMPLATE = app
> SOURCES += main.cpp
>
> I try to write a CMakeList.txt, try qt4_wrap_cpp qt4_automoc and
> qt4_generate_moc, but They did not seem to work
>
> PROJECT(mytest)
> CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
> FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui REQUIRED)
> INCLUDE(${QT_USE_FILE})
> SET(pro_SOURCES main.cpp)
>
> #QT4_WRAP_CPP(${pro_SOURCES})
> #QT4_AUTOMOC(${pro_SOURCES})
> #QT4_GENERATE_MOC(${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
> ${CMAKE_CURRENT_BINARY_DIR}/main.moc)
>
> INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
> ADD_DEFINITIONS(${QT_DEFINITIONS})
> ADD_EXECUTABLE(mytest ${pro_SOURCES})
> TARGET_LINK_LIBRARIES(mytest ${QT_LIBRARIES})
>
> Is there any solution to this?
>
> thanks
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
More information about the CMake
mailing list