[Qt-interest] Lots of problems with cmake.

Clinton Stimpson clinton at elemtech.com
Fri Jun 12 17:56:54 CEST 2009


Dorosky, Christopher G wrote:
>
> This has been a real chore.
>
> I’ve got a development project that runs cmake nicely. Now I am adding 
> QT. Let the fun begin.
>
> As an example, I decided to try to get the broadcastsender example to 
> compile and link.
>
> What misery. It seems like there is an awful lot of bad information on 
> the web.
>
> Here is the CMakeLists.txt
>
> I’ve crammed lots of different suggestions in here, so it’s a mess.
>
> cmake_minimum_required(VERSION 2.6)
>
> # why do I have to do this, shouldn't this work already?
>
> # I don’t have to do it for other cmake projects….
>
> set(CMAKE_FIND_LIBRARY_PREFIXES lib)
>
> set(CMAKE_FIND_LIBRARY_SUFFIXES .so)
>
> # find QT4
>
> find_package(Qt4 REQUIRED)
>
> # one problem at a time, comment out for now.
>
> #set(QT_USE_OPENGL TRUE)
>
> # what on earth does this do?
>
> include(${QT_USE_FILE})
>
> #convenience variables.
>
> set(qtproject_SRCS main.cpp sender.cpp)
>
> set(qtproject_INC sender.h)
>
> #start the project settings.
>
> PROJECT (qttest)
>
> ADD_EXECUTABLE(qttest ${qtproject_SRCS})
>
> QT4_WRAP_CPP(${qtproject_SRCS} ${qtproject_INC})
>
> # The QT4_WRAP_CPP generates this cmake error
>
> #CMake Error: Attempt to add a custom rule to output
>
> # "/home/doroskcg/code/qhrimgr/qttest/moc_sender.cxx.rule" which 
> already has a
>
> # custom rule.
>
> # without it, I get a Makefile and can compile but not link since 
> there are
>
> # no moc files. I get vtable lookup errors.
>
> #what on earth does this do?
>
> #add_definitions( ${QT_DEFINITIONS})
>
> # bad mojo. it wants moc files that have to be manually generated???
>
> #qt4_automoc(${qtproject_SRCS} ${qtproject_INC})
>
> # Complete guesses at library names.
>
> TARGET_LINK_LIBRARIES(qttest ${QT_LIBRARIES} ${QT_QTNETWORK_LIBRARIES} 
> ${QT_QTGUI_LIBRARIES} ${QT_QTCORE_LIBRARIES})
>
> As you can see, I’m totally grasping at straws trying to get this to 
> work.
>
> Any help is appreciated.
>
> Chris
>

Try something like this:

cmake_minimum_required(VERSION 2.6)
PROJECT (qttest)

# find QT4
find_package(Qt4 REQUIRED)

# specify additional Qt modules to use besides the default QtGui and QtCore
set(QT_USE_QTOPENGL TRUE)
set(QT_USE_QTNETWORK TRUE)

# set up the build environment for any following library/executable 
(also accounts for additional Qt modules to use)
include(${QT_USE_FILE})

#convenience variables.
set(qtproject_SRCS main.cpp sender.cpp)
set(qtproject_INC sender.h)

# files needing moc put into moc_SRCS variable
QT4_WRAP_CPP(moc_SRCS ${qtproject_INC})

# build the executable out of sources and moc'd sources (also include 
headers so they show up in IDEs for convenience)
ADD_EXECUTABLE(qttest ${qtproject_SRCS} ${moc_SRCS} ${qtproject_INC})
# link qt libraries to the executable (which qt libraries was specified 
earlier)
TARGET_LINK_LIBRARIES(qttest ${QT_LIBRARIES})

Clint





More information about the Qt-interest-old mailing list