From 068d8616fa7398c03972da547affe2115b4b26ab Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Thu, 27 May 2021 16:03:28 +0200 Subject: ecm_gperf_generate(): add option for target arg to add the gen. source to --- find-modules/FindGperf.cmake | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'find-modules/FindGperf.cmake') diff --git a/find-modules/FindGperf.cmake b/find-modules/FindGperf.cmake index 78dacb4b..4eb00e70 100644 --- a/find-modules/FindGperf.cmake +++ b/find-modules/FindGperf.cmake @@ -29,14 +29,16 @@ target: and the following public function: :: - ecm_gperf_generate( + ecm_gperf_generate( [GENERATION_FLAGS ]) Run ``gperf`` on ```` to generate ````, adding it to the ```` variable which contains the source for the target -where ```` is going to be built. The optional -``GENERATION_FLAGS`` argument is needed to pass extra parameters to -``gperf`` (note you cannot override that way the output file). +where ```` is going to be built or, since KF 5.83, if the given +argument is a target, to the list of private sources of that target. The +target must not be an alias. The optional ``GENERATION_FLAGS`` argument is +needed to pass extra parameters to ``gperf`` (note you cannot override that +way the output file). A simple invocation would be: @@ -82,7 +84,7 @@ set_package_properties(Gperf PROPERTIES include(CMakeParseArguments) -function(ecm_gperf_generate input_file output_file out_var) +function(ecm_gperf_generate input_file output_file _target_or_sources_var) # Parse arguments set(oneValueArgs GENERATION_FLAGS) cmake_parse_arguments(ARGS "" "${oneValueArgs}" "" ${ARGN}) @@ -90,6 +92,12 @@ function(ecm_gperf_generate input_file output_file out_var) if(ARGS_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Unknown keywords given to ecm_gperf_generate(): \"${ARGS_UNPARSED_ARGUMENTS}\"") endif() + if (TARGET ${_target_or_sources_var}) + get_target_property(aliased_target ${_target_or_sources_var} ALIASED_TARGET) + if(aliased_target) + message(FATAL_ERROR "Target argument passed to ecm_gperf_generate must not be an alias: ${_target_or_sources_var}") + endif() + endif() get_filename_component(_infile ${input_file} ABSOLUTE) set(_extraopts "${ARGS_GENERATION_FLAGS}") @@ -102,6 +110,9 @@ function(ecm_gperf_generate input_file output_file out_var) ) set_property(SOURCE ${output_file} PROPERTY SKIP_AUTOMOC ON) - list(APPEND ${out_var} "${output_file}") - set(${out_var} ${${out_var}} PARENT_SCOPE) + if (TARGET ${_target_or_sources_var}) + target_sources(${_target_or_sources_var} PRIVATE ${output_file}) + else() + set(${_target_or_sources_var} ${${_target_or_sources_var}} ${output_file} PARENT_SCOPE) + endif() endfunction() -- cgit v1.2.1