File: ecbuild_find_lexyacc.cmake

package info (click to toggle)
ecbuild 3.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,068 kB
  • sloc: sh: 1,404; perl: 732; f90: 472; cpp: 466; python: 383; ansic: 304; fortran: 43; makefile: 15
file content (95 lines) | stat: -rw-r--r-- 3,041 bytes parent folder | download | duplicates (27)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# (C) Copyright 2011- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation nor
# does it submit to any jurisdiction.

##############################################################################
#.rst:
#
# ecbuild_find_lexyacc
# ====================
#
# Find flex and bison (preferred) or lex and yacc.
#
# Input variables
# ---------------
#
# The following CMake variables can set to skip search for bison or yacc:
#
# :SKIP_BISON: do not search for flex and bison
# :SKIP_YACC:  do not search for lex and yacc
#
# Output variables
# ----------------
#
# The following CMake variables are set if flex and bison were found:
#
# :FLEX_FOUND:       flex was found
# :BISON_FOUND:      bison was found
# :FLEX_EXECUTABLE:  path to the flex executable
# :BISON_EXECUTABLE: path to the bison executable
#
# The following CMake variables are set if lex and yacc were found:
#
# :LEXYACC_FOUND:   Found suitable combination of bison, lex, yacc, flex
# :LEX_FOUND:       lex was found
# :YACC_FOUND:      yacc was found
# :LEX_EXECUTABLE:  path to the lex executable
# :YACC_EXECUTABLE: path to the yacc executable
#
##############################################################################

macro( ecbuild_find_lexyacc )

  # find preferably bison or else yacc

  if( NOT SKIP_BISON )

    find_package( BISON )
    if(BISON_FOUND AND BISON_VERSION VERSION_LESS 2.3 )
        ecbuild_critical( "Bison found with version ${BISON_VERSION} is less than 2.3.\nPlease define BISON_EXECUTABLE to an appropriate version or define SKIP_BISON to try finding Yacc instead" )
    endif()
    find_package( FLEX )

  endif()

  if( NOT BISON_FOUND AND NOT SKIP_YACC )

    find_package( YACC )
    find_package( LEX  )

  endif()

  set( LEXYACC_FOUND 1 )

  if( NOT YACC_FOUND AND NOT BISON_FOUND ) # neither bison nor yacc were found
    ecbuild_debug( "Neither bison or yacc were found - at least one is required (together with its lexical analyser" )
    set( LEXYACC_FOUND 0 )
  endif()

  if( NOT YACC_FOUND ) # check for both bison & flex together
    if( BISON_FOUND AND NOT FLEX_FOUND )
      set( LEXYACC_FOUND 0 )
      ecbuild_debug( "Both bison and flex are required - flex not found" )
    endif()
    if( FLEX_FOUND AND NOT BISON_FOUND )
      set( LEXYACC_FOUND 0 )
      ecbuild_debug( "Both bison and flex are required - bison not found" )
    endif()
  endif()

  if( NOT BISON_FOUND ) # check for both yacc & lex together
    if( YACC_FOUND AND NOT LEX_FOUND )
      set( LEXYACC_FOUND 0 )
      ecbuild_debug( "Both yacc and lex are required - lex not found" )
    endif()
    if( LEX_FOUND AND NOT YACC_FOUND )
      set( LEXYACC_FOUND 0 )
      ecbuild_debug( "Both yacc and lex are required - yacc not found" )
    endif()
  endif()

endmacro( ecbuild_find_lexyacc )