Skip to content

Commit

Permalink
Do not use both TARGET and DEPENDS in ADD_CUSTOM_COMMAND.
Browse files Browse the repository at this point in the history
Modern cmake warns like this:

CMake Warning (dev) at po/CMakeLists.txt:20 (ADD_CUSTOM_COMMAND):
  The following keywords are not supported when using
  add_custom_command(TARGET): DEPENDS.

Rewrite the build instructions to have an additional level of dependencies.
Before, we have one build target, the compiles all *.po files. Now we let
the main target ("translations") depend on the output files (*.gmo), which
themselves depend on their respective *.po file via ADD_CUSTOM_COMMAND.

I took the example CMakeLists.txt at Techbase[1] as inspiration how to
rewrite the target chain.

[1] https://techbase.kde.org/Development/Tutorials/Localization/i18n_Build_Systems/Outside_KDE_repositories
  • Loading branch information
j6t committed Jan 25, 2025
1 parent bb85640 commit 48060b8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions po/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ ELSE(NOT GETTEXT_MSGFMT_EXECUTABLE)

SET(catalogname kdbg)

ADD_CUSTOM_TARGET(translations ALL)

FILE(GLOB PO_FILES *.po)
SET(GMO_FILES)

FOREACH(_poFile ${PO_FILES})
GET_FILENAME_COMPONENT(_lang ${_poFile} NAME_WE)
SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo)

ADD_CUSTOM_COMMAND(TARGET translations
ADD_CUSTOM_COMMAND(OUTPUT ${_gmoFile}
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} --check -o ${_gmoFile} ${_poFile}
DEPENDS ${_poFile})
INSTALL(FILES ${_gmoFile}
DESTINATION ${LOCALE_INSTALL_DIR}/${_lang}/LC_MESSAGES/
RENAME ${catalogname}.mo)
LIST(APPEND GMO_FILES ${_gmoFile})

ENDFOREACH(_poFile ${PO_FILES})

ADD_CUSTOM_TARGET(translations ALL DEPENDS ${GMO_FILES})

ENDIF(NOT GETTEXT_MSGFMT_EXECUTABLE)

0 comments on commit 48060b8

Please sign in to comment.