]> git.lyx.org Git - lyx.git/blob - development/cmake/modules/FindLyXGettext.cmake
CMake: Make sure the first po file is also processed
[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 set(hints HINTS "${GNUWIN32_DIR}/gettext-tools")
16 FIND_PROGRAM(GETTEXT_MSGMERGE_EXECUTABLE msgmerge ${hints})
17 FIND_PROGRAM(GETTEXT_MSGFMT_EXECUTABLE   msgfmt   ${hints})
18 FIND_PROGRAM(GETTEXT_XGETTEXT_EXECUTABLE xgettext ${hints})
19 FIND_PROGRAM(GETTEXT_MSGUNIQ_EXECUTABLE  msguniq  ${hints})
20
21 MACRO(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFile)
22
23    SET(_gmoFiles)
24    # remove only the last extension e.g
25    #    LyX2.0.pot ==> LyX2.0
26    # and not LyX2.0.pot ==> LyX2
27    # as it would be with NAME_WE
28    # GET_FILENAME_COMPONENT(_potBasename ${_potFile} NAME_WE)
29    GET_FILENAME_COMPONENT(_potname ${_potFile} NAME)
30    if (_potname MATCHES "^\(.+\)\\.[^\\.]+$")
31        set(_potBasename ${CMAKE_MATCH_1})
32    else()
33        set(_potBasename ${_potname})
34    endif()
35    GET_FILENAME_COMPONENT(_absPotFile ${_potFile} ABSOLUTE)
36
37    SET(_addToAll)
38    IF(${_firstPoFile} STREQUAL "ALL")
39       SET(_addToAll "ALL")
40       SET(_firstPoFile)
41    ENDIF(${_firstPoFile} STREQUAL "ALL")
42
43    FOREACH (_currentPoFile ${_firstPoFile} ${ARGN})
44       GET_FILENAME_COMPONENT(_absFile ${_currentPoFile} ABSOLUTE)
45       GET_FILENAME_COMPONENT(_abs_PATH ${_absFile} PATH)
46       GET_FILENAME_COMPONENT(_lang ${_absFile} NAME_WE)
47       SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo)
48
49       ADD_CUSTOM_COMMAND( 
50          OUTPUT ${_gmoFile} 
51          COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none ${_absFile} ${_absPotFile}
52          COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -c --statistics -o ${_gmoFile} ${_absFile}
53          DEPENDS ${_absPotFile} ${_absFile} 
54       )
55
56       INSTALL(FILES ${_gmoFile} DESTINATION ${LYX_DATA_SUBDIR}${LYX_LOCALEDIR}/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo) 
57       SET(_gmoFiles ${_gmoFiles} ${_gmoFile})
58
59    ENDFOREACH (_currentPoFile )
60
61    ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_gmoFiles})
62    set_target_properties(translations PROPERTIES FOLDER "i18n")
63
64 ENDMACRO(GETTEXT_CREATE_TRANSLATIONS )
65
66 IF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
67    SET(GETTEXT_FOUND TRUE)
68 ELSE (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
69    SET(GETTEXT_FOUND FALSE)
70    IF (GetText_REQUIRED)
71       MESSAGE(FATAL_ERROR "GetText not found")
72    ENDIF (GetText_REQUIRED)
73 ENDIF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
74
75 mark_as_advanced(GETTEXT_MSGMERGE_EXECUTABLE GETTEXT_MSGFMT_EXECUTABLE GETTEXT_XGETTEXT_EXECUTABLE GETTEXT_MSGUNIQ_EXECUTABLE)
76