~mc-return/compiz/compiz.merge-src-screen.cpp-improvements

« back to all changes in this revision

Viewing changes to cmake/CompizPlugin.cmake

  • Committer: Dennis kasprzyk
  • Author(s): Dennis Kasprzyk
  • Date: 2009-03-15 05:09:18 UTC
  • Revision ID: git-v1:163f6b6f3c3b7764987cbdf8e03cc355edeaa499
New generalized build system.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#######################################################################
 
2
#
 
3
# Generic Compiz Fusion plugin cmake module
 
4
#
 
5
# Copyright : (C) 2008 by Dennis Kasprzyk
 
6
# E-mail    : onestone@opencompositing.org
 
7
#
 
8
#
 
9
# This program is free software; you can redistribute it and/or
 
10
# modify it under the terms of the GNU General Public License
 
11
# as published by the Free Software Foundation; either version 2
 
12
# of the License, or (at your option) any later version.
 
13
#
 
14
# This program is distributed in the hope that it will be useful,
 
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
# GNU General Public License for more details.
 
18
#
 
19
#######################################################################
 
20
#
 
21
# This module provides the following macro:
 
22
#
 
23
# compiz_plugin (<plugin name>
 
24
#                       [PKGDEPS dep1 dep2 ...]
 
25
#                       [PLUGINDEPS plugin1 plugin2 ...]
 
26
#                       [LDFLAGSADD flag1 flag2 ...]
 
27
#                       [CFLAGSADD flag1 flag2 ...]
 
28
#                       [LIBRARIES lib1 lib2 ...]
 
29
#                       [LIBDIRS dir1 dir2 ...]
 
30
#                       [INCDIRS dir1 dir2 ...])
 
31
#
 
32
# PKGDEPS    = pkgconfig dependencies
 
33
# PLUGINDEPS = compiz plugin dependencies
 
34
# LDFLAGSADD = flags added to the link command
 
35
# CFLAGSADD  = flags added to the compile command
 
36
# LIBRARIES  = libraries added to link command
 
37
# LIBDIRS    = additional link directories
 
38
# INCDIRS    = additional include directories
 
39
#
 
40
# The following variables will be used by this macro:
 
41
#
 
42
# BUILD_GLOBAL=true Environment variable to install a plugin
 
43
#                   into the compiz directories
 
44
#
 
45
# COMPIZ_PLUGIN_INSTALL_TYPE = (package | compiz | local (default))
 
46
#     package = Install into ${CMAKE_INSTALL_PREFIX}
 
47
#     compiz  = Install into compiz prefix (BUILD_GLOBAL=true)
 
48
#     local   = Install into home directory
 
49
#
 
50
# COMPIZ_I18N_DIR      = Translation file directory
 
51
#
 
52
# COMPIZ_DISABLE_SCHEMAS_INSTALL  = Disables gconf schema installation with gconftool
 
53
# COMPIZ_INSTALL_GCONF_SCHEMA_DIR = Installation path of the gconf schema file
 
54
#
 
55
# VERSION = package version that is added to a plugin pkg-version file
 
56
#
 
57
#######################################################################
 
58
 
 
59
include (CompizCommon)
 
60
include (CompizBcop)
 
61
 
 
62
if (COMPIZ_GCONF_SCHEMAS_SUPPORT)
 
63
    include (CompizGconf)
 
64
endif ()
 
65
 
 
66
# determinate installation directories
 
67
macro (_prepare_directories)
 
68
 
 
69
    if ("${COMPIZ_PLUGIN_INSTALL_TYPE}" STREQUAL "package")
 
70
        set (PLUGIN_BUILDTYPE global)
 
71
        set (PLUGIN_PREFIX    ${CMAKE_INSTALL_PREFIX})
 
72
        set (PLUGIN_LIBDIR    ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/compiz)
 
73
        set (PLUGIN_INCDIR    ${CMAKE_INSTALL_PREFIX}/include/compiz)
 
74
        set (PLUGIN_PKGDIR    ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig)
 
