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(
44  OUTPUT "${_pv_generate_tr_h_RESULT_FILE}"
45  DEPENDS ${_pv_generate_tr_h_INPUT_FILES}
46  COMMAND "$<TARGET_FILE:Python3::Interpreter>"
47  "${_ParaViewTranslations_cmake_dir}/XML_translations_header_generator.py"
48  -o "${_pv_generate_tr_h_RESULT_FILE}"
49  ${_pv_generate_tr_h_INPUT_FILES}
50  -s "${CMAKE_SOURCE_DIR}/")
51  add_custom_target("${_pv_generate_tr_h_TARGET}"
52  DEPENDS "${_pv_generate_tr_h_RESULT_FILE}")
53 endfunction()
54 
55 #[==[
56 @brief Generate a Qt translation source file from the given source files
57 
58 ~~~
59 paraview_create_translation(
60  TARGET <name>
61  INPUT_FILES <files...>
62  OUTPUT_TS <file>
63 ~~~
64 
65  * `TARGET`: (Required) The name of the target that generate the translation
66  source file.
67  * `INPUT_FILES`: (Required) The source files to search translatable strings in.
68  * `OUTPUT_TS`: (Required) The absolute path of the desired result file.
69 #]==]
70 function(paraview_create_translation)
71  cmake_parse_arguments(PARSE_ARGV 0 _pv_create_tr
72  ""
73  "TARGET;OUTPUT_TS"
74  "FILES")
75  if (_pv_create_tr_UNPARSED_ARGUMENTS)
76  message(FATAL_ERROR
77  "Unrecognized arguments for paraview_create_translation: "
78  "${_pv_create_tr_UNPARSED_ARGUMENTS}.")
79  endif ()
80  if (NOT DEFINED _pv_create_tr_TARGET)
81  message(FATAL_ERROR
82  "The `TARGET` argument is required.")
83  endif ()
84  if (NOT DEFINED _pv_create_tr_FILES)
85  message(FATAL_ERROR
86  "The `FILES` argument is required.")
87  endif ()
88  if (NOT DEFINED _pv_create_tr_OUTPUT_TS)
89  message(FATAL_ERROR
90  "The `OUTPUT_TS` argument is required.")
91  endif ()
92 
93  # Transforms all relative paths in the provided
94  # FILES by their absolute paths.
95  set(_pv_create_tr_files)
96  foreach (_pv_create_tr_in_file IN LISTS _pv_create_tr_FILES)
97  if (NOT IS_ABSOLUTE "${_pv_create_tr_in_file}")
98  string(PREPEND _pv_create_tr_in_file
99  "${CMAKE_CURRENT_SOURCE_DIR}/")
100  endif ()
101  list(APPEND _pv_create_tr_files ${_pv_create_tr_in_file})
102  endforeach ()
103  find_package("Qt${PARAVIEW_QT_MAJOR_VERSION}" REQUIRED QUIET COMPONENTS LinguistTools)
104  get_filename_component(_pv_create_tr_directory ${_pv_create_tr_OUTPUT_TS} DIRECTORY)
105  file(MAKE_DIRECTORY "${_pv_create_tr_directory}")
106  # List of files is stored in a .pro file because the command can reach the Windows limit of character
107  set(_pv_create_tr_pro_file "${CMAKE_CURRENT_BINARY_DIR}/${_pv_create_tr_TARGET}.pro")
108  string(REPLACE ";" " \\\n" _translations_files_list "${_pv_create_tr_files}")
109  configure_file(
110  "${CMAKE_SOURCE_DIR}/CMake/paraview_translation_files_list.pro.in"
111  "${_pv_create_tr_pro_file}")
112  add_custom_command(
113  OUTPUT "${_pv_create_tr_OUTPUT_TS}"
114  COMMAND "$<TARGET_FILE:Qt${PARAVIEW_QT_MAJOR_VERSION}::lupdate>"
115  "${_pv_create_tr_pro_file}"
116  DEPENDS ${_pv_create_tr_files}
117  "${_pv_create_tr_pro_file}")
118  add_custom_target("${_pv_create_tr_TARGET}"
119  DEPENDS "${_pv_create_tr_OUTPUT_TS}")
120 endfunction()
function paraview_create_translation()
Generate a Qt translation source file from the given source files.
function paraview_generate_translation_header()
Generate a C++ header with input XML labels and UI strings that can be parsed by Qt Linguist tools...