-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
61 lines (52 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
cmake_minimum_required(VERSION 3.13)
project(compiler)
# settings
# set to OFF to enable C mode
set(CPP_MODE ON)
if(CPP_MODE)
set(FB_EXT ".cpp")
else()
set(FB_EXT ".c")
endif()
message(STATUS "Flex/Bison generated source file extension: ${FB_EXT}")
# enable all warnings
if(MSVC)
add_compile_options(/W3)
else()
# disable warnings caused by old version of Flex
add_compile_options(-Wall -Wno-register)
endif()
# options about libraries and includes
set(LIB_DIR "$ENV{CDE_LIBRARY_PATH}/native" CACHE STRING "directory of libraries")
set(INC_DIR "$ENV{CDE_INCLUDE_PATH}" CACHE STRING "directory of includes")
message(STATUS "Library directory: ${LIB_DIR}")
message(STATUS "Include directory: ${INC_DIR}")
# find Flex/Bison
find_package(FLEX REQUIRED)
find_package(BISON REQUIRED)
# generate lexer/parser
file(GLOB_RECURSE L_SOURCES "src/*.l")
file(GLOB_RECURSE Y_SOURCES "src/*.y")
if(NOT (L_SOURCES STREQUAL "" AND Y_SOURCES STREQUAL ""))
string(REGEX REPLACE ".*/(.*)\\.l" "${CMAKE_CURRENT_BINARY_DIR}/\\1.lex${FB_EXT}" L_OUTPUTS "${L_SOURCES}")
string(REGEX REPLACE ".*/(.*)\\.y" "${CMAKE_CURRENT_BINARY_DIR}/\\1.tab${FB_EXT}" Y_OUTPUTS "${Y_SOURCES}")
flex_target(Lexer ${L_SOURCES} ${L_OUTPUTS})
bison_target(Parser ${Y_SOURCES} ${Y_OUTPUTS} COMPILE_FLAGS -v)
add_flex_bison_dependency(Lexer Parser)
endif()
# project link directories
link_directories(${LIB_DIR})
# project include directories
include_directories(src)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${INC_DIR})
# all of C/C++ source files
file(GLOB_RECURSE C_SOURCES "src/*.c")
file(GLOB_RECURSE CXX_SOURCES "src/*.cpp")
file(GLOB_RECURSE CC_SOURCES "src/*.cc")
set(SOURCES ${C_SOURCES} ${CXX_SOURCES} ${CC_SOURCES}
${FLEX_Lexer_OUTPUTS} ${BISON_Parser_OUTPUT_SOURCE})
# executable
add_executable(compiler ${SOURCES})
set_target_properties(compiler PROPERTIES C_STANDARD 11 CXX_STANDARD 17)
target_link_libraries(compiler koopa pthread dl)