CMakeLists.txt 3.53 KB
Newer Older
Rohit Yadav's avatar
Rohit Yadav committed
1 2 3 4 5
#
# VLMC build system
# Authors: Ludovic Fauvet <etix@vlmc.org>
#          Rohit Yadav <rohityadav89@gmail.com>
#
6

7
## RCC file
8
SET(TS_QRC ${CMAKE_SOURCE_DIR}/ts/resources-ts.qrc)
9

10 11 12 13 14 15
IF(NOT QT_LUPDATE_EXECUTABLE)
    MESSAGE(WARNING "VLMC could not find lupdate. You won't be able to update translations.")
ENDIF(NOT QT_LUPDATE_EXECUTABLE)

IF(NOT QT_LRELEASE_EXECUTABLE)
    MESSAGE(WARNING "VLMC could not find lrelease. Your build won't contain translations.")
16 17
    ## Create an empty RCC file
    FILE(WRITE ${TS_QRC} "<RCC></RCC>")
18 19
ENDIF(NOT QT_LRELEASE_EXECUTABLE)

20

21 22
## Wraps the supplied .ts files in lrelease commands
MACRO(QT4_ADD_TRANSLATIONS outfiles)
23
    FILE(WRITE ${TS_QRC} "<RCC><qresource prefix=\"ts\">\n")
24 25 26 27
    FOREACH (it ${ARGN})
        GET_FILENAME_COMPONENT(it ${it} ABSOLUTE)
        GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)

28 29
        FILE(APPEND ${TS_QRC} "<file>${outfile}.qm</file>\n")

30 31 32 33 34 35 36 37 38 39 40
        SET(outfile ${CMAKE_SOURCE_DIR}/ts/${outfile}.qm)

        ADD_CUSTOM_COMMAND(
            OUTPUT ${outfile}
            COMMAND ${QT_LRELEASE_EXECUTABLE}
            ARGS -compress -silent -nounfinished ${it} -qm ${outfile}
            MAIN_DEPENDENCY ${it}
        )

        SET(${outfiles} ${${outfiles}} ${outfile})
    ENDFOREACH(it)
41
    FILE(APPEND ${TS_QRC} "</qresource></RCC>")
42 43
ENDMACRO(QT4_ADD_TRANSLATIONS)

Rohit Yadav's avatar
Rohit Yadav committed
44 45 46 47 48 49 50
## Set availbale translations file ids here
OPTION(LANGUAGES "Using translations")
SET(ALL_LANGUAGES
        ca
        cs
        de
        es
51
        eu
Rohit Yadav's avatar
Rohit Yadav committed
52 53
        fr
        gl
Ludovic Fauvet's avatar
Ludovic Fauvet committed
54
        el
55
        hu
Rohit Yadav's avatar
Rohit Yadav committed
56 57 58 59 60 61 62
        it
        ja
        nl
        pl
        pt
        ro
        ru
Ludovic Fauvet's avatar
Ludovic Fauvet committed
63
        sl
Rohit Yadav's avatar
Rohit Yadav committed
64 65 66
        sk
        sv
        ta
67
        te
Rohit Yadav's avatar
Rohit Yadav committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
        tr
        uk
        zh
   )

## Check if user has provided specific LANGS option
IF(NOT DEFINED LANGS)
    SET(LANGUAGES ${ALL_LANGUAGES} CACHE STRING "Using translations" FORCE)
ELSE(NOT DEFINED LANGS)
    IF(NOT LANGS)
        SET(LANGUAGES "" CACHE STRING "Using translations" FORCE)
    ELSEIF(LANGS STREQUAL *)
        SET(LANGUAGES ${ALL_LANGUAGES} CACHE STRING "Using translations" FORCE)
    ELSE(NOT LANGS)
        STRING(REGEX MATCHALL [a-zA-Z_]+
               langs1 ${LANGS})
        SET(LANGUAGES ${langs1} CACHE STRING "Using translations" FORCE)
    ENDIF(NOT LANGS)
ENDIF(NOT DEFINED LANGS)

## Display what translations files will be processed
MESSAGE(STATUS "Translations: ${LANGUAGES}")

## Collect all translations files that are to be processed
FOREACH(LANGUAGE ${LANGUAGES})
    FILE(GLOB temp_TS ${CMAKE_SOURCE_DIR}/ts/vlmc*${LANGUAGE}*.ts)
    LIST(APPEND vlmc_TS ${temp_TS})
ENDFOREACH()
96 97 98

IF(QT_LRELEASE_EXECUTABLE)
    ## Wraps the collected translations
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
99
    qt5_add_translation(vlmc_QMS ${vlmc_TS})
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

    ## Create a target that runs lrelease for all the .ts files
    ## "ALL" means that it will be run by default.
    ADD_CUSTOM_TARGET(translations ALL DEPENDS ${vlmc_QMS})
ENDIF(QT_LRELEASE_EXECUTABLE)

IF(QT_LUPDATE_EXECUTABLE)
    ## Search for all translatable strings in the sources directory
    FILE(GLOB_RECURSE translate_SRCS ${CMAKE_SOURCE_DIR}/src/*.cpp
                                 ${CMAKE_SOURCE_DIR}/src/*.hpp)
    FILE(GLOB_RECURSE translate_HDRS ${CMAKE_SOURCE_DIR}/src/*.h)
    FILE(GLOB_RECURSE translate_UIS ${CMAKE_SOURCE_DIR}/src/*.ui)

    SET(translate_SRCS ${translate_SRCS} ${translate_HDRS} ${translate_UIS})

    ## Create a target that runs lupdate for all the sources and UI files
    ADD_CUSTOM_TARGET(lupdate
117
        COMMAND ${QT_LUPDATE_EXECUTABLE} -noobsolete ${translate_SRCS} -ts ${vlmc_TS} ${CMAKE_SOURCE_DIR}/ts/template.ts
118 119 120
    )
ENDIF(QT_LUPDATE_EXECUTABLE)