cmake: only optionally modify in-source .ts files (Qt lupdate)

The creation of .qm output files from .ts input data undoubtedly needs
to be an unconditional part of the build process. The modification of
.ts source files in contrast needs to remain an intentional activity
during development. The mere act of compiling sources to binaries shall
never modify the source tree. Move the lupdate(1) invocation out of the
default build process, while lrelease(1) remains in place.

Ideally we could have a "make ts-update" target for developers to invoke
as needed. But that'd be more involved since the qt5_create_translation()
cmake routine is involved, which needs to be passed variables content
that is only available at configure time. A future implementation could
investigate the add_custom_target() approach. This commit introduces the
ENABLE_TS_UPDATE cmake option to quickly address the issue.

How to reproduce:

  $ cd $SRC
  $ cmake --build $OUT
  $ git status -s
  $ cmake -DENABLE_TS_UPDATE=ON $OUT
  $ cmake --build $OUT
  $ git status -s

This commit also happens to bring build steps in closer promixity, while
making development iterations stand out more perceivably.
This commit is contained in:
Gerhard Sittig 2023-04-22 09:28:12 +02:00
parent cfcda2e615
commit 3903edbd71
1 changed files with 7 additions and 4 deletions

View File

@ -48,6 +48,7 @@ option(ENABLE_DECODE "Build with libsigrokdecode" TRUE)
option(ENABLE_FLOW "Build with libsigrokflow" FALSE)
option(ENABLE_TESTS "Enable unit tests" FALSE)
option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE)
option(ENABLE_TS_UPDATE "Update .ts source files (Qt l10n)" FALSE)
if(WIN32)
# On Windows/MinGW we need to statically link to libraries.
@ -528,14 +529,16 @@ endif ()
if(Qt5_FOUND)
qt5_add_translation(QM_FILES ${TS_FILES})
qt5_create_translation(QM_FILES ${pulseview_SOURCES} ${TS_FILES})
qt5_add_resources(pulseview_RESOURCES_RCC ${CMAKE_BINARY_DIR}/translations.qrc)
if (ENABLE_TS_UPDATE)
qt5_create_translation(QM_FILES ${pulseview_SOURCES} ${TS_FILES})
endif ()
else()
qt6_add_translation(QM_FILES ${TS_FILES})
qt6_create_translation(QM_FILES ${pulseview_SOURCES} ${TS_FILES})
qt6_add_resources(pulseview_RESOURCES_RCC ${CMAKE_BINARY_DIR}/translations.qrc)
if (ENABLE_TS_UPDATE)
qt6_create_translation(QM_FILES ${pulseview_SOURCES} ${TS_FILES})
endif ()
endif()
#===============================================================================