[Qt-interest] cmake: ui library?
Bo Thorsen
bo at fioniasoftware.dk
Tue Feb 14 08:46:59 CET 2012
Den 13-02-2012 22:16, Rui Maciel skrev:
> I'm a cmake newbie and I've started a small pet project which relies on Qt
> for the UI, and the project's build process is managed with cmake.
>
> The project tree follows a deep structure, with the Qt source code and forms
> stored in ~/src/ui, being ~ the project directory.
>
> The UI has been designed following design by contract principles, and
> therefore the remaining components only interact with the UI through a set
> of interfaces which were defined previously.
>
> Due to this, I would like to organize the UI part of this project as a
> static library. With that in mind, I've added a CMakeLists.txt file to
> ~/src/ui, with the following content:
>
> <example ~/src/ui/CMakeLists.txt>
> INCLUDE(${QT_USE_FILE})
> ADD_DEFINITIONS(${QT_DEFINITIONS})
>
> set(libui_HEADERS
> # some headers with Qt code
> )
>
> set(libui_SOURCES
> # some sources which Qt code
> )
>
> set(libui_FORMS
> #some Qt forms
> )
> </example>
>
> Then, I proceeded to pass libui to the TARGET_LINK_LIBRARIES() command and
> add ${libui_HEADERS} to the projec_HEADERS list.
>
> Yet, when I try to compile the project, the compiler throws a series of
> errors about "undefined reference to `vtable for<ui class name here>'".
>
> So, does anyone know how to setup cmake to churn out a static library from
> Qt code?
I had this in one of my projects (it's now replaced with a qmake based
build):
SET(headers ...)
SET(moc_headers ...)
SET(sources ...)
QT4_WRAP_CPP(moc_generated ${moc_headers})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)
INCLUDE(${QT_USE_FILE})
SOURCE_GROUP("Generated Files" REGULAR_EXPRESSION
"(moc_.*cxx|ui_.*h|vbtest_.*cpp)$")
SOURCE_GROUP("UI Files" REGULAR_EXPRESSION ".*.ui$")
ADD_LIBRARY(tools STATIC ${headers} ${moc_headers} ${sources}
${moc_generated})
SET_TARGET_PROPERTIES(tools PROPERTIES LINKER_LANGUAGE CXX)
SET_TARGET_PROPERTIES(tools PROPERTIES PROJECT_LABEL "libtools")
TARGET_LINK_LIBRARIES(tools ${QT_LIBRARIES})
You could find some inspiration for Qt cmake stuff from the example
application I have on my website:
http://www.fioniasoftware.dk/fseditor.html
It's not a complicated build, but there are a few cmake tricks in it you
might want to copy over. Before QtCreator, cmake + VS was my preferred
build environment. But with QtC as good as it is now - especially the
QML integration - I prefer qmake + QtC.
Bo Thorsen,
Fionia Software.
--
Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk
More information about the Qt-interest-old
mailing list