kdelibs/cmake/modules/KDE4Macros.cmake

259 lines
9 KiB
CMake
Raw Normal View History

2014-11-13 01:04:59 +02:00
# for documentation look at FindKDE4Internal.cmake
# this file contains the following macros (or functions):
# KDE4_ADD_KCFG_FILES
# KDE4_ADD_PLUGIN
# KDE4_ADD_TEST
# KDE4_ADD_WIDGET
2014-11-13 01:04:59 +02:00
# KDE4_INSTALL_ICONS
# KDE4_INSTALL_AUTH_HELPER_FILES
# Copyright (c) 2006-2009 Alexander Neundorf, <neundorf@kde.org>
# Copyright (c) 2006, 2007, Laurent Montel, <montel@kde.org>
# Copyright (c) 2007 Matthias Kretz <kretz@kde.org>
# Copyright (c) 2015 Ivailo Monev <xakepa10@gmail.com>
2014-11-13 01:04:59 +02:00
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
2015-09-03 05:08:47 +03:00
macro(KDE4_ADD_KCFG_FILES _sources )
foreach(_current_FILE ${ARGN})
get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
get_filename_component(_abs_PATH ${_tmp_FILE} DIRECTORY)
get_filename_component(_basename ${_tmp_FILE} NAME_WE)
2015-09-03 05:08:47 +03:00
file(READ ${_tmp_FILE} _contents)
string(REGEX REPLACE "^(.*\n)?File=([^\n]+kcfg).*\n.*$" "\\2" _kcfg_FILENAME "${_contents}")
set(_src_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp)
set(_header_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h)
set(_kcfg_FILE ${_abs_PATH}/${_kcfg_FILENAME})
# Maybe the .kcfg is a generated file?
if(NOT EXISTS "${_kcfg_FILE}")
set(_kcfg_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_kcfg_FILENAME})
endif()
if(NOT EXISTS "${_kcfg_FILE}")
message(ERROR "${_kcfg_FILENAME} not found; tried in ${_abs_PATH} and ${CMAKE_CURRENT_BINARY_DIR}")
endif()
2015-09-03 05:08:47 +03:00
# make sure the directory exist in the build directory
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/")
endif()
2015-09-03 05:08:47 +03:00
# the command for creating the source file from the kcfg file
add_custom_command(OUTPUT ${_header_FILE} ${_src_FILE}
COMMAND ${KDE4_KCFGC_EXECUTABLE}
ARGS ${_kcfg_FILE} ${_tmp_FILE} -d "${CMAKE_CURRENT_BINARY_DIR}/"
MAIN_DEPENDENCY ${_tmp_FILE}
DEPENDS ${_kcfg_FILE}
)
2015-09-03 05:08:47 +03:00
list(APPEND ${_sources} ${_src_FILE} ${_header_FILE})
2015-09-03 05:08:47 +03:00
endforeach (_current_FILE)
endmacro(KDE4_ADD_KCFG_FILES)
2014-11-13 01:04:59 +02:00
# KDE 4 / icon naming specification compatibility
set(_KDE4_ICON_GROUP_mimetypes "mimetypes")
set(_KDE4_ICON_GROUP_places "places")
set(_KDE4_ICON_GROUP_devices "devices")
set(_KDE4_ICON_GROUP_apps "apps")
set(_KDE4_ICON_GROUP_actions "actions")
set(_KDE4_ICON_GROUP_categories "categories")
set(_KDE4_ICON_GROUP_status "status")
set(_KDE4_ICON_GROUP_emblems "emblems")
set(_KDE4_ICON_GROUP_emotes "emotes")
set(_KDE4_ICON_GROUP_animations "animations")
set(_KDE4_ICON_GROUP_intl "intl")
# a "map" of short theme names to the theme directory
set(_KDE4_ICON_THEME_ox "ariya")
2014-11-13 01:04:59 +02:00
set(_KDE4_ICON_THEME_lo "locolor")
set(_KDE4_ICON_THEME_hi "hicolor")
# only used internally by KDE4_INSTALL_ICONS
macro(_KDE4_ADD_ICON_INSTALL_RULE _install_PATH _group _orig_NAME _install_NAME _l10n_SUBDIR)
2015-09-03 05:08:47 +03:00
# if the string doesn't match the pattern, the result is the full string,
# so all three have the same content
if(NOT ${_group} STREQUAL ${_install_NAME})
set(_icon_GROUP ${_KDE4_ICON_GROUP_${_group}})
if(NOT _icon_GROUP)
set(_icon_GROUP "actions")
endif()
# message(STATUS "path: ${_install_PATH} group: ${_group} name: ${_install_NAME} l10n: ${_l10n_SUBDIR}")
2015-09-03 05:08:47 +03:00
install(
FILES ${_orig_NAME}
DESTINATION ${_install_PATH}/${_icon_GROUP}/${_l10n_SUBDIR}/
RENAME ${_install_NAME}
)
endif()
endmacro(_KDE4_ADD_ICON_INSTALL_RULE)
macro(KDE4_INSTALL_ICONS _defaultpath )
# the l10n-subdir if language given as second argument (localized icon)
set(_lang ${ARGV1})
if(_lang)
set(_l10n_SUBDIR l10n/${_lang})
else()
set(_l10n_SUBDIR ".")
endif()
# first the png icons
file(GLOB _icons *.png)
foreach(_current_ICON ${_icons} )
2015-09-03 05:08:47 +03:00
# since CMake 2.6 regex matches are stored in special variables
# CMAKE_MATCH_x, if it didn't match, they are empty
string(
REGEX MATCH "^.*/([a-zA-Z]+)([0-9]+)\\-([a-z]+)\\-(.+\\.png)$"
_dummy "${_current_ICON}"
)
set(_type "${CMAKE_MATCH_1}")
set(_size "${CMAKE_MATCH_2}")
set(_group "${CMAKE_MATCH_3}")
set(_name "${CMAKE_MATCH_4}")
set(_theme_GROUP ${_KDE4_ICON_THEME_${_type}})
if( _theme_GROUP)
_KDE4_ADD_ICON_INSTALL_RULE(
${_defaultpath}/${_theme_GROUP}/${_size}x${_size}
${_group}
${_current_ICON}
${_name}
${_l10n_SUBDIR}
)
endif( _theme_GROUP)
endforeach(_current_ICON)
# and now the svg icons
file(GLOB _icons *.svgz)
foreach(_current_ICON ${_icons})
2015-09-03 05:08:47 +03:00
string(
REGEX MATCH "^.*/([a-zA-Z]+)sc\\-([a-z]+)\\-(.+\\.svgz)$"
_dummy "${_current_ICON}"
)
set(_type "${CMAKE_MATCH_1}")
set(_group "${CMAKE_MATCH_2}")
set(_name "${CMAKE_MATCH_3}")
set(_theme_GROUP ${_KDE4_ICON_THEME_${_type}})
if(_theme_GROUP)
_KDE4_ADD_ICON_INSTALL_RULE(
${_defaultpath}/${_theme_GROUP}/scalable
${_group}
${_current_ICON}
${_name}
${_l10n_SUBDIR}
2014-11-13 01:04:59 +02:00
)
endif()
endforeach()
endmacro(KDE4_INSTALL_ICONS)
# If "WITH_PREFIX" is in the arugments then the standard "lib" prefix will be
# preserved
macro(KDE4_ADD_PLUGIN _target_NAME)
set(_plugin_prefix)
set(_plugin_srcs)
2015-09-01 04:56:26 +03:00
foreach(arg ${ARGN})
if(arg STREQUAL "WITH_PREFIX")
set(_plugin_prefix TRUE)
else()
list(APPEND _plugin_srcs ${arg})
endif()
2015-09-01 04:56:26 +03:00
endforeach()
add_library(${_target_NAME} MODULE ${_plugin_srcs})
if(NOT "${_plugin_prefix}")
set_target_properties(${_target_NAME} PROPERTIES PREFIX "")
endif()
endmacro(KDE4_ADD_PLUGIN)
# Add a unit test, which is executed when running make test. The targets are
# always created and built unless ENABLE_TESTING is set to negative value.
macro(KDE4_ADD_TEST _targetName)
2015-09-05 05:16:46 +00:00
KDE4_ADD_MANUAL_TEST(${_targetName} ${ARGN})
add_test(
NAME ${_targetName}
COMMAND "${CMAKE_BINARY_DIR}/kde4_exec.sh" "${CMAKE_CURRENT_BINARY_DIR}/${_targetName}"
)
2015-09-05 05:16:46 +00:00
endmacro(KDE4_ADD_TEST)
macro(KDE4_ADD_MANUAL_TEST _targetName)
add_executable(${_targetName} ${ARGN})
2014-11-13 01:04:59 +02:00
2015-09-03 05:08:47 +03:00
target_compile_definitions(
${_targetName} PRIVATE
-DKDESRCDIR="${CMAKE_CURRENT_SOURCE_DIR}/"
-DKDEBINDIR="${CMAKE_CURRENT_BINARY_DIR}/"
2015-09-03 05:08:47 +03:00
)
2015-09-05 05:16:46 +00:00
set_target_properties(
${_targetName} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endmacro(KDE4_ADD_MANUAL_TEST)
2014-11-13 01:04:59 +02:00
macro(KDE4_ADD_WIDGET _output _sources)
foreach(_current_FILE ${_sources})
get_filename_component(_input ${_current_FILE} ABSOLUTE)
get_filename_component(_basename ${_input} NAME_WE)
2014-11-13 01:04:59 +02:00
set(_source ${CMAKE_CURRENT_BINARY_DIR}/${_basename}widgets.cpp)
set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_basename}widgets.moc)
2014-11-13 01:04:59 +02:00
# create source file from the .widgets file
add_custom_command(
OUTPUT ${_source}
COMMAND ${KDE4_MAKEKDEWIDGETS_EXECUTABLE} -o ${_source} ${_input}
MAIN_DEPENDENCY ${_input}
)
2014-11-13 01:04:59 +02:00
qt4_generate_moc("${_source}" "${_moc}")
add_library(${_basename}_autowidgets OBJECT ${_source} ${_moc})
set(${_output} ${${_output}} ${_source} ${_moc})
endforeach(_current_FILE)
endmacro(KDE4_ADD_WIDGET)
2014-11-13 01:04:59 +02:00
2015-09-03 05:08:47 +03:00
# This macro adds the needed files for an helper executable meant to be used by
# applications using KAuth. It accepts the helper target, the helper ID (the
# DBUS name) and the user under which the helper will run on. The macro also
# takes care of generate the needed files, and install them in the right
# location. This boils down to a DBus policy to let the helper register on the
# system bus, and a service file for letting the helper being automatically
# activated by the system bus.
#
generic: replace installation paths with KDE4_ prefixed this is TODO from issue #9. CPack and CTest configs will not be supported. most of the changes done to other repisitories is automated via: find -type f -exec sed -i -e 's|${INSTALL_DIR}|${KDE4_INSTALL_DIR}|g' \ -e 's|${EXEC_INSTALL_PREFIX}|${KDE4_EXEC_INSTALL_PREFIX}|g' \ -e 's|${SHARE_INSTALL_PREFIX}|${KDE4_SHARE_INSTALL_PREFIX}|g' \ -e 's|${BIN_INSTALL_DIR}|${KDE4_BIN_INSTALL_DIR}|g' \ -e 's|${SBIN_INSTALL_DIR}|${KDE4_SBIN_INSTALL_DIR}|g' \ -e 's|${LIB_INSTALL_DIR}|${KDE4_LIB_INSTALL_DIR}|g' \ -e 's|${LIBEXEC_INSTALL_DIR}|${KDE4_LIBEXEC_INSTALL_DIR}|g' \ -e 's|${INCLUDE_INSTALL_DIR}|${KDE4_INCLUDE_INSTALL_DIR}|g' \ -e 's|${PLUGIN_INSTALL_DIR}|${KDE4_PLUGIN_INSTALL_DIR}|g' \ -e 's|${IMPORTS_INSTALL_DIR}|${KDE4_IMPORTS_INSTALL_DIR}|g' \ -e 's|${CONFIG_INSTALL_DIR}|${KDE4_CONFIG_INSTALL_DIR}|g' \ -e 's|${DATA_INSTALL_DIR}|${KDE4_DATA_INSTALL_DIR}|g' \ -e 's|${ICON_INSTALL_DIR}|${KDE4_ICON_INSTALL_DIR}|g' \ -e 's|${KCFG_INSTALL_DIR}|${KDE4_KCFG_INSTALL_DIR}|g' \ -e 's|${LOCALE_INSTALL_DIR}|${KDE4_LOCALE_INSTALL_DIR}|g' \ -e 's|${MIME_INSTALL_DIR}|${KDE4_MIME_INSTALL_DIR}|g' \ -e 's|${SERVICES_INSTALL_DIR}|${KDE4_SERVICES_INSTALL_DIR}|g' \ -e 's|${SERVICETYPES_INSTALL_DIR}|${KDE4_SERVICETYPES_INSTALL_DIR}|g' \ -e 's|${SOUND_INSTALL_DIR}|${KDE4_SOUND_INSTALL_DIR}|g' \ -e 's|${TEMPLATES_INSTALL_DIR}|${KDE4_TEMPLATES_INSTALL_DIR}|g' \ -e 's|${WALLPAPER_INSTALL_DIR}|${KDE4_WALLPAPER_INSTALL_DIR}|g' \ -e 's|${AUTOSTART_INSTALL_DIR}|${KDE4_AUTOSTART_INSTALL_DIR}|g' \ -e 's|${XDG_APPS_INSTALL_DIR}|${KDE4_XDG_APPS_INSTALL_DIR}|g' \ -e 's|${XDG_DIRECTORY_INSTALL_DIR}|${KDE4_XDG_DIRECTORY_INSTALL_DIR}|g' \ -e 's|${XDG_MIME_INSTALL_DIR}|${KDE4_XDG_MIME_INSTALL_DIR}|g' \ -e 's|${SYSCONF_INSTALL_DIR}|${KDE4_SYSCONF_INSTALL_DIR}|g' \ -e 's|${MAN_INSTALL_DIR}|${KDE4_MAN_INSTALL_DIR}|g' \ -e 's|${INFO_INSTALL_DIR}|${KDE4_INFO_INSTALL_DIR}|g' \ -e 's|${DBUS_INTERFACES_INSTALL_DIR}|${KDE4_DBUS_INTERFACES_INSTALL_DIR}|g' \ -e 's|${DBUS_SERVICES_INSTALL_DIR}|${KDE4_DBUS_SERVICES_INSTALL_DIR}|g' \ -e 's|${DBUS_SYSTEM_SERVICES_INSTALL_DIR}|${KDE4_DBUS_SYSTEM_SERVICES_INSTALL_DIR}|g' \ -e 's|${KAUTH_HELPER_PLUGIN_DIR}|${KDE4_KAUTH_HELPER_PLUGIN_DIR}|g' \ -e 's|${KAUTH_BACKEND_PLUGIN_DIR}|${KDE4_KAUTH_BACKEND_PLUGIN_DIR}|g' {} + note that if you execute this command you may corrupt the git repository files so move the .git directory out of the way. you can also verify that there are no other reference to the compatibility installation paths via: git grep \ -e INSTALL_DIR \ -e EXEC_INSTALL_PREFIX \ -e SHARE_INSTALL_PREFIX \ -e BIN_INSTALL_DIR \ -e SBIN_INSTALL_DIR \ -e LIB_INSTALL_DIR \ -e LIBEXEC_INSTALL_DIR \ -e INCLUDE_INSTALL_DIR \ -e PLUGIN_INSTALL_DIR \ -e IMPORTS_INSTALL_DIR \ -e CONFIG_INSTALL_DIR \ -e DATA_INSTALL_DIR \ -e ICON_INSTALL_DIR \ -e KCFG_INSTALL_DIR \ -e LOCALE_INSTALL_DIR \ -e MIME_INSTALL_DIR \ -e SERVICES_INSTALL_DIR \ -e SERVICETYPES_INSTALL_DIR \ -e SOUND_INSTALL_DIR \ -e TEMPLATES_INSTALL_DIR \ -e WALLPAPER_INSTALL_DIR \ -e AUTOSTART_INSTALL_DIR \ -e XDG_APPS_INSTALL_DIR \ -e XDG_DIRECTORY_INSTALL_DIR \ -e XDG_MIME_INSTALL_DIR \ -e SYSCONF_INSTALL_DIR \ -e MAN_INSTALL_DIR \ -e INFO_INSTALL_DIR \ -e DBUS_INTERFACES_INSTALL_DIR \ -e DBUS_SERVICES_INSTALL_DIR \ -e DBUS_SYSTEM_SERVICES_INSTALL_DIR \ -e KAUTH_HELPER_PLUGIN_DIR \ -e KAUTH_BACKEND_PLUGIN_DIR | grep -v KDE4_ this change should make default installation Filesystem Hierarchy Standard (FHS) compliant and packaging easier since library suffix (e.g. 64 for x86_64 hosts) will not have to be specified explicitly, it may solve possible conflicts with installation path variables from other projects which use custom installation paths aswell Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
2020-02-08 20:46:43 +00:00
# *WARNING* You have to install the helper in ${KDE4_LIBEXEC_INSTALL_DIR} to make
2015-09-03 05:08:47 +03:00
# sure everything will work.
2014-11-13 01:04:59 +02:00
function(KDE4_INSTALL_AUTH_HELPER_FILES HELPER_TARGET HELPER_ID HELPER_USER)
if(_kdeBootStrapping)
set(_stubFilesDir ${CMAKE_SOURCE_DIR}/kdecore)
else()
set(_stubFilesDir ${KDE4_DATA_INSTALL_DIR}/kauth)
endif()
configure_file(
${_stubFilesDir}/dbus_policy.stub
${CMAKE_CURRENT_BINARY_DIR}/${HELPER_ID}.conf
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${HELPER_ID}.conf
DESTINATION ${KDE4_SYSCONF_INSTALL_DIR}/dbus-1/system.d/
)
configure_file(
${_stubFilesDir}/dbus_service.stub
${CMAKE_CURRENT_BINARY_DIR}/${HELPER_ID}.service
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${HELPER_ID}.service
DESTINATION ${KDE4_DBUS_SYSTEM_SERVICES_INSTALL_DIR}
)
2014-11-13 01:04:59 +02:00
endfunction(KDE4_INSTALL_AUTH_HELPER_FILES)