75
        set (PLUGIN_XMLDIR    ${CMAKE_INSTALL_PREFIX}/share/compiz)
 
76
        set (PLUGIN_IMAGEDIR  ${CMAKE_INSTALL_PREFIX}/share/compiz)
 
77
        set (PLUGIN_DATADIR   ${CMAKE_INSTALL_PREFIX}/share/compiz)
 
78
        if (NOT COMPIZ_INSTALL_GCONF_SCHEMA_DIR)
 
79
            set (PLUGIN_SCHEMADIR "${CMAKE_INSTALL_PREFIX}/share/gconf/schemas")
 
80
        else (NOT COMPIZ_INSTALL_GCONF_SCHEMA_DIR)
 
81
            set (PLUGIN_SCHEMADIR "${COMPIZ_INSTALL_GCONF_SCHEMA_DIR}")
 
82
        endif (NOT COMPIZ_INSTALL_GCONF_SCHEMA_DIR)
 
83
 
 
84
    elseif ("${COMPIZ_PLUGIN_INSTALL_TYPE}" STREQUAL "compiz" OR
 
85
            "$ENV{BUILD_GLOBAL}" STREQUAL "true")
 
86
        set (PLUGIN_BUILDTYPE global)
 
87
        set (PLUGIN_PREFIX    ${COMPIZ_PREFIX})
 
88
        set (PLUGIN_LIBDIR    ${COMPIZ_LIBDIR}/compiz)
 
89
        set (PLUGIN_INCDIR    ${COMPIZ_INCLUDEDIR})
 
90
        set (PLUGIN_PKGDIR    ${COMPIZ_LIBDIR}/pkgconfig)
 
91
        set (PLUGIN_XMLDIR    ${COMPIZ_PREFIX}/share/compiz)
 
92
        set (PLUGIN_IMAGEDIR  ${COMPIZ_PREFIX}/share/compiz)
 
93
        set (PLUGIN_DATADIR   ${COMPIZ_PREFIX}/share/compiz)
 
94
        if (NOT COMPIZ_INSTALL_GCONF_SCHEMA_DIR)
 
95
            set (PLUGIN_SCHEMADIR "${COMPIZ_PREFIX}/share/gconf/schemas")
 
96
        else (NOT COMPIZ_INSTALL_GCONF_SCHEMA_DIR)
 
97
            set (PLUGIN_SCHEMADIR "${COMPIZ_INSTALL_GCONF_SCHEMA_DIR}")
 
98
        endif (NOT COMPIZ_INSTALL_GCONF_SCHEMA_DIR)
 
99
        
 
100
        if (NOT "${CMAKE_BUILD_TYPE}")
 
101
            compiz_set (CMAKE_BUILD_TYPE debug)
 
102
        endif (NOT "${CMAKE_BUILD_TYPE}")       
 
103
    else ("${COMPIZ_PLUGIN_INSTALL_TYPE}" STREQUAL "compiz" OR
 
104
          "$ENV{BUILD_GLOBAL}" STREQUAL "true")
 
105
        set (PLUGIN_BUILDTYPE local)
 
106
        set (PLUGIN_PREFIX    $ENV{HOME}/.compiz)
 
107
        set (PLUGIN_LIBDIR    $ENV{HOME}/.compiz/plugins)
 
108
        set (PLUGIN_XMLDIR    $ENV{HOME}/.compiz/metadata)
 
109
        set (PLUGIN_IMAGEDIR  $ENV{HOME}/.compiz/images)
 
110
        set (PLUGIN_DATADIR   $ENV{HOME}/.compiz/data)
 
111
 
 
112
        if (NOT COMPIZ_INSTALL_GCONF_SCHEMA_DIR)
 
113
            set (PLUGIN_SCHEMADIR "$ENV{HOME}/.gconf/schemas")
 
114
        else (NOT COMPIZ_INSTALL_GCONF_SCHEMA_DIR)
 
115
            set (PLUGIN_SCHEMADIR "${COMPIZ_INSTALL_GCONF_SCHEMA_DIR}")
 
