]> git.sesse.net Git - vlc/blob - bindings/phonon/cmake/modules/PhononMacros.cmake
Phonon Backend using VLC
[vlc] / bindings / phonon / cmake / modules / PhononMacros.cmake
1
2 # Phonon helper macros:
3 #
4 # macro (phonon_add_executable _target)
5 # macro (PHONON_ADD_UNIT_TEST _test_NAME)
6 # macro (PHONON_UPDATE_ICONCACHE)
7 # macro (PHONON_UPDATE_ICONCACHE)
8 # macro (_PHONON_ADD_ICON_INSTALL_RULE _install_SCRIPT _install_PATH _group _orig_NAME _install_NAME _l10n_SUBDIR)
9 # macro (PHONON_INSTALL_ICONS _defaultpath )
10
11 set(_global_add_executable_param)
12 if (Q_WS_MAC)
13    set(_global_add_executable_param MACOSX_BUNDLE)
14 endif (Q_WS_MAC)
15 if (WIN32)
16    # no WIN32 here - all executables are command line executables
17    set(_global_add_executable_param)
18 endif (WIN32)
19
20 macro(phonon_add_executable _target)
21    set(_srcs ${ARGN})
22    automoc4_add_executable(${_target} ${_global_add_executable_param} ${_srcs})
23 endmacro(phonon_add_executable _target)
24
25 macro (PHONON_ADD_UNIT_TEST _test_NAME)
26    set(_srcList ${ARGN})
27    set(_nogui)
28    list(GET ${_srcList} 0 first_PARAM)
29    set(_add_executable_param ${_global_add_executable_param})
30    if(${first_PARAM} STREQUAL "NOGUI")
31       set(_nogui "NOGUI")
32       set(_add_executable_param)
33    endif(${first_PARAM} STREQUAL "NOGUI")
34
35    if (NOT PHONON_BUILD_TESTS)
36       set(_add_executable_param ${_add_executable_param} EXCLUDE_FROM_ALL)
37    endif (NOT PHONON_BUILD_TESTS)
38
39    automoc4_add_executable(${_test_NAME} ${_add_executable_param} ${_srcList})
40
41    if(NOT PHONON_TEST_OUTPUT)
42       set(PHONON_TEST_OUTPUT plaintext)
43    endif(NOT PHONON_TEST_OUTPUT)
44    set(PHONON_TEST_OUTPUT ${PHONON_TEST_OUTPUT} CACHE STRING "The output to generate when running the QTest unit tests")
45
46    set(using_qtest "")
47    foreach(_filename ${_srcList})
48       if(NOT using_qtest)
49          if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_filename}")
50             file(READ ${_filename} file_CONTENT)
51             string(REGEX MATCH "QTEST_(KDE)?MAIN" using_qtest "${file_CONTENT}")
52          endif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_filename}")
53       endif(NOT using_qtest)
54    endforeach(_filename)
55
56    set(_executable ${EXECUTABLE_OUTPUT_PATH}/${_test_NAME})
57    if (Q_WS_MAC AND NOT _nogui)
58       set(_executable ${EXECUTABLE_OUTPUT_PATH}/${_test_NAME}.app/Contents/MacOS/${_test_NAME})
59    else (Q_WS_MAC AND NOT _nogui)
60       # Use .shell wrapper where available, to use uninstalled libs.
61       #if (UNIX)
62       #   set(_executable ${_executable}.shell)
63       #endif (UNIX)
64    endif (Q_WS_MAC AND NOT _nogui)
65
66    if (using_qtest AND PHONON_TEST_OUTPUT STREQUAL "xml")
67       add_test( ${_test_NAME} ${_executable} -xml -o ${_test_NAME}.tml)
68    else (using_qtest AND PHONON_TEST_OUTPUT STREQUAL "xml")
69       add_test( ${_test_NAME} ${_executable} )
70    endif (using_qtest AND PHONON_TEST_OUTPUT STREQUAL "xml")
71
72    if (NOT MSVC_IDE)   #not needed for the ide
73       # if the tests are EXCLUDE_FROM_ALL, add a target "buildtests" to build all tests
74       if (NOT PHONON_BUILD_TESTS)
75          get_directory_property(_buildtestsAdded BUILDTESTS_ADDED)
76          if(NOT _buildtestsAdded)
77             add_custom_target(buildtests)
78             set_directory_properties(PROPERTIES BUILDTESTS_ADDED TRUE)
79          endif(NOT _buildtestsAdded)
80          add_dependencies(buildtests ${_test_NAME})
81       endif (NOT PHONON_BUILD_TESTS)
82    endif (NOT MSVC_IDE)
83 endmacro (PHONON_ADD_UNIT_TEST)
84
85 macro (PHONON_UPDATE_ICONCACHE)
86     # Update mtime of hicolor icon theme dir.
87     # We don't always have touch command (e.g. on Windows), so instead create
88     #  and delete a temporary file in the theme dir.
89    install(CODE "
90     set(DESTDIR_VALUE \"\$ENV{DESTDIR}\")
91     if (NOT DESTDIR_VALUE)
92         file(WRITE \"${ICON_INSTALL_DIR}/hicolor/temp.txt\" \"update\")
93         file(REMOVE \"${ICON_INSTALL_DIR}/hicolor/temp.txt\")
94     endif (NOT DESTDIR_VALUE)
95     ")
96 endmacro (PHONON_UPDATE_ICONCACHE)
97
98 # a "map" of short type names to the directories
99 # unknown names should give empty results
100 # KDE 3 compatibility
101 set(_PHONON_ICON_GROUP_mime       "mimetypes")
102 set(_PHONON_ICON_GROUP_filesys    "places")
103 set(_PHONON_ICON_GROUP_device     "devices")
104 set(_PHONON_ICON_GROUP_app        "apps")
105 set(_PHONON_ICON_GROUP_action     "actions")
106 # KDE 4 / icon naming specification compatibility
107 set(_PHONON_ICON_GROUP_mimetypes  "mimetypes")
108 set(_PHONON_ICON_GROUP_places     "places")
109 set(_PHONON_ICON_GROUP_devices    "devices")
110 set(_PHONON_ICON_GROUP_apps       "apps")
111 set(_PHONON_ICON_GROUP_actions    "actions")
112 set(_PHONON_ICON_GROUP_categories "categories")
113 set(_PHONON_ICON_GROUP_status     "status")
114 set(_PHONON_ICON_GROUP_emblems    "emblems")
115 set(_PHONON_ICON_GROUP_emotes     "emotes")
116 set(_PHONON_ICON_GROUP_animations "animations")
117 set(_PHONON_ICON_GROUP_intl       "intl")
118
119 # a "map" of short theme names to the theme directory
120 set(_PHONON_ICON_THEME_ox "oxygen")
121 set(_PHONON_ICON_THEME_cr "crystalsvg")
122 set(_PHONON_ICON_THEME_lo "locolor")
123 set(_PHONON_ICON_THEME_hi "hicolor")
124
125 macro (_PHONON_ADD_ICON_INSTALL_RULE _install_SCRIPT _install_PATH _group _orig_NAME _install_NAME _l10n_SUBDIR)
126
127    # if the string doesn't match the pattern, the result is the full string, so all three have the same content
128    if (NOT ${_group} STREQUAL ${_install_NAME} )
129       set(_icon_GROUP  ${_PHONON_ICON_GROUP_${_group}})
130       if(NOT _icon_GROUP)
131          set(_icon_GROUP "actions")
132       endif(NOT _icon_GROUP)
133 #      message(STATUS "icon: ${_current_ICON} size: ${_size} group: ${_group} name: ${_name} l10n: ${_l10n_SUBDIR}")
134       install(FILES ${_orig_NAME} DESTINATION ${_install_PATH}/${_icon_GROUP}/${_l10n_SUBDIR}/ RENAME ${_install_NAME} )
135    endif (NOT ${_group} STREQUAL ${_install_NAME} )
136
137 endmacro (_PHONON_ADD_ICON_INSTALL_RULE)
138
139
140 macro (PHONON_INSTALL_ICONS _defaultpath )
141
142    # the l10n-subdir if language given as second argument (localized icon)
143    set(_lang ${ARGV1})
144    if(_lang)
145       set(_l10n_SUBDIR l10n/${_lang})
146    else(_lang)
147       set(_l10n_SUBDIR ".")
148    endif(_lang)
149
150    # first the png icons
151    file(GLOB _icons *.png)
152    foreach (_current_ICON ${_icons} )
153       # since CMake 2.6 regex matches are stored in special variables CMAKE_MATCH_x, if it didn't match, they are empty
154       string(REGEX MATCH "^.*/([a-zA-Z]+)([0-9]+)\\-([a-z]+)\\-(.+\\.png)$" _dummy  "${_current_ICON}")
155       set(_type  "${CMAKE_MATCH_1}")
156       set(_size  "${CMAKE_MATCH_2}")
157       set(_group "${CMAKE_MATCH_3}")
158       set(_name  "${CMAKE_MATCH_4}")
159
160       set(_theme_GROUP ${_PHONON_ICON_THEME_${_type}})
161       if( _theme_GROUP)
162          _PHONON_ADD_ICON_INSTALL_RULE(${CMAKE_CURRENT_BINARY_DIR}/install_icons.cmake
163                     ${_defaultpath}/${_theme_GROUP}/${_size}x${_size}
164                     ${_group} ${_current_ICON} ${_name} ${_l10n_SUBDIR})
165       endif( _theme_GROUP)
166    endforeach (_current_ICON)
167
168    # mng icons
169    file(GLOB _icons *.mng)
170    foreach (_current_ICON ${_icons} )
171       # since CMake 2.6 regex matches are stored in special variables CMAKE_MATCH_x, if it didn't match, they are empty
172       string(REGEX MATCH "^.*/([a-zA-Z]+)([0-9]+)\\-([a-z]+)\\-(.+\\.mng)$" _dummy  "${_current_ICON}")
173       set(_type  "${CMAKE_MATCH_1}")
174       set(_size  "${CMAKE_MATCH_2}")
175       set(_group "${CMAKE_MATCH_3}")
176       set(_name  "${CMAKE_MATCH_4}")
177
178       set(_theme_GROUP ${_PHONON_ICON_THEME_${_type}})
179       if( _theme_GROUP)
180          _PHONON_ADD_ICON_INSTALL_RULE(${CMAKE_CURRENT_BINARY_DIR}/install_icons.cmake
181                 ${_defaultpath}/${_theme_GROUP}/${_size}x${_size}
182                 ${_group} ${_current_ICON} ${_name} ${_l10n_SUBDIR})
183       endif( _theme_GROUP)
184    endforeach (_current_ICON)
185
186    # and now the svg icons
187    file(GLOB _icons *.svgz)
188    foreach (_current_ICON ${_icons} )
189       # since CMake 2.6 regex matches are stored in special variables CMAKE_MATCH_x, if it didn't match, they are empty
190       string(REGEX MATCH "^.*/([a-zA-Z]+)sc\\-([a-z]+)\\-(.+\\.svgz)$" _dummy "${_current_ICON}")
191       set(_type  "${CMAKE_MATCH_1}")
192       set(_group "${CMAKE_MATCH_2}")
193       set(_name  "${CMAKE_MATCH_3}")
194
195       set(_theme_GROUP ${_PHONON_ICON_THEME_${_type}})
196       if( _theme_GROUP)
197           _PHONON_ADD_ICON_INSTALL_RULE(${CMAKE_CURRENT_BINARY_DIR}/install_icons.cmake
198                             ${_defaultpath}/${_theme_GROUP}/scalable
199                             ${_group} ${_current_ICON} ${_name} ${_l10n_SUBDIR})
200       endif( _theme_GROUP)
201    endforeach (_current_ICON)
202
203    phonon_update_iconcache()
204
205 endmacro (PHONON_INSTALL_ICONS)
206