forked from altera-fpga/hls-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
executable file
·385 lines (317 loc) · 16 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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# Direct CMake to use icpx rather than the default C++ compiler/linker on Linux
# and icx-cl on Windows
if(UNIX)
set(CMAKE_CXX_COMPILER icpx)
else() # Windows
include (CMakeForceCompiler)
CMAKE_FORCE_CXX_COMPILER (icx-cl IntelDPCPP)
include (Platform/Windows-Clang)
endif()
cmake_minimum_required (VERSION 3.7.2)
project(decompress CXX)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
###############################################################################
### Customize these build variables
###############################################################################
set(SOURCE_FILES src/main.cpp)
set(TARGET_NAME decompress)
# Use cmake -DFPGA_DEVICE=<board-support-package>:<board-variant> to choose a
# different device.
# Note that depending on your installation, you may need to specify the full
# path to the board support package (BSP), this usually is in your install
# folder.
#
# You can also specify a device family (E.g. "Arria10" or "Stratix10") or a
# specific part number (E.g. "10AS066N3F40E2SG") to generate a standalone IP.
if(NOT DEFINED FPGA_DEVICE)
set(FPGA_DEVICE "Agilex7")
message(STATUS "FPGA_DEVICE was not specified.\
\nConfiguring the design to the default FPGA family target: ${FPGA_DEVICE}\
\nPlease refer to the README for information on target selection.")
set(DEVICE_FLAG "Agilex7")
else()
message(STATUS "Configuring the design with the following target: ${FPGA_DEVICE}")
string(TOLOWER ${FPGA_DEVICE} FPGA_DEVICE_NAME)
if(FPGA_DEVICE_NAME MATCHES ".*a10.*" OR FPGA_DEVICE_NAME MATCHES ".*arria10.*")
set(DEVICE_FLAG "A10")
elseif(FPGA_DEVICE_NAME MATCHES ".*s10.*" OR FPGA_DEVICE_NAME MATCHES ".*stratix10.*")
set(DEVICE_FLAG "S10")
elseif(FPGA_DEVICE_NAME MATCHES ".*agilex.*")
set(DEVICE_FLAG "Agilex7")
endif()
# Check if the target is a BSP
if(IS_BSP MATCHES "1")
set(BSP_FLAG "-DIS_BSP")
else()
message(STATUS "The selected target ${FPGA_DEVICE} is assumed to be an FPGA part number, so USM will be enabled by default.")
message(STATUS "If the target is actually a BSP that does not support USM, run cmake with -DIS_BSP=1.")
endif()
endif()
if(NOT DEFINED DEVICE_FLAG)
message(FATAL_ERROR "An unrecognized or custom board was passed, but DEVICE_FLAG was not specified. \
Please make sure you have set -DDEVICE_FLAG=A10, -DDEVICE_FLAG=S10 or \
-DDEVICE_FLAG=Agilex7.")
endif()
message("\tDEVICE_FLAG set to ${DEVICE_FLAG}")
# Select between SNAPPY and GZIP decompression
if(DEFINED SNAPPY AND DEFINED GZIP)
message(FATAL_ERROR "Cannot compile for both SNAPPY and GZIP compression. You must define exactly one of -DSNAPPY=1 and -DGZIP=1")
else()
# check whether user wants GZIP or SNAPPY decompression - default is SNAPPY
if(DEFINED GZIP)
message(STATUS "Compiling for GZIP decompression")
set(DECOMPRESS_FORMAT_FLAG "-DGZIP")
else()
if(NOT DEFINED SNAPPY)
message(STATUS "Neither GZIP nor SNAPPY was defined. Defaulting to SNAPPY decompression")
endif()
message(STATUS "Compiling for SNAPPY decompression")
set(DECOMPRESS_FORMAT_FLAG "-DSNAPPY")
endif()
set(ignoreMe "${GZIP}${SNAPPY}")
endif()
# Increase the allowable constexpr steps for the front end. This allows the
# front-end compiler to do more compile-time computation.
if(WIN32)
set(CONSTEXPR_STEPS "-constexpr:steps5084968")
else()
set(CONSTEXPR_STEPS "-fconstexpr-steps=5084968")
endif()
if(IGNORE_DEFAULT_SEED)
set(SEED_FLAG "")
else()
if (NOT DEFINED SEED)
# the default seed for each FPGA type
if(DEVICE_FLAG MATCHES "A10")
set(SEED 1)
elseif(DEVICE_FLAG MATCHES "S10")
set(SEED 2)
elseif(DEVICE_FLAG MATCHES "Agilex7")
set(SEED 3)
else()
message(STATUS "SEED not defined and no known seed for this board -- defaulting to SEED = 1")
set(SEED 1)
endif()
endif()
set(SEED_FLAG "-Xsseed=${SEED}")
endif()
# Allow the user to set how many literals are processed at once
# e.g. cmake .. -DLITERALS_PER_CYCLE=2
if(DEFINED LITERALS_PER_CYCLE)
set(LITERALS_PER_CYCLE_FLAG "-DLITERALS_PER_CYCLE=${LITERALS_PER_CYCLE}")
endif()
# Use cmake -DUSER_FPGA_FLAGS=<flags> to set extra flags for FPGA backend
# compilation.
set(USER_FPGA_FLAGS ${USER_FPGA_FLAGS};${SEED_FLAG})
# Use cmake -DUSER_FLAGS=<flags> to set extra flags for general compilation.
set(USER_FLAGS ${USER_FLAGS};${CONSTEXPR_STEPS};${DECOMPRESS_FORMAT_FLAG};${LITERALS_PER_CYCLE_FLAG};${BSP_FLAG})
# Use cmake -DUSER_INCLUDE_PATHS=<paths> to set extra paths for general
# compilation.
set(USER_INCLUDE_PATHS ../../include;${USER_INCLUDE_PATHS})
###############################################################################
### no changes after here
###############################################################################
# Set the names of the makefile targets to be generated by cmake
set(EMULATOR_TARGET fpga_emu)
set(SIMULATOR_TARGET fpga_sim)
set(REPORT_TARGET report)
set(FPGA_TARGET fpga)
# Set the names of the generated files per makefile target
set(EMULATOR_OUTPUT_NAME ${TARGET_NAME}.${EMULATOR_TARGET})
set(SIMULATOR_OUTPUT_NAME ${TARGET_NAME}.${SIMULATOR_TARGET})
set(REPORT_OUTPUT_NAME ${TARGET_NAME}.${REPORT_TARGET})
set(FPGA_OUTPUT_NAME ${TARGET_NAME}.${FPGA_TARGET})
message(STATUS "Additional USER_FPGA_FLAGS=${USER_FPGA_FLAGS}")
message(STATUS "Additional USER_FLAGS=${USER_FLAGS}")
include_directories(${USER_INCLUDE_PATHS})
message(STATUS "Additional USER_INCLUDE_PATHS=${USER_INCLUDE_PATHS}")
link_directories(${USER_LIB_PATHS})
message(STATUS "Additional USER_LIB_PATHS=${USER_LIB_PATHS}")
link_libraries(${USER_LIBS})
message(STATUS "Additional USER_LIBS=${USER_LIBS}")
if(WIN32)
# add qactypes for Windows
set(QACTYPES "-Qactypes")
# This is a Windows-specific flag that enables exception handling in host code
set(WIN_FLAG "/EHsc")
else()
# add qactypes for Linux
set(QACTYPES "-qactypes")
endif()
string(TOLOWER "${CMAKE_BUILD_TYPE}" LOWER_BUILD_TYPE)
if(LOWER_BUILD_TYPE MATCHES debug)
# Set debug flags
if(WIN32)
set(DEBUG_FLAGS /DEBUG /Od)
else()
set(DEBUG_FLAGS -g -O0)
endif()
else()
set(DEBUG_FLAGS "")
endif()
if(WIN32)
set(EXT ".exe")
endif()
set(COMMON_COMPILE_FLAGS -fintelfpga -Wall ${WIN_FLAG} ${QACTYPES} ${USER_FLAGS})
set(COMMON_LINK_FLAGS -fintelfpga ${QACTYPES} ${USER_FLAGS})
# A SYCL ahead-of-time (AoT) compile processes the device code in two stages.
# 1. The "compile" stage compiles the device code to an intermediate
# representation (SPIR-V).
# 2. The "link" stage invokes the compiler's FPGA backend before linking. For
# this reason, FPGA backend flags must be passed as link flags in CMake.
set(EMULATOR_COMPILE_FLAGS -DFPGA_EMULATOR ${DEBUG_FLAGS})
set(EMULATOR_LINK_FLAGS )
set(REPORT_COMPILE_FLAGS -DFPGA_HARDWARE)
set(REPORT_LINK_FLAGS -Xshardware -Xstarget=${FPGA_DEVICE} ${USER_FPGA_FLAGS} -fsycl-link=early)
set(SIMULATOR_COMPILE_FLAGS -Xssimulation -DFPGA_SIMULATOR)
set(SIMULATOR_LINK_FLAGS -Xssimulation -Xsghdl -Xstarget=${FPGA_DEVICE} ${USER_FPGA_FLAGS} -reuse-exe=${CMAKE_BINARY_DIR}/${SIMULATOR_OUTPUT_NAME}${EXT})
set(FPGA_COMPILE_FLAGS -DFPGA_HARDWARE)
set(FPGA_LINK_FLAGS -Xshardware -Xstarget=${FPGA_DEVICE} ${USER_FPGA_FLAGS} -reuse-exe=${CMAKE_BINARY_DIR}/${FPGA_OUTPUT_NAME}${EXT})
###############################################################################
### FPGA Emulator
###############################################################################
add_executable(${EMULATOR_TARGET} ${SOURCE_FILES})
target_compile_options(${EMULATOR_TARGET} PRIVATE ${COMMON_COMPILE_FLAGS})
target_compile_options(${EMULATOR_TARGET} PRIVATE ${EMULATOR_COMPILE_FLAGS})
target_link_libraries(${EMULATOR_TARGET} ${COMMON_LINK_FLAGS})
target_link_libraries(${EMULATOR_TARGET} ${EMULATOR_LINK_FLAGS})
set_target_properties(${EMULATOR_TARGET} PROPERTIES OUTPUT_NAME ${EMULATOR_OUTPUT_NAME})
###############################################################################
### FPGA Simulator
###############################################################################
add_executable(${SIMULATOR_TARGET} EXCLUDE_FROM_ALL ${SOURCE_FILES})
target_compile_options(${SIMULATOR_TARGET} PRIVATE ${COMMON_COMPILE_FLAGS})
target_compile_options(${SIMULATOR_TARGET} PRIVATE ${SIMULATOR_COMPILE_FLAGS})
target_link_libraries(${SIMULATOR_TARGET} ${COMMON_LINK_FLAGS})
target_link_libraries(${SIMULATOR_TARGET} ${SIMULATOR_LINK_FLAGS})
set_target_properties(${SIMULATOR_TARGET} PROPERTIES OUTPUT_NAME ${SIMULATOR_OUTPUT_NAME})
###############################################################################
### Generate Report
###############################################################################
add_executable(${REPORT_TARGET} EXCLUDE_FROM_ALL ${SOURCE_FILES})
target_compile_options(${REPORT_TARGET} PRIVATE ${COMMON_COMPILE_FLAGS})
target_compile_options(${REPORT_TARGET} PRIVATE ${REPORT_COMPILE_FLAGS})
# The report target does not need the QACTYPES flag at link stage
set(MODIFIED_COMMON_LINK_FLAGS_REPORT ${COMMON_LINK_FLAGS})
list(REMOVE_ITEM MODIFIED_COMMON_LINK_FLAGS_REPORT ${QACTYPES})
target_link_libraries(${REPORT_TARGET} ${MODIFIED_COMMON_LINK_FLAGS_REPORT})
target_link_libraries(${REPORT_TARGET} ${REPORT_LINK_FLAGS})
set_target_properties(${REPORT_TARGET} PROPERTIES OUTPUT_NAME ${REPORT_OUTPUT_NAME})
###############################################################################
### FPGA Hardware
###############################################################################
add_executable(${FPGA_TARGET} EXCLUDE_FROM_ALL ${SOURCE_FILES})
target_compile_options(${FPGA_TARGET} PRIVATE ${COMMON_COMPILE_FLAGS})
target_compile_options(${FPGA_TARGET} PRIVATE ${FPGA_COMPILE_FLAGS})
target_link_libraries(${FPGA_TARGET} ${COMMON_LINK_FLAGS})
target_link_libraries(${FPGA_TARGET} ${FPGA_LINK_FLAGS})
set_target_properties(${FPGA_TARGET} PROPERTIES OUTPUT_NAME ${FPGA_OUTPUT_NAME})
###############################################################################
### This part only manipulates cmake variables to print the commands cmake is expected to run to the user
###############################################################################
# set the correct object file extension depending on the target platform
if(WIN32)
set(OBJ_EXTENSION "obj")
else()
set(OBJ_EXTENSION "o")
endif()
# Set the source file names in a string
set(SOURCE_FILE_NAME "${SOURCE_FILES}")
function(getCompileCommands common_compile_flags special_compile_flags common_link_flags special_link_flags target output_name)
set(file_names ${SOURCE_FILE_NAME})
set(COMPILE_COMMAND )
set(LINK_COMMAND )
foreach(source ${file_names})
# Get the relative path to the source and object files
file(RELATIVE_PATH CURRENT_SOURCE_FILE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/${source})
file(RELATIVE_PATH OBJ_FILE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${target}.dir/${source}.${OBJ_EXTENSION})
# Creating a string that contains the compile command
# Start by the compiler invocation
set(COMPILE_COMMAND "${COMPILE_COMMAND}${CMAKE_CXX_COMPILER}")
# Add all the potential includes
foreach(INCLUDE ${USER_INCLUDE_PATHS})
if(NOT IS_ABSOLUTE ${INCLUDE})
file(RELATIVE_PATH INCLUDE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/${INCLUDE})
endif()
set(COMPILE_COMMAND "${COMPILE_COMMAND} -I${INCLUDE}")
endforeach()
# Add all the common compile flags
foreach(FLAG ${common_compile_flags})
set(COMPILE_COMMAND "${COMPILE_COMMAND} ${FLAG}")
endforeach()
# Add all the specific compile flags
foreach(FLAG ${special_compile_flags})
set(COMPILE_COMMAND "${COMPILE_COMMAND} ${FLAG}")
endforeach()
# Get the location of the object file
file(RELATIVE_PATH OBJ_FILE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${target}.dir/${source}.${OBJ_EXTENSION})
# Add the source file and the output file
set(COMPILE_COMMAND "${COMPILE_COMMAND} -c ${CURRENT_SOURCE_FILE} -o ${OBJ_FILE}\n")
endforeach()
set(COMPILE_COMMAND "${COMPILE_COMMAND}" PARENT_SCOPE)
# Creating a string that contains the link command
# Start by the compiler invocation
set(LINK_COMMAND "${LINK_COMMAND}${CMAKE_CXX_COMPILER}")
# Add all the common link flags
foreach(FLAG ${common_link_flags})
set(LINK_COMMAND "${LINK_COMMAND} ${FLAG}")
endforeach()
# Add all the specific link flags
foreach(FLAG ${special_link_flags})
set(LINK_COMMAND "${LINK_COMMAND} ${FLAG}")
endforeach()
# Add the output file
set(LINK_COMMAND "${LINK_COMMAND} -o ${output_name}")
foreach(source ${file_names})
# Get the relative path to the source and object files
file(RELATIVE_PATH OBJ_FILE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${target}.dir/${source}.${OBJ_EXTENSION})
# Add the source file and the output file
set(LINK_COMMAND "${LINK_COMMAND} ${OBJ_FILE}")
endforeach()
# Add all the potential library paths
foreach(LIB_PATH ${USER_LIB_PATHS})
if(NOT IS_ABSOLUTE ${LIB_PATH})
file(RELATIVE_PATH LIB_PATH ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/${LIB_PATH})
endif()
if(NOT WIN32)
set(LINK_COMMAND "${LINK_COMMAND} -L${LIB_PATH}")
else()
set(LINK_COMMAND "${LINK_COMMAND} -L${LIB_PATH} -Wl,-rpath,${LIB_PATH}")
endif()
endforeach()
# Add all the potential includes
foreach(LIB ${USER_LIBS})
set(LINK_COMMAND "${LINK_COMMAND} -l${LIB}")
endforeach()
set(LINK_COMMAND "${LINK_COMMAND}" PARENT_SCOPE)
endfunction()
# Windows executable is going to have the .exe extension
if(WIN32)
set(EXECUTABLE_EXTENSION ".exe")
endif()
# Display the compile instructions in the emulation flow
getCompileCommands("${COMMON_COMPILE_FLAGS}" "${EMULATOR_COMPILE_FLAGS}" "${COMMON_LINK_FLAGS}" "${EMULATOR_LINK_FLAGS}" "${EMULATOR_TARGET}" "${EMULATOR_OUTPUT_NAME}${EXECUTABLE_EXTENSION}")
add_custom_target( displayEmulationCompileCommands
${CMAKE_COMMAND} -E cmake_echo_color --cyan ""
COMMENT "\nTo compile manually:\n${COMPILE_COMMAND}\nTo link manually:\n${LINK_COMMAND}")
add_dependencies(${EMULATOR_TARGET} displayEmulationCompileCommands)
# Display the compile instructions in the simulation flow
getCompileCommands("${COMMON_COMPILE_FLAGS}" "${SIMULATOR_COMPILE_FLAGS}" "${COMMON_LINK_FLAGS}" "${SIMULATOR_LINK_FLAGS}" "${SIMULATOR_TARGET}" "${SIMULATOR_OUTPUT_NAME}${EXECUTABLE_EXTENSION}")
add_custom_target( displaySimulationCompileCommands
${CMAKE_COMMAND} -E cmake_echo_color --cyan ""
COMMENT "\nTo compile manually:\n${COMPILE_COMMAND}\nTo link manually:\n${LINK_COMMAND}")
add_dependencies(${SIMULATOR_TARGET} displaySimulationCompileCommands)
# Display the compile instructions in the report flow
getCompileCommands("${COMMON_COMPILE_FLAGS}" "${REPORT_COMPILE_FLAGS}" "${MODIFIED_COMMON_LINK_FLAGS_REPORT}" "${REPORT_LINK_FLAGS}" "${REPORT_TARGET}" "${REPORT_OUTPUT_NAME}${EXECUTABLE_EXTENSION}")
add_custom_target( displayReportCompileCommands
${CMAKE_COMMAND} -E cmake_echo_color --cyan ""
COMMENT "\nTo compile manually:\n${COMPILE_COMMAND}\nTo link manually:\n${LINK_COMMAND}")
add_dependencies(${REPORT_TARGET} displayReportCompileCommands)
# Display the compile instructions in the fpga flow
getCompileCommands("${COMMON_COMPILE_FLAGS}" "${FPGA_COMPILE_FLAGS}" "${COMMON_LINK_FLAGS}" "${FPGA_LINK_FLAGS}" "${FPGA_TARGET}" "${FPGA_OUTPUT_NAME}${EXECUTABLE_EXTENSION}")
add_custom_target( displayFPGACompileCommands
${CMAKE_COMMAND} -E cmake_echo_color --cyan ""
COMMENT "\nTo compile manually:\n${COMPILE_COMMAND}\nTo link manually:\n${LINK_COMMAND}")
add_dependencies(${FPGA_TARGET} displayFPGACompileCommands)