-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathAddHDLModelSim.cmake
308 lines (248 loc) · 9.04 KB
/
AddHDLModelSim.cmake
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
# Copyright 2018 Tymoteusz Blazejczyk
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if (COMMAND add_hdl_modelsim)
return()
endif()
find_package(ModelSim)
if (NOT DEFINED _HDL_CMAKE_ROOT_DIR)
set(_HDL_CMAKE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL
"HDL CMake root directory" FORCE)
endif()
if (MODELSIM_FOUND)
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/modelsim/libraries")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/modelsim/libraries/.placeholders")
if (NOT EXISTS "${CMAKE_BINARY_DIR}/modelsim/libraries/work/_info")
execute_process(
COMMAND
${MODELSIM_VLIB}
work
WORKING_DIRECTORY
"${CMAKE_BINARY_DIR}/modelsim/libraries"
OUTPUT_QUIET
)
endif()
if (NOT EXISTS "${CMAKE_BINARY_DIR}/modelsim/libraries/modelsim.ini")
execute_process(
COMMAND
${MODELSIM_VMAP}
work
"${CMAKE_BINARY_DIR}/modelsim/libraries/work"
WORKING_DIRECTORY
"${CMAKE_BINARY_DIR}/modelsim/libraries"
OUTPUT_QUIET
)
endif()
if (NOT TARGET modelsim-compile-all)
add_custom_target(modelsim-compile-all ALL)
endif()
endif()
function(add_hdl_modelsim)
if (NOT MODELSIM_FOUND)
return()
endif()
if (DEFINED ARG_COMPILE_EXCLUDE)
if (ARG_COMPILE_EXCLUDE MATCHES ModelSim)
return()
endif()
endif()
if (DEFINED ARG_COMPILE)
if (NOT ARG_COMPILE MATCHES ALL AND NOT ARG_COMPILE MATCHES ModelSim)
return()
endif()
endif()
if (TARGET modelsim-compile-${ARG_NAME})
message(FATAL_ERROR "ModelSim target ${ARG_NAME} already exist")
endif()
if (NOT ARG_TYPE MATCHES Verilog AND NOT ARG_TYPE MATCHES VHDL AND
NOT ARG_TYPE MATCHES Qsys)
return()
endif()
set(modelsim_libraries_dir "${CMAKE_BINARY_DIR}/modelsim/libraries")
set(modelsim_library_dir "${modelsim_libraries_dir}/${ARG_NAME}")
set(modelsim_ini_file "${_HDL_CMAKE_ROOT_DIR}/modelsim.ini")
set(modelsim_flags "")
set(modelsim_vcom_flags "")
set(modelsim_vlog_flags "")
list(APPEND modelsim_flags -modelsimini "${modelsim_ini_file}")
if (ARG_TYPE MATCHES SystemVerilog OR ARG_TYPE MATCHES Qsys)
list(APPEND modelsim_vlog_flags -sv)
endif()
foreach (hdl_define ${ARG_DEFINES})
list(APPEND modelsim_vlog_flags +define+${hdl_define})
endforeach()
foreach (hdl_include ${ARG_INCLUDES})
list(APPEND modelsim_vlog_flags +incdir+"${hdl_include}")
endforeach()
list(APPEND modelsim_vcom_flags -2008)
if (ARG_MODELSIM_LINT)
list(APPEND modelsim_flags -lint)
endif()
if (ARG_MODELSIM_PEDANTICERRORS)
list(APPEND modelsim_flags -pedanticerrors)
endif()
if (ARG_MODELSIM_WARNING_AS_ERROR)
list(APPEND modelsim_flags -warning error)
endif()
list(APPEND modelsim_flags -work ${ARG_NAME})
if (DEFINED ARG_MODELSIM_SUPPRESS)
list(LENGTH ARG_MODELSIM_SUPPRESS len)
if (len GREATER 0)
list(GET ARG_MODELSIM_SUPPRESS 0 suppress)
list(REMOVE_AT ARG_MODELSIM_SUPPRESS 0)
foreach (value ${ARG_MODELSIM_SUPPRESS})
set(suppress "${suppress},${value}")
endforeach()
list(APPEND modelsim_flags -suppress ${suppress})
endif()
endif()
if (ARG_MODELSIM_FLAGS)
list(APPEND modelsim_flags ${ARG_MODELSIM_FLAGS})
endif()
set(modelsim_sources "")
set(modelsim_depends "")
set(modelsim_includes "")
set(modelsim_libraries "")
list(APPEND modelsim_sources
${ARG_MODELSIM_SOURCES}
${ARG_SOURCES}
${ARG_SOURCE}
)
list(APPEND modelsim_includes ${ARG_INCLUDES})
get_hdl_depends(${ARG_NAME} depends)
foreach (name ${depends})
get_target_property(hdl_compile_exclude ${name} HDL_COMPILE_EXCLUDE)
if (hdl_compile_exclude MATCHES ModelSim)
continue()
endif()
get_target_property(hdl_compile ${name} HDL_COMPILE)
if (NOT hdl_compile MATCHES ALL AND NOT hdl_compile MATCHES ModelSim)
continue()
endif()
get_target_property(hdl_package ${name} HDL_PACKAGE)
if (hdl_package)
get_target_property(hdl_source ${name} HDL_SOURCE)
list(APPEND modelsim_sources "${hdl_source}")
list(APPEND modelsim_depends modelsim-compile-${name})
get_target_property(hdl_includes ${name} HDL_INCLUDES)
foreach (hdl_include ${hdl_includes})
list(APPEND modelsim_includes "${hdl_include}")
endforeach()
list(APPEND modelsim_libraries ${name})
endif()
endforeach()
list(REMOVE_DUPLICATES modelsim_depends)
list(REMOVE_DUPLICATES modelsim_sources)
list(REMOVE_DUPLICATES modelsim_includes)
if (modelsim_libraries)
list(APPEND modelsim_flags -Ldir "${CMAKE_BINARY_DIR}/modelsim/libraries")
endif()
foreach (modelsim_library ${modelsim_libraries})
list(APPEND modelsim_flags -L ${modelsim_library})
endforeach()
set(modelsim_vcom_sources "")
set(modelsim_vlog_sources "")
foreach (modelsim_source ${ARG_SOURCES})
if (modelsim_source MATCHES "\.s?v$")
list(APPEND modelsim_vlog_sources "${modelsim_source}")
elseif (modelsim_source MATCHES "\.vhd$")
list(APPEND modelsim_vcom_sources "${modelsim_source}")
endif()
endforeach()
get_target_property(modelsim_files ${ARG_NAME} HDL_MODELSIM_VCOM_FILES)
list(APPEND modelsim_sources ${modelsim_files})
foreach (modelsim_file ${modelsim_files})
list(APPEND modelsim_vcom_flags -f ${modelsim_file})
endforeach()
get_target_property(modelsim_files ${ARG_NAME} HDL_MODELSIM_VLOG_FILES)
list(APPEND modelsim_sources ${modelsim_files})
foreach (modelsim_file ${modelsim_files})
list(APPEND modelsim_vlog_flags -f ${modelsim_file})
endforeach()
if (ARG_TYPE MATCHES Verilog)
list(APPEND modelsim_vlog_sources "${ARG_SOURCE}")
elseif (ARG_TYPE MATCHES VHDL)
list(APPEND modelsim_vcom_sources "${ARG_SOURCE}")
elseif (ARG_TYPE MATCHES Qsys)
list(APPEND modelsim_depends qsys-compile-${ARG_NAME})
endif()
set(modelsim_commands "")
if (modelsim_vcom_sources)
list(APPEND modelsim_commands
COMMAND
${MODELSIM_VCOM}
ARGS
${modelsim_flags}
${modelsim_vcom_flags}
${modelsim_vcom_sources}
)
endif()
if (modelsim_vlog_sources)
list(APPEND modelsim_commands
COMMAND
${MODELSIM_VLOG}
ARGS
${modelsim_flags}
${modelsim_vlog_flags}
${modelsim_vlog_sources}
)
endif()
if (modelsim_commands)
add_custom_command(
OUTPUT
"${modelsim_libraries_dir}/.placeholders/${ARG_NAME}"
COMMAND
${MODELSIM_VLIB}
ARGS
${ARG_NAME}
COMMAND
${CMAKE_COMMAND}
ARGS
-E touch
"${modelsim_libraries_dir}/.placeholders/${ARG_NAME}"
WORKING_DIRECTORY
"${modelsim_libraries_dir}"
COMMENT
"ModelSim creating library ${ARG_NAME}"
)
add_custom_command(
OUTPUT
"${modelsim_library_dir}/_info"
"${modelsim_library_dir}/_vmake"
"${modelsim_library_dir}/_lib.qdb"
${modelsim_commands}
DEPENDS
${modelsim_sources}
${modelsim_includes}
"${modelsim_ini_file}"
"${modelsim_libraries_dir}/.placeholders/${ARG_NAME}"
WORKING_DIRECTORY
"${modelsim_libraries_dir}"
COMMENT
"ModelSim compiling ${ARG_NAME}"
)
add_custom_target(modelsim-compile-${ARG_NAME}
DEPENDS
"${modelsim_library_dir}/_info"
"${modelsim_library_dir}/_vmake"
"${modelsim_library_dir}/_lib.qdb"
)
else()
add_custom_target(modelsim-compile-${ARG_NAME})
endif()
if (modelsim_depends)
add_dependencies(modelsim-compile-${ARG_NAME} ${modelsim_depends})
endif()
add_dependencies(modelsim-compile-all modelsim-compile-${ARG_NAME})
add_dependencies(${ARG_NAME} modelsim-compile-${ARG_NAME})
endfunction()