Integrate the i18n CMake into the main CMake

This adds a new target i18n that will compile all the translation
files.
This commit is contained in:
Ian McInerney 2020-12-03 23:56:26 +00:00
parent e89316b0d5
commit e9fa9f68b2
3 changed files with 61 additions and 33 deletions

View File

@ -98,6 +98,14 @@ option( KICAD_SPICE
"Build KiCad with internal Spice simulator."
ON )
option( KICAD_BUILD_I18N
"Buid the translations."
ON )
option( KICAD_I18N_UNIX_STRICT_PATH
"Use standard Unix locale lookup path (default OFF)."
OFF )
# Not supported by all platforms (for instance mingw)
option( KICAD_SANITIZE
"Build KiCad with sanitizer options. WARNING: Not compatible with gold linker"
@ -614,6 +622,10 @@ include( ExternalProject )
#================================================
include( CheckFindPackageResult )
if( KICAD_BUILD_I18N )
find_package( Gettext REQUIRED )
endif()
#
# Find OpenGL library, required
#
@ -1068,7 +1080,13 @@ add_subdirectory( utils )
add_subdirectory( qa )
# Resources
if ( KICAD_INSTALL_DEMOS )
add_subdirectory( demos )
if( KICAD_INSTALL_DEMOS )
add_subdirectory( demos )
endif ( KICAD_INSTALL_DEMOS )
# I18n Translations
if( KICAD_BUILD_I18N )
add_subdirectory( translation )
endif()
add_subdirectory( template )

View File

@ -116,3 +116,36 @@ macro( add_conffiles )
set( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_CURRENT_BINARY_DIR}/conffiles )
endif()
endmacro( add_conffiles )
# Function translate_language
#
# This is a function to add the targets and install step for translating a language
#
# Arguments:
# - LANG is the code for the language (which must be the same as the directory name)
# - OUT_FILE is the file (including directory) to save the translations to
function( translate_language LANG OUT_FILE)
# Make the output directory (if it doesn't already exist)
get_filename_component( OUT_DIR ${OUT_FILE} DIRECTORY )
file( MAKE_DIRECTORY ${OUT_DIR} )
add_custom_command(
OUTPUT ${OUT_FILE}
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/${LANG}/kicad.po
-o ${OUT_FILE}
COMMENT "Building translation library for ${LANG}"
)
if( UNIX AND KICAD_I18N_UNIX_STRICT_PATH )
install( FILES ${OUT_FILE}
DESTINATION ${KICAD_I18N_PATH}/${LANG}/LC_MESSAGES
COMPONENT resources )
else()
install( FILES ${OUT_FILE}
DESTINATION ${KICAD_I18N_PATH}/${LANG}
COMPONENT resources )
endif()
endfunction()

View File

@ -1,21 +1,3 @@
cmake_minimum_required( VERSION 2.8.4 FATAL_ERROR )
if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} )
message( FATAL_ERROR
"In-source builds not allowed. Please make a new directory (called"
" a build directory) and run CMake from there, points here."
" You may need to remove CMakeCache.txt." )
endif()
project( kicad-i18n NONE )
find_package( Gettext REQUIRED )
option( KICAD_I18N_UNIX_STRICT_PATH
"Use standard Unix locale lookup path (default OFF)."
OFF
)
if( UNIX AND KICAD_I18N_UNIX_STRICT_PATH )
set( KICAD_I18N_PATH ${CMAKE_INSTALL_PREFIX}/share/locale
CACHE PATH "Location of KiCad i18n files." )
@ -27,21 +9,16 @@ endif()
file(STRINGS LINGUAS LANG_ARRAY REGEX "^[^#].*")
# Add the commands to translate each language file
foreach( LANG ${LANG_ARRAY} )
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${LANG})
set( OUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${LANG}/kicad.mo" )
execute_process( COMMAND ${GETTEXT_MSGFMT_EXECUTABLE}
${CMAKE_SOURCE_DIR}/${LANG}/kicad.po
-o ${CMAKE_BINARY_DIR}/${LANG}/kicad.mo )
translate_language( ${LANG} ${OUT_FILE} )
if( UNIX AND KICAD_I18N_UNIX_STRICT_PATH )
install( FILES ${CMAKE_BINARY_DIR}/${LANG}/kicad.mo
DESTINATION ${KICAD_I18N_PATH}/${LANG}/LC_MESSAGES
COMPONENT resources )
else()
install( FILES ${CMAKE_BINARY_DIR}/${LANG}/kicad.mo
DESTINATION ${KICAD_I18N_PATH}/${LANG}
COMPONENT resources )
endif()
# Keep a list of the language files that are created to add to the target
list( APPEND LANG_FILES "${OUT_FILE}" )
endforeach()
# Add the target that executes the translation commands
add_custom_target( i18n ALL
DEPENDS ${LANG_FILES} )