ParaViewTranslations.cmake
Go to the documentation of this file.
1 set(_ParaViewTranslations_cmake_dir "${CMAKE_CURRENT_LIST_DIR}")
2 
3 #[==[
4 @brief Generate a C++ header with input XML labels and UI strings that can be parsed by
5 Qt Linguist tools. It is using a python utility at
6 Utilities/Localization/XML_translations_header_generator.py
7 
8 ~~~
10  TARGET <name>
11  INPUT_FILES <file>...
12  RESULT_FILE <file>)
13 ~~~
14 
15  * `TARGET`: (Required) The name of the target that generate the translation
16  header file.
17  * `INPUT_FILES`: (Required) The absolute path of the input files.
18  * `RESULT_FILE`: (Required) The absolute path of the desired result file.
19 #]==]
21  cmake_parse_arguments(PARSE_ARGV 0 _pv_generate_tr_h
22  ""
23  "TARGET;RESULT_FILE"
24  "INPUT_FILES")
25  if (_pv_generate_tr_h_UNPARSED_ARGUMENTS)
26  message(FATAL_ERROR
27  "Unrecognized arguments for paraview_generate_translation_header: "
28  "${_pv_generate_tr_h_UNPARSED_ARGUMENTS}.")
29  endif ()
30  if (NOT DEFINED _pv_generate_tr_h_RESULT_FILE)
31  message(FATAL_ERROR
32  "The `RESULT_FILE` argument is required.")
33  endif ()
34  if (NOT DEFINED _pv_generate_tr_h_INPUT_FILES)
35  message(FATAL_ERROR
36  "The `INPUT_FILES` argument is required.")
37  endif ()
38  if (NOT DEFINED _pv_generate_tr_h_TARGET)
39  message(FATAL_ERROR
40  "The `TARGET` argument is required.")
41  endif ()
42  find_package(Python3 QUIET REQUIRED COMPONENTS Interpreter)
43  add_custom_command(OUTPUT ${_pv_generate_tr_h_RESULT_FILE}
44  COMMAND "$<TARGET_FILE:Python3::Interpreter>" "${_ParaViewTranslations_cmake_dir}/XML_translations_header_generator.py" -o "${_pv_generate_tr_h_RESULT_FILE}" ${_pv_generate_tr_h_INPUT_FILES} -s "${CMAKE_SOURCE_DIR}/")
45  add_custom_target("${_pv_generate_tr_h_TARGET}"
46  DEPENDS "${_pv_generate_tr_h_RESULT_FILE}")
47 endfunction()
48 
49 #[==[
50 @brief Generate a Qt translation source file from the given source files
51 
52 ~~~
54  TARGET <name>
55  INPUT_FILES <files...>
56  OUTPUT_TS <file>
57 ~~~
58 
59  * `TARGET`: (Required) The name of the target that generate the translation
60  source file.
61  * `INPUT_FILES`: (Required) The source files to search translatable strings in.
62  * `OUTPUT_TS`: (Required) The absolute path of the desired result file.
63 #]==]
65  cmake_parse_arguments(PARSE_ARGV 0 _pv_create_tr
66  ""
67  "TARGET;OUTPUT_TS"
68  "FILES")
69  if (_pv_create_tr_UNPARSED_ARGUMENTS)
70  message(FATAL_ERROR
71  "Unrecognized arguments for paraview_create_translation: "
72  "${_pv_create_tr_UNPARSED_ARGUMENTS}.")
73  endif ()
74  if (NOT DEFINED _pv_create_tr_TARGET)
75  message(FATAL_ERROR
76  "The `TARGET` argument is required.")
77  endif ()
78  if (NOT DEFINED _pv_create_tr_FILES)
79  message(FATAL_ERROR
80  "The `FILES` argument is required.")
81  endif ()
82  if (NOT DEFINED _pv_create_tr_OUTPUT_TS)
83  message(FATAL_ERROR
84  "The `OUTPUT_TS` argument is required.")
85  endif ()
86 
87  # Transforms all relative paths in the provided
88  # FILES by their absolute paths.
89  set(_pv_create_tr_files)
90  foreach (_pv_create_tr_in_file IN LISTS _pv_create_tr_FILES)
91  if (NOT IS_ABSOLUTE "${_pv_create_tr_in_file}")
92  string(PREPEND _pv_create_tr_in_file
93  "${CMAKE_CURRENT_SOURCE_DIR}/")
94  endif ()
95  list(APPEND _pv_create_tr_files ${_pv_create_tr_in_file})
96  endforeach ()
97  find_package("Qt${PARAVIEW_QT_MAJOR_VERSION}" REQUIRED QUIET COMPONENTS LinguistTools)
98  get_filename_component(_pv_create_tr_directory ${_pv_create_tr_OUTPUT_TS} DIRECTORY)
99  file(MAKE_DIRECTORY "${_pv_create_tr_directory}")
100  # List of files is stored in a .pro file because the command can reach the Windows limit of character
101  set(_pv_create_tr_pro_file "${CMAKE_CURRENT_BINARY_DIR}/${_pv_create_tr_TARGET}.pro")
102  string(REPLACE ";" " \\\n" _translations_files_list "${_pv_create_tr_files}")
103  configure_file(
104  "${CMAKE_SOURCE_DIR}/CMake/paraview_translation_files_list.pro.in"
105  "${_pv_create_tr_pro_file}")
106  add_custom_command(
107  OUTPUT "${_pv_create_tr_OUTPUT_TS}"
108  COMMAND "$<TARGET_FILE:Qt${PARAVIEW_QT_MAJOR_VERSION}::lupdate>" ${_pv_create_tr_pro_file}
109  DEPENDS ${_pv_create_tr_files})
110  add_custom_target("${_pv_create_tr_TARGET}"
111  DEPENDS "${_pv_create_tr_OUTPUT_TS}")
112 endfunction()
source
source
paraview_generate_translation_header
function paraview_generate_translation_header()
Generate a C++ header with input XML labels and UI strings that can be parsed by Qt Linguist tools.
Definition: ParaViewTranslations.cmake:20
paraview_create_translation
function paraview_create_translation()
Generate a Qt translation source file from the given source files.
Definition: ParaViewTranslations.cmake:64
translation
translation