forked from beefytech/Beef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
334 lines (281 loc) · 10.7 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
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
################### Variables. ####################
# Change if you want modify path or other values. #
###################################################
set(PROJECT_NAME IDEHelper)
# Output Variables
set(OUTPUT_DEBUG Debug/bin)
set(CMAKE_DEBUG_POSTFIX "_d")
set(OUTPUT_RELEASE Release/bin)
###
### Use LLVM Libraries.
###
# https://stackoverflow.com/questions/30867712/add-llvm-to-project-using-cmake
# https://llvm.org/docs/CMake.html
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
set(REQUIRED_LLVM_VERSION "13")
# https://stackoverflow.com/questions/7485227/how-to-increment-variable
MATH(EXPR NEWER_LLVM_VERSION "${REQUIRED_LLVM_VERSION}+1")
# testing for exact version: https://gitlab.kitware.com/cmake/cmake/-/issues/18067
if (${LLVM_PACKAGE_VERSION} VERSION_LESS REQUIRED_LLVM_VERSION)
message(FATAL_ERROR "Found old, incompatible LLVM version ${LLVM_PACKAGE_VERSION}. Upgrade LLVM to at least version ${REQUIRED_LLVM_VERSION}.")
endif()
if (NOT ${LLVM_PACKAGE_VERSION} VERSION_LESS NEWER_LLVM_VERSION)
message(FATAL_ERROR "Newer LLVM version ${LLVM_PACKAGE_VERSION} currently not supported. Required LLVM version: ${REQUIRED_LLVM_VERSION}. Install this version and assign environment variable 'CMAKE_PREFIX_PATH' to the corresponding folder before running cmake (see 'bin/build_release.sh').")
endif()
include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
############## CMake Project ################
# The main options of project #
#############################################
project(${PROJECT_NAME} CXX C)
# Define Release by default.
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
message(STATUS "Build type not specified: Use Debug by default.")
endif(NOT CMAKE_BUILD_TYPE)
# Definition of Macros
add_definitions(
-DIDEHELPER_EXPORTS
-DBFSYSLIB_DYNAMIC
-DUNICODE
-D_UNICODE
-DBF_NO_FBX
-DFT2_BUILD_LIBRARY
-DBFSYSLIB_DYNAMIC
)
set (CMAKE_CXX_STANDARD 14)
#add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
INCLUDE(CheckIncludeFiles)
CHECK_INCLUDE_FILES(backtrace.h HAVE_BACKTRACE_HEADERS)
if (HAVE_BACKTRACE_HEADERS)
add_definitions(-DBFP_HAS_BACKTRACE)
endif ()
if (${APPLE})
include_directories(
.
../
../BeefySysLib/
../BeefySysLib/third_party
../BeefySysLib/third_party/freetype/include
../extern/llvm-project_13_0_1/llvm/include
../extern/llvm-project_13_0_1/llvm/lib/Target
../BeefySysLib/platform/osx
)
else()
include_directories(
.
../
../BeefySysLib/
../BeefySysLib/third_party
# ../BeefySysLib/third_party/freetype/include
# ../extern/llvm-project_13_0_1/llvm/include
# ../extern/llvm-project_13_0_1/llvm/lib/Target
../BeefySysLib/platform/linux
)
endif()
############## Artefacts Output #################
# Defines outputs , depending Debug or Release. #
#################################################
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(
-D_DEBUG
)
# include_directories(
# ../extern/llvm_linux_13_0_1/include
# ../extern/llvm_linux_13_0_1/lib/Target/X86
# ../extern/llvm_linux_13_0_1/lib/Target/AArch64
# )
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")
set(CMAKE_EXECUTABLE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")
# set(LLVM_LIB "${CMAKE_CURRENT_SOURCE_DIR}/../extern/llvm_linux_13_0_1/lib")
else()
# include_directories(
# ../extern/llvm_linux_rel_13_0_1/include
# ../extern/llvm_linux_rel_13_0_1/lib/Target/X86
# ../extern/llvm_linux_rel_13_0_1/lib/Target/AArch64
# )
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_RELEASE}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_RELEASE}")
set(CMAKE_EXECUTABLE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_RELEASE}")
# set(LLVM_LIB "${CMAKE_CURRENT_SOURCE_DIR}/../extern/llvm_linux_rel_13_0_1/lib")
endif()
################### Dependencies ##################
# Add Dependencies to project. #
###################################################
option(BUILD_DEPENDS
"Build other CMake project."
ON
)
# Dependencies : disable BUILD_DEPENDS to link with lib already build.
if(BUILD_DEPENDS)
else()
endif()
################# Flags ################
# Defines Flags for Windows and Linux. #
########################################
if(MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W3 /MD /MDd /Od /EHsc")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /W3 /GL /Od /Oi /Gy /EHsc")
endif(MSVC)
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fno-rtti -Wno-multichar -Wno-invalid-offsetof")
endif(NOT MSVC)
################ Files ################
# -- Add files to project. -- #
#######################################
file(GLOB SRC_FILES
BfDiff.cpp
Debugger.cpp
DebugManager.cpp
DebugVisualizers.cpp
NetManager.cpp
SpellChecker.cpp
Targets.cpp
# deactivate the custom X86 backend, since it seems to require the LLVM sources.
# X64.cpp
# X86.cpp
# X86Target.cpp
X86XmmInfo.cpp
LinuxDebugger.cpp
Beef/BfCommon.cpp
Clang/CDepChecker.cpp
Clang/ClangHelper.cpp
Compiler/BfAst.cpp
Compiler/BfAstAllocator.cpp
Compiler/BfAutoComplete.cpp
Compiler/BfCodeGen.cpp
Compiler/BfCompiler.cpp
Compiler/BfConstResolver.cpp
Compiler/BfContext.cpp
Compiler/BfDefBuilder.cpp
Compiler/BfDeferEvalChecker.cpp
Compiler/BfDemangler.cpp
Compiler/BfElementVisitor.cpp
Compiler/BfNamespaceVisitor.cpp
Compiler/BfExprEvaluator.cpp
Compiler/BfIRBuilder.cpp
Compiler/BfIRCodeGen.cpp
Compiler/BfMangler.cpp
Compiler/BfModule.cpp
Compiler/BfModuleTypeUtils.cpp
Compiler/BfParser.cpp
Compiler/BfPrinter.cpp
Compiler/BfReducer.cpp
Compiler/BfResolvedTypeUtils.cpp
Compiler/BfResolvePass.cpp
Compiler/BfSource.cpp
Compiler/BfSourceClassifier.cpp
Compiler/BfSourcePositionFinder.cpp
Compiler/BfStmtEvaluator.cpp
Compiler/BfSystem.cpp
Compiler/BfUtil.cpp
Compiler/BfVarDeclChecker.cpp
Compiler/BfTargetTriple.cpp
Compiler/CeMachine.cpp
Compiler/CeDebugger.cpp
Compiler/MemReporter.cpp
Backend/BeContext.cpp
Backend/BeIRCodeGen.cpp
Backend/BeModule.cpp
)
# Add library to build.
add_library(${PROJECT_NAME} SHARED
${SRC_FILES}
)
#execute_process(
# COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../extern/llvm_linux_13_0_1/bin/llvm-config --system-libs --link-static
# OUTPUT_VARIABLE LLVM_SYSTEM_LIBS
# OUTPUT_STRIP_TRAILING_WHITESPACE
# RESULT_VARIABLE EXEC_RESULT
#)
if (EXEC_RESULT AND NOT EXEC_RESULT EQUAL 0)
if (EXEC_RESULT MATCHES "^[0-9]+$")
message(FATAL_ERROR "llvm-config exited with code ${EXEC_RESULT}.")
else()
message(FATAL_ERROR "llvm-config couldn't be executed: ${EXEC_RESULT}")
endif()
endif()
set(TARGET_LIBS_OS "${LLVM_SYSTEM_LIBS}")
if (HAVE_BACKTRACE_HEADERS)
string(APPEND TARGET_LIBS_OS " -lbacktrace")
string(STRIP ${TARGET_LIBS_OS} TARGET_LIBS_OS)
endif()
list(APPEND LLVM_LIBS
${LLVM_LIB}/libLLVMCore.a
${LLVM_LIB}/libLLVMCodeGen.a
${LLVM_LIB}/libLLVMMC.a
${LLVM_LIB}/libLLVMMCParser.a
${LLVM_LIB}/libLLVMMCDisassembler.a
${LLVM_LIB}/libLLVMObject.a
${LLVM_LIB}/libLLVMBitReader.a
${LLVM_LIB}/libLLVMAsmParser.a
${LLVM_LIB}/libLLVMTarget.a
${LLVM_LIB}/libLLVMScalarOpts.a
${LLVM_LIB}/libLLVMInstCombine.a
${LLVM_LIB}/libLLVMSelectionDAG.a
${LLVM_LIB}/libLLVMProfileData.a
${LLVM_LIB}/libLLVMAnalysis.a
${LLVM_LIB}/libLLVMAsmPrinter.a
${LLVM_LIB}/libLLVMBitWriter.a
${LLVM_LIB}/libLLVMVectorize.a
${LLVM_LIB}/libLLVMipo.a
${LLVM_LIB}/libLLVMInstrumentation.a
${LLVM_LIB}/libLLVMDebugInfoDWARF.a
${LLVM_LIB}/libLLVMDebugInfoPDB.a
${LLVM_LIB}/libLLVMDebugInfoCodeView.a
${LLVM_LIB}/libLLVMGlobalISel.a
${LLVM_LIB}/libLLVMTransformUtils.a
${LLVM_LIB}/libLLVMBinaryFormat.a
${LLVM_LIB}/libLLVMIRReader.a
${LLVM_LIB}/libLLVMLinker.a
${LLVM_LIB}/libLLVMAggressiveInstCombine.a
${LLVM_LIB}/libLLVMBitstreamReader.a
${LLVM_LIB}/libLLVMCFGuard.a
${LLVM_LIB}/libLLVMTextAPI.a
${LLVM_LIB}/libLLVMRemarks.a
${LLVM_LIB}/libLLVMX86Info.a
${LLVM_LIB}/libLLVMX86Desc.a
${LLVM_LIB}/libLLVMX86CodeGen.a
${LLVM_LIB}/libLLVMX86AsmParser.a
${LLVM_LIB}/libLLVMX86Disassembler.a
${LLVM_LIB}/libLLVMARMDesc.a
${LLVM_LIB}/libLLVMARMUtils.a
${LLVM_LIB}/libLLVMARMInfo.a
${LLVM_LIB}/libLLVMARMCodeGen.a
${LLVM_LIB}/libLLVMARMAsmParser.a
${LLVM_LIB}/libLLVMARMDisassembler.a
${LLVM_LIB}/libLLVMAArch64Desc.a
${LLVM_LIB}/libLLVMAArch64Utils.a
${LLVM_LIB}/libLLVMAArch64Info.a
${LLVM_LIB}/libLLVMAArch64CodeGen.a
${LLVM_LIB}/libLLVMAArch64AsmParser.a
${LLVM_LIB}/libLLVMAArch64Disassembler.a
${LLVM_LIB}/libLLVMWebAssemblyDesc.a
${LLVM_LIB}/libLLVMWebAssemblyInfo.a
${LLVM_LIB}/libLLVMWebAssemblyCodeGen.a
${LLVM_LIB}/libLLVMWebAssemblyAsmParser.a
${LLVM_LIB}/libLLVMWebAssemblyDisassembler.a
${LLVM_LIB}/libLLVMWebAssemblyUtils.a
${LLVM_LIB}/libLLVMSupport.a
${LLVM_LIB}/libLLVMDemangle.a)
#FOREACH (lib ${LLVM_LIBS})
# string(APPEND TARGET_LIBS_OS " " ${lib})
#ENDFOREACH()
# this yields an empty "IDEHelper_libs.txt" on linux when using distro llvm libs.
# still compiles and links. so presumably it is only for providing location of self-compiled llvm to ide.
if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
FILE(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/../IDE/dist/IDEHelper_libs_d.txt" ${TARGET_LIBS_OS})
else()
FILE(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/../IDE/dist/IDEHelper_libs.txt" ${TARGET_LIBS_OS})
endif()
# Link with other dependencies.
if(MSVC)
target_link_libraries(${PROJECT_NAME} BeefySysLib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib LLVMX86Disassembler.lib LLVMMCDisassembler.lib LLVMSupport.lib LLVMX86Info.lib LLVMX86Desc.lib %(AdditionalDependencies) LLVMMC.lib LLVMObject.lib LLVMCore.lib LLVMBitReader.lib LLVMAsmParser.lib LLVMMCParser.lib LLVMCodeGen.lib LLVMTarget.lib LLVMX86CodeGen.lib LLVMScalarOpts.lib LLVMInstCombine.lib LLVMSelectionDAG.lib LLVMProfileData.lib LLVMTransformUtils.lib LLVMAnalysis.lib LLVMX86AsmParser.lib LLVMAsmPrinter.lib LLVMBitWriter.lib LLVMVectorize.lib LLVMipo.lib LLVMInstrumentation.lib LLVMDebugInfoDWARF.lib LLVMDebugInfoPDB.lib LLVMDebugInfoCodeView.lib LLVMGlobalISel.lib LLVMBinaryFormat.lib LLVMAggressiveInstCombine.lib libcurl_a.lib)
else()
# target_link_libraries(${PROJECT_NAME} BeefySysLib hunspell pthread dl ${TARGET_LIBS_OS}
target_link_libraries(${PROJECT_NAME} BeefySysLib hunspell pthread dl LLVM)
endif()