Warning, /frameworks/kdelibs4support/src/KDEUIMacros.cmake is written in an unsupported language. File is not indexed.
0001 # Copyright (c) 2006-2009 Alexander Neundorf, <neundorf@kde.org>
0002 # Copyright (c) 2006, 2007, Laurent Montel, <montel@kde.org>
0003 # Copyright (c) 2007 Matthias Kretz <kretz@kde.org>
0004 #
0005 # Redistribution and use is allowed according to the terms of the BSD license.
0006 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
0007
0008
0009 get_filename_component(KDE4UI_MODULE_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
0010
0011 # TODO: These macros belong with the framework they relate to.
0012
0013 #create the implementation files from the ui files and add them to the list of sources
0014 #usage: KDE4_ADD_UI_FILES(foo_SRCS ${ui_files})
0015 macro (KDE4_ADD_UI_FILES _sources )
0016 foreach (_current_FILE ${ARGN})
0017
0018 get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
0019 get_filename_component(_basename ${_tmp_FILE} NAME_WE)
0020 set(_header ${CMAKE_CURRENT_BINARY_DIR}/ui_${_basename}.h)
0021
0022 get_target_property(QT_UIC_EXECUTABLE Qt5::uic LOCATION)
0023 # we need to run uic and replace some things in the generated file
0024 # this is done by executing the cmake script kde4uic.cmake
0025 add_custom_command(OUTPUT ${_header}
0026 COMMAND ${CMAKE_COMMAND}
0027 ARGS
0028 -DKDE4_HEADER:BOOL=ON
0029 -DKDE_UIC_EXECUTABLE:FILEPATH=${QT_UIC_EXECUTABLE}
0030 -DKDE_UIC_FILE:FILEPATH=${_tmp_FILE}
0031 -DKDE_UIC_H_FILE:FILEPATH=${_header}
0032 -DKDE_UIC_BASENAME:STRING=${_basename}
0033 -P ${KDE4UI_MODULE_DIR}/kde4uic.cmake
0034 MAIN_DEPENDENCY ${_tmp_FILE}
0035 )
0036 list(APPEND ${_sources} ${_header})
0037 endforeach (_current_FILE)
0038 endmacro (KDE4_ADD_UI_FILES)
0039
0040
0041 macro (KDE4_UPDATE_ICONCACHE)
0042 # Update mtime of hicolor icon theme dir.
0043 # We don't always have touch command (e.g. on Windows), so instead create
0044 # and delete a temporary file in the theme dir.
0045 install(CODE "
0046 set(DESTDIR_VALUE \"\$ENV{DESTDIR}\")
0047 if (NOT DESTDIR_VALUE)
0048 file(WRITE \"${ICON_INSTALL_DIR}/hicolor/temp.txt\" \"update\")
0049 file(REMOVE \"${ICON_INSTALL_DIR}/hicolor/temp.txt\")
0050 endif (NOT DESTDIR_VALUE)
0051 ")
0052 endmacro (KDE4_UPDATE_ICONCACHE)
0053
0054 # a "map" of short type names to the directories
0055 # unknown names should give empty results
0056 # KDE 3 compatibility
0057 set(_KDE4_ICON_GROUP_mime "mimetypes")
0058 set(_KDE4_ICON_GROUP_filesys "places")
0059 set(_KDE4_ICON_GROUP_device "devices")
0060 set(_KDE4_ICON_GROUP_app "apps")
0061 set(_KDE4_ICON_GROUP_action "actions")
0062 # KDE 4 / icon naming specification compatibility
0063 set(_KDE4_ICON_GROUP_mimetypes "mimetypes")
0064 set(_KDE4_ICON_GROUP_places "places")
0065 set(_KDE4_ICON_GROUP_devices "devices")
0066 set(_KDE4_ICON_GROUP_apps "apps")
0067 set(_KDE4_ICON_GROUP_actions "actions")
0068 set(_KDE4_ICON_GROUP_categories "categories")
0069 set(_KDE4_ICON_GROUP_status "status")
0070 set(_KDE4_ICON_GROUP_emblems "emblems")
0071 set(_KDE4_ICON_GROUP_emotes "emotes")
0072 set(_KDE4_ICON_GROUP_animations "animations")
0073 set(_KDE4_ICON_GROUP_intl "intl")
0074
0075 # a "map" of short theme names to the theme directory
0076 set(_KDE4_ICON_THEME_ox "oxygen")
0077 set(_KDE4_ICON_THEME_cr "crystalsvg")
0078 set(_KDE4_ICON_THEME_lo "locolor")
0079 set(_KDE4_ICON_THEME_hi "hicolor")
0080
0081
0082 # only used internally by KDE4_INSTALL_ICONS
0083 macro (_KDE4_ADD_ICON_INSTALL_RULE _install_SCRIPT _install_PATH _group _orig_NAME _install_NAME _l10n_SUBDIR)
0084
0085 # if the string doesn't match the pattern, the result is the full string, so all three have the same content
0086 if (NOT ${_group} STREQUAL ${_install_NAME} )
0087 set(_icon_GROUP ${_KDE4_ICON_GROUP_${_group}})
0088 if(NOT _icon_GROUP)
0089 set(_icon_GROUP "actions")
0090 endif(NOT _icon_GROUP)
0091 # message(STATUS "icon: ${_current_ICON} size: ${_size} group: ${_group} name: ${_name} l10n: ${_l10n_SUBDIR}")
0092 install(FILES ${_orig_NAME} DESTINATION ${_install_PATH}/${_icon_GROUP}/${_l10n_SUBDIR}/ RENAME ${_install_NAME} )
0093 endif (NOT ${_group} STREQUAL ${_install_NAME} )
0094
0095 endmacro (_KDE4_ADD_ICON_INSTALL_RULE)
0096
0097
0098 macro (KDE4_INSTALL_ICONS _defaultpath )
0099
0100 # the l10n-subdir if language given as second argument (localized icon)
0101 set(_lang ${ARGV1})
0102 if(_lang)
0103 set(_l10n_SUBDIR l10n/${_lang})
0104 else(_lang)
0105 set(_l10n_SUBDIR ".")
0106 endif(_lang)
0107
0108 # first the png icons
0109 file(GLOB _icons *.png)
0110 foreach (_current_ICON ${_icons} )
0111 # since CMake 2.6 regex matches are stored in special variables CMAKE_MATCH_x, if it didn't match, they are empty
0112 string(REGEX MATCH "^.*/([a-zA-Z]+)([0-9]+)\\-([a-z]+)\\-(.+\\.png)$" _dummy "${_current_ICON}")
0113 set(_type "${CMAKE_MATCH_1}")
0114 set(_size "${CMAKE_MATCH_2}")
0115 set(_group "${CMAKE_MATCH_3}")
0116 set(_name "${CMAKE_MATCH_4}")
0117
0118 set(_theme_GROUP ${_KDE4_ICON_THEME_${_type}})
0119 if( _theme_GROUP)
0120 _KDE4_ADD_ICON_INSTALL_RULE(${CMAKE_CURRENT_BINARY_DIR}/install_icons.cmake
0121 ${_defaultpath}/${_theme_GROUP}/${_size}x${_size}
0122 ${_group} ${_current_ICON} ${_name} ${_l10n_SUBDIR})
0123 endif( _theme_GROUP)
0124 endforeach (_current_ICON)
0125
0126 # mng icons
0127 file(GLOB _icons *.mng)
0128 foreach (_current_ICON ${_icons} )
0129 # since CMake 2.6 regex matches are stored in special variables CMAKE_MATCH_x, if it didn't match, they are empty
0130 string(REGEX MATCH "^.*/([a-zA-Z]+)([0-9]+)\\-([a-z]+)\\-(.+\\.mng)$" _dummy "${_current_ICON}")
0131 set(_type "${CMAKE_MATCH_1}")
0132 set(_size "${CMAKE_MATCH_2}")
0133 set(_group "${CMAKE_MATCH_3}")
0134 set(_name "${CMAKE_MATCH_4}")
0135
0136 set(_theme_GROUP ${_KDE4_ICON_THEME_${_type}})
0137 if( _theme_GROUP)
0138 _KDE4_ADD_ICON_INSTALL_RULE(${CMAKE_CURRENT_BINARY_DIR}/install_icons.cmake
0139 ${_defaultpath}/${_theme_GROUP}/${_size}x${_size}
0140 ${_group} ${_current_ICON} ${_name} ${_l10n_SUBDIR})
0141 endif( _theme_GROUP)
0142 endforeach (_current_ICON)
0143
0144 # and now the svg icons
0145 file(GLOB _icons *.svgz)
0146 foreach (_current_ICON ${_icons} )
0147 # since CMake 2.6 regex matches are stored in special variables CMAKE_MATCH_x, if it didn't match, they are empty
0148 string(REGEX MATCH "^.*/([a-zA-Z]+)sc\\-([a-z]+)\\-(.+\\.svgz)$" _dummy "${_current_ICON}")
0149 set(_type "${CMAKE_MATCH_1}")
0150 set(_group "${CMAKE_MATCH_2}")
0151 set(_name "${CMAKE_MATCH_3}")
0152
0153 set(_theme_GROUP ${_KDE4_ICON_THEME_${_type}})
0154 if( _theme_GROUP)
0155 _KDE4_ADD_ICON_INSTALL_RULE(${CMAKE_CURRENT_BINARY_DIR}/install_icons.cmake
0156 ${_defaultpath}/${_theme_GROUP}/scalable
0157 ${_group} ${_current_ICON} ${_name} ${_l10n_SUBDIR})
0158 endif( _theme_GROUP)
0159 endforeach (_current_ICON)
0160
0161 kde4_update_iconcache()
0162
0163 endmacro (KDE4_INSTALL_ICONS)
0164
0165
0166 set(KDEWIDGETS_MAKEKDEWIDGETS_EXECUTABLE ${KF5DESIGNERPLUGIN_GENERATOR_EXECUTABLE})
0167 set(_KDE4_MAKEKDEWIDGETS_DEP ${_KF5DESIGNERPLUGIN_GENERATOR_EXECUTABLE_DEP})
0168 macro (KDE4_ADD_WIDGET_FILES _sources)
0169 foreach (_current_FILE ${ARGN})
0170
0171 get_filename_component(_input ${_current_FILE} ABSOLUTE)
0172 get_filename_component(_basename ${_input} NAME_WE)
0173 set(_source ${CMAKE_CURRENT_BINARY_DIR}/${_basename}widgets.cpp)
0174 set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_basename}widgets.moc)
0175
0176 # create source file from the .widgets file
0177 add_custom_command(OUTPUT ${_source}
0178 COMMAND ${KDEWIDGETS_MAKEKDEWIDGETS_EXECUTABLE}
0179 ARGS -o ${_source} ${_input}
0180 MAIN_DEPENDENCY ${_input} DEPENDS ${_KDE4_MAKEKDEWIDGETS_DEP})
0181
0182 # create moc file
0183 qt5_generate_moc(${_source} ${_moc} )
0184
0185 list(APPEND ${_sources} ${_source} ${_moc})
0186
0187 endforeach (_current_FILE)
0188
0189 endmacro (KDE4_ADD_WIDGET_FILES)
0190
0191 # adds application icon to target source list
0192 # 'appsources' - the sources of the application
0193 # 'pngfiles' - specifies the list of icon files
0194 # example: KDE4_ADD_WIN32_APP_ICON(myapp_SRCS "pics/cr16-myapp.png;pics/cr32-myapp.png")
0195 macro (KDE4_ADD_WIN32_APP_ICON appsources)
0196 message(STATUS "KDE4_ADD_WIN32_APP_ICON() is deprecated, use KDE4_ADD_APP_ICON() instead")
0197 if (WIN32)
0198 if(NOT WINCE)
0199 find_program(PNG2ICO_EXECUTABLE NAMES png2ico)
0200 else(NOT WINCE)
0201 find_program(PNG2ICO_EXECUTABLE NAMES png2ico PATHS ${HOST_BINDIR} NO_DEFAULT_PATH )
0202 endif(NOT WINCE)
0203 string(REPLACE _SRCS "" appname ${appsources})
0204 if (PNG2ICO_EXECUTABLE)
0205 set (_outfilename ${CMAKE_CURRENT_BINARY_DIR}/${appname})
0206
0207 # png2ico is found by the above find_program
0208 # message("png2ico ${_outfilename}.ico ${ARGN}")
0209 exec_program(png2ico ARGS ${_outfilename}.ico ${ARGN})
0210
0211 # now make rc file for adding it to the sources
0212 file(WRITE ${_outfilename}.rc "IDI_ICON1 ICON DISCARDABLE \"${_outfilename}.ico\"\n")
0213 list(APPEND ${appsources} ${CMAKE_CURRENT_BINARY_DIR}/${appname}.rc)
0214 endif(PNG2ICO_EXECUTABLE)
0215 endif(WIN32)
0216 endmacro (KDE4_ADD_WIN32_APP_ICON)
0217
0218 # adds application icon to target source list
0219 # for detailed documentation see the top of FindKDE4Internal.cmake
0220 macro (KDE4_ADD_APP_ICON appsources pattern)
0221 set (_outfilename ${CMAKE_CURRENT_BINARY_DIR}/${appsources})
0222
0223 if (WIN32)
0224 if(NOT WINCE)
0225 find_program(PNG2ICO_EXECUTABLE NAMES png2ico)
0226 else(NOT WINCE)
0227 find_program(PNG2ICO_EXECUTABLE NAMES png2ico PATHS ${HOST_BINDIR} NO_DEFAULT_PATH )
0228 endif(NOT WINCE)
0229 if (PNG2ICO_EXECUTABLE)
0230 string(REPLACE "*" "(.*)" pattern_rx "${pattern}")
0231 file(GLOB files "${pattern}")
0232 foreach (it ${files})
0233 string(REGEX REPLACE "${pattern_rx}" "\\1" fn "${it}")
0234 if (fn MATCHES ".*16.*" )
0235 list (APPEND _icons ${it})
0236 endif (fn MATCHES ".*16.*")
0237 if (fn MATCHES ".*32.*" )
0238 list (APPEND _icons ${it})
0239 endif (fn MATCHES ".*32.*")
0240 if (fn MATCHES ".*48.*" )
0241 list (APPEND _icons ${it})
0242 endif (fn MATCHES ".*48.*")
0243 if (fn MATCHES ".*64.*" )
0244 list (APPEND _icons ${it})
0245 endif (fn MATCHES ".*64.*")
0246 if (fn MATCHES ".*128.*" )
0247 list (APPEND _icons ${it})
0248 endif (fn MATCHES ".*128.*")
0249 endforeach (it)
0250 if (_icons)
0251 add_custom_command(OUTPUT ${_outfilename}.ico ${_outfilename}.rc
0252 COMMAND ${PNG2ICO_EXECUTABLE} ARGS --rcfile ${_outfilename}.rc ${_outfilename}.ico ${_icons}
0253 DEPENDS ${PNG2ICO_EXECUTABLE} ${_icons}
0254 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
0255 )
0256 list(APPEND ${appsources} ${_outfilename}.rc)
0257 else(_icons)
0258 message(STATUS "Unable to find a related icon that matches pattern ${pattern} for variable ${appsources} - application will not have an application icon!")
0259 endif(_icons)
0260 else(PNG2ICO_EXECUTABLE)
0261 message(STATUS "Unable to find the png2ico utility - application will not have an application icon!")
0262 endif(PNG2ICO_EXECUTABLE)
0263 endif(WIN32)
0264 if (APPLE)
0265 # first convert image to a tiff using the Mac OS X "sips" utility,
0266 # then use tiff2icns to convert to an icon
0267 find_program(SIPS_EXECUTABLE NAMES sips)
0268 find_program(TIFF2ICNS_EXECUTABLE NAMES tiff2icns)
0269 if (SIPS_EXECUTABLE AND TIFF2ICNS_EXECUTABLE)
0270 file(GLOB_RECURSE files "${pattern}")
0271 # we can only test for the 128-icon like that - we don't use patterns anymore
0272 foreach (it ${files})
0273 if (it MATCHES ".*128.*" )
0274 set (_icon ${it})
0275 endif (it MATCHES ".*128.*")
0276 endforeach (it)
0277
0278 if (_icon)
0279
0280 # first, get the basename of our app icon
0281 add_custom_command(OUTPUT ${_outfilename}.icns ${outfilename}.tiff
0282 COMMAND ${SIPS_EXECUTABLE} -s format tiff ${_icon} --out ${outfilename}.tiff
0283 COMMAND ${TIFF2ICNS_EXECUTABLE} ${outfilename}.tiff ${_outfilename}.icns
0284 DEPENDS ${_icon}
0285 )
0286
0287 # This will register the icon into the bundle
0288 set(MACOSX_BUNDLE_ICON_FILE ${appsources}.icns)
0289
0290 # Append the icns file to the sources list so it will be a dependency to the
0291 # main target
0292 list(APPEND ${appsources} ${_outfilename}.icns)
0293
0294 # Install the icon into the Resources dir in the bundle
0295 set_source_files_properties(${_outfilename}.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
0296
0297 else(_icon)
0298 # TODO - try to scale a non-128 icon...? Try to convert an SVG on the fly?
0299 message(STATUS "Unable to find an 128x128 icon that matches pattern ${pattern} for variable ${appsources} - application will not have an application icon!")
0300 endif(_icon)
0301
0302 else(SIPS_EXECUTABLE AND TIFF2ICNS_EXECUTABLE)
0303 message(STATUS "Unable to find the sips and tiff2icns utilities - application will not have an application icon!")
0304 endif(SIPS_EXECUTABLE AND TIFF2ICNS_EXECUTABLE)
0305 endif(APPLE)
0306 endmacro (KDE4_ADD_APP_ICON)
0307