]> git.proxmox.com Git - mirror_linux-firmware.git/blob - carl9170fw/extra/FindGPERF.cmake
linux-firmware: Update firmware file for Intel Bluetooth 8265
[mirror_linux-firmware.git] / carl9170fw / extra / FindGPERF.cmake
1 # - Find gperf executable and provides a macro to generate custom build rules
2 #
3 # The module defines the following variables:
4 # GPERF_FOUND - true is gperf executable is found
5 # GPERF_EXECUTABLE - the path to the gperf executable
6 # GPERF_VERSION - the version of gperf
7 # GPERF_LIBRARIES - The gperf libraries
8 #
9 # The minimum required version of gperf can be specified using the
10 # standard syntax, e.g. FIND_PACKAGE(GPERF 2.5.13)
11 #
12 #
13 # If gperf is found on the system, the module provides the macro:
14 # GPERF_TARGET(Name GperfInput GperfOutput [COMPILE_FLAGS <string>])
15 # which creates a custom command to generate the <GperfOutput> file from
16 # the <GperfInput> file. If COMPILE_FLAGS option is specified, the next
17 # parameter is added to the gperf command line. Name is an alias used to
18 # get details of this custom command. Indeed the macro defines the
19 # following variables:
20 # GPERF_${Name}_DEFINED - true is the macro ran successfully
21 # GPERF_${Name}_OUTPUTS - the source file generated by the custom rule, an
22 # alias for GperfOutput
23 # GPERF_${Name}_INPUT - the gperf source file, an alias for ${GperfInput}
24 #
25 # Gperf scanners oftenly use tokens defined by Bison: the code generated
26 # by Gperf depends of the header generated by Bison. This module also
27 # defines a macro:
28 # ADD_GPERF_BISON_DEPENDENCY(GperfTarget BisonTarget)
29 # which adds the required dependency between a scanner and a parser
30 # where <GperfTarget> and <BisonTarget> are the first parameters of
31 # respectively GPERF_TARGET and BISON_TARGET macros.
32 #
33 # ====================================================================
34 # Example:
35 #
36 # find_package(GPERF)
37 #
38 # GPERF_TARGET(MyHash hash.gperf ${CMAKE_CURRENT_BINARY_DIR}/hash.c)
39 #
40 # ====================================================================
41
42 #=============================================================================
43 # Copyright 2009 Kitware, Inc.
44 # Copyright 2006 Tristan Carel
45 #
46 # Redistribution and use in source and binary forms, with or without
47 # modification, are permitted provided that the following conditions
48 # are met:
49 #
50 # * Redistributions of source code must retain the above copyright
51 # notice, this list of conditions and the following disclaimer.
52 #
53 # * Redistributions in binary form must reproduce the above copyright
54 # notice, this list of conditions and the following disclaimer in the
55 # documentation and/or other materials provided with the distribution.
56 #
57 # * Neither the names of Kitware, Inc., the Insight Software Consortium,
58 # nor the names of their contributors may be used to endorse or promote
59 # products derived from this software without specific prior written
60 # permission.
61 #
62 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
63 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
64 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
65 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
66 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
67 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
68 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
69 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
70 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
71 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
72 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
73
74 cmake_minimum_required(VERSION 2.8.4)
75
76 FIND_PROGRAM(GPERF_EXECUTABLE gperf DOC "path to the gperf executable")
77 MARK_AS_ADVANCED(GPERF_EXECUTABLE)
78
79 FIND_LIBRARY(FL_LIBRARY NAMES fl
80 DOC "path to the fl library")
81 MARK_AS_ADVANCED(FL_LIBRARY)
82 SET(GPERF_LIBRARIES ${FL_LIBRARY})
83
84 IF(GPERF_EXECUTABLE)
85
86 EXECUTE_PROCESS(COMMAND ${GPERF_EXECUTABLE} --version
87 OUTPUT_VARIABLE GPERF_version_output
88 ERROR_VARIABLE GPERF_version_error
89 RESULT_VARIABLE GPERF_version_result
90 OUTPUT_STRIP_TRAILING_WHITESPACE)
91
92 SET(ENV{LC_ALL} ${_Bison_SAVED_LC_ALL})
93
94 IF(NOT ${GPERF_version_result} EQUAL 0)
95 MESSAGE(SEND_ERROR "Command \"${GPERF_EXECUTABLE} --version\" failed with output:\n${GPERF_version_error}")
96 ELSE()
97 STRING(REGEX REPLACE "^GNU gperf ([^\n]+)\n.*" "\\1"
98 GPERF_VERSION "${GPERF_version_output}")
99 ENDIF()
100
101 #============================================================
102 # GPERF_TARGET (public macro)
103 #============================================================
104 #
105 MACRO(GPERF_TARGET Name Input Output)
106 SET(GPERF_TARGET_usage "GPERF_TARGET(<Name> <Input> <Output> [COMPILE_FLAGS <string>]")
107 IF(${ARGC} GREATER 3)
108 IF(${ARGC} EQUAL 5)
109 IF("${ARGV3}" STREQUAL "COMPILE_FLAGS")
110 SET(GPERF_EXECUTABLE_opts "${ARGV4}")
111 SEPARATE_ARGUMENTS(GPERF_EXECUTABLE_opts)
112 ELSE()
113 MESSAGE(SEND_ERROR ${GPERF_TARGET_usage})
114 ENDIF()
115 ELSE()
116 MESSAGE(SEND_ERROR ${GPERF_TARGET_usage})
117 ENDIF()
118 ENDIF()
119
120 ADD_CUSTOM_COMMAND(OUTPUT ${Output}
121 COMMAND ${GPERF_EXECUTABLE}
122 ARGS ${GPERF_EXECUTABLE_opts} < ${Input} > ${Output}
123 DEPENDS ${Input}
124 COMMENT "[GPERF][${Name}] Building hash with gperf ${GPERF_VERSION}"
125 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
126
127 SET(GPERF_${Name}_DEFINED TRUE)
128 SET(GPERF_${Name}_OUTPUTS ${Output})
129 SET(GPERF_${Name}_INPUT ${Input})
130 SET(GPERF_${Name}_COMPILE_FLAGS ${GPERF_EXECUTABLE_opts})
131 ENDMACRO(GPERF_TARGET)
132 #============================================================
133
134
135 #============================================================
136 # ADD_GPERF_BISON_DEPENDENCY (public macro)
137 #============================================================
138 #
139 MACRO(ADD_GPERF_BISON_DEPENDENCY GperfTarget BisonTarget)
140
141 IF(NOT GPERF_${GperfTarget}_OUTPUTS)
142 MESSAGE(SEND_ERROR "Gperf target `${GperfTarget}' does not exists.")
143 ENDIF()
144
145 IF(NOT BISON_${BisonTarget}_OUTPUT_HEADER)
146 MESSAGE(SEND_ERROR "Bison target `${BisonTarget}' does not exists.")
147 ENDIF()
148
149 SET_SOURCE_FILES_PROPERTIES(${GPERF_${GperfTarget}_OUTPUTS}
150 PROPERTIES OBJECT_DEPENDS ${BISON_${BisonTarget}_OUTPUT_HEADER})
151 ENDMACRO(ADD_GPERF_BISON_DEPENDENCY)
152 #============================================================
153
154 ENDIF(GPERF_EXECUTABLE)
155
156 INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
157 FIND_PACKAGE_HANDLE_STANDARD_ARGS(GPERF REQUIRED_VARS GPERF_EXECUTABLE
158 VERSION_VAR GPERF_VERSION)
159
160 # FindGPERF.cmake ends here