[CMake] Trying to create lupdate target for Qt

Patrick Noffke Patrick.Noffke at adpro.com.au
Mon Jul 10 22:44:48 EDT 2006


I am trying to incorporate lupdate and lrelease into my build process.  I can get lrelease to work just fine.  The trouble is with lupdate.  The purpose of lupdate is to update translation XML files (.ts extension below), in order to pick up any recent text changes.  But these files are for all intents and purposes source files.  Once they are generated the first time, you open them in linguist (or some other tool) to edit the translations, and you want to keep those translations in tact.  Then when text is added or removed, rerun lupdate and you can do an incremental translation.  To me it makes sense to have a separate lupdate build target (i.e. so I can manually run "(n)make lupdate").

It seems the trouble is because I'm trying to define a custom command that has output in the source directory.  When I SET tsfile to be in the binary dir (by uncommenting the line in the macro below), lupdate is run (it fails because the translations dir doesn't exist, and I don't want it to write to the binary dir anyway).  But when the output is in the source directory, it is not run.

Could someone please suggest a better way to handle this?

Thanks,
Patrick



# QT4_WRAP_TS(lupdate_outputs lrelease_outputs prefix lang1 lang2 ... )
MACRO (QT4_WRAP_TS lupdate_outputs lrelease_outputs prefix)
    FOREACH (it ${ARGN})
      SET(tsfile ${CMAKE_CURRENT_SOURCE_DIR}/translations/${prefix}_${it}.ts)
#      SET(tsfile ${CMAKE_CURRENT_BINARY_DIR}/translations/${prefix}_${it}.ts)
      ADD_CUSTOM_COMMAND(OUTPUT ${tsfile}
        COMMAND ${QT_LUPDATE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR} -ts ${tsfile}
      )

      SET(qmfile ${CMAKE_CURRENT_BINARY_DIR}/${prefix}_${it}.qm)
      ADD_CUSTOM_COMMAND(OUTPUT ${qmfile}
        COMMAND ${QT_LRELEASE_EXECUTABLE} ${tsfile} -qm ${qmfile}
      )

      SET(${lupdate_outputs} ${${lupdate_outputs}} ${tsfile})
      SET(${lrelease_outputs} ${${lrelease_outputs}} ${qmfile})
    ENDFOREACH(it)
ENDMACRO (QT4_WRAP_TS)


# Create our translation files.
QT4_WRAP_TS(lupdate_outputs lrelease_outputs
  foo
  en_AU en_US en_GB fr_FR de_DE ja_JM zh_CN
)

# We only want to run lupdate manually (need to check out all the .ts files),
# and this is typically only done when the UI text has changed.  So we don't
# include lupdate as part of the default build target.
# But we want to run lrelease every time, so the lrelease outputs will become
# part of the windows_installer target (which will in turn be part of the
# default build target).
ADD_CUSTOM_TARGET(lupdate
  DEPENDS ${lupdate_outputs}
)


More information about the CMake mailing list