FindKDE4

Note

This module is specifically intended for KDE version 4, which is obsolete and no longer maintained. For modern application development using KDE technologies with CMake, use a newer version of KDE, and refer to the KDE documentation.

Finds the KDE 4 installation:

find_package(KDE4 [...])

This module is a wrapper around the following upstream KDE 4 modules:

FindKDE4Internal.cmake

Upstream internal module, which finds the KDE 4 include directories, libraries, and KDE-specific preprocessor tools. It provides usage requirements for building KDE 4 software and defines several helper commands to simplify working with KDE 4 in CMake.

KDE4Macros.cmake

Upstream utility module that defines all additional KDE4-specific commands to use KDE 4 in CMake. For example: kde4_automoc(), kde4_add_executable(), kde4_add_library(), kde4_add_ui_files(), kde4_add_ui3_files(), kde4_add_kcfg_files(), kde4_add_kdeinit_executable(), etc.

Upstream KDE 4 modules are installed by the KDE 4 distribution package in $KDEDIRS/share/apps/cmake/modules/. This path is automatically appended to the CMAKE_MODULE_PATH variable when calling find_package(KDE4), so any additional KDE 4 modules can be included in the project with include(). For example:

KDE4Defaults.cmake

Upstream internal module that sets some CMake options which are useful, but not required for building KDE 4 software. If these settings should be used, include this module after finding KDE 4:

find_package(KDE4)
include(KDE4Defaults)

For usage details, refer to the upstream KDE 4 documentation. For example, at the top of the FindKDE4Internal module a complete documentation is available for all variables and commands these modules provide.

Hints

This module accepts the following variables before calling the find_package(KDE4):

ENV{KDEDIRS}

Environment variable containing the path to the KDE 4 installation.

KDE 4 is searched in the following directories in the given order:

Examples

Example: Basic Usage

Finding KDE 4 as required and using it in CMake:

find_package(KDE4 REQUIRED)

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

# The kde4_*() commands are provided by the KDE4Macros module, which is
# included automatically by FindKDE4, if KDE4 is found:
kde4_automoc(${sources})
kde4_add_executable(example ${sources})

target_include_directories(example PRIVATE ${KDE4_INCLUDES})
target_link_libraries(example PRIVATE ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS})

install(TARGETS example DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES kfoo.desktop DESTINATION ${XDG_APPS_DIR})

Example: The kdeinit Executable

In the following example, the so called kdeinit executable is created. The kde4_add_kdeinit_executable() command creates both an executable with the given name and a library with the given name prefixed with kdeinit_. The target_link_libraries() command adds all required libraries to the kdeinit_kbar library, and then links the kbar against the kdeinit_kbar:

find_package(KDE4 REQUIRED)

# ...

kde4_add_kdeinit_executable(kbar ${kbarSources})
target_link_libraries(kdeinit_kbar ${KDE4_KIO_LIBS})
target_link_libraries(kbar kdeinit_kbar)

install(TARGETS kbar DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS kdeinit_kbar DESTINATION ${CMAKE_INSTALL_LIBDIR})

Example: Removing Compile Definitions

Sometimes, a default compile definition passed to the compiler needs to be removed. The remove_definitions() command can be used. For example, by default, the KDE4 build system sets the -DQT_NO_STL flag. If the project code uses some of the Qt STL compatibility layer, this flag should be removed:

find_package(KDE4 REQUIRED)

add_definitions(${KDE4_DEFINITIONS})

# ...

remove_definitions(-DQT_NO_STL)