CMake and GNU Gettext

I wanted to add translation support to my personal project using CMake and Gettext. CMake itself contains a module to find and work with Gettext translation files. It looked simple, but not everything goes according to plans.

It is always easy to blame someone else. I got confused by different examples. First example showed a file structure as locale/${language}/MyApp.po, which failed me when I was trying to integrate it into my program. This in combination with me playing with it cause the CMake generation fail in error basicaly saying The target with the name "MyApp" already exists.. That is because the basename is the same between multiple languages.

Second example is showing a different file folder structure locale/${language}.po. This one worked like a charm, but it looks ugly, I wanted the first variant and was keeping at it for hours to give up in the end.

A short note on my failure to realize that I should debug the CMake itself instead of blindly searching online for hours without a proper solution since there is not that much information online, which means it either others are much smarter than me or that this is underused module / feature in CMake.

Example Configuration

Example of the CMake configuration I used:

Messages.sh

#!/bin/sh

xgettext --keyword=gttr --from-code=utf-8 -p locale -o MyApp.pot `find . -name '*.cpp' -o -name '*.hpp'`

CmakeLists.txt

find_package(Gettext)

if (Gettext_FOUND)
	add_custom_target(
		ExtractTranslations
		ALL
		WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
		COMMENT "Extract translations from the source code."
		COMMAND Messages.sh
	)

	gettext_create_translations(
		locale/MyApp.pot
		ALL
		locale/sk_SK.po
	)
endif()

Articles from blogs I follow:

Test and verification technique effectiveness with GPT-6 Astra

When we looked at how well agents used test/verification techniques in August1, we saw that GPT-5.6 Sol generally did what you might call a caricature of various techniques when asked to use a technique or library such as TDD, QuickCheck, Lean 4, etc.; no…

via danluu.com November 2, 2026

With "AI" coding the future of software development looks more grim than ever before!

This is not just a rant, this is a serious call and warning to every company or project developing software.

via Unix Digest - Articles October 20, 2026

GPG Update 2026

A recent toot of mine got the response “friends don’t let friends use GPG” which, I suppose, is true enough. It certainly isn’t the attestation-friendly thing to use, and the opsec failures that are so easy with GPG-encrypted mail make it a hazard there. …

via [bobulate] February 3, 2026

Generated by openring