2010-12-27 16:51:45 +00:00
|
|
|
# This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2020-07-30 19:33:41 +00:00
|
|
|
# Copyright (C) 2010-2020 Kicad Developers, see AUTHORS.txt for contributors.
|
2010-12-27 16:51:45 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, you may find one here:
|
|
|
|
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
# or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
# or you may write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
|
2013-05-31 21:22:34 +00:00
|
|
|
|
2024-01-05 04:32:06 +00:00
|
|
|
# make_lexer_export
|
|
|
|
# This function performs the same job as make_lexer but with two additional parameters to specify
|
|
|
|
# the export macro
|
|
|
|
function( make_lexer_export outputTarget inputFile outHeaderFile outCppFile enum exportMacro exportMacroInclude )
|
2010-12-27 16:51:45 +00:00
|
|
|
add_custom_command(
|
2019-07-03 09:08:55 +00:00
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${outHeaderFile}
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${outCppFile}
|
2010-12-27 16:51:45 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND}
|
|
|
|
-Denum=${enum}
|
2019-07-03 09:08:55 +00:00
|
|
|
-DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/${inputFile}
|
|
|
|
-DoutHeaderFile=${CMAKE_CURRENT_BINARY_DIR}/${outHeaderFile}
|
|
|
|
-DoutCppFile=${CMAKE_CURRENT_BINARY_DIR}/${outCppFile}
|
2024-01-05 04:32:06 +00:00
|
|
|
-DexportMacro=${exportMacro}
|
|
|
|
-DexportMacroInclude=${exportMacroInclude}
|
2023-01-04 00:12:56 +00:00
|
|
|
-P ${KICAD_CMAKE_MODULE_PATH}/BuildSteps/TokenList2DsnLexer.cmake
|
2010-12-27 16:51:45 +00:00
|
|
|
COMMENT "TokenList2DsnLexer.cmake creating:
|
|
|
|
${outHeaderFile} and
|
|
|
|
${outCppFile} from
|
|
|
|
${inputFile}"
|
2019-07-03 09:08:55 +00:00
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${inputFile}
|
2023-01-04 00:12:56 +00:00
|
|
|
${KICAD_CMAKE_MODULE_PATH}/BuildSteps/TokenList2DsnLexer.cmake
|
2019-06-05 05:09:54 +00:00
|
|
|
)
|
2013-05-31 21:22:34 +00:00
|
|
|
|
2019-07-03 09:08:55 +00:00
|
|
|
target_sources( ${outputTarget} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/${outCppFile} )
|
|
|
|
target_include_directories( ${outputTarget} PUBLIC ${CMAKE_CURRENT_BINARY_DIR} )
|
2010-12-27 16:51:45 +00:00
|
|
|
endfunction()
|
|
|
|
|
2013-10-17 19:03:36 +00:00
|
|
|
|
2024-01-05 04:32:06 +00:00
|
|
|
# Function make_lexer
|
|
|
|
# is a standard way to invoke TokenList2DsnLexer.cmake.
|
|
|
|
# Extra arguments are treated as source files which depend on the generated
|
|
|
|
# files. Some detail here on the indirection:
|
|
|
|
# - Parallel builds all depend on the same files, and CMake will generate the same file multiple times in the same location.
|
|
|
|
# This can be problematic if the files are generated at the same time and overwrite each other.
|
|
|
|
# - To fix this, we create a custom target (outputTarget) that the parallel builds depend on.
|
|
|
|
# AND build dependencies. This creates the needed rebuild for appropriate source object changes.
|
|
|
|
function( make_lexer outputTarget inputFile outHeaderFile outCppFile enum )
|
|
|
|
make_lexer_export( ${outputTarget} ${inputFile} ${outHeaderFile} ${outCppFile} ${enum} "" "" )
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
2020-07-30 19:33:41 +00:00
|
|
|
# Function generate_lemon_grammar
|
|
|
|
#
|
|
|
|
# This is a function to create a custom command to generate a parser grammar using lemon.
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# - TGT is the target to add the consuming file to
|
|
|
|
# - GRAMMAR_DIR is the path relative to CMAKE_CURRENT_BINARY_DIR for the directory where the files will be generated into
|
|
|
|
# - CONSUMING_FILE is the file relative to CMAKE_CURRENT_SOURCE_DIR that will include the grammar.c/h file
|
|
|
|
# - GRAMMAR_FILE is the file relative to CMAKE_CURRENT_SOURCE_DIR of the grammar file to use.
|
|
|
|
function( generate_lemon_grammar TGT GRAMMAR_DIR CONSUMING_FILE GRAMMAR_FILE )
|
|
|
|
# Get the name without extension
|
|
|
|
get_filename_component( GRAMMAR_BASE ${GRAMMAR_FILE} NAME_WE )
|
|
|
|
|
|
|
|
file( MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${GRAMMAR_DIR} )
|
|
|
|
|
2023-04-11 00:27:33 +00:00
|
|
|
set( LEMON_EXE $<TARGET_FILE:lemon> CACHE FILEPATH "Path to Lemon Executable" )
|
2020-07-30 19:33:41 +00:00
|
|
|
|
|
|
|
get_property( LEMON_TEMPLATE
|
|
|
|
TARGET lemon
|
|
|
|
PROPERTY lemon_template
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${GRAMMAR_DIR}/${GRAMMAR_BASE}.c
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${GRAMMAR_DIR}/${GRAMMAR_BASE}.h
|
|
|
|
COMMAND ${CMAKE_COMMAND}
|
|
|
|
-DLEMON_EXE=${LEMON_EXE}
|
|
|
|
-DLEMON_TEMPLATE=${LEMON_TEMPLATE}
|
|
|
|
-DGRAMMAR_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${GRAMMAR_FILE}
|
|
|
|
-DGRAMMAR_DIR=${CMAKE_CURRENT_BINARY_DIR}/${GRAMMAR_DIR}
|
2023-01-04 00:12:56 +00:00
|
|
|
-P ${KICAD_CMAKE_MODULE_PATH}/BuildSteps/LemonParserGenerator.cmake
|
2020-07-30 19:33:41 +00:00
|
|
|
COMMENT "Running Lemon on ${GRAMMAR_FILE} to generate ${GRAMMAR_DIR}/${GRAMMAR_BASE}.c"
|
|
|
|
DEPENDS lemon
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/${GRAMMAR_FILE}
|
2023-01-04 00:12:56 +00:00
|
|
|
${KICAD_CMAKE_MODULE_PATH}/BuildSteps/LemonParserGenerator.cmake
|
2020-07-30 19:33:41 +00:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${GRAMMAR_DIR}
|
|
|
|
)
|
|
|
|
|
2022-08-19 00:48:14 +00:00
|
|
|
if(MSVC)
|
|
|
|
# lemon has a habit of generating empty switch cases which we can ignore
|
|
|
|
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/${CONSUMING_FILE} PROPERTIES COMPILE_FLAGS /wd4065)
|
|
|
|
endif()
|
|
|
|
|
2020-07-30 19:33:41 +00:00
|
|
|
# Mark the consuming file with a direct dependency on the generated grammar so that
|
|
|
|
# it isn't compiled until the grammar is generated
|
|
|
|
set_source_files_properties(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/${CONSUMING_FILE}
|
|
|
|
PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${GRAMMAR_DIR}/${GRAMMAR_BASE}.c
|
|
|
|
)
|
|
|
|
|
|
|
|
target_sources( ${TGT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${CONSUMING_FILE} )
|
|
|
|
target_include_directories( ${TGT} PUBLIC ${CMAKE_CURRENT_BINARY_DIR} )
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
2020-12-03 23:56:26 +00:00
|
|
|
# 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}
|
2021-01-27 21:07:23 +00:00
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/pofiles/${LANG}.po
|
2020-12-03 23:56:26 +00:00
|
|
|
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE}
|
2021-01-16 18:08:19 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/pofiles/${LANG}.po
|
2020-12-03 23:56:26 +00:00
|
|
|
-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()
|
2021-01-16 18:09:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Function linux_metadata_translation
|
|
|
|
#
|
|
|
|
# This is a macro to handle the translation of the linux metadata files using
|
|
|
|
# the existing .po files.
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# - SRC_FILE is the file to use as the translation source
|
|
|
|
# - OUT_FILE is the file (including directory) to save the translations to
|
|
|
|
# - PO_DIR is the directory containing the raw po files
|
|
|
|
macro( linux_metadata_translation SRC_FILE OUT_FILE PO_DIR )
|
|
|
|
get_filename_component( OUT_DIR ${OUT_FILE} DIRECTORY )
|
|
|
|
get_filename_component( OUT_FNAME ${OUT_FILE} NAME )
|
|
|
|
|
|
|
|
file( MAKE_DIRECTORY ${OUT_DIR} )
|
|
|
|
|
2021-01-27 21:07:23 +00:00
|
|
|
|
|
|
|
# Find all the po files to setup the dependency chain
|
|
|
|
file( STRINGS ${PO_DIR}/LINGUAS LANG_ARRAY REGEX "^[^#].*" )
|
|
|
|
|
|
|
|
set( LANG_FILES "" )
|
|
|
|
|
|
|
|
foreach( LANG ${LANG_ARRAY} )
|
|
|
|
# Keep a list of the language files that are created to add to the target
|
|
|
|
list( APPEND LANG_FILES "${PO_DIR}/${LANG}.po" )
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
2021-01-16 18:09:59 +00:00
|
|
|
# Add the command to translate the file
|
|
|
|
if( KICAD_BUILD_I18N )
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${OUT_FILE}
|
2021-01-28 00:19:09 +00:00
|
|
|
DEPENDS ${SRC_FILE}
|
|
|
|
${LANG_FILES}
|
2023-01-04 00:12:56 +00:00
|
|
|
${KICAD_CMAKE_MODULE_PATH}/BuildSteps/TranslatePlatformMetadata_linux.cmake
|
2021-01-28 00:19:09 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND}
|
|
|
|
-DMSGFMT_EXE="${GETTEXT_MSGFMT_EXECUTABLE}"
|
|
|
|
-DPO_DIR="${PO_DIR}"
|
|
|
|
-DSRC_FILE="${SRC_FILE}"
|
|
|
|
-DDEST_FILE="${OUT_FILE}"
|
2023-01-04 00:12:56 +00:00
|
|
|
-P ${KICAD_CMAKE_MODULE_PATH}/BuildSteps/TranslatePlatformMetadata_linux.cmake
|
2021-01-16 19:15:12 +00:00
|
|
|
COMMENT "Translating file ${OUT_FNAME}"
|
2021-01-16 18:09:59 +00:00
|
|
|
)
|
|
|
|
else()
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${OUT_FILE}
|
|
|
|
DEPENDS ${SRC_FILE}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SRC_FILE}" "${OUT_FILE}"
|
2021-01-16 19:15:12 +00:00
|
|
|
COMMENT "Copying file ${OUT_FNAME}"
|
2021-01-16 18:09:59 +00:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endmacro()
|