-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
359 lines (272 loc) · 10.8 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
cmake_minimum_required(VERSION 3.17.0 FATAL_ERROR)
# set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_MESSAGE_LOG_LEVEL DEBUG)
set(VERSION_MAJOR 0) # Set manually
set(VERSION_MINOR 3) # Set manually
set(VERSION_PATCH 0) # Set manually
set(VERSION_HEADER "version.h")
set(VERSION_FILE "version.cpp")
if(WIN32)
set(CMD cmd "/c")
message(FATAL_ERROR "Support windows not tested!")
elseif(UNIX)
set(CMD bash "-c")
else()
message(FATAL_ERROR "Unsupport platform!")
endif()
execute_process(COMMAND ${CMD} "git describe --abbrev=0 --tags" OUTPUT_VARIABLE GIT_TAG_VERSION)
string(REPLACE "\n" "" GIT_TAG_VERSION ${GIT_TAG_VERSION})
execute_process(COMMAND ${CMD} "git rev-parse --short HEAD" OUTPUT_VARIABLE GIT_SHORT_HASH)
string(REPLACE "\n" "" GIT_SHORT_HASH ${GIT_SHORT_HASH})
string(TIMESTAMP DATE_BUILD "%y.%m.%d %H:%M:%S")
set(GIT_SOURCE_ID "${GIT_TAG_VERSION}-${GIT_SHORT_HASH}")
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
# message(DEBUG ${GIT_TAG_VERSION})
# message(DEBUG ${GIT_SHORT_HASH})
# message(DEBUG ${DATE_BUILD})
# message(DEBUG ${GIT_SOURCE_ID})
# message(DEBUG ${VERSION})
if("${GIT_SHORT_HASH}" STREQUAL "")
message(FATAL_ERROR "Fail read git hash on repo!")
endif()
if(NOT "${GIT_TAG_VERSION}" STREQUAL "v${VERSION}")
message(FATAL_ERROR "Git TAG ${GIT_TAG_VERSION} differ version v${VERSION}")
endif()
project(NewLang VERSION ${VERSION} HOMEPAGE_URL "https://newlang.net" LANGUAGES CXX)
message(STATUS "Used git source ${GIT_SOURCE_ID}")
function(CHECK_NEW_FILE name skip)
if(NOT EXISTS "${name}.temp")
message(FATAL_ERROR "File name '${name}.temp' not found!")
endif()
if(NOT EXISTS "${name}")
file(RENAME "${name}.temp" "${name}")
else()
file(READ "${name}.temp" NEW_FILE_STR)
file(READ "${name}" OLD_FILE_STR)
string(SUBSTRING "${NEW_FILE_STR}" ${skip} 100000 NEW_FILE_STR)
string(SUBSTRING "${OLD_FILE_STR}" ${skip} 100000 OLD_FILE_STR)
if("${NEW_FILE_STR}" STREQUAL "${OLD_FILE_STR}")
file(REMOVE "${name}.temp")
message(STATUS "Use file ${name} for current build")
else()
file(REMOVE "${name}")
file(RENAME "${name}.temp" "${name}")
message(STATUS "Make file ${name} for version ${GIT_SOURCE_ID} at date ${DATE_BUILD}")
endif()
endif()
endfunction()
function(CREATE_DOC dir suffix)
if(NOT ${suffix} STREQUAL "")
set(dir "${dir}/${suffix}")
set(suffix "_${suffix}")
endif()
execute_process(COMMAND ${CMD} "echo -n \"\" > ${dir}/newlang_doc.md")
foreach(DOC_FILE
syntax.md
syntax_macro.md
types.md
type_nor.md
type_str.md
type_func.md
type_oop.md
type_native.md
type_iter.md
type_other.md
ops.md
syntax_dsl.md
)
if(NOT EXISTS "${dir}/${DOC_FILE}")
message(FATAL_ERROR "File name '${dir}/${DOC_FILE}' not found!")
endif()
execute_process(COMMAND ${CMD} "cat ${dir}/${DOC_FILE} >> ${dir}/newlang_doc.md")
execute_process(COMMAND ${CMD} "echo \"------\n${DOC_FILE}\n\n\" >> ${dir}/newlang_doc.md")
endforeach()
execute_process(COMMAND ${CMD} "pandoc -t plain ${dir}/newlang_doc.md > ${dir}/newlang_doc.txt")
execute_process(COMMAND ${CMD} "${CMAKE_SOURCE_DIR}/contrib/text2cpp/output/bin/text2cpp ${dir}/newlang_doc.md ${CMAKE_SOURCE_DIR}/src/syntax_help${suffix}.cpp.temp newlang_syntax_help${suffix} c")
cmake_language(CALL CHECK_NEW_FILE "${CMAKE_SOURCE_DIR}/src/syntax_help${suffix}.cpp" 0)
endfunction()
#cmake_language(CALL CREATE_DOC "${CMAKE_SOURCE_DIR}/docs" "en")
#cmake_language(CALL CREATE_DOC "${CMAKE_SOURCE_DIR}/docs" "ru")
add_custom_target(doc ALL
# cmake_language(CALL CREATE_DOC "${CMAKE_SOURCE_DIR}/docs" "en")
COMMAND ${CMD} "${CMAKE_SOURCE_DIR}/build_doc.sh"
#COMMAND CREATE_DOC "${CMAKE_SOURCE_DIR}/docs" "ru"
)
execute_process(COMMAND ${CMD} "${CMAKE_SOURCE_DIR}/contrib/text2cpp/output/bin/text2cpp ${CMAKE_SOURCE_DIR}/examples/dsl.src ${CMAKE_SOURCE_DIR}/src/dsl.cpp.temp newlang_dsl c")
cmake_language(CALL CHECK_NEW_FILE "${CMAKE_SOURCE_DIR}/src/dsl.cpp" 0)
execute_process(COMMAND ${CMD} "echo -n \"\" > ${CMAKE_SOURCE_DIR}/src/${VERSION_HEADER}.temp")
foreach(VERSION_HEADER_STR
"/** @file ${VERSION_HEADER}"
"* Auto generate file for identification current build"
"* Date build ${DATE_BUILD}"
"*/"
""
"#define VERSION_DATE_BUILD_STR \"${DATE_BUILD}\""
"#define VERSION_SOURCE_FULL_ID \"${GIT_SOURCE_ID} ${DATE_BUILD}\""
""
"#include <stdint.h>"
""
"extern const uint8_t VERSION_MAJOR;"
"extern const uint8_t VERSION_MINOR;"
"extern const uint8_t VERSION_PATCH;"
"extern const uint16_t VERSION_BUILD;"
""
"#define VERSION (${VERSION_MAJOR} << 4 | ${VERSION_MINOR})"
"#define VERSION_GIT_SOURCE \"${GIT_SOURCE_ID}\""
""
"extern const char * GIT_SOURCE;"
"extern const char * DATE_BUILD_STR;"
"extern const char * SOURCE_FULL_ID;"
""
)
execute_process(COMMAND ${CMD} "echo '${VERSION_HEADER_STR}' >> ${CMAKE_SOURCE_DIR}/src/${VERSION_HEADER}.temp")
endforeach()
cmake_language(CALL CHECK_NEW_FILE "${CMAKE_SOURCE_DIR}/src/${VERSION_HEADER}" 250)
execute_process(COMMAND ${CMD} "echo -n \"\" > ${CMAKE_SOURCE_DIR}/src/${VERSION_FILE}.temp")
foreach(VERSION_FILE_STR
"/** @file ${VERSION_FILE}"
"* Auto generate file for identification current build"
"* Date build ${DATE_BUILD}"
"*/"
""
"#include \"version.h\""
""
"const uint8_t VERSION_MAJOR=${VERSION_MAJOR};"
"const uint8_t VERSION_MINOR=${VERSION_MINOR};"
"const uint8_t VERSION_PATCH=${VERSION_PATCH};"
""
"const char * GIT_SOURCE = VERSION_GIT_SOURCE;"
"const char * DATE_BUILD_STR = VERSION_DATE_BUILD_STR;"
"const char * SOURCE_FULL_ID = VERSION_SOURCE_FULL_ID;"
""
)
execute_process(COMMAND ${CMD} "echo '${VERSION_FILE_STR}' >> ${CMAKE_SOURCE_DIR}/src/${VERSION_FILE}.temp")
endforeach()
cmake_language(CALL CHECK_NEW_FILE "${CMAKE_SOURCE_DIR}/src/${VERSION_FILE}" 110)
get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY)
# option(MYLIB_TESTING "Включить модульное тестирование" ON)
# option(MYLIB_COVERAGE "Включить измерение покрытия кода тестами" OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
execute_process(COMMAND ${CMD} "llvm-config-15 --cxxflags" OUTPUT_VARIABLE LLVM_CONFIG)
separate_arguments(LLVM_CONFIG UNIX_COMMAND ${LLVM_CONFIG})
add_compile_options(
${LLVM_CONFIG}
-Wno-trigraphs
-Winvalid-pch
-Werror=return-type
-Wformat
-Wuninitialized
-fexceptions
-fcxx-exceptions
-Wall
-Wextra
-Werror
-Wfloat-equal
-Wundef
-Wcast-align
-Wwrite-strings
-Wmissing-declarations
-Wredundant-decls
-Wshadow
-Woverloaded-virtual
-Wno-trigraphs
-Wno-invalid-source-encoding
-stdlib=libstdc++
-fvisibility=default
-Wno-error=unused-variable
-Wno-error=unused-parameter
-fsanitize=undefined-trap
-fsanitize-undefined-trap-on-error
# remove after correct source
-Wno-error=switch
-Wno-error=trigraphs
-Wno-undefined-var-template
-Wno-switch
)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
execute_process(COMMAND ${CMD} "${CMAKE_SOURCE_DIR}/src/compile_syntax.sh" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/src")
# add_custom_command(
# OUTPUT
# # ${ATXT}
# ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.yy.h
# ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.yy.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/lexer.yy.h
# ${CMAKE_CURRENT_SOURCE_DIR}/src/lexer.yy.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/location.hh
# COMMAND ./compile_syntax.sh
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src
# COMMENT "Compile syntax from files parser.y and lexer.l"
# DEPENDS
# ${CMAKE_CURRENT_SOURCE_DIR}/src/compile_syntax.sh
# ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.y
# ${CMAKE_CURRENT_SOURCE_DIR}/src/lexer.l
# VERBATIM)
file(GLOB src_SRC
# Generated files
${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/lexer.yy.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/parser.yy.cpp
# Source files
${CMAKE_CURRENT_SOURCE_DIR}/src/builtin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/context.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/lexer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/newlang.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/object.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/parser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/term.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/variable.cpp
# Contrib files
${CMAKE_CURRENT_SOURCE_DIR}/contrib/logger/logger.cpp
#contrib/tensorboard_logger/src/crc.cc
#contrib/tensorboard_logger/src/tensorboard_logger.cc
)
file(GLOB TEST_SRC
${CMAKE_CURRENT_SOURCE_DIR}/src/test/*.cpp)
file(GLOB NLC_SRC
${CMAKE_CURRENT_SOURCE_DIR}/src/nlc.cpp)
link_directories(contrib/libtorch/lib)
link_directories(contrib/libffi/output/lib)
link_libraries(
${CMAKE_DL_LIBS}
Threads::Threads
libffi.a
c10
torch
torch_cpu
crypto
LLVM-15
)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR})
add_executable(nlc ${src_SRC})
target_sources(nlc PRIVATE ${NLC_SRC})
add_executable(newlang-unit-tests ${src_SRC})
target_sources(newlang-unit-tests PRIVATE ${TEST_SRC})
ADD_DEFINITIONS(-DLOG_LEVEL_NORMAL=LOG_LEVEL_DEBUG)
# ADD_DEFINITIONS(-DPDC_WIDE)
ADD_DEFINITIONS(-DDEBUG)
target_compile_options(newlang-unit-tests PRIVATE -DUNITTEST)
target_precompile_headers(newlang-unit-tests PRIVATE src/pch.h)
target_precompile_headers(nlc PRIVATE src/pch.h)
SET(PCH_DST src/pch.h)
target_sources(newlang-unit-tests PRIVATE contrib/googletest/googletest/src/gtest_main.cc)
target_sources(newlang-unit-tests PRIVATE contrib/googletest/googletest/src/gtest-all.cc)
target_include_directories(newlang-unit-tests PUBLIC contrib/googletest/googletest)
target_include_directories(newlang-unit-tests PUBLIC contrib/googletest/googletest/include)
include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src
contrib/Lyra/include
contrib/libtorch/include/torch/csrc/api/include
contrib/libtorch/include
contrib/tensorboard_logger/include
)
# if(NOT MYLIB_TESTING)
# message(STATUS "Тестирование проекта Mylib выключено")
# elseif(IS_SUBPROJECT)
# message(STATUS "Mylib не тестируется в режиме подмодуля")
# else()
# target_sources(newlang-unit-tests PRIVATE src/test/)
# endif()
# enable_testing()