[Qt-interest] cmake: how to set up a deep project tree

Andreas Pakulat apaku at gmx.de
Tue Feb 14 13:52:37 CET 2012


On 14.02.12 12:17:16, Rui Maciel wrote:
> <file name="~/CMakeLists.txt">
> CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
> 
> SET(CMAKE_CXX_FLAGS "-O0 -g -Wall -std=c++0x")
> 
> PROJECT (foo)
> FIND_PACKAGE( Qt4 REQUIRED)
> FIND_PACKAGE(PkgConfig REQUIRED)
> 
> # check for libraries
> pkg_check_modules(SIGC2 REQUIRED sigc++-2.0>=2.1)

Its recommended to instead store the result of pkg_check_modules in an
internal variable and then use find_path and find_library with HINTS to
let cmake setup the actual library/include variables. The benefit of
this is proper dependency tracking by cmake's makefiles for those
external libraries. See the FindLibXml2.cmake shipped with CMake module
for an example.

> <file name="~/src/CMakeLists.txt">
> include_directories ("${PROJECT_SOURCE_DIR}/data")
> include_directories ("${PROJECT_SOURCE_DIR}/ui")
> include_directories ("${PROJECT_BINARY_DIR}/src")
> include_directories ("${PROJECT_BINARY_DIR}/src/ui")
> 
> add_subdirectory (data)
> add_subdirectory (ui)
> 
> SET(foo_SOURCES main.c++ )
> 
> SET(foo_HEADERS )
> SET(foo_FORMS )
> 
> QT4_WRAP_CPP(foo_HEADERS_MOC ${foo_HEADERS})
> QT4_WRAP_UI(foo_FORMS_HEADERS ${foo_FORMS})
> 
> INCLUDE(${QT_USE_FILE})

This is unecessary here since its already done in the top-level file.

> ADD_DEFINITIONS(${QT_DEFINITIONS})

This is unecessary when using the QT_USE_FILE, see the cmake manual for
FindQt4.

Personally I wouldn't use static libs for data or ui (at least not in
such small projects), but simply handle everything in the
src/CMakeLists.txt via relative paths (i.e. data/data.c
ui/MainWindow.cpp).

Andreas




More information about the Qt-interest-old mailing list