forked from Juan-Burda/bubblegum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
126 lines (104 loc) · 4.62 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Versión mínima requerida de CMake. Se puede reducir o incrementar a riesgo del desarrollador.
# @see https://cmake.org/download/
cmake_minimum_required(VERSION 3.22)
# Nombre del proyecto, y lenguaje utilizado (C, en este caso).
project(Compiler C)
# Compilar el parser con Bison, generando contra-ejemplos en caso de que se presenten conflictos.
add_custom_command(
OUTPUT ../src/frontend/syntactic-analysis/bison-parser.c ../src/frontend/syntactic-analysis/bison-parser.h
COMMAND bison -Wcounterexamples -d ../src/frontend/syntactic-analysis/bison-grammar.y -o ../src/frontend/syntactic-analysis/bison-parser.c)
# Seleccionar estrategia según el compilador de C disponible en el sistema.
# @see https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
message(NOTICE "El compilador de C es GCC.")
# Opciones para GCC.
add_compile_options(-static-libgcc)
add_compile_options(-std=gnu99)
add_compile_options(-O3)
# Compilar el scanner con Flex.
add_custom_command(
OUTPUT ../src/frontend/lexical-analysis/flex-scanner.c
COMMAND flex -o ../src/frontend/lexical-analysis/flex-scanner.c ../src/frontend/lexical-analysis/flex-patterns.l
DEPENDS ../src/frontend/syntactic-analysis/bison-parser.c ../src/frontend/syntactic-analysis/bison-parser.h)
elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
message(NOTICE "El compilador de C es Microsoft Visual Studio.")
# Opciones para MSVC.
# add_compile_options(...)
# Compilar el scanner con Flex, usando compatibilidad con Microsoft Windows.
add_custom_command(
OUTPUT ../src/frontend/lexical-analysis/flex-scanner.c
COMMAND flex --wincompat -o ../src/frontend/lexical-analysis/flex-scanner.c ../src/frontend/lexical-analysis/flex-patterns.l
DEPENDS ../src/frontend/syntactic-analysis/bison-parser.c ../src/frontend/syntactic-analysis/bison-parser.h)
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
message(NOTICE "El compilador de C es LLVM Clang.")
# Opciones para Clang.
# add_compile_options(...)
# Compilar el scanner con Flex.
add_custom_command(
OUTPUT ../src/frontend/lexical-analysis/flex-scanner.c
COMMAND flex -o ../src/frontend/lexical-analysis/flex-scanner.c ../src/frontend/lexical-analysis/flex-patterns.l
DEPENDS ../src/frontend/syntactic-analysis/bison-parser.c ../src/frontend/syntactic-analysis/bison-parser.h)
else ()
message(NOTICE "El compilador de C es desconocido.")
message(NOTICE "No se generará el scanner con Flex.")
message(NOTICE "Incluya un 'elseif' adicional para manejar su compilador.")
endif ()
# Generar código Web Assembly. Solo en entornos con emscripten.
option(WEB_ENV "Generación de código Web Assembly para ejecutar en un entorno web" OFF)
# Web assembly no necesita de un main
if (WEB_ENV)
add_executable(Compiler
src/web.c)
add_definitions(-D WEB_ENV)
else()
add_executable(Compiler
src/main.c)
endif ()
# Especificar punto de entrada del proyecto y códigos fuente (extensión *.c).
# Los *.h se incluyen automáticamente desde estos fuentes.
target_sources(Compiler PRIVATE
src/utils/ast-utils.c
src/utils/stringify.c
src/utils/wrapper-functions.c
src/utils/errors/problem-context.c
src/libs/list-adt.c
src/utils/stringify.c
src/utils/sb.c
src/backend/code-generation/generator.c
src/backend/code-generation/animation/animation.c
src/backend/code-generation/layout/layout.c
src/backend/code-generation/shape/shape.c
src/backend/code-generation/media/media.c
src/backend/code-generation/text/text.c
src/backend/support/logger.c
src/backend/support/symbol-table.c
src/frontend/lexical-analysis/flex-actions.c
src/frontend/lexical-analysis/flex-scanner.c
src/frontend/syntactic-analysis/bison-actions/general-actions.c
src/frontend/syntactic-analysis/bison-actions/animation-actions.c
src/frontend/syntactic-analysis/bison-actions/layout-actions.c
src/frontend/syntactic-analysis/bison-actions/shape-actions.c
src/frontend/syntactic-analysis/bison-actions/media-actions.c
src/frontend/syntactic-analysis/bison-actions/data-type-actions.c
src/frontend/syntactic-analysis/bison-actions/text-actions.c
src/frontend/syntactic-analysis/bison-parser.c
# Agregar otros archivos *.c (si no se incluyen, no se compilan).
# ...
)
if (WEB_ENV)
target_link_options(Compiler PUBLIC
-O3
-sMODULARIZE=1
-sEXPORT_NAME='createCompilerModule'
-sENVIRONMENT='web'
-sSINGLE_FILE=1
-sEXPORT_ES6=1
-sUSE_ES6_IMPORT_META=0
--no-entry
-sEXPORTED_FUNCTIONS=['_getCode','_malloc','_free','_freeCode']
-sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','getValue','stringToNewUTF8','UTF8ToString']
-sASYNCIFY
)
endif ()
# Linkear el proyecto y sus librerías.
target_link_libraries(Compiler)