mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-16 01:41:55 +00:00
allow to build with helps of cmake
This commit is contained in:
14
cmake/FindGettextTools/config.cmake.in
Normal file
14
cmake/FindGettextTools/config.cmake.in
Normal file
@@ -0,0 +1,14 @@
|
||||
# This file is automatically generated by GettextTools.
|
||||
# It WILL be overwritten by CMake, so editing it is futile. Sorry!
|
||||
|
||||
set(hierarchy "${_parsedArguments_HIERARCHY}")
|
||||
set(keywords "${_parsedArguments_KEYWORDS}")
|
||||
set(domain "${_parsedArguments_DOMAIN}")
|
||||
set(sourcePrefix "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(stockDir "${_parsedArguments_STOCK_DIR}")
|
||||
set(langDir "${_parsedArguments_LANG_DIR}")
|
||||
set(outDir "${_parsedArguments_OUT_DIR}")
|
||||
set(XGETTEXT_EXECUTABLE "${GETTEXT_XGETTEXT_EXECUTABLE}")
|
||||
set(MSGMERGE_EXECUTABLE "${GETTEXT_MSGMERGE_EXECUTABLE}")
|
||||
set(MSGFMT_EXECUTABLE "${GETTEXT_MSGFMT_EXECUTABLE}")
|
||||
set(sourceFiles "${_parsedArguments_SOURCE}")
|
||||
103
cmake/FindGettextTools/script.cmake
Normal file
103
cmake/FindGettextTools/script.cmake
Normal file
@@ -0,0 +1,103 @@
|
||||
# ----- Set up variables.
|
||||
|
||||
# Read variables from the generated config.
|
||||
include(${CMAKE_ARGV3})
|
||||
|
||||
# Transform keywords in to flags.
|
||||
set(keywordArgs "")
|
||||
foreach(keyword ${keywords})
|
||||
list(APPEND keywordArgs "--keyword=${keyword}")
|
||||
endforeach()
|
||||
|
||||
# ----- Make the pot file.
|
||||
|
||||
message("Creating translation template...")
|
||||
|
||||
file(MAKE_DIRECTORY ${langDir})
|
||||
|
||||
set(potFile "${langDir}/${domain}.pot")
|
||||
|
||||
execute_process(COMMAND ${XGETTEXT_EXECUTABLE}
|
||||
"--output=${potFile}"
|
||||
"--omit-header" "--add-comments"
|
||||
${keywordArgs}
|
||||
${sourceFiles}
|
||||
WORKING_DIRECTORY ${sourcePrefix})
|
||||
|
||||
message(" '${domain}.pot' done.")
|
||||
|
||||
# ----- Copy and merge across the po files that come with the source.
|
||||
|
||||
message("Copying and updating stock translations...")
|
||||
|
||||
file(GLOB poFiles "${stockDir}/*.po")
|
||||
|
||||
foreach(file ${poFiles})
|
||||
# Get the language name, like en_US or zh_CN from the name of the po file, so
|
||||
# 'en_US.po' or 'zh_CN.po' become 'en_US' or 'zh_CN.po'
|
||||
get_filename_component(langName ${file} NAME_WE)
|
||||
|
||||
set(newFile "${langDir}/${langName}.po")
|
||||
|
||||
if(NOT EXISTS ${newFile})
|
||||
execute_process(COMMAND ${MSGMERGE_EXECUTABLE}
|
||||
"--output-file" ${newFile} ${file} ${potFile}
|
||||
OUTPUT_QUIET ERROR_VARIABLE error RESULT_VARIABLE ret)
|
||||
|
||||
if(ret) # Have to do this hack as msgmerge prints to stderr.
|
||||
message(SEND_ERROR "${error}")
|
||||
endif()
|
||||
|
||||
message(" '${langName}' copied.")
|
||||
elseif(${file} IS_NEWER_THAN ${newFile})
|
||||
execute_process(COMMAND ${MSGMERGE_EXECUTABLE}
|
||||
"--update" ${newFile} ${file}
|
||||
OUTPUT_QUIET ERROR_VARIABLE error RESULT_VARIABLE ret)
|
||||
|
||||
if(ret) # Have to do this hack as msgmerge prints to stderr.
|
||||
message(SEND_ERROR "${error}")
|
||||
endif()
|
||||
|
||||
message(" '${langName}' merged.")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# ----- Process the files in to mo files.
|
||||
|
||||
message("Compiling translations...")
|
||||
|
||||
file(GLOB localPoFiles "${langDir}/*.po")
|
||||
|
||||
foreach(file ${localPoFiles})
|
||||
execute_process(COMMAND ${MSGMERGE_EXECUTABLE}
|
||||
"--update" ${file} ${potFile}
|
||||
OUTPUT_QUIET ERROR_VARIABLE error RESULT_VARIABLE ret)
|
||||
|
||||
if(ret) # Have to do this hack as msgmerge prints to stderr.
|
||||
message(SEND_ERROR "${error}")
|
||||
endif()
|
||||
|
||||
get_filename_component(langName ${file} NAME_WE)
|
||||
|
||||
set(binaryFile "${hierarchy}")
|
||||
string(REPLACE "{1}" "${outDir}" binaryFile "${binaryFile}")
|
||||
string(REPLACE "{2}" "${langName}" binaryFile "${binaryFile}")
|
||||
string(REPLACE "{3}" "LC_MESSAGES" binaryFile "${binaryFile}")
|
||||
string(REPLACE "{4}" "${domain}" binaryFile "${binaryFile}")
|
||||
|
||||
if(${file} IS_NEWER_THAN ${binaryFile})
|
||||
get_filename_component(binaryDir ${binaryFile} PATH)
|
||||
|
||||
file(MAKE_DIRECTORY ${binaryDir})
|
||||
|
||||
execute_process(COMMAND ${MSGFMT_EXECUTABLE}
|
||||
${file} "--output-file" ${binaryFile}
|
||||
OUTPUT_QUIET ERROR_VARIABLE error RESULT_VARIABLE ret)
|
||||
|
||||
if(ret) # Have to do this hack as msgfmt prints to stderr.
|
||||
message(SEND_ERROR "${error}")
|
||||
endif()
|
||||
|
||||
message(" '${langName}' done.")
|
||||
endif()
|
||||
endforeach()
|
||||
Reference in New Issue
Block a user