Changeset View
Changeset View
Standalone View
Standalone View
find-modules/FindGperf.cmake
- This file was added.
1 | #.rst: | ||||
---|---|---|---|---|---|
2 | # FindGperf | ||||
3 | # ----------- | ||||
4 | # | ||||
5 | # Try to find GNU gperf. | ||||
6 | # | ||||
7 | # If the gperf executable is not in your PATH, you can provide | ||||
8 | # an alternative name or full path location with the ``Gperf_EXECUTABLE`` | ||||
9 | # variable. | ||||
10 | # | ||||
11 | # This will define the following variables: | ||||
12 | # | ||||
13 | # ``Gperf_FOUND`` | ||||
14 | # True if gperf is available. | ||||
15 | # | ||||
16 | # ``Gperf_EXECUTABLE`` | ||||
17 | # The gperf executable. | ||||
18 | # | ||||
19 | # If ``Gperf_FOUND`` is TRUE, it will also define the following imported | ||||
20 | # target: | ||||
21 | # | ||||
22 | # ``GPerf::Gperf`` | ||||
23 | # The gperf executable. | ||||
24 | # | ||||
25 | # and the following public function: | ||||
26 | # | ||||
27 | # ecm_gperf_generate(<GperfInput> <OutputFile> <OutputVariable> | ||||
28 | # [GENERATION_FLAGS <flags>]) | ||||
29 | # | ||||
30 | # Run ``gperf`` on ``<GperfInput>`` to generate ``<OutputFile>``, adding it to | ||||
31 | # the ``<OutputVariable>`` variable which contains the source for the target | ||||
32 | # where ``<OutputFile>`` is going to be built. The optional | ||||
33 | # ``GENERATION_FLAGS`` argument is needed to pass extra parameters to | ||||
34 | # ``gperf`` (note you cannot override that way the output file). | ||||
35 | # | ||||
36 | # A simple invocation would be: | ||||
37 | # | ||||
38 | # ecm_gperf_generate(simple.gperf simple.h MySources) | ||||
39 | # | ||||
40 | # Since 5.31.0. | ||||
41 | | ||||
42 | #============================================================================= | ||||
43 | # Copyright 2016 Pino Toscano <pino@kde.org> | ||||
44 | # | ||||
45 | # Redistribution and use in source and binary forms, with or without | ||||
46 | # modification, are permitted provided that the following conditions | ||||
47 | # are met: | ||||
48 | # | ||||
49 | # 1. Redistributions of source code must retain the copyright | ||||
50 | # notice, this list of conditions and the following disclaimer. | ||||
51 | # 2. Redistributions in binary form must reproduce the copyright | ||||
52 | # notice, this list of conditions and the following disclaimer in the | ||||
53 | # documentation and/or other materials provided with the distribution. | ||||
54 | # 3. The name of the author may not be used to endorse or promote products | ||||
55 | # derived from this software without specific prior written permission. | ||||
56 | # | ||||
57 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||||
58 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||||
59 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||||
60 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||||
61 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||||
62 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||||
63 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||||
64 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||
65 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||||
66 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
67 | #============================================================================= | ||||
68 | | ||||
69 | include(${CMAKE_CURRENT_LIST_DIR}/ECMFindModuleHelpersStub.cmake) | ||||
70 | | ||||
71 | ecm_find_package_version_check(Gperf) | ||||
72 | | ||||
73 | # Find gperf | ||||
74 | find_program(Gperf_EXECUTABLE NAMES gperf) | ||||
75 | | ||||
76 | include(FindPackageHandleStandardArgs) | ||||
77 | find_package_handle_standard_args(Gperf | ||||
78 | FOUND_VAR | ||||
79 | Gperf_FOUND | ||||
80 | REQUIRED_VARS | ||||
81 | Gperf_EXECUTABLE | ||||
82 | ) | ||||
83 | | ||||
84 | mark_as_advanced(Gperf_EXECUTABLE) | ||||
85 | | ||||
86 | if (Gperf_FOUND) | ||||
87 | if (NOT TARGET GPerf::Gperf) | ||||
88 | add_executable(GPerf::Gperf IMPORTED) | ||||
89 | set_target_properties(GPerf::Gperf PROPERTIES | ||||
90 | IMPORTED_LOCATION "${Gperf_EXECUTABLE}" | ||||
91 | ) | ||||
92 | endif() | ||||
93 | endif() | ||||
94 | | ||||
95 | include(FeatureSummary) | ||||
96 | set_package_properties(Gperf PROPERTIES | ||||
97 | URL "http://www.gnu.org/software/gperf/" | ||||
98 | DESCRIPTION "Perfect hash function generator" | ||||
99 | ) | ||||
100 | | ||||
101 | | ||||
102 | include(CMakeParseArguments) | ||||
103 | | ||||
104 | function(ecm_gperf_generate input_file output_file out_var) | ||||
105 | # Parse arguments | ||||
106 | set(oneValueArgs GENERATION_FLAGS) | ||||
107 | cmake_parse_arguments(ARGS "" "${oneValueArgs}" "" ${ARGN}) | ||||
108 | | ||||
109 | if(ARGS_UNPARSED_ARGUMENTS) | ||||
110 | message(FATAL_ERROR "Unknown keywords given to ecm_gperf_generate(): \"${ARGS_UNPARSED_ARGUMENTS}\"") | ||||
111 | endif() | ||||
112 | | ||||
113 | get_filename_component(_infile ${input_file} ABSOLUTE) | ||||
114 | set(_extraopts "${ARGS_GENERATION_FLAGS}") | ||||
115 | separate_arguments(_extraopts) | ||||
116 | add_custom_command(OUTPUT ${output_file} | ||||
117 | COMMAND ${Gperf_EXECUTABLE} ${_extraopts} --output-file=${output_file} ${_infile} | ||||
118 | DEPENDS ${_infile} | ||||
119 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||||
120 | VERBATIM | ||||
121 | ) | ||||
122 | set(_outfile "${CMAKE_CURRENT_BINARY_DIR}/${output_file}") | ||||
123 | | ||||
124 | list(APPEND ${out_var} "${_outfile}") | ||||
125 | set(${out_var} ${${out_var}} PARENT_SCOPE) | ||||
126 | endfunction() |