-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCMakeLists.txt
96 lines (82 loc) · 3.11 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
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
96
cmake_minimum_required(VERSION 3.13)
project(MiniVM VERSION "0.2.1")
# set CMake module path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# # set compiler path
# set(CMAKE_C_COMPILER "/usr/local/opt/gcc/bin/gcc-10")
# set(CMAKE_CXX_COMPILER "/usr/local/opt/gcc/bin/g++-10")
# set(CMAKE_CXX_COMPILER_ID "GNU")
# C++17 standard support
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# enable all warnings and treat them as errors
if(MSVC)
add_compile_options(/W3 /WX)
else()
# disable warnings caused by old version of Flex
add_compile_options(-Wall -Werror -Wno-register)
endif()
# definitions about version information
add_compile_definitions(APP_NAME="MiniVM Eeyore/Tigger Virtual Machine")
add_compile_definitions(APP_VERSION="${PROJECT_VERSION}")
add_compile_definitions(APP_VERSION_MAJOR=${PROJECT_VERSION_MAJOR})
add_compile_definitions(APP_VERSION_MINOR=${PROJECT_VERSION_MINOR})
add_compile_definitions(APP_VERSION_PATCH=${PROJECT_VERSION_PATCH})
# no debugger: disable the built-in debugger of MiniVM
option(NO_DEBUGGER "disable the built-in debugger" OFF)
if(NO_DEBUGGER)
message("The built-in debugger (MiniDbg) has been disabled.")
add_compile_definitions(NO_DEBUGGER)
endif()
# find Flex/Bison
find_package(FLEX REQUIRED)
find_package(BISON REQUIRED)
# find Readline
if(NOT NO_DEBUGGER)
find_package(Readline)
endif()
# generate lexer/parser of Eeyore
flex_target(EeyoreLexer src/front/eeyore.l
${CMAKE_CURRENT_BINARY_DIR}/eeyore.lexer.cpp
COMPILE_FLAGS "-P eeyore_")
bison_target(EeyoreParser src/front/eeyore.y
${CMAKE_CURRENT_BINARY_DIR}/eeyore.parser.cpp
COMPILE_FLAGS "-p eeyore_")
add_flex_bison_dependency(EeyoreLexer EeyoreParser)
# generate lexer/parser of Tigger
flex_target(TiggerLexer src/front/tigger.l
${CMAKE_CURRENT_BINARY_DIR}/tigger.lexer.cpp
COMPILE_FLAGS "-P tigger_")
bison_target(TiggerParser src/front/tigger.y
${CMAKE_CURRENT_BINARY_DIR}/tigger.parser.cpp
COMPILE_FLAGS "-p tigger_")
add_flex_bison_dependency(TiggerLexer TiggerParser)
# project include directories
include_directories(src)
include_directories(3rdparty/xstl)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if(NOT NO_DEBUGGER)
include_directories(${Readline_INCLUDE_DIR})
endif()
# embedded text files
file(GLOB_RECURSE EMBEDDED_FILES "src/back/c/embed/*.c")
# all of C++ source files
file(GLOB_RECURSE SOURCES "src/*.cpp")
if (NO_DEBUGGER)
file(GLOB_RECURSE DEBUGGER_SRCS "src/debugger/*.cpp")
# do not remove 'srcreader.cpp' as it's used by the C backend
list(REMOVE_ITEM DEBUGGER_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/debugger/minidbg/srcreader.cpp")
list(REMOVE_ITEM SOURCES ${DEBUGGER_SRCS})
endif()
list(REMOVE_ITEM SOURCES ${EMBEDDED_FILES})
set(SOURCES ${SOURCES} ${FLEX_EeyoreLexer_OUTPUTS}
${BISON_EeyoreParser_OUTPUT_SOURCE})
set(SOURCES ${SOURCES} ${FLEX_TiggerLexer_OUTPUTS}
${BISON_TiggerParser_OUTPUT_SOURCE})
# executable
add_executable(minivm ${SOURCES})
if(NOT NO_DEBUGGER)
target_link_libraries(minivm ${Readline_LIBRARY})
endif()