Warning, /frameworks/extra-cmake-modules/find-modules/FindGperf.cmake is written in an unsupported language. File is not indexed.

0001 # SPDX-FileCopyrightText: 2016-2017 Pino Toscano <pino@kde.org>
0002 #
0003 # SPDX-License-Identifier: BSD-3-Clause
0004 
0005 #[=======================================================================[.rst:
0006 FindGperf
0007 -----------
0008 
0009 Try to find GNU gperf.
0010 
0011 If the gperf executable is not in your PATH, you can provide
0012 an alternative name or full path location with the ``Gperf_EXECUTABLE``
0013 variable.
0014 
0015 This will define the following variables:
0016 
0017 ``Gperf_FOUND``
0018     True if gperf is available.
0019 
0020 ``Gperf_EXECUTABLE``
0021     The gperf executable.
0022 
0023 ``Gperf_VERSION``
0024     The gperf version. (since 5.85)
0025 
0026 If ``Gperf_FOUND`` is TRUE, it will also define the following imported
0027 target:
0028 
0029 ``GPerf::Gperf``
0030     The gperf executable.
0031 
0032 and the following public function:
0033 ::
0034 
0035   ecm_gperf_generate(<GperfInput> <OutputFile> <OutputVariable(|target (since 5.83))>
0036                      [GENERATION_FLAGS <flags>])
0037 
0038 Run ``gperf`` on ``<GperfInput>`` to generate ``<OutputFile>``, adding it to
0039 the ``<OutputVariable>`` variable which contains the source for the target
0040 where ``<OutputFile>`` is going to be built or, since KF 5.83, if the given
0041 argument is a target, to the list of private sources of that target. The
0042 target must not be an alias. The optional ``GENERATION_FLAGS`` argument is
0043 needed to pass extra parameters to ``gperf`` (note you cannot override that
0044 way the output file).
0045 
0046 A simple invocation would be:
0047 
0048 .. code-block:: cmake
0049 
0050   ecm_gperf_generate(simple.gperf ${CMAKE_CURRENT_BINARY_DIR}/simple.h MySources)
0051 
0052 Since 5.35.0.
0053 #]=======================================================================]
0054 
0055 include(${CMAKE_CURRENT_LIST_DIR}/ECMFindModuleHelpersStub.cmake)
0056 
0057 ecm_find_package_version_check(Gperf)
0058 
0059 # Find gperf
0060 find_program(Gperf_EXECUTABLE NAMES gperf)
0061 
0062 if(Gperf_EXECUTABLE)
0063     execute_process(COMMAND ${Gperf_EXECUTABLE} -v
0064         OUTPUT_VARIABLE _version_string
0065         ERROR_QUIET
0066         OUTPUT_STRIP_TRAILING_WHITESPACE)
0067     if(_version_string MATCHES "^GNU gperf ([-0-9\\.]+)")
0068         set(Gperf_VERSION "${CMAKE_MATCH_1}")
0069     endif()
0070     unset(_version_string)
0071 else()
0072     set(Gperf_VERSION)
0073 endif()
0074 
0075 include(FindPackageHandleStandardArgs)
0076 find_package_handle_standard_args(Gperf
0077     FOUND_VAR
0078         Gperf_FOUND
0079     REQUIRED_VARS
0080         Gperf_EXECUTABLE
0081     VERSION_VAR
0082         Gperf_VERSION
0083 )
0084 
0085 mark_as_advanced(Gperf_EXECUTABLE)
0086 
0087 if (Gperf_FOUND)
0088     if (NOT TARGET GPerf::Gperf)
0089         add_executable(GPerf::Gperf IMPORTED)
0090         set_target_properties(GPerf::Gperf PROPERTIES
0091             IMPORTED_LOCATION "${Gperf_EXECUTABLE}"
0092         )
0093     endif()
0094 endif()
0095 
0096 include(FeatureSummary)
0097 set_package_properties(Gperf PROPERTIES
0098     URL "https://www.gnu.org/software/gperf/"
0099     DESCRIPTION "Perfect hash function generator"
0100 )
0101 
0102 function(ecm_gperf_generate input_file output_file _target_or_sources_var)
0103     # Parse arguments
0104     set(oneValueArgs GENERATION_FLAGS)
0105     cmake_parse_arguments(ARGS "" "${oneValueArgs}" "" ${ARGN})
0106 
0107     if(ARGS_UNPARSED_ARGUMENTS)
0108         message(FATAL_ERROR "Unknown keywords given to ecm_gperf_generate(): \"${ARGS_UNPARSED_ARGUMENTS}\"")
0109     endif()
0110     if (TARGET ${_target_or_sources_var})
0111         get_target_property(aliased_target ${_target_or_sources_var} ALIASED_TARGET)
0112         if(aliased_target)
0113             message(FATAL_ERROR "Target argument passed to ecm_gperf_generate must not be an alias: ${_target_or_sources_var}")
0114         endif()
0115     endif()
0116 
0117     get_filename_component(_infile ${input_file} ABSOLUTE)
0118     set(_extraopts "${ARGS_GENERATION_FLAGS}")
0119     separate_arguments(_extraopts)
0120     add_custom_command(OUTPUT ${output_file}
0121         COMMAND ${Gperf_EXECUTABLE} ${_extraopts} --output-file=${output_file} ${_infile}
0122         DEPENDS ${_infile}
0123         WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
0124         VERBATIM
0125     )
0126     set_property(SOURCE ${output_file} PROPERTY SKIP_AUTOMOC ON)
0127 
0128     if (TARGET ${_target_or_sources_var})
0129         target_sources(${_target_or_sources_var} PRIVATE ${output_file})
0130     else()
0131         set(${_target_or_sources_var} ${${_target_or_sources_var}} ${output_file} PARENT_SCOPE)
0132     endif()
0133 endfunction()