aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-04-07 11:09:47 +0200
committerfiaxh <git@mx.ax.lt>2017-04-10 15:47:21 +0200
commit9bc83539d124f9645dc92e9e39001cb0192dae61 (patch)
treea4b22a8ea3e10b6d0050c2e5669729919a1cb477 /cmake
parentd8881c4b16a1cd376dd69304c44444aee581da32 (diff)
downloaddino-9bc83539d124f9645dc92e9e39001cb0192dae61.tar.gz
dino-9bc83539d124f9645dc92e9e39001cb0192dae61.zip
Gettext support
Diffstat (limited to 'cmake')
-rw-r--r--cmake/FindGettext.cmake18
-rw-r--r--cmake/UseGettext.cmake28
2 files changed, 46 insertions, 0 deletions
diff --git a/cmake/FindGettext.cmake b/cmake/FindGettext.cmake
new file mode 100644
index 00000000..7d2d260c
--- /dev/null
+++ b/cmake/FindGettext.cmake
@@ -0,0 +1,18 @@
+find_program(XGETTEXT_EXECUTABLE xgettext)
+find_program(MSGMERGE_EXECUTABLE msgmerge)
+find_program(MSGFMT_EXECUTABLE msgfmt)
+find_program(MSGCAT_EXECUTABLE msgcat)
+
+if(XGETTEXT_EXECUTABLE)
+ execute_process(COMMAND ${XGETTEXT_EXECUTABLE} "--version"
+ OUTPUT_VARIABLE GETTEXT_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REGEX REPLACE "xgettext \\(GNU gettext-tools\\) ([0-9\\.]*).*" "\\1" GETTEXT_VERSION "${GETTEXT_VERSION}")
+endif(XGETTEXT_EXECUTABLE)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Gettext
+ REQUIRED_VARS XGETTEXT_EXECUTABLE MSGMERGE_EXECUTABLE MSGFMT_EXECUTABLE MSGCAT_EXECUTABLE
+ VERSION_VAR GETTEXT_VERSION)
+
+set(GETTEXT_USE_FILE "${CMAKE_CURRENT_LIST_DIR}/UseGettext.cmake") \ No newline at end of file
diff --git a/cmake/UseGettext.cmake b/cmake/UseGettext.cmake
new file mode 100644
index 00000000..3abf418e
--- /dev/null
+++ b/cmake/UseGettext.cmake
@@ -0,0 +1,28 @@
+function(_gettext_mkdir_for_file file)
+ get_filename_component(dir "${file}" DIRECTORY)
+ file(MAKE_DIRECTORY "${dir}")
+endfunction()
+
+function(gettext_compile project_name)
+ cmake_parse_arguments(ARGS "" "MO_FILES_NAME;TARGET_NAME;SOURCE_DIR;PROJECT_NAME" "" ${ARGN})
+
+ if(NOT ARGS_SOURCE_DIR)
+ set(ARGS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+ endif(NOT ARGS_SOURCE_DIR)
+ file(STRINGS "${ARGS_SOURCE_DIR}/LINGUAS" LINGUAS)
+ set(target_files)
+ foreach(lang ${LINGUAS})
+ set(source_file ${ARGS_SOURCE_DIR}/${lang}.po)
+ set(target_file ${CMAKE_BINARY_DIR}/locale/${lang}/LC_MESSAGES/${project_name}.mo)
+ _gettext_mkdir_for_file(${target_file})
+ list(APPEND target_files ${target_file})
+ add_custom_command(OUTPUT ${target_file} COMMAND ${MSGFMT_EXECUTABLE} -o ${target_file} ${source_file} DEPENDS ${source_file})
+ install(FILES ${target_file} DESTINATION ${LOCALE_INSTALL_DIR}/${lang}/LC_MESSAGES)
+ endforeach(lang)
+ if(ARGS_MO_FILES_NAME)
+ set(${ARGS_MO_FILES_NAME} ${target_files} PARENT_SCOPE)
+ endif(ARGS_MO_FILES_NAME)
+ if(ARGS_TARGET_NAME)
+ add_custom_target(${ARGS_TARGET_NAME} DEPENDS ${target_files})
+ endif(ARGS_TARGET_NAME)
+endfunction(gettext_compile) \ No newline at end of file