116
        endif (NOT COMPIZ_INSTALL_GCONF_SCHEMA_DIR)
 
117
        
 
118
        if (NOT "${CMAKE_BUILD_TYPE}")
 
119
            compiz_set (CMAKE_BUILD_TYPE debug)
 
120
        endif (NOT "${CMAKE_BUILD_TYPE}")
 
121
    endif ("${COMPIZ_PLUGIN_INSTALL_TYPE}" STREQUAL "package")
 
122
endmacro (_prepare_directories)
 
123
 
 
124
# parse plugin macro parameter
 
125
macro (_get_plugin_parameters _prefix)
 
126
    set (_current_var _foo)
 
127
    set (_supported_var PKGDEPS PLUGINDEPS LDFLAGSADD CFLAGSADD LIBRARIES LIBDIRS INCDIRS)
 
128
    foreach (_val ${_supported_var})
 
129
        set (${_prefix}_${_val})
 
130
    endforeach (_val)
 
131
    foreach (_val ${ARGN})
 
132
        set (_found FALSE)
 
133
        foreach (_find ${_supported_var})
 
134
            if ("${_find}" STREQUAL "${_val}")
 
135
                set (_found TRUE)
 
136
            endif ("${_find}" STREQUAL "${_val}")
 
137
        endforeach (_find)
 
138
        
 
139
        if (_found)
 
140
            set (_current_var ${_prefix}_${_val})
 
141
        else (_found)
 
142
            list (APPEND ${_current_var} ${_val})
 
143
        endif (_found)
 
144
    endforeach (_val)
 
145
endmacro (_get_plugin_parameters)
 
146
 
 
147
# check pkgconfig dependencies
 
148
macro (_check_plugin_pkg_deps _prefix)
 
149
    set (${_prefix}_HAS_PKG_DEPS TRUE)
 
150
    foreach (_val ${ARGN})
 
151
        string (REGEX REPLACE "[<>=\\.]" "_" _name ${_val})
 
152
        string (TOUPPER ${_name} _name)
 
153
 
 
154
        compiz_pkg_check_modules (_${_name} ${_val})
 
155
 
 
156
        if (_${_name}_FOUND)
 
157
            list (APPEND ${_prefix}_PKG_LIBDIRS "${_${_name}_LIBRARY_DIRS}")
 
158
            list (APPEND ${_prefix}_PKG_LIBRARIES "${_${_name}_LIBRARIES}")
 
159
            list (APPEND ${_prefix}_PKG_INCDIRS "${_${_name}_INCLUDE_DIRS}")
 
160
        else ()
 
161
            set (${_prefix}_HAS_PKG_DEPS FALSE)
 
162
            compiz_set (COMPIZ_${_prefix}_MISSING_DEPS "${COMPIZ_${_prefix}_MISSING_DEPS} ${_val}")
 
163
            set(__pkg_config_checked__${_name} 0 CACHE INTERNAL "" FORCE)
 
164
        endif ()
 
165
    endforeach ()
 
166
endmacro ()
 
167
 
 
168
# check plugin dependencies
 
169
macro (_check_plugin_plugin_deps _prefix)
 
170
    set (${_prefix}_HAS_PLUGIN_DEPS TRUE)
 
171
    foreach (_val ${ARGN})
 
172
        string (TOUPPER ${_val} _name)
 
173
 
 
174
        find_file (
 
175
            _plugin_dep_${_val}
 
176
            compiz-${_val}.pc.in
 
177
            PATHS ${CMAKE_CURRENT_SOURCE_DIR}/../${_val}
 
178
            NO_DEFAULT_PATH
 
179
        )
 
180
        
 
181
        if (_plugin_dep_${_val})
 
182
            file (RELATIVE_PATH _relative ${CMAKE_CURRENT_SOURCE_DIR} ${_plugin_dep_${_val}})
 
183
            get_filename_component (_plugin_inc_dir ${_relative} PATH)
 
