CMake:How To Build KDE4 Software: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
Line 27: Line 27:
Give the project a name, find KDE 4 and setup CMAKE_MODULE_PATH. This has the effect that cmake will also use check the ${CMAKE_SOURCE_DIR}/cmake directory for files if you use include(somefile) or find_package(something). Please note that this directory is added to the former contents of CMAKE_MODULE_PATH. This is important, since if find_package(KDE4) was successfully, it will have setup CMAKE_MODULE_PATH so that it points to the directory where the cmake files installed with kdelibs are located.
Give the project a name, find KDE 4 and setup CMAKE_MODULE_PATH. This has the effect that cmake will also use check the ${CMAKE_SOURCE_DIR}/cmake directory for files if you use include(somefile) or find_package(something). Please note that this directory is added to the former contents of CMAKE_MODULE_PATH. This is important, since if find_package(KDE4) was successfully, it will have setup CMAKE_MODULE_PATH so that it points to the directory where the cmake files installed with kdelibs are located.
<pre>
<pre>
project(allForK)
project(kfoo)


find_package(KDE4 REQUIRED)
find_package(KDE4 REQUIRED)


set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
</pre>
Then apply the required settings:
<pre>
include_directories( ${KDE4_INCLUDE_DIRS})
add_definitions( ${KDE4_DEFINITIONS} )
</pre>
Set up your sources:
<pre>
set(kfooSources main.cpp myappl.cpp view.cpp)
</pre>
If you have Qt designer ui files version 3 or 4 add them this way:
<pre>
kde4_add_ui_files( kfooSources maindialog.ui logindialog.ui)
kde4_add_ui3_files( kfooSources printerdlg.ui previewdlg.ui)
</pre>
If you have files for the kconfig_compiler add them this way:
<pre>
kde4_add_kcfg_files( kfooSources settings.kcfg )
</pre>
</pre>

Revision as of 21:01, 8 April 2006

A simple example

Let's just start with a simple example for an application, let's name it, well, kFoo. The CMakeLists.txt below gives the project a name, so that the project files for KDevelop/XCode/MSVC will have a good name. It will then find the KDE 4 installation on the system and setup the required include directories. The list of source files will be put into a variable named mySources, which will be automoced and then used to build an executable from it. The executable and its desktop file will finally be installed.

project(kfoo)

find_package(KDE4 REQUIRED)

include_directories( ${KDE4_INCLUDES} )

set(mySources main.cpp mywidget.cpp mypart.cpp)

kde4_automoc( ${mySources} )

kde4_add_executable(kfoo ${mySources})

target_link_libraries(kfoo ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS} )

install_targets( /bin kfoo)
install_files( ${XDG_APPS_DIR} FILES kfoo.desktop)

A full-featured example

Ok, and now for a full-featured but non-working example.

Give the project a name, find KDE 4 and setup CMAKE_MODULE_PATH. This has the effect that cmake will also use check the ${CMAKE_SOURCE_DIR}/cmake directory for files if you use include(somefile) or find_package(something). Please note that this directory is added to the former contents of CMAKE_MODULE_PATH. This is important, since if find_package(KDE4) was successfully, it will have setup CMAKE_MODULE_PATH so that it points to the directory where the cmake files installed with kdelibs are located.

project(kfoo)

find_package(KDE4 REQUIRED)

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

Then apply the required settings:

include_directories( ${KDE4_INCLUDE_DIRS})
add_definitions( ${KDE4_DEFINITIONS} )

Set up your sources:

set(kfooSources main.cpp myappl.cpp view.cpp)

If you have Qt designer ui files version 3 or 4 add them this way:

kde4_add_ui_files( kfooSources maindialog.ui logindialog.ui)

kde4_add_ui3_files( kfooSources printerdlg.ui previewdlg.ui)

If you have files for the kconfig_compiler add them this way:

kde4_add_kcfg_files( kfooSources settings.kcfg )