CMake: avoid unnecessarily remaking all .mo files on each build

All the .mo files had a dependency on the target directory, which meant that
every change to the timestamp of that directory caused all the files to be
remade; and each file remade caused a change to the directory's timestamp ...

Since CMake 3.0, "cmake -E make_directory" has been deprecated in favor of
"file(MAKE_DIRECTORY ...)", so use that instead of the custom command. This
means the directories are created when the cmake config is generated, instead
of during the subsequent make steps.

Note: the mo-update target which builds the .mo files is only run when the
build is configured with ENABLE_NLS=ON. Both before and after this change,
none of the .mo files are rebuilt when ENABLE_NLS=OFF.
This commit is contained in:
Steve Cotton 2021-01-27 16:08:26 +01:00 committed by Steve Cotton
parent 09be367357
commit eab006f02c

View file

@ -239,12 +239,7 @@ if(ENABLE_NLS)
foreach(DOMAIN ${DOMAINS})
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/${LOCALEDIR}/${LINGUA}/LC_MESSAGES
COMMAND ${CMAKE_COMMAND} -E make_directory
${CMAKE_SOURCE_DIR}/${LOCALEDIR}/${LINGUA}/LC_MESSAGES
COMMENT "mo-update [${LINGUA}]: Creating locale directory."
)
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/${LOCALEDIR}/${LINGUA}/LC_MESSAGES)
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/${LOCALEDIR}/${LINGUA}/LC_MESSAGES/${DOMAIN}.mo
@ -252,7 +247,6 @@ if(ENABLE_NLS)
${GETTEXT_MSGFMT_PARAMETER}
-o ${CMAKE_SOURCE_DIR}/${LOCALEDIR}/${LINGUA}/LC_MESSAGES/${DOMAIN}.mo ${LINGUA}.po
DEPENDS
${CMAKE_SOURCE_DIR}/${LOCALEDIR}/${LINGUA}/LC_MESSAGES
${PROJECT_SOURCE_DIR}/po/${DOMAIN}/${LINGUA}.po
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/po/${DOMAIN}
COMMENT "mo-update [${DOMAIN}-${LINGUA}]: Creating mo file."