-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
70 lines (56 loc) · 1.93 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 2.8.5)
project(Pascal)
find_program(LEX_EXE
flex
)
if(LEX_EXE STREQUAL "LEX_EXE-NOTFOUND")
message(FATAL_ERROR "dear user, plase install flex!")
endif(LEX_EXE STREQUAL "LEX_EXE-NOTFOUND")
find_program(YACC_EXE
bison
)
if(YACC_EXE STREQUAL "YACC_EXE-NOTFOUND")
message(FATAL_ERROR "dear user, plase install bison!")
endif(YACC_EXE STREQUAL "YACC_EXE-NOTFOUND")
# reuseable cmake macro for yacc
MACRO(YACC_FILE)
ADD_CUSTOM_COMMAND(
SOURCE ${PROJECT_SOURCE_DIR}/src/pascal.l
COMMAND ${LEX_EXE}
ARGS -o${PROJECT_BINARY_DIR}/comp/pascal_lexer.c
${PROJECT_SOURCE_DIR}/src/pascal.l
TARGET FooParser
OUTPUTS ${PROJECT_BINARY_DIR}/comp/pascal_lexer.c)
ENDMACRO(YACC_FILE)
# reuseable cmake macro for lex
MACRO(LEX_FILE)
ADD_CUSTOM_COMMAND(
SOURCE ${PROJECT_SOURCE_DIR}/src/pascal.y
COMMAND ${YACC_EXE}
ARGS -o${PROJECT_BINARY_DIR}/comp/y.tab.c
-y -d -v ${PROJECT_SOURCE_DIR}/src/pascal.y
TARGET FooParser
DEPENDS ${PROJECT_BINARY_DIR}/comp/pascal_lexer.c
OUTPUTS ${PROJECT_BINARY_DIR}/comp/y.tab.c
${PROJECT_BINARY_DIR}/comp/y.tab.h)
ENDMACRO(LEX_FILE)
# just one more parsing executable
file(MAKE_DIRECTORY comp)
FILE(COPY ${PROJECT_SOURCE_DIR}/src/custom.h
DESTINATION ${PROJECT_BINARY_DIR}/comp/)
FILE(COPY ${PROJECT_SOURCE_DIR}/src/converter.sh
DESTINATION ${PROJECT_BINARY_DIR}/)
YACC_FILE()
LEX_FILE()
# Add parser.c to the list of sources
SET(PROJECT_SRCS ${PROJECT_SRCS} ${PROJECT_BINARY_DIR}/comp/y.tab.c)
SET(PROJECT_SRCS ${PROJECT_SRCS} ${PROJECT_BINARY_DIR}/comp/y.tab.h)
# Since parser.c does not exists yet when cmake is run, mark
# it as generated
SET_SOURCE_FILES_PROPERTIES(${PROJECT_BINARY_DIR}/comp/y.tab.c GENERATED)
# Include binary directory to include lexer.c in parser.c
INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR}/comp/)
add_executable(pas2c
${PROJECT_BINARY_DIR}/comp/y.tab.c
${PROJECT_BINARY_DIR}/comp/pascal_lexer.c
)