PDA

View Full Version : compiling qt4 applications with cmake



elcuco
13th October 2006, 18:21
Hi,

I am toying with cmake. It looks interesting, and much more flexibly then QMake. I have read: http://wiki.qtcentre.org/index.php?title=Compiling_Qt4_apps_with_CMake and
http://qtnode.net/wiki/Qt_with_cmake#cmake_for_Qt_4

I have a basic CMakeLists.txt and it does not want to generate the UI files. The output I get is:


elcuco@linux:~/src/svn/qtedit4/tools/qtsourceview/demos/demo1/build> cmake ../ && make
-- Found Qt-Version 4.2.0-snapshot-20061002
-- Configuring done
-- Generating done
-- Build files have been written to: /home/elcuco/src/svn/qtedit4/tools/qtsourceview/demos/demo1/build
[ 20%] Building CXX object CMakeFiles/demo1.dir/mainwindow1.o
In file included from /home/elcuco/src/svn/qtedit4/tools/qtsourceview/demos/demo1/mainwindow1.cpp:12:
/home/elcuco/src/svn/qtedit4/tools/qtsourceview/demos/demo1/mainwindow1.h:5:28: error: ui_mainwindow1.h: No such file or directory
/home/elcuco/src/svn/qtedit4/tools/qtsourceview/demos/demo1/mainwindow1.h:11: error: ‘Ui’ has not been declared
/home/elcuco/src/svn/qtedit4/tools/qtsourceview/demos/demo1/mainwindow1.h:11: error: invalid use of undefined type ‘class MainWindow1’
/home/elcuco/src/svn/qtedit4/tools/qtsourceview/demos/demo1/mainwindow1.h:11: error: forward declaration of ‘class MainWindow1’
/home/elcuco/src/svn/qtedit4/tools/qtsourceview/demos/demo1/mainwindow1.cpp: In constructor ‘MainWindow1::MainWindow1(QMainWindow*)’:
/home/elcuco/src/svn/qtedit4/tools/qtsourceview/demos/demo1/mainwindow1.cpp:17: error: ‘setupUi’ was not declared in this scope
/home/elcuco/src/svn/qtedit4/tools/qtsourceview/demos/demo1/mainwindow1.cpp:28: error: ‘textEdit’ was not declared in this scope
/home/elcuco/src/svn/qtedit4/tools/qtsourceview/demos/demo1/mainwindow1.cpp:30: error: invalid use of undefined type ‘struct QStatusBar’
/usr/local/Trolltech/qt4-rsync/include/QtGui/qmainwindow.h:38: error: forward declaration of ‘struct QStatusBar’
/home/elcuco/src/svn/qtedit4/tools/qtsourceview/demos/demo1/mainwindow1.cpp: In member function ‘void MainWindow1::on_action_New_triggered()’:
/home/elcuco/src/svn/qtedit4/tools/qtsourceview/demos/demo1/mainwindow1.cpp:35: error: ‘textEdit’ was not declared in this scope
/home/elcuco/src/svn/qtedit4/tools/qtsourceview/demos/demo1/mainwindow1.cpp: In member function ‘void MainWindow1::on_action_Open_triggered()’:
/home/elcuco/src/svn/qtedit4/tools/qtsourceview/demos/demo1/mainwindow1.cpp:57: error: ‘textEdit’ was not declared in this scope
/home/elcuco/src/svn/qtedit4/tools/qtsourceview/demos/demo1/mainwindow1.cpp:60: error: invalid use of undefined type ‘struct QStatusBar’
/usr/local/Trolltech/qt4-rsync/include/QtGui/qmainwindow.h:38: error: forward declaration of ‘struct QStatusBar’
make[2]: *** [CMakeFiles/demo1.dir/mainwindow1.o] Error 1
make[1]: *** [CMakeFiles/demo1.dir/all] Error 2
make: *** [all] Error 2


I am attaching here my CMakeLists.txt. Help will be appreciated.

jacek
13th October 2006, 23:40
I have read: http://wiki.qtcentre.org/index.php?title=Compiling_Qt4_apps_with_CMake
I guess you missed that part:
# we need this to be able to include headers produced by uic in our code
# (CMAKE_BINARY_DIR holds a path to the build directory, while INCLUDE_DIRECTORIES() works just like INCLUDEPATH from qmake)
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} )

elcuco
14th October 2006, 01:06
I modified the include to this line (I am not building insource)


INCLUDE_DIRECTORIES ( ${QT_INCLUDE_DIR} ${CMAKE_BINARY_DIR} ../../src )


Now the code compiles. Wow... This was not that trivial to understand, but thanks for pointing it out once again!

jacek
14th October 2006, 16:51
I am not building insource
That's why you had to add ${CMAKE_BINARY_DIR} to INCLUDE_DIRECTORIES, since all generated files will are stored in that directory.