forked from xcore/tool_axe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
231 lines (210 loc) · 5.78 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
cmake_minimum_required(VERSION 2.6)
project(AXE)
if(CMAKE_COMPILER_IS_GNUCXX )
set(COMPILER_IS_GCC_COMPATIBLE ON)
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(COMPILER_IS_GCC_COMPATIBLE ON)
endif()
# Add path for custom modules
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
)
find_package(LibXml2 REQUIRED)
find_package(LibElf REQUIRED)
find_package(LLVM REQUIRED)
find_package(Clang REQUIRED)
add_executable(not
not.cpp
)
add_executable(instgen
InstructionGen.cpp
)
add_executable(genHex
genHex.c
)
add_executable(axe
main.cpp
Core.h
Core.cpp
Runnable.h
RunnableQueue.h
RunnableQueue.cpp
Thread.h
Thread.cpp
SyscallHandler.h
SyscallHandler.cpp
Exceptions.h
Exceptions.cpp
XE.h
XE.cpp
SymbolInfo.h
SymbolInfo.cpp
Resource.h
Resource.cpp
ChanEndpoint.h
ChanEndpoint.cpp
Chanend.h
Chanend.cpp
ClockBlock.h
ClockBlock.cpp
CRC.h
InstructionBitcode.h
InstructionBitcode.cpp
JIT.h
JIT.cpp
JITInstructionFunction.h
JITOptimize.h
JITOptimize.cpp
Lock.cpp
Lock.h
LLVMExtra.h
LLVMExtra.cpp
Signal.h
Synchroniser.cpp
Synchroniser.h
Timer.cpp
Timer.h
PortInterface.h
PortSplitter.h
PortSplitter.cpp
Port.h
Port.cpp
PortArg.h
PortArg.cpp
PortNames.h
PortNames.cpp
Register.h
Trace.h
Trace.cpp
Stats.h
Stats.cpp
BitManip.h
Config.h
ScopedArray.h
ring_buffer.h
Instruction.h
Instruction.cpp
InstructionDefinitions.cpp
InstructionHelpers.h
InstructionHelpers.cpp
InstructionMacrosCommon.h
InstructionProperties.h
InstructionProperties.cpp
TerminalColours.h
TerminalColours.cpp
Node.h
Node.cpp
SystemState.h
SystemState.cpp
Token.h
SSwitch.h
SSwitch.cpp
SSwitchCtrlRegs.h
SSwitchCtrlRegs.cpp
WaveformTracer.h
WaveformTracer.cpp
UartRx.h
UartRx.cpp
PeripheralRegistry.h
PeripheralRegistry.cpp
registerAllPeripherals.h
registerAllPeripherals.cpp
Peripheral.h
Peripheral.cpp
PeripheralDescriptor.h
PeripheralDescriptor.cpp
Property.h
Property.cpp
AccessSecondIterator.h
ConfigSchema.rng
${AXE_BINARY_DIR}/InstructionGenOutput.inc
${AXE_BINARY_DIR}/ConfigSchema.inc
${AXE_BINARY_DIR}/InstructionBitcode.inc
)
if (COMPILER_IS_GCC_COMPATIBLE)
set_source_files_properties(LLVMExtra.cpp PROPERTIES
COMPILE_FLAGS "-fno-rtti")
endif()
include_directories(${AXE_SOURCE_DIR}/thirdparty/boost)
# make sure cmake addes the binary directory for the project to the include path
include_directories(${AXE_BINARY_DIR})
# add the executable that will do the generation
get_target_property(INSTGEN_EXE instgen LOCATION)
get_target_property(GENHEX_EXE genHex LOCATION)
# add the custom command that will run the generator
add_custom_command(
OUTPUT ${AXE_BINARY_DIR}/InstructionGenOutput.inc
COMMAND ${INSTGEN_EXE} ${AXE_BINARY_DIR} > ${AXE_BINARY_DIR}/InstructionGenOutput.inc
DEPENDS instgen
)
# add the custom command that compiles InstructionDefinitions.cpp to LLVM
# bitcode
get_directory_property(INCLUDES_DIRS INCLUDE_DIRECTORIES)
set(CLANG_INCLUDE_FLAGS "")
foreach(dir ${INCLUDES_DIRS})
set(CLANG_INCLUDE_FLAGS ${CLANG_INCLUDE_FLAGS} "-I${dir}")
endforeach()
add_custom_command(
OUTPUT ${AXE_BINARY_DIR}/InstructionBitcode.bc
COMMAND ${CLANGPLUSPLUS_EXECUTABLE} ${CMAKE_CXX_FLAGS} -O2 -g0 ${CLANG_INCLUDE_FLAGS}
-c -emit-llvm ${AXE_SOURCE_DIR}/InstructionDefinitions.cpp
-o ${AXE_BINARY_DIR}/InstructionBitcode.bc
DEPENDS ${AXE_BINARY_DIR}/InstructionGenOutput.inc
IMPLICIT_DEPENDS CXX $(AXE_SOURCE_DIR)/InstructionDefinitions.cpp
)
# add the custom command that turns the LLVM bitcode into hex
add_custom_command(
OUTPUT ${AXE_BINARY_DIR}/InstructionBitcode.inc
COMMAND ${GENHEX_EXE} ${AXE_BINARY_DIR}/InstructionBitcode.bc ${AXE_BINARY_DIR}/InstructionBitcode.inc
DEPENDS genHex ${AXE_BINARY_DIR}/InstructionBitcode.bc
)
# add the custom command that turns the schema into hex
add_custom_command(
OUTPUT ${AXE_BINARY_DIR}/ConfigSchema.inc
COMMAND ${GENHEX_EXE} ${AXE_SOURCE_DIR}/ConfigSchema.rng ${AXE_BINARY_DIR}/ConfigSchema.inc
DEPENDS genHex ConfigSchema.rng
)
if(COMPILER_IS_GCC_COMPATIBLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -Wno-unused-parameter")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -Wno-unused-parameter")
elseif(MSVC)
# Disable the following warnings:
# C4355 'this' : used in base member initializer list.
# Deprecation warnings for less secure CRT functions.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4355 /D_CRT_SECURE_NO_WARNINGS=1")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D_CRT_SECURE_NO_WARNINGS=1")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CFLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LLVM_CFLAGS}")
include_directories(
${LIBELF_INCLUDE_DIRS}
${LIBXML2_INCLUDE_DIR})
if (MSVC)
find_path(LIBICONV_INCLUDE_DIR iconv.h REQUIRED)
include_directories(${LIBICONV_INCLUDE_DIR})
endif()
target_link_libraries(
axe ${LIBELF_LIBRARIES} ${LIBXML2_LIBRARIES} ${LLVM_LIBRARIES})
set_target_properties(axe PROPERTIES LINK_FLAGS ${LLVM_LDFLAGS})
install(TARGETS axe DESTINATION bin)
if (MSVC)
find_file(LIBZLIB_DLL zlib1.dll REQUIRED)
find_file(LIBICONV_DLL iconv.dll REQUIRED)
find_file(LIBXML2_DLL libxml2.dll REQUIRED)
find_file(LIBELF_DLL libelf.dll REQUIRED)
install(FILES ${LIBZLIB_DLL} ${LIBICONV_DLL} ${LIBXML2_DLL} ${LIBELF_DLL} DESTINATION bin)
endif()
if (MSVC)
SET(CPACK_GENERATOR "ZIP")
else()
SET(CPACK_GENERATOR "TGZ")
endif()
INCLUDE(CPack)
configure_file(${CMAKE_SOURCE_DIR}/test/lit.site.cfg.in ${CMAKE_BINARY_DIR}/test/lit.site.cfg)
find_package(PythonInterp)
if (PYTHONINTERP_FOUND)
add_custom_target(check ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/thirdparty/lit/lit.py ${CMAKE_BINARY_DIR}/test)
else()
add_custom_target(check ${CMAKE_COMMAND} -E echo "Not running tests as python is missing")
endif()