Development/CMake/Addons for KDE: Difference between revisions

    From KDE TechBase
    No edit summary
    m (→‎Implementation Notes: link to the file in question)
     
    (7 intermediate revisions by 2 users not shown)
    Line 6: Line 6:
    CMake supports different build types for compiling the source code.
    CMake supports different build types for compiling the source code.
    The following built-in build types are available to the CMake buildsystem:
    The following built-in build types are available to the CMake buildsystem:
    {{note|The build types are '''case-sensitive'''.  This may be fixed in the future however, so don't rely on this behavior.}}


    ;Release: optimized for speed, no debug symbols or qDebug/kDebug messages, no asserts
    ;Release: optimized for speed, no debug symbols or qDebug/kDebug messages, no asserts
    ;RelWithDebInfo: similiar to ''release'', but with debug symbols for backtraces (-g)
    ;RelWithDebInfo: similiar to ''release'', but with debug symbols for backtraces (-g). This is the default if none other is chosen.
    ;Debug: optimized for speed, but debuggable and with debug symbols for backtraces (-g)
    ;Debug: optimized for speed, but debuggable (you can still single-step through functions and set most breakpoints) and with debug symbols for backtraces (-g)
    ;debugfull: no optimizations, full debug support (-g3)
    ;DebugFull: no optimizations, full debug support and information (-g3). Note that some compiler warnings rely on the optimizer being available.
    ;Profile: adds coverage flags (-ftest-coverage -fprofile-arcs) to debugfull
    ;Profile: adds coverage flags (-ftest-coverage -fprofile-arcs) to DebugFull.
    ;None: the build flags are manually set using the CMAKE_CXX_FLAGS option.
    ;None: the build flags are manually set using the CMAKE_CXX_FLAGS option.


    You can tell CMake the desired build type by passing the relevant type as command line option, for instance:
    You can tell CMake the desired build type by passing the relevant type as command line option, for instance:
      cmake /path/to/source -DCMAKE_BUILD_TYPE=debugfull
      cmake /path/to/source -DCMAKE_BUILD_TYPE=Debug
    The default value is ''RelWithDebInfo''.


    === Debugging Features in Detail ===
    === Debugging Features in Detail ===
    Line 31: Line 28:
    | Debug||yes||yes||yes||yes||yes
    | Debug||yes||yes||yes||yes||yes
    |-
    |-
    | debugfull||no||yes||yes||yes||yes
    | DebugFull||no||yes||yes||yes||yes
    |-
    |-
    | Profile||no||yes||yes||yes||yes
    | Profile||no||yes||yes||yes||yes
    Line 37: Line 34:


    === Implementation Notes ===
    === Implementation Notes ===
    Please refer to [http://websvn.kde.org/*checkout*/trunk/KDE/kdelibs/cmake/modules/FindKDE4Internal.cmake FindKDE4Internal.cmake] for further details and the actual flags used.
    Please refer to the source for further details and the actual flags used.<br />
    [http://quickgit.kde.org/?p=kdelibs.git&a=blob&f=cmake/modules/FindKDE4Internal.cmake kdelibs.git/cmake/modules/FindKDE4Internal.cmake]


    == Variables ==
    == Variables ==
    Line 95: Line 93:
    * '''WALLPAPER_INSTALL_DIR'''    - the install dir for wallpapers
    * '''WALLPAPER_INSTALL_DIR'''    - the install dir for wallpapers
    * '''KCONF_UPDATE_INSTALL_DIR''' - the kconf_update install dir
    * '''KCONF_UPDATE_INSTALL_DIR''' - the kconf_update install dir
    * '''XDG_APPS_INSTALL_DIR'''    - the XDG apps dir
    * '''XDG_APPS_INSTALL_DIR'''    - the application install directory from [http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html the definition] by X Development Group which is the former name for [http://FreeDeskTop.org FreeDeskTop.org].
    * '''XDG_DIRECTORY_INSTALL_DIR''' - the XDG directory
    * '''XDG_DIRECTORY_INSTALL_DIR''' - the XDG directory
    * '''XDG_MIME_INSTALL_DIR'''    - the XDG mimetypes install dir
    * '''XDG_MIME_INSTALL_DIR'''    - the XDG mimetypes install dir
    Line 185: Line 183:
    Notifies the icon cache that new icons have been installed by updating mtime of ${ICON_INSTALL_DIR}/hicolor directory.
    Notifies the icon cache that new icons have been installed by updating mtime of ${ICON_INSTALL_DIR}/hicolor directory.


    * '''KDE4_INSTALL_ICONS(path theme)'''
    * '''[http://quickgit.kde.org/?p=kdelibs.git&a=blob&f=cmake/modules/KDE4Macros.cmake KDE4_INSTALL_ICONS(path theme)]'''


    Installs all png and svgz files in the current directory to the icon directory given in path, in the subdirectory for the given icon theme.
    Installs all png and svgz files in the current directory that comply to the [[Development/Tutorials/Icons#The_icon_naming_scheme|icon naming scheme]] to the icon directory given in path, in the subdirectory for the given icon theme.


    * '''KDE4_ADD_APP_ICON(appsources pattern)'''
    * '''KDE4_ADD_APP_ICON(appsources pattern)'''

    Latest revision as of 02:48, 21 July 2012

    A page to document the variables, macros and other useful stuff we have to use CMake as the KDE4 buildsystem.

    You may also want to visit the automatically generated documentation for FindKDE4Internal.cmake, which is generated directly from the current FindKDE4Internal.cmake and may be more up-to-date.

    Buildtypes

    CMake supports different build types for compiling the source code. The following built-in build types are available to the CMake buildsystem:

    Release
    optimized for speed, no debug symbols or qDebug/kDebug messages, no asserts
    RelWithDebInfo
    similiar to release, but with debug symbols for backtraces (-g). This is the default if none other is chosen.
    Debug
    optimized for speed, but debuggable (you can still single-step through functions and set most breakpoints) and with debug symbols for backtraces (-g)
    DebugFull
    no optimizations, full debug support and information (-g3). Note that some compiler warnings rely on the optimizer being available.
    Profile
    adds coverage flags (-ftest-coverage -fprofile-arcs) to DebugFull.
    None
    the build flags are manually set using the CMAKE_CXX_FLAGS option.

    You can tell CMake the desired build type by passing the relevant type as command line option, for instance:

    cmake /path/to/source -DCMAKE_BUILD_TYPE=Debug
    

    Debugging Features in Detail

    CMAKE_BUILD_TYPE Optimized Symbols qDebug kDebug Asserts
    Release yes no no no no
    RelWithDebInfo yes yes no no no
    Debug yes yes yes yes yes
    DebugFull no yes yes yes yes
    Profile no yes yes yes yes

    Implementation Notes

    Please refer to the source for further details and the actual flags used.
    kdelibs.git/cmake/modules/FindKDE4Internal.cmake

    Variables

    The tools required to compile KDE software

    • KDE4_KCFGC_EXECUTABLE - the kconfig_compiler executable
    • KDE4_AUTOMOC_EXECUTABLE - the kde4automoc executable
    • KDE4_MEINPROC_EXECUTABLE - the meinproc4 executable
    • KDE4_MAKEKDEWIDGETS_EXECUTABLE - the makekdewidgets executable

    The location of the KDE libraries

    • KDE4_KDECORE_LIBS - the kdecore library and all depending libraries
    • KDE4_KDEUI_LIBS - the kdeui library and all depending libraries
    • KDE4_KIO_LIBS - the kio library and all depending libraries
    • KDE4_KPARTS_LIBS - the kparts library and all depending libraries
    • KDE4_KUTILS_LIBS - the kutils library and all depending libraries
    • KDE4_KDE3SUPPORT_LIBS - the kde3support library and all depending libraries
    • KDE4_KFILE_LIBS - the kfile library and all depending libraries
    • KDE4_KHTML_LIBS - the khtml library and all depending libraries
    • KDE4_KJS_LIBS - the kjs library and all depending libraries
    • KDE4_KNEWSTUFF2_LIBS - the knewstuff2 library and all depending libraries
    • KDE4_KDEPRINT_LIBS - the kdeprint library and all depending libraries
    • KDE4_KDNSSD_LIBS - the kdnssd library and all depending libraries
    • KDE4_KDESU_LIBS - the kdesu library and all depending libraries
    • KDE4_PHONON_LIBS - the phonon library and all depending librairies
    • KDE4_KDEFX_LIBS - the kdefx library and all depending librairies
    • KDE4_THREADWEAVER_LIBRARIES - the threadweaver library and all depending libraries
    • KDE4_SOLID_LIBS - the solid library and all depending libraries
    • KDE4_KNOTIFYCONFIG_LIBS - the knotify config library and all depending libraries
    • KDE4_KROSSCORE_LIBS - the kross core library and all depending libraries
    • KDE4_KROSSUI_LIBS - the kross ui library which includes core and all depending libraries
    • KDE4_KTEXTEDITOR_LIBS - the ktexteditor library and all depending libraries
    • KDE4_KNEPOMUK_LIBS - the knepomuk library and all depending libraries
    • KDE4_KMETADATA_LIBS - the kmetadata library and all depending libraries

    The locations of install directories

    They are all interpreted relative to CMAKE_INSTALL_PREFIX

    • BIN_INSTALL_DIR - the directory where executables be installed (default is prefix/bin)
    • SBIN_INSTALL_DIR - the directory where system executables will be installed (default is prefix/sbin)
    • LIB_INSTALL_DIR - the directory where libraries will be installed (default is prefix/lib)
    • CONFIG_INSTALL_DIR - the config file install dir
    • DATA_INSTALL_DIR - the parent directory where applications can install their data
    • HTML_INSTALL_DIR - the HTML install dir for documentation
    • ICON_INSTALL_DIR - the icon install dir (default is prefix/share/icons)
    • INFO_INSTALL_DIR - the kde info install dir (default is prefix/info)
    • KCFG_INSTALL_DIR - the install dir for kconfig files
    • LOCALE_INSTALL_DIR - the install dir for translations
    • MAN_INSTALL_DIR - the kde man page install dir (default is prefix/man)
    • MIME_INSTALL_DIR - the install dir for the mimetype desktop files
    • PLUGIN_INSTALL_DIR - the subdirectory relative to the install prefix where plugins will be installed (default is ${KDE4_LIB_INSTALL_DIR}/kde4)
    • SERVICES_INSTALL_DIR - the install dir for service (desktop, protocol, ...) files
    • SERVICETYPES_INSTALL_DIR - the install dir for servicestypes desktop files
    • SOUND_INSTALL_DIR - the install dir for sound files
    • TEMPLATES_INSTALL_DIR - the install dir for templates (Create new file...)
    • WALLPAPER_INSTALL_DIR - the install dir for wallpapers
    • KCONF_UPDATE_INSTALL_DIR - the kconf_update install dir
    • XDG_APPS_INSTALL_DIR - the application install directory from the definition by X Development Group which is the former name for FreeDeskTop.org.
    • XDG_DIRECTORY_INSTALL_DIR - the XDG directory
    • XDG_MIME_INSTALL_DIR - the XDG mimetypes install dir
    • DBUS_INTERFACES_INSTALL_DIR - the directory where dbus interfaces be installed (default is prefix/share/dbus-1/interfaces)
    • DBUS_SERVICES_INSTALL_DIR - the directory where dbus services be installed (default is prefix/share/dbus-1/services)

    Macros

    Lots of useful macros: (Question: Is there a URL to download these macros?)

    • KDE4_ADD_UI_FILES (SRCS_VAR file1.ui ... fileN.ui)

    Use this to add Qt designer ui files to your application/library.

    • KDE4_ADD_UI3_FILES (SRCS_VAR file1.ui ... fileN.ui)

    Use this to add Qt designer ui files from Qt version 3 to your application/library.

    • KDE4_ADD_KCFG_FILES (SRCS_VAR [GENERATE_MOC] file1.kcfgc ... fileN.kcfgc)

    Use this to add KDE config compiler files to your application/library.

    Use optional GENERATE_MOC to generate moc if you use signals in your kcfg files.

    • KDE4_ADD_WIDGET_FILES (SRCS_VAR file1.widgets ... fileN.widgets)

    Use this to add widget description files for the makekdewidgets code generator for Qt Designer plugins.

    • KDE4_ADD_PLUGIN ( name [WITH_PREFIX] file1 ... fileN )

    Create a KDE plugin (KPart, kioslave, etc.) from the given source files.

    It supports KDE4_ENABLE_FINAL.

    If WITH_PREFIX is given, the resulting plugin will have the prefix "lib", otherwise it won't.

    It creates and installs an appropriate libtool la-file.

    • KDE4_ADD_KDEINIT_EXECUTABLE (name [NOGUI] [RUN_UNINSTALLED] file1 ... fileN)

    Create a KDE application in the form of a module loadable via kdeinit.

    A library named kdeinit_<name> will be created and a small executable which links to it.

    It supports KDE4_ENABLE_FINAL

    If the executable has to be run from the buildtree (e.g. unit tests and code generators used later on when compiling), set the option RUN_UNINSTALLED.

    If the executable doesn't have a GUI, use the option NOGUI. By default on OS X application bundles are created, with the NOGUI option no bundles but simple executables are created. Currently it doesn't have any effect on other platforms.

    • KDE4_ADD_EXECUTABLE (name [NOGUI] [RUN_UNINSTALLED] file1 ... fileN)

    Equivalent to ADD_EXECUTABLE(), but additionally adds some more features:

    ** support for KDE4_ENABLE_FINAL
    ** support for automoc
    ** automatic RPATH handling
    

    If the executable has to be run from the buildtree (e.g. unit tests and code generators used later on when compiling), set the option RUN_UNINSTALLED.

    If the executable doesn't have a GUI, use the option NOGUI. By default on OS X application bundles are created, with the NOGUI option no bundles but simple executables are created. Currently it doesn't have any effect on other platforms.

    • KDE4_ADD_LIBRARY (name [STATIC | SHARED | MODULE ] file1 ... fileN)

    Equivalent to ADD_LIBRARY(), but additionally it supports KDE4_ENABLE_FINAL and under Windows it adds a -DMAKE_<name>_LIB definition to the compilation.

    • KDE4_ADD_UNIT_TEST (testname [TESTNAME targetname] file1 ... fileN)

    Add a unit test, which is executed when running make test

    It will be built with RPATH pointing to the build dir

    The targets are always created, but only built for the "all" target if the option KDE4_BUILD_TESTS is enabled. Otherwise the rules for the target are created but not built by default. You can build them by manually building the target.

    The name of the target can be specified using TESTNAME <targetname>, if it is not given the macro will default to the <testname>

    • KDE4_ADD_TEST_EXECUTABLE (name file1 ... fileN)

    Add a test executable

    It will be built with RPATH pointing to the build dir

    The targets are always created, but only built for the "all" target if the option KDE4_BUILD_TESTS is enabled. Otherwise the rules for the target are created but not built by default. You can build them by manually building the target.

    KDESRCDIR is set to the source directory of the test, this can be used with KGlobal::dirs()->addResourceDir( "data", KDESRCDIR ); to be able to use xmlgui and other things in the test, that normally require installation

    • KDE4_UPDATE_ICONCACHE()

    Notifies the icon cache that new icons have been installed by updating mtime of ${ICON_INSTALL_DIR}/hicolor directory.

    Installs all png and svgz files in the current directory that comply to the icon naming scheme to the icon directory given in path, in the subdirectory for the given icon theme.

    • KDE4_ADD_APP_ICON(appsources pattern)

    Mac OS X and Windows only: Adds application icon to target source list. This macro adds an application icon to the specified target. Mac OS X notes: the application icon is added to a Mac OS X bundle so that Finder and friends show the right thing. You need to provide a 128x128 version of the icon for this to work. Windows notes: the application icon(s) are compiled into the application binary.

    Parameters:

    1. 'appsources' - specifies the list of source files
    2. 'pattern' - regular expression for searching application icons

    Examples: KDE4_ADD_APP_ICON(myapp_sources "pics/cr*-myapp.png") or KDE4_ADD_APP_ICON(myapp_sources "${KDE4_INSTALL_DIR}/share/icons/oxygen/*/apps/myapp.png")

    • KDE4_CREATE_HANDBOOK( docbookfile )

    Create the handbook from the docbookfile (using meinproc)

    • KDE4_SET_CUSTOM_TARGET_PROPERTY - deprecated, do not use
    • KDE4_GET_CUSTOM_TARGET_PROPERTY - deprecated, do not use
    • KDE4_MOC_HEADERS
    • KDE4_HANDLE_AUTOMOC
    • KDE4_CREATE_FINAL_FILES
    • KDE4_REMOVE_OBSOLETE_CMAKE_FILES
    • KDE4_NO_ENABLE_FINAL