This repository has been archived by the owner on Jul 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathCMakeLists.txt
134 lines (115 loc) · 3.46 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
cmake_minimum_required(VERSION 3.10)
project(JitFromScratch)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
if(NOT CMAKE_TOOLCHAIN_FILE)
include(DefaultToolchain)
endif()
include(LLVM)
if(LLVM_ENABLE_RTTI)
message(WARNING "LLVM built with RTTI; enabling it for JitFromScratch to avoid quirks")
set(rtti_flags ${HOST_ENABLE_RTTI})
else()
set(rtti_flags ${HOST_DISABLE_RTTI})
endif()
# If we have a LLVM source-tree, symlink it for debug source maps
if(LLVM_BUILD_MAIN_SRC_DIR AND EXISTS "${LLVM_BUILD_MAIN_SRC_DIR}" AND UNIX)
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink ${LLVM_BUILD_MAIN_SRC_DIR}
${CMAKE_BINARY_DIR}/llvm-project
)
endif()
# Import extra CMake helpers from LLVM
list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR})
include(AddLLVM)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No explicit CMAKE_BUILD_TYPE provided; JitFromScratch defaults to the build type of LLVM")
set(CMAKE_BUILD_TYPE ${LLVM_BUILD_TYPE} CACHE STRING "" FORCE)
elseif(NOT ${LLVM_BUILD_TYPE} STREQUAL ${CMAKE_BUILD_TYPE})
message(WARNING "JitFromScratch set to build as ${CMAKE_BUILD_TYPE}, which differs from LLVM's build type")
endif()
add_executable(JitFromScratch
main.cpp
JitFromScratch.cpp
SimpleOptimizer.cpp
SimpleObjectCache.cpp
)
target_include_directories(JitFromScratch PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${LLVM_INCLUDE_DIRS}
)
set(llvm_libs
LLVMAggressiveInstCombine
LLVMAnalysis
LLVMAsmParser
LLVMAsmPrinter
LLVMBinaryFormat
LLVMBitReader
LLVMBitWriter
LLVMBitstreamReader
LLVMCodeGen
LLVMCore
LLVMDebugInfoCodeView
LLVMDebugInfoDWARF
LLVMDebugInfoMSF
LLVMDemangle
LLVMExecutionEngine
LLVMGlobalISel
LLVMInstCombine
LLVMInstrumentation
LLVMipo
LLVMJITLink
LLVMLinker
LLVMIRReader
LLVMMC
LLVMMCDisassembler
LLVMMCParser
LLVMObject
LLVMOrcJIT
LLVMProfileData
LLVMRemarks
LLVMRuntimeDyld
LLVMScalarOpts
LLVMSelectionDAG
LLVMSupport
LLVMTarget
LLVMTransformUtils
LLVMVectorize
LLVMX86AsmParser
LLVMX86CodeGen
LLVMX86Desc
LLVMX86Info
LLVMX86Utils
)
separate_arguments(LLVM_DEFINITIONS)
target_compile_definitions(JitFromScratch PRIVATE ${LLVM_DEFINITIONS})
target_link_libraries(JitFromScratch PRIVATE ${llvm_libs})
target_compile_options(JitFromScratch PRIVATE ${rtti_flags})
# Allow dlopen() to access exported symbols.
# This will add linker flags like -Wl,--export-dynamic -rdynamic
export_executable_symbols(JitFromScratch)
function(dump_target_properties target property)
get_target_property(values ${target} ${property})
if(values)
if(NOT "${values}" STREQUAL "${property}-NOTFOUND")
message(STATUS "${target} ${property}=${values}")
endif()
endif()
endfunction()
dump_target_properties(JitFromScratch INCLUDE_DIRECTORIES)
dump_target_properties(JitFromScratch COMPILE_OPTIONS)
dump_target_properties(JitFromScratch COMPILE_DEFINITIONS)
dump_target_properties(JitFromScratch LINK_LIBRARIES)
dump_target_properties(JitFromScratch LINK_FLAGS)
# Only LLVM Debug builds can parse debug arguments
if(${LLVM_BUILD_TYPE} STREQUAL "Debug" AND CMAKE_BUILD_TYPE STREQUAL "Debug")
set(debug_args -debug -debug-only=jitfromscratch)
endif()
add_custom_target(run
COMMAND $<TARGET_FILE:JitFromScratch> ${debug_args}
COMMENT "Running JitFromScratch"
)
add_custom_target(run-cached
COMMAND $<TARGET_FILE:JitFromScratch> ${debug_args} -cache-dir=cache/
COMMENT "Running JitFromScratch (with object cache)"
)
add_subdirectory(test)