184
            list (APPEND ${_prefix}_LOCAL_INCDIRS "${_plugin_inc_dir}/include")
 
185
            list (APPEND ${_prefix}_LOCAL_LIBRARIES ${_val})
 
186
        else ()
 
187
            # fallback to pkgconfig
 
188
            compiz_pkg_check_modules (_${_name} compiz-${_val})
 
189
            if (_${_name}_FOUND)
 
190
                list (APPEND ${_prefix}_PKG_LIBDIRS "${_${_name}_LIBRARY_DIRS}")
 
191
                list (APPEND ${_prefix}_PKG_LIBRARIES "${_${_name}_LIBRARIES}")
 
192
                list (APPEND ${_prefix}_PKG_INCDIRS "${_${_name}_INCLUDE_DIRS}")
 
193
            else ()
 
194
                set (${_prefix}_HAS_PLUGIN_DEPS FALSE)
 
195
                _COMPIZ_set (COMPIZ_${_prefix}_MISSING_DEPS "${COMPIZ_${_prefix}_MISSING_DEPS} compiz-${_val}")
 
196
            endif ()
 
197
        endif ()
 
198
 
 
199
        compiz_set (_plugin_dep_${_val} "${_plugin_dep_${_val}}")
 
200
 
 
201
    endforeach ()
 
202
endmacro ()
 
203
 
 
204
 
 
205
 
 
206
 
 
207
# main function
 
208
function (_build_compiz_plugin plugin)
 
209
    string (TOUPPER ${plugin} _PLUGIN)
 
210
 
 
211
    if (COMPIZ_PLUGIN_INSTALL_TYPE)
 
212
        set (
 
213
            COMPIZ_PLUGIN_INSTALL_TYPE ${COMPIZ_PLUGIN_INSTALL_TYPE} CACHE STRING
 
214
            "Where a plugin should be installed \(package | compiz | local\)"
 
215
        )
 
216
    else (COMPIZ_PLUGIN_INSTALL_TYPE)
 
217
        set (
 
218
            COMPIZ_PLUGIN_INSTALL_TYPE "local" CACHE STRING
 
219
            "Where a plugin should be installed \(package | compiz | local\)"
 
220
        )
 
221
    endif (COMPIZ_PLUGIN_INSTALL_TYPE)
 
222
 
 
223
    _get_plugin_parameters (${_PLUGIN} ${ARGN})
 
224
    _prepare_directories ()
 
225
 
 
226
    find_file (
 
227
        _${plugin}_xml_in ${plugin}.xml.in
 
228
        PATHS ${CMAKE_CURRENT_SOURCE_DIR}
 
229
        NO_DEFAULT_PATH
 
230
    )
 
231
    if (_${plugin}_xml_in)
 
232
        set (_${plugin}_xml ${_${plugin}_xml_in})
 
233
    else ()
 
234
        find_file (
 
235
            _${plugin}_xml ${plugin}.xml
 
236
            PATHS ${CMAKE_CURRENT_SOURCE_DIR} }
 
237
            NO_DEFAULT_PATH
 
238
        )
 
239
    endif ()
 
240
 
 
241
    set (${_PLUGIN}_HAS_PKG_DEPS)
 
242
    set (${_PLUGIN}_HAS_PLUGIN_DEPS)
 
243
 
 
244
    # check dependencies
 
245
    compiz_unset (COMPIZ_${_PLUGIN}_MISSING_DEPS)
 
246
    _check_plugin_plugin_deps (${_PLUGIN} ${${_PLUGIN}_PLUGINDEPS})
 
247
    _check_plugin_pkg_deps (${_PLUGIN} ${${_PLUGIN}_PKGDEPS})
 
248
 
 
249
    if (${_PLUGIN}_HAS_PKG_DEPS AND ${_PLUGIN}_HAS_PLUGIN_DEPS)
 
250
 
 
251
        compiz_set (COMPIZ_${_PLUGIN}_BUILD TRUE PARENT_SCOPE)
 
252
 
 
253
        if (NOT EXISTS ${CMAKE_BINARY_DIR}/generated)
 
254
            file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/generated)
 
255
        endif (NOT EXISTS ${CMAKE_BINARY_DIR}/generated)
 
256
        
 
257
        if (_${plugin}_xml_in)
 
258
            # translate xml
 
259
            compiz_translate_xml ( ${_${plugin}_xml_in} "${CMAKE_BINARY_DIR}/generated/${plugin}.xml")
 
260
            set (_translation_sources "${CMAKE_BINARY_DIR}/generated/${plugin}.xml")
 
261
            set (_translated_xml ${CMAKE_BINARY_DIR}/generated/${plugin}.xml)
 
262
        else ()
 
263
            if (_${plugin}_xml)
 
264
                set (_translated_xml ${_${plugin}_xml})
 
265
            endif ()
 
266
        endif ()
 
267
        
 
268
        if (_${plugin}_xml)
 
269
            # do we need bcop for our plugin
 
270
            compiz_plugin_needs_bcop (${_${plugin}_xml} _needs_bcop)
 
271
            if (_needs_bcop)
 
272
                # initialize everything we need for bcop
 
273
                compiz_add_bcop_targets (${plugin} ${_${plugin}_xml} _bcop_sources)
 
274
            endif ()
 
275
        endif ()
 
276
        
 
277
        if (_translated_xml)
 
278
            if (COMPIZ_GCONF_SCHEMAS_SUPPORT)
 
279
                # generate gconf schema
 
280
                compiz_gconf_schema (${_translated_xml} "${CMAKE_BINARY_DIR}/generated/compiz-${plugin}.schemas" ${PLUGIN_SCHEMADIR})
 
281
                set (_schema_sources "${CMAKE_BINARY_DIR}/generated/compiz-${plugin}.schemas")
 
282
            endif ()
 
283
 
 
284
            # install xml
 
285
            install (
 
286
                FILES ${_translated_xml}
 
287
                DESTINATION ${PLUGIN_XMLDIR}
 
288
            )
 
289
        endif (_translated_xml)
 
290
        
 
291
        find_file (
 
292
            _${plugin}_pkg compiz-${plugin}.pc.in
 
293
            PATHS ${CMAKE_CURRENT_SOURCE_DIR}
 
294
            NO_DEFAULT_PATH
 
295
        )
 
296
 
 
297
        # generate pkgconfig file and install it and the plugin header file
 
298
        if (_${plugin}_pkg AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include/${plugin})
 
299
            if ("${PLUGIN_BUILDTYPE}" STREQUAL "local")
 
300
                message (STATUS "[WARNING] The plugin ${plugin} might be needed by other plugins. Install it systemwide.")
 
301
            else ()
 
302
                set (prefix ${PLUGIN_PREFIX})
 
303
                set (libdir ${PLUGIN_LIBDIR})
 
304
                set (includedir ${PLUGIN_INCDIR})
 
305
                if (NOT VERSION)
 
306
                    set (VERSION 0.0.1-git)
 
307
                endif (NOT VERSION)
 
308
 
 
309
                compiz_configure_file (
 
310
                    ${_${plugin}_pkg}
 
311
                    ${CMAKE_BINARY_DIR}/generated/compiz-${plugin}.pc
 
312
                    COMPIZ_REQUIRES
 
313
                    COMPIZ_CFLAGS
 
314
                )
 
315
                
 
316
                install (
 
317
                    FILES ${CMAKE_BINARY_DIR}/generated/compiz-${plugin}.pc
 
318
                    DESTINATION ${PLUGIN_PKGDIR}
 
319
                )
 
320
                install (
 
321
                    DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/${plugin}
 
322
                    DESTINATION ${PLUGIN_INCDIR}/${plugin}
 
323
                )
 
324
            endif ()
 
325
        endif ()
 
326
 
 
327
        # install plugin data files
 
328
        if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/data)
 
329
            install (
 
330
                DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data
 
331
                DESTINATION ${PLUGIN_DATADIR}
 
332
            )
 
333
        endif ()
 
334
 
 
335
        # install plugin image files
 
336
        if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/images)
 
337
            install (
 
338
                DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/images
 
339
                DESTINATION ${PLUGIN_IMAGEDIR}
 
340
            )
 
341
        endif ()
 
342
        
 
343
        # find files for build
 
344
        file (GLOB _h_files "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h")
 
345
        file (GLOB _h_ins_files "${CMAKE_CURRENT_SOURCE_DIR}/include/${plugin}/*.h")
 
346
        file (GLOB _cpp_files "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
 
347
 
 
348
#       set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs")
 
349
 
 
350
#       set (_cflags "-Wall -Wpointer-arith  -fno-strict-aliasing")
 
351
        
 
352
 
 
353
        add_definitions (-DPREFIX='\"${PLUGIN_PREFIX}\"'
 
354
                         -DIMAGEDIR='\"${PLUGIN_IMAGEDIR}\"'
 
355
                         -DDATADIR='\"${PLUGIN_DATADIR}\"')
 
356
 
 
357
        include_directories (
 
358
            ${CMAKE_CURRENT_SOURCE_DIR}/src
 
359
            ${CMAKE_CURRENT_SOURCE_DIR}/include
 
360
            ${CMAKE_BINARY_DIR}/generated
 
361
            ${${_PLUGIN}_LOCAL_INCDIRS}
 
362
            ${${_PLUGIN}_PKG_INCDIRS}
 
363
            ${COMPIZ_INCLUDE_DIRS}
 
364
        )
 
365
 
 
366
        link_directories (
 
367
            ${COMPIZ_LINK_DIRS}
 
368
            ${${_PLUGIN}_PKG_LIBDIRS}
 
369
        )
 
370
 
 
371
        add_library (
 
372
            ${plugin} SHARED ${_cpp_files}
 
373
                             ${_h_files}
 
374
                             ${_h_ins_files}
 
375
                             ${_bcop_sources}
 
376
                             ${_translation_sources}
 
377
                             ${_schema_sources}
 
378
        )
 
379
 
 
380
        set_target_properties (
 
381
            ${plugin} PROPERTIES
 
382
            COMPILE_FLAGS "${${_PLUGIN}_CFLAGSADD}"
 
383
            LINK_FLAGS "${${_PLUGIN}_LDFLAGSADD}"
 
384
        )
 
385
 
 
386
        target_link_libraries (
 
387
            ${plugin} ${COMPIZ_LIBRARIES}
 
388
                      ${${_PLUGIN}_LOCAL_LIBRARIES}
 
389
                      ${${_PLUGIN}_PKG_LIBRARIES}
 
390
        )
 
391
 
 
392
        install (
 
393
            TARGETS ${plugin}
 
394
            LIBRARY DESTINATION ${PLUGIN_LIBDIR}
 
395
        )
 
396
 
 
397
        compiz_add_uninstall ()
 
398
 
 
399
    else ()
 
400
        message (STATUS "[WARNING] One or more dependencies for compiz plugin ${plugin} not found. Skipping plugin.")
 
401
        message (STATUS "Missing dependencies :${COMPIZ_${_PLUGIN}_MISSING_DEPS}")
 
402
        _COMPIZ_set (COMPIZ_${_PLUGIN}_BUILD FALSE)
 
403
    endif ()
 
404
endfunction ()
 
405
 
 
406
macro (compiz_plugin plugin)
 
407
    string (TOUPPER ${plugin} _PLUGIN)
 
408
 
 
409
    option (
 
410
        COMPIZ_DISABLE_PLUGIN_${_PLUGIN}
 
411
        "Disable building of plugin \"${plugin}\""
 
412
        OFF
 
413
    )
 
414
 
 
415
    if (NOT COMPIZ_DISABLE_PLUGIN_${_PLUGIN})
 
416
        _build_compiz_plugin (${plugin} ${ARGN})
 
417
    endif (NOT COMPIZ_DISABLE_PLUGIN_${_PLUGIN})
 
418
endmacro ()