~mateo-salta/touch-rss-scope/utfeed1

« back to all changes in this revision

Viewing changes to cmake/FindXGettext.cmake

  • Committer: Mateo Salta
  • Date: 2014-11-30 22:43:28 UTC
  • Revision ID: mateo_salta@yahoo.com-20141130224328-1bshkjh7chb1kwvs
- Added 4 more custom feeds

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2013 Canonical Ltd
 
2
#
 
3
# This program is free software: you can redistribute it and/or modify
 
4
# it under the terms of the GNU Lesser General Public License version 3 as
 
5
# published by the Free Software Foundation.
 
6
#
 
7
# This program is distributed in the hope that it will be useful,
 
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
# GNU Lesser General Public License for more details.
 
11
#
 
12
# You should have received a copy of the GNU Lesser General Public License
 
13
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
14
 
 
15
# This package provides macros that wrap the xgettext program.
 
16
 
17
# An example of common usage is:
 
18
#
 
19
#    set(
 
20
#        POT_FILE
 
21
#        "${CMAKE_CURRENT_SOURCE_DIR}/${GETTEXT_PACKAGE}.pot"
 
22
#    )
 
23
#
 
24
#    file(
 
25
#        GLOB_RECURSE SRC_FILES
 
26
#        RELATIVE ${CMAKE_SOURCE_DIR}
 
27
#        ${SOURCE_DIR}/*.cpp
 
28
#        ${SOURCE_DIR}/*.c
 
29
#        ${SOURCE_DIR}/*.h
 
30
#    )
 
31
#
 
32
#    xgettext_create_pot_file(
 
33
#        ${POT_FILE}
 
34
#        CPP
 
35
#        QT
 
36
#        INPUT ${SOURCES}
 
37
#        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
 
38
#        ADD_COMMENTS "TRANSLATORS"
 
39
#        KEYWORDS "_" "N_"
 
40
#        PACKAGE_NAME ${GETTEXT_PACKAGE}
 
41
#        COPYRIGHT_HOLDER "Canonical Ltd."
 
42
#    )
 
43
 
 
44
find_package(Gettext REQUIRED)
 
45
 
 
46
find_program(XGETTEXT_EXECUTABLE xgettext)
 
47
 
 
48
if(XGETTEXT_EXECUTABLE)
 
49
    execute_process(
 
50
        COMMAND ${XGETTEXT_EXECUTABLE} --version
 
51
        OUTPUT_VARIABLE xgettext_version
 
52
        ERROR_QUIET
 
53
        OUTPUT_STRIP_TRAILING_WHITESPACE)
 
54
    if (xgettext_version MATCHES "^xgettext \\(.*\\) [0-9]")
 
55
        string(
 
56
            REGEX REPLACE "^xgettext \\([^\\)]*\\) ([0-9\\.]+[^ \n]*).*" "\\1"
 
57
            XGETTEXT_VERSION_STRING "${xgettext_version}"
 
58
        )
 
59
    endif()
 
60
    unset(xgettext_version)
 
61
endif()
 
62
 
 
63
include(FindPackageHandleStandardArgs)
 
64
 
 
65
find_package_handle_standard_args(
 
66
    XGettext
 
67
    REQUIRED_VARS XGETTEXT_EXECUTABLE
 
68
    VERSION_VAR XGETTEXT_VERSION_STRING
 
69
)
 
70
 
 
71
function(APPEND_EACH LISTNAME GLUE OUTPUT)
 
72
    set(_tmp_list "")
 
73
    foreach(VAL ${${LISTNAME}})
 
74
        list(APPEND _tmp_list "${GLUE}${VAL}")
 
75
    endforeach(VAL ${${LISTNAME}})
 
76
    set(${OUTPUT} "${_tmp_list}" PARENT_SCOPE)
 
77
endfunction()
 
78
 
 
79
function(XGETTEXT_CREATE_POT_FILE _potFile)
 
80
    set(_options ALL QT CPP)
 
81
    set(_oneValueArgs ADD_COMMENTS PACKAGE_NAME COPYRIGHT_HOLDER WORKING_DIRECTORY)
 
82
    set(_multiValueArgs INPUT KEYWORDS)
 
83
 
 
84
    cmake_parse_arguments(_ARG "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
 
85
    
 
86
    set(_QT "")
 
87
    if(_ARG_QT)
 
88
        set(_QT "--qt")
 
89
    endif()
 
90
    
 
91
    set(_CPP "")
 
92
    if(_ARG_CPP)
 
93
        set(_CPP "--c++")
 
94
    endif()
 
95
    
 
96
    set(_KEYWORD "")
 
97
    if(_ARG_KEYWORDS)
 
98
        append_each(_ARG_KEYWORDS "--keyword=" _KEYWORD)
 
99
    endif()
 
100
    
 
101
    set(_ADD_COMMENTS "")
 
102
    if(_ARG_ADD_COMMENTS)
 
103
        set(_ADD_COMMENTS --add-comments="${_ARG_ADD_COMMENTS}")
 
104
    endif()
 
105
    
 
106
    set(_PACKAGE_NAME "")
 
107
    if(_ARG_PACKAGE_NAME)
 
108
        set(_PACKAGE_NAME --package-name="${_ARG_PACKAGE_NAME}")
 
109
    endif()
 
110
    
 
111
    set(_COPYRIGHT_HOLDER "")
 
112
    if(_ARG_COPYRIGHT_HOLDER)
 
113
        set(_COPYRIGHT_HOLDER --copyright-holder="${_ARG_COPYRIGHT_HOLDER}")
 
114
    endif()
 
115
 
 
116
    add_custom_command(
 
117
        OUTPUT "${_potFile}"
 
118
        COMMAND ${XGETTEXT_EXECUTABLE} --output="${_potFile}" ${_KEYWORD} ${_PACKAGE_NAME} ${_COPYRIGHT_HOLDER} ${_QT} ${_CPP} ${_ADD_COMMENTS} ${_ARG_INPUT}
 
119
        WORKING_DIRECTORY ${_ARG_WORKING_DIRECTORY}
 
120
    )
 
121
    
 
122
    _GETTEXT_GET_UNIQUE_TARGET_NAME(_potFile _uniqueTargetName)
 
123
    
 
124
    if(_ARG_ALL)
 
125
        add_custom_target(${_uniqueTargetName} ALL DEPENDS ${_potFile})
 
126
    else()
 
127
        add_custom_target(${_uniqueTargetName} DEPENDS ${_potFile})
 
128
    endif()
 
129
 
 
130
endfunction()
 
131