diff options
author | Friedrich W. H. Kossebau <kossebau@kde.org> | 2021-05-17 10:54:41 +0200 |
---|---|---|
committer | Friedrich W. H. Kossebau <kossebau@kde.org> | 2021-05-21 13:37:14 +0000 |
commit | f7b1cf93e67e3eba07597bf7891b854bd8c954ba (patch) | |
tree | 47386186f26553aee31a1472eb1a25b6a365063f /modules | |
parent | 9d22f7b72412c7ccdd843de6e41028fe903f570a (diff) | |
download | extra-cmake-modules-f7b1cf93e67e3eba07597bf7891b854bd8c954ba.tar.gz extra-cmake-modules-f7b1cf93e67e3eba07597bf7891b854bd8c954ba.tar.bz2 |
ecm_create_qm_loader: support target as alternative argument
Diffstat (limited to 'modules')
-rw-r--r-- | modules/ECMPoQmTools.cmake | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/modules/ECMPoQmTools.cmake b/modules/ECMPoQmTools.cmake index d1f90b6b..86480b71 100644 --- a/modules/ECMPoQmTools.cmake +++ b/modules/ECMPoQmTools.cmake @@ -32,10 +32,13 @@ added to the "all" target (and so the .qm files will be built by default). :: - ecm_create_qm_loader(<source_files_var> <catalog_name>) + ecm_create_qm_loader(<sources_var_name(|target (since 5.83))> <catalog_name>) Generates C++ code which ensures translations are automatically loaded at -startup. The generated files are appended to ``<source_files_var>``. +startup. The generated files are appended to the variable named +``<sources_var_name>`` or, if the first argument is a target (since 5.83), to +the SOURCES property of ``<target>``. Any target must be created with +add_executable() or add_library() and not be an alias. It assumes that the .qm file for the language code ``<lang>`` is installed as ``<sharedir>/locale/<lang>/LC_MESSAGES/<catalog_name>.qm``, where @@ -47,9 +50,13 @@ Typical usage is like: .. code-block:: cmake set(mylib_SRCS foo.cpp bar.cpp) - ecm_create_qm_loader(mylib_SRCS mylib) + ecm_create_qm_loader(mylib_SRCS mycatalog) add_library(mylib ${mylib_SRCS}) + # Or, since 5.83: + add_library(mylib foo.cpp bar.cpp) + ecm_create_qm_loader(mylib mycatalog) + :: ecm_install_po_files_as_qm(<podir>) @@ -90,17 +97,33 @@ function(_ecm_qm_get_unique_target_name _name _unique_name) endfunction() -function(ecm_create_qm_loader out_var catalog_name) +function(ecm_create_qm_loader sourcesvar_or_target catalog_name) + if (TARGET ${sourcesvar_or_target}) + get_target_property(target_type ${sourcesvar_or_target} TYPE) + set(allowed_types "EXECUTABLE" "STATIC_LIBRARY" "MODULE_LIBRARY" "SHARED_LIBRARY" "OBJECT_LIBRARY" "INTERFACE_LIBRARY") + if (NOT target_type IN_LIST allowed_types) + message(FATAL_ERROR "Target argument passed to ecm_create_qm_loader is not an executable or a library: ${appsources_or_target}") + endif() + get_target_property(aliased_target ${sourcesvar_or_target} ALIASED_TARGET) + if(aliased_target) + message(FATAL_ERROR "Target argument passed to ecm_create_qm_loader must not be an alias: ${sourcesvar_or_target}") + endif() + endif() set(loader_base ${CMAKE_CURRENT_BINARY_DIR}/ECMQmLoader-${catalog_name}) set(QM_LOADER_CATALOG_NAME "${catalog_name}") + set(QM_LOADER_CPP_FILE "${loader_base}.cpp") configure_file( ${ECM_MODULE_DIR}/ECMQmLoader.cpp.in - "${loader_base}.cpp" + ${QM_LOADER_CPP_FILE} @ONLY ) - set(${out_var} "${${out_var}}" "${loader_base}.cpp" PARENT_SCOPE) + if (TARGET ${sourcesvar_or_target}) + target_sources(${sourcesvar_or_target} PRIVATE ${QM_LOADER_CPP_FILE}) + else() + set(${sourcesvar_or_target} "${${sourcesvar_or_target}}" ${QM_LOADER_CPP_FILE} PARENT_SCOPE) + endif() endfunction() |