This forum has been archived. All content is frozen. Please use KDE Discuss instead.

cmake and moc

Tags: None
(comma "," separated)
deadeyes
Registered Member
Posts
34
Karma
0

cmake and moc

Tue Jan 25, 2011 8:53 pm
Hi all,

I created a project at first with KDevelop.
Later on I added slots to a new class and found out I couldn't use it (When running I got a message that this slot does not exist).

I found out that moc should be run on this file and then it worked for me.

Someone proposed to use qt4_wrap_cpp to get this done automatically.
However I didn't get it working.

I looked here:
http://techbase.kde.org/Development/Too ... eLists.txt

And found:
Then you can add two lines per target to your CMakeLists.txt and you never need to worry about moc files anymore:

set(foobar_srcs main.cpp foobar.cpp)
add_executable(foobar ${foobar_srcs})

then becomes

find_package(Automoc4 REQUIRED)

set(foobar_srcs main.cpp foobar.cpp)
automoc4_add_executable(foobar ${foobar_srcs})


So I tried a few things but none gave me the correct result. This is the CMakeLists file I have now:
Code: Select all
project(diskspacefree)
find_package(KDE4 REQUIRED)
include (KDE4Defaults)

set(diskspacefree_SRCS mountpoint.cpp directorymodel.cpp directoryparser.cpp directory.cpp
   diskspacefree.cpp
   main.cpp
   diskspacefreeview.cpp
 )

find_package(Automoc4 REQUIRED)
automoc4_add_executable(diskspacefreee ${diskspacefree_SRCS})

include_directories( ${KDE4_INCLUDES} ${QT_INCLUDES} )

cmake_minimum_required(VERSION 2.8)

kde4_add_ui_files(diskspacefree_SRCS diskspacefreeview_base.ui prefs_base.ui)

kde4_add_kcfg_files(diskspacefree_SRCS settings.kcfgc )

kde4_add_executable(diskspacefree ${diskspacefree_SRCS})

target_link_libraries(diskspacefree ${KDE4_KDEUI_LIBS} ${QT_QTTEST_LIBRARY})

install(TARGETS diskspacefree ${INSTALL_TARGETS_DEFAULT_ARGS} )

########### install files ###############

install( FILES diskspacefree.desktop  DESTINATION ${XDG_APPS_INSTALL_DIR} )
install( FILES diskspacefree.kcfg  DESTINATION  ${KCFG_INSTALL_DIR} )
install( FILES diskspacefreeui.rc  DESTINATION  ${DATA_INSTALL_DIR}/diskspacefree )



This file got generated by KDevelop. So I actually don't have any experience writing this.
I added these lines:
Code: Select all
find_package(Automoc4 REQUIRED)
automoc4_add_executable(diskspacefree ${diskspacefree_SRCS})

However that came up with some errors about invalid reference.
Automoc4 is installed.
I tried commenting out kde4_add_executable but that didn't help either.

Can anyone point me in the correct direction?

Thanks in advance!


EDIT:

Errrr... I was just fiddling around and I got it compiling:

Code: Select all
#kde4_add_executable(diskspacefree ${diskspacefree_SRCS})

find_package(Automoc4 REQUIRED)
automoc4_add_executable(diskspacefree ${diskspacefree_SRCS})

The first line I commented out and the automoc lines I added after it.
Make clean
make

This seems to compile and link.

However I am still wondering if this is the way it should be done.

Thanks in advance on any remarks!
Musikolo
Registered Member
Posts
27
Karma
0
OS

Re: cmake and moc

Wed Jan 26, 2011 11:22 pm
Hi,

I have also recently started to program in Qt4 on KDevelop. So, I have suffered the same problem you have. Fortunately, I think I have a solution for your problem. Quite likely, all you have to do it's follow the next steps:

1.- First of all, go to your build dir and remove it all (rm .../build/* -rf)
2.- If your class ExampleClass is in file exampleclass.h and exampleclass.cpp, add at the end of exampleclass.cpp the next line:
Code: Select all
#include "exampleclass.moc"

You will see the exampleclass.moc file is creating when you build. Pay attention to this as it's essential.

Regarding your CMakeLists.txt file, the only thing you must make sure to include it's the next line:
Code: Select all
qt4_automoc(${<YOUR_PROJECT_NAME>_SRCS})
where <YOUR_PROJECT_NAME> is the name you have defined in the project statement.

Now it's time to build your project and keep your finger crossed.

I hope it works! ;)


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft