]> granicus.if.org Git - icinga2/blob - cmake/FindFLEX.cmake
Fix the .bundle validation.
[icinga2] / cmake / FindFLEX.cmake
1 # - Find flex executable and provides a macro to generate custom build rules
2 #
3 # The module defines the following variables:
4 #  FLEX_FOUND - true is flex executable is found
5 #  FLEX_EXECUTABLE - the path to the flex executable
6 #  FLEX_VERSION - the version of flex
7 #  FLEX_LIBRARIES - The flex libraries
8 #
9 # The minimum required version of flex can be specified using the
10 # standard syntax, e.g. FIND_PACKAGE(FLEX 2.5.13)
11 #
12 #
13 # If flex is found on the system, the module provides the macro:
14 #  FLEX_TARGET(Name FlexInput FlexOutput [COMPILE_FLAGS <string>])
15 # which creates a custom command  to generate the <FlexOutput> file from
16 # the <FlexInput> file.  If  COMPILE_FLAGS option is specified, the next
17 # parameter is added to the flex  command line. Name is an alias used to
18 # get  details of  this custom  command.  Indeed the  macro defines  the
19 # following variables:
20 #  FLEX_${Name}_DEFINED - true is the macro ran successfully
21 #  FLEX_${Name}_OUTPUTS - the source file generated by the custom rule, an
22 #  alias for FlexOutput
23 #  FLEX_${Name}_INPUT - the flex source file, an alias for ${FlexInput}
24 #
25 # Flex scanners oftenly use tokens  defined by Bison: the code generated
26 # by Flex  depends of the header  generated by Bison.   This module also
27 # defines a macro:
28 #  ADD_FLEX_BISON_DEPENDENCY(FlexTarget BisonTarget)
29 # which  adds the  required dependency  between a  scanner and  a parser
30 # where  <FlexTarget>  and <BisonTarget>  are  the  first parameters  of
31 # respectively FLEX_TARGET and BISON_TARGET macros.
32 #
33 #  ====================================================================
34 #  Example:
35 #
36 #   find_package(BISON)
37 #   find_package(FLEX)
38 #
39 #   BISON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
40 #   FLEX_TARGET(MyScanner lexer.l  ${CMAKE_CURRENT_BIANRY_DIR}/lexer.cpp)
41 #   ADD_FLEX_BISON_DEPENDENCY(MyScanner MyParser)
42 #
43 #   include_directories(${CMAKE_CURRENT_BINARY_DIR})
44 #   add_executable(Foo
45 #      Foo.cc
46 #      ${BISON_MyParser_OUTPUTS}
47 #      ${FLEX_MyScanner_OUTPUTS}
48 #   )
49 #  ====================================================================
50
51 #=============================================================================
52 # Copyright 2009 Kitware, Inc.
53 # Copyright 2006 Tristan Carel
54 # Modified 2010 by Jon Siwek, backporting for CMake 2.6 compat
55 #
56 # Distributed under the OSI-approved BSD License (the "License"):
57 # CMake - Cross Platform Makefile Generator
58 # Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
59 # All rights reserved.
60
61 # Redistribution and use in source and binary forms, with or without
62 # modification, are permitted provided that the following conditions
63 # are met:
64 #
65 # * Redistributions of source code must retain the above copyright
66 #   notice, this list of conditions and the following disclaimer.
67 #
68 # * Redistributions in binary form must reproduce the above copyright
69 #   notice, this list of conditions and the following disclaimer in the
70 #   documentation and/or other materials provided with the distribution.
71 #
72 # * Neither the names of Kitware, Inc., the Insight Software Consortium,
73 #   nor the names of their contributors may be used to endorse or promote
74 #   products derived from this software without specific prior written
75 #   permission.
76 #
77 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
78 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
79 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
80 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
81 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
82 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
83 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
84 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
85 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
86 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
87 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
88 #
89 # This software is distributed WITHOUT ANY WARRANTY; without even the
90 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
91 # See the License for more information.
92 #=============================================================================
93
94 FIND_PROGRAM(FLEX_EXECUTABLE flex DOC "path to the flex executable")
95 MARK_AS_ADVANCED(FLEX_EXECUTABLE)
96
97 FIND_LIBRARY(FL_LIBRARY NAMES fl
98   DOC "path to the fl library")
99 MARK_AS_ADVANCED(FL_LIBRARY)
100 SET(FLEX_LIBRARIES ${FL_LIBRARY})
101
102 IF(FLEX_EXECUTABLE)
103
104   EXECUTE_PROCESS(COMMAND ${FLEX_EXECUTABLE} --version
105     OUTPUT_VARIABLE FLEX_version_output
106     ERROR_VARIABLE FLEX_version_error
107     RESULT_VARIABLE FLEX_version_result
108     OUTPUT_STRIP_TRAILING_WHITESPACE)
109   IF(NOT ${FLEX_version_result} EQUAL 0)
110     IF(FLEX_FIND_REQUIRED)
111       MESSAGE(SEND_ERROR "Command \"${FLEX_EXECUTABLE} --version\" failed with output:\n${FLEX_version_output}\n${FLEX_version_error}")
112     ELSE()
113       MESSAGE("Command \"${FLEX_EXECUTABLE} --version\" failed with output:\n${FLEX_version_output}\n${FLEX_version_error}\nFLEX_VERSION will not be available")
114     ENDIF()
115   ELSE()
116     STRING(REGEX REPLACE "^flex (.*)$" "\\1"
117       FLEX_VERSION "${FLEX_version_output}")
118   ENDIF()
119
120   #============================================================
121   # FLEX_TARGET (public macro)
122   #============================================================
123   #
124   MACRO(FLEX_TARGET Name Input Output)
125     SET(FLEX_TARGET_usage "FLEX_TARGET(<Name> <Input> <Output> [COMPILE_FLAGS <string>]")
126     IF(${ARGC} GREATER 3)
127       IF(${ARGC} EQUAL 5)
128         IF("${ARGV3}" STREQUAL "COMPILE_FLAGS")
129           SET(FLEX_EXECUTABLE_opts  "${ARGV4}")
130           SEPARATE_ARGUMENTS(FLEX_EXECUTABLE_opts)
131         ELSE()
132           MESSAGE(SEND_ERROR ${FLEX_TARGET_usage})
133         ENDIF()
134       ELSE()
135         MESSAGE(SEND_ERROR ${FLEX_TARGET_usage})
136       ENDIF()
137     ENDIF()
138
139     ADD_CUSTOM_COMMAND(OUTPUT ${Output}
140       COMMAND ${FLEX_EXECUTABLE}
141       ARGS ${FLEX_EXECUTABLE_opts} -o${Output} ${Input}
142       DEPENDS ${Input}
143       COMMENT "[FLEX][${Name}] Building scanner with flex ${FLEX_VERSION}"
144       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
145
146     SET(FLEX_${Name}_DEFINED TRUE)
147     SET(FLEX_${Name}_OUTPUTS ${Output})
148     SET(FLEX_${Name}_INPUT ${Input})
149     SET(FLEX_${Name}_COMPILE_FLAGS ${FLEX_EXECUTABLE_opts})
150   ENDMACRO(FLEX_TARGET)
151   #============================================================
152
153
154   #============================================================
155   # ADD_FLEX_BISON_DEPENDENCY (public macro)
156   #============================================================
157   #
158   MACRO(ADD_FLEX_BISON_DEPENDENCY FlexTarget BisonTarget)
159
160     IF(NOT FLEX_${FlexTarget}_OUTPUTS)
161       MESSAGE(SEND_ERROR "Flex target `${FlexTarget}' does not exists.")
162     ENDIF()
163
164     IF(NOT BISON_${BisonTarget}_OUTPUT_HEADER)
165       MESSAGE(SEND_ERROR "Bison target `${BisonTarget}' does not exists.")
166     ENDIF()
167
168     SET_SOURCE_FILES_PROPERTIES(${FLEX_${FlexTarget}_OUTPUTS}
169       PROPERTIES OBJECT_DEPENDS ${BISON_${BisonTarget}_OUTPUT_HEADER})
170   ENDMACRO(ADD_FLEX_BISON_DEPENDENCY)
171   #============================================================
172
173 ENDIF(FLEX_EXECUTABLE)
174
175 INCLUDE(FindPackageHandleStandardArgs)
176 FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLEX FLEX_EXECUTABLE
177                                        FLEX_VERSION)
178
179 # FindFLEX.cmake ends here