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

« back to all changes in this revision

Viewing changes to cmake/CompizCommon.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
cmake_minimum_required (VERSION 2.6)
 
2
 
 
3
if ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
 
4
    message (SEND_ERROR "Building in the source directory is not supported.")
 
5
    message (FATAL_ERROR "Please remove the created \"CMakeCache.txt\" file, the \"CMakeFiles\" directory and create a build directory and call \"${CMAKE_COMMAND} <path to the sources>\".")
 
6
endif ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
 
7
 
 
8
#### policies
 
9
 
 
10
cmake_policy (SET CMP0000 OLD)
 
11
cmake_policy (SET CMP0002 OLD)
 
12
cmake_policy (SET CMP0003 NEW)
 
13
cmake_policy (SET CMP0005 OLD)
 
14
 
 
15
 
 
16
set (
 
17
    VERSION ${VERSION} CACHE STRING
 
18
    "Package version that is added to a plugin pkg-version file"
 
19
)
 
20
 
 
21
set (
 
22
    COMPIZ_I18N_DIR ${COMPIZ_I18N_DIR} CACHE PATH "Translation file directory"
 
23
)
 
24
 
 
25
# unsets the given variable
 
26
macro (compiz_unset var)
 
27
    set (${var} "" CACHE INTERNAL "")
 
28
endmacro ()
 
29
 
 
30
# sets the given variable
 
31
macro (compiz_set var value)
 
32
    set (${var} ${value} CACHE INTERNAL "")
 
33
endmacro ()
 
34
 
 
35
macro (compiz_format_string str length return)
 
36
    string (LENGTH "${str}" _str_len)
 
37
    math (EXPR _add_chr "${length} - ${_str_len}")
 
38
    set (${return} "${str}")
 
39
    while (_add_chr GREATER 0)
 
40
        set (${return} "${${return}} ")
 
41
        math (EXPR _add_chr "${_add_chr} - 1")
 
42
    endwhile ()
 
43
endmacro ()
 
44
 
 
45
string (ASCII 27 _escape)
 
46
function (compiz_color_message _str)
 
47
    if (CMAKE_COLOR_MAKEFILE)
 
48
        message (${_str})
 
49
    else ()
 
50
        string (REGEX REPLACE "${_escape}.[0123456789;]*m" "" __str ${_str})
 
51
        message (${__str})
 
52
    endif ()
 
53
endfunction ()
 
54
 
 
55
function (compiz_configure_file _src _dst)
 
56
    foreach (_val ${ARGN})
 
57
        set (_${_val}_sav ${${_val}})
 
58
        set (${_val} "")
 
59
        foreach (_word ${_${_val}_sav})
 
60
            set (${_val} "${${_val}}${_word} ")
 
61
        endforeach (_word ${_${_val}_sav})
 
62
    endforeach (_val ${ARGN})
 
63
 
 
64
    configure_file (${_src} ${_dst} @ONLY)
 
65
 
 
66
    foreach (_val ${ARGN})
 
67
        set (${_val} ${_${_val}_sav})
 
68
        set (_${_val}_sav "")
 
69
    endforeach (_val ${ARGN})
 
70
endfunction ()
 
71
 
 
72
function (compiz_add_plugins_in_folder folder)
 
73
    file (
 
74
        GLOB _plugins_in
 
75
        RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/${folder}"
 
76
        "${CMAKE_CURRENT_SOURCE_DIR}/${folder}/*/CMakeLists.txt"
 
77
    )
 
78
 
 
79
    foreach (_plugin ${_plugins_in})
 
80
        get_filename_component (_plugin_dir ${_plugin} PATH)
 
81
        add_subdirectory (${folder}/${_plugin_dir})
 
82
    endforeach ()
 
83
endfunction ()
 
84
 
 
85
#### pkg-config handling
 
86
 
 
87
include (FindPkgConfig)
 
88
 
 
89
set (PKGCONFIG_REGEX ".*${CMAKE_INSTALL_PREFIX}/lib/pkgconfig:${CMAKE_INSTALL_PREFIX}/share/pkgconfig.*")
 
90
 
 
91
# add install prefix to pkgconfig search path if needed
 
92
if (NOT "$ENV{PKG_CONFIG_PATH}" MATCHES "${PKGCONFIG_REGEX}")
 
93
    if ("" STREQUAL "$ENV{PKG_CONFIG_PATH}")
 
94
        set (ENV{PKG_CONFIG_PATH} "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig:${CMAKE_INSTALL_PREFIX}/share/pkgconfig")
 
95
    else ("" STREQUAL "$ENV{PKG_CONFIG_PATH}")
 
96
        set (ENV{PKG_CONFIG_PATH}
 
97
             "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig:${CMAKE_INSTALL_PREFIX}/share/pkgconfig:$ENV{PKG_CONFIG_PATH}")
 
98
    endif ("" STREQUAL "$ENV{PKG_CONFIG_PATH}")
 
99
endif (NOT "$ENV{PKG_CONFIG_PATH}" MATCHES "${PKGCONFIG_REGEX}")
 
100
 
 
101
function (compiz_pkg_check_modules _var _req)
 
102
    if (NOT ${_var})
 
103
        pkg_check_modules (${_var} ${_req} ${ARGN})
 
104
        if (${_var}_FOUND)
 
105
            set (${_var} 1 CACHE INTERNAL "" FORCE)
 
106
        endif ()
 
107
        set(__pkg_config_checked_${_var} 0 CACHE INTERNAL "" FORCE)
 
108
    endif ()
 
109
endfunction ()
 
110
 
 
111
#### translations
 
112
 
 
113
# translate metadata file
 
114
function (compiz_translate_xml _src _dst)
 
115
    find_program (INTLTOOL_MERGE_EXECUTABLE intltool-merge)
 
116
    mark_as_advanced (FORCE INTLTOOL_MERGE_EXECUTABLE)
 
117
 
 
118
    if (INTLTOOL_MERGE_EXECUTABLE
 
119
        AND COMPIZ_I18N_DIR
 
120
        AND EXISTS ${COMPIZ_I18N_DIR})
 
121
        add_custom_command (
 
122
            OUTPUT ${_dst}
 
123
            COMMAND ${INTLTOOL_MERGE_EXECUTABLE} -x -u -c
 
124
                    ${CMAKE_BINARY_DIR}/.intltool-merge-cache
 
125
                    ${COMPIZ_I18N_DIR}
 
126
                    ${_src}
 
127
                    ${_dst}
 
128
            DEPENDS ${_src}
 
129
        )
 
130
    else ()
 
131
        add_custom_command (
 
132
            OUTPUT ${_dst}
 
133
            COMMAND cat ${_src} |
 
134
                    sed -e 's;<_;<;g' -e 's;</_;</;g' > 
 
135
                    ${_dst}
 
136
            DEPENDS ${_src}
 
137
        )
 
138
    endif ()
 
139
endfunction ()
 
140
 
 
141
function (compiz_translate_desktop_file _src _dst)
 
142
    find_program (INTLTOOL_MERGE_EXECUTABLE intltool-merge)
 
143
    mark_as_advanced (FORCE INTLTOOL_MERGE_EXECUTABLE)
 
144
 
 
145
    if (INTLTOOL_MERGE_EXECUTABLE
 
146
        AND COMPIZ_I18N_DIR
 
147
        AND EXISTS ${COMPIZ_I18N_DIR})
 
148
        add_custom_command (
 
149
            OUTPUT ${_dst}
 
150
            COMMAND ${INTLTOOL_MERGE_EXECUTABLE} -d -u -c
 
151
                    ${CMAKE_BINARY_DIR}/.intltool-merge-cache
 
152
                    ${COMPIZ_I18N_DIR}
 
153
                    ${_src}
 
154
                    ${_dst}
 
155
            DEPENDS ${_src}
 
156
        )
 
157
    else ()
 
158
        add_custom_command (
 
159
            OUTPUT ${_dst}
 
160
            COMMAND cat ${_src} |
 
161
                    sed -e 's;^_;;g' >
 
162
                    ${_dst}
 
163
            DEPENDS ${_src}
 
164
        )
 
165
    endif ()
 
166
endfunction ()
 
167
 
 
168
#### uninstall
 
169
 
 
170
macro (compiz_add_uninstall)
 
171
   if (NOT _compiz_uninstall_rule_created)
 
172
        compiz_set(_compiz_uninstall_rule_created TRUE)
 
173
 
 
174
        set (_file "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake")
 
175
 
 
176
        file (WRITE  ${_file} "if (NOT EXISTS \"${CMAKE_BINARY_DIR}/install_manifest.txt\")\n")
 
177
        file (APPEND ${_file} "  message (FATAL_ERROR \"Cannot find install manifest: \\\"${CMAKE_BINARY_DIR}/install_manifest.txt\\\"\")\n")
 
178
        file (APPEND ${_file} "endif (NOT EXISTS \"${CMAKE_BINARY_DIR}/install_manifest.txt\")\n\n")
 
179
        file (APPEND ${_file} "file (READ \"${CMAKE_BINARY_DIR}/install_manifest.txt\" files)\n")
 
180
        file (APPEND ${_file} "string (REGEX REPLACE \"\\n\" \";\" files \"\${files}\")\n")
 
181
        file (APPEND ${_file} "foreach (file \${files})\n")
 
182
        file (APPEND ${_file} "  message (STATUS \"Uninstalling \\\"\${file}\\\"\")\n")
 
183
        file (APPEND ${_file} "  if (EXISTS \"\${file}\")\n")
 
184
        file (APPEND ${_file} "    exec_program(\n")
 
185
        file (APPEND ${_file} "      \"${CMAKE_COMMAND}\" ARGS \"-E remove \\\"\${file}\\\"\"\n")
 
186
        file (APPEND ${_file} "      OUTPUT_VARIABLE rm_out\n")
 
187
        file (APPEND ${_file} "      RETURN_VALUE rm_retval\n")
 
188
        file (APPEND ${_file} "      )\n")
 
189
        file (APPEND ${_file} "    if (\"\${rm_retval}\" STREQUAL 0)\n")
 
190
        file (APPEND ${_file} "    else (\"\${rm_retval}\" STREQUAL 0)\n")
 
191
        file (APPEND ${_file} "      message (FATAL_ERROR \"Problem when removing \\\"\${file}\\\"\")\n")
 
192
        file (APPEND ${_file} "    endif (\"\${rm_retval}\" STREQUAL 0)\n")
 
193
        file (APPEND ${_file} "  else (EXISTS \"\${file}\")\n")
 
194
        file (APPEND ${_file} "    message (STATUS \"File \\\"\${file}\\\" does not exist.\")\n")
 
195
        file (APPEND ${_file} "  endif (EXISTS \"\${file}\")\n")
 
196
        file (APPEND ${_file} "endforeach (file)\n")
 
197
 
 
198
        add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake")
 
199
 
 
200
    endif ()
 
201
endmacro ()
 
202