forked from planetfederal/QGIS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Flex.cmake
89 lines (71 loc) · 2.49 KB
/
Flex.cmake
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
# Macros for Bison
# ~~~~~~~~~~~~~~~~
# Copyright (c) 2007, Martin Dobias <wonder.sk at gmail.com>
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
# flex a .ll file
# search flex
MACRO(FIND_FLEX)
IF(NOT FLEX_EXECUTABLE)
IF (MSVC)
FIND_PROGRAM(FLEX_EXECUTABLE
NAMES flex.exe
PATHS $ENV{LIB_DIR}/bin c:/cygwin/bin $ENV{PROGRAMFILES}/GnuWin32/bin
)
ELSE(MSVC)
FIND_PROGRAM(FLEX_EXECUTABLE flex)
ENDIF (MSVC)
IF (NOT FLEX_EXECUTABLE)
MESSAGE(FATAL_ERROR "flex not found - aborting")
ENDIF (NOT FLEX_EXECUTABLE)
ENDIF(NOT FLEX_EXECUTABLE)
ENDMACRO(FIND_FLEX)
MACRO(ADD_FLEX_FILES _sources )
FIND_FLEX()
FOREACH (_current_FILE ${ARGN})
GET_FILENAME_COMPONENT(_in ${_current_FILE} ABSOLUTE)
GET_FILENAME_COMPONENT(_basename ${_current_FILE} NAME_WE)
SET(_out ${CMAKE_CURRENT_BINARY_DIR}/flex_${_basename}.cpp)
# -d option for flex means that it will produce output to stderr while analyzing
ADD_CUSTOM_COMMAND(
OUTPUT ${_out}
COMMAND ${FLEX_EXECUTABLE}
ARGS
-o${_out}
${_in}
DEPENDS ${_in}
)
SET(${_sources} ${${_sources}} ${_out} )
# Disable warnings
IF(MSVC)
SET_SOURCE_FILES_PROPERTIES(${_out} PROPERTIES COMPILE_FLAGS /W0)
ELSE(MSVC)
SET_SOURCE_FILES_PROPERTIES(${_out} PROPERTIES COMPILE_FLAGS -w)
ENDIF(MSVC)
ENDFOREACH (_current_FILE)
ENDMACRO(ADD_FLEX_FILES)
MACRO(ADD_FLEX_FILES_PREFIX _sources prefix )
FIND_FLEX()
FOREACH (_current_FILE ${ARGN})
GET_FILENAME_COMPONENT(_in ${_current_FILE} ABSOLUTE)
GET_FILENAME_COMPONENT(_basename ${_current_FILE} NAME_WE)
SET(_out ${CMAKE_CURRENT_BINARY_DIR}/flex_${_basename}.cpp)
# -d option for flex means that it will produce output to stderr while analyzing
ADD_CUSTOM_COMMAND(
OUTPUT ${_out}
COMMAND ${FLEX_EXECUTABLE}
ARGS
-P${prefix}
-o${_out}
${_in}
DEPENDS ${_in}
)
SET(${_sources} ${${_sources}} ${_out} )
# Disable warnings
IF(MSVC)
SET_SOURCE_FILES_PROPERTIES(${_out} PROPERTIES COMPILE_FLAGS /W0)
ELSE(MSVC)
SET_SOURCE_FILES_PROPERTIES(${_out} PROPERTIES COMPILE_FLAGS -w)
ENDIF(MSVC)
ENDFOREACH (_current_FILE)
ENDMACRO(ADD_FLEX_FILES_PREFIX)