]> git.lyx.org Git - lyx.git/blob - development/cmake/modules/FindLyXGettext.cmake
Mark created moc-files as GENERATED
[lyx.git] / development / cmake / modules / FindLyXGettext.cmake
1 # - Slightly modified Find GNU gettext tools
2 # This module looks for the GNU gettext tools. This module defines the 
3 # following values:
4 #  GETTEXT_MSGMERGE_EXECUTABLE: the full path to the msgmerge tool.
5 #  GETTEXT_MSGFMT_EXECUTABLE: the full path to the msgfmt tool.
6 #  GETTEXT_FOUND: True if gettext has been found.
7 #
8 # Additionally it provides the following macros:
9 # GETTEXT_CREATE_TRANSLATIONS ( outputFile [ALL] file1 ... fileN )
10 #    This will create a target "translations" which will convert the 
11 #    given input po files into the binary output mo file. If the 
12 #    ALL option is used, the translations will also be created when
13 #    building the default target.
14
15 FIND_PROGRAM(GETTEXT_MSGMERGE_EXECUTABLE msgmerge)
16 FIND_PROGRAM(GETTEXT_MSGFMT_EXECUTABLE msgfmt)
17 FIND_PROGRAM(GETTEXT_XGETTEXT_EXECUTABLE xgettext)
18 FIND_PROGRAM(GETTEXT_MSGUNIQ_EXECUTABLE msguniq)
19
20 MACRO(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFile)
21
22    SET(_gmoFiles)
23    # remove only the last extension e.g
24    #    LyX2.0.pot ==> LyX2.0
25    # and not LyX2.0.pot ==> LyX2
26    # as it would be with NAME_WE
27    # GET_FILENAME_COMPONENT(_potBasename ${_potFile} NAME_WE)
28    GET_FILENAME_COMPONENT(_potname ${_potFile} NAME)
29    if (_potname MATCHES "^\(.+\)\\.[^\\.]+$")
30        set(_potBasename ${CMAKE_MATCH_1})
31    else()
32        set(_potBasename ${_potname})
33    endif()
34    GET_FILENAME_COMPONENT(_absPotFile ${_potFile} ABSOLUTE)
35
36    SET(_addToAll)
37    IF(${_firstPoFile} STREQUAL "ALL")
38       SET(_addToAll "ALL")
39       SET(_firstPoFile)
40    ENDIF(${_firstPoFile} STREQUAL "ALL")
41
42    FOREACH (_currentPoFile ${ARGN})
43       GET_FILENAME_COMPONENT(_absFile ${_currentPoFile} ABSOLUTE)
44       GET_FILENAME_COMPONENT(_abs_PATH ${_absFile} PATH)
45       GET_FILENAME_COMPONENT(_lang ${_absFile} NAME_WE)
46       SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo)
47
48       ADD_CUSTOM_COMMAND( 
49          OUTPUT ${_gmoFile} 
50          COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none ${_absFile} ${_absPotFile}
51          COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_absFile}
52          DEPENDS ${_absPotFile} ${_absFile} 
53       )
54
55       INSTALL(FILES ${_gmoFile} DESTINATION ${LYX_ABS_INSTALLED_LOCALEDIR}/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo) 
56       SET(_gmoFiles ${_gmoFiles} ${_gmoFile})
57
58    ENDFOREACH (_currentPoFile )
59
60    ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_gmoFiles})
61
62 ENDMACRO(GETTEXT_CREATE_TRANSLATIONS )
63
64 IF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
65    SET(GETTEXT_FOUND TRUE)
66 ELSE (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
67    SET(GETTEXT_FOUND FALSE)
68    IF (GetText_REQUIRED)
69       MESSAGE(FATAL_ERROR "GetText not found")
70    ENDIF (GetText_REQUIRED)
71 ENDIF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
72
73 mark_as_advanced(GETTEXT_MSGMERGE_EXECUTABLE GETTEXT_MSGFMT_EXECUTABLE GETTEXT_XGETTEXT_EXECUTABLE GETTEXT_MSGUNIQ_EXECUTABLE)
74