forked from open-simh/simh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_simulator.cmake
426 lines (361 loc) · 15.5 KB
/
add_simulator.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
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
## Put everything together into one nice function.
include (CTest)
## Regenerate the git commit ID if git exists.
find_program(GIT_COMMAND git)
if (GIT_COMMAND)
message(STATUS "Git command is ${GIT_COMMAND}")
else ()
message(STATUS "Git not found -- will not update or include .git-commit-id.h")
endif ()
add_custom_target(update_sim_commit ALL
COMMAND ${CMAKE_COMMAND}
-D GIT_COMMIT_DEST=${CMAKE_SOURCE_DIR}
-P ${CMAKE_SOURCE_DIR}/cmake/git-commit-id.cmake
BYPRODUCTS
${CMAKE_SOURCE_DIR}/.git-commit-id
${CMAKE_SOURCE_DIR}/.git-commit-id.h
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
)
## Simulator sources and library:
set(SIM_SOURCES
${CMAKE_SOURCE_DIR}/scp.c
${CMAKE_SOURCE_DIR}/sim_card.c
${CMAKE_SOURCE_DIR}/sim_console.c
${CMAKE_SOURCE_DIR}/sim_disk.c
${CMAKE_SOURCE_DIR}/sim_ether.c
${CMAKE_SOURCE_DIR}/sim_fio.c
${CMAKE_SOURCE_DIR}/sim_imd.c
${CMAKE_SOURCE_DIR}/sim_scsi.c
${CMAKE_SOURCE_DIR}/sim_serial.c
${CMAKE_SOURCE_DIR}/sim_sock.c
${CMAKE_SOURCE_DIR}/sim_tape.c
${CMAKE_SOURCE_DIR}/sim_timer.c
${CMAKE_SOURCE_DIR}/sim_tmxr.c
${CMAKE_SOURCE_DIR}/sim_video.c)
set(SIM_VIDEO_SOURCES
${CMAKE_SOURCE_DIR}/display/display.c
${CMAKE_SOURCE_DIR}/display/sim_ws.c)
function(build_simcore _targ)
cmake_parse_arguments(SIMH "VIDEO;INT64;ADDR64;BESM6_SDL_HACK" "" "" ${ARGN})
add_library(${_targ} STATIC ${SIM_SOURCES})
# Components that need to be turned on while building the library, but
# don't export out to the dependencies (hence PRIVATE.)
set_target_properties(${_targ} PROPERTIES
C_STANDARD 99
)
target_compile_definitions(${_targ} PRIVATE USE_SIM_CARD USE_SIM_IMD)
target_compile_options(${_targ} PRIVATE ${EXTRA_TARGET_CFLAGS})
target_link_options(${_targ} PRIVATE ${EXTRA_TARGET_LFLAGS})
# Make sure that the top-level directory is part of the libary's include path:
target_include_directories("${_targ}" PUBLIC "${CMAKE_SOURCE_DIR}")
if (SIMH_INT64)
target_compile_definitions(${_targ} PUBLIC USE_INT64)
endif (SIMH_INT64)
if (SIMH_ADDR64)
target_compile_definitions(${_targ} PUBLIC USE_ADDR64)
endif (SIMH_ADDR64)
if (SIMH_VIDEO)
if (WITH_VIDEO)
# It's the video library
target_sources(${_targ} PRIVATE ${SIM_VIDEO_SOURCES})
target_link_libraries(${_targ} PUBLIC simh_video)
endif ()
if (CMAKE_HOST_APPLE AND NOT SIMH_BESM6_SDL_HACK)
## (a) The BESM6 SDL hack is temporary. If SDL_MAIN_AVAILABLE needs
## to be defined, it belongs in the simh_video interface library.
## (b) BESM6 doesn't use SIMH's video capabilities correctly and
## the makefile filters out SDL_MAIN_AVAILABLE on macOS.
## (c) This shouldn't be just an Apple platform quirk; SDL_main should
## be used by all platforms. <sigh!>
target_compile_definitions("${_targ}" PUBLIC SDL_MAIN_AVAILABLE)
endif ()
endif ()
target_link_libraries(${_targ} PUBLIC
simh_network
simh_regexp
os_features
thread_lib
)
# Define SIM_BUILD_TOOL for the simulator'
target_compile_definitions("${_targ}" PRIVATE
"SIM_BUILD_TOOL=CMake (${CMAKE_GENERATOR})"
)
# Ensure that sim_rev.h picks up .git-commit-id.h if the git command is
# available.
if (GIT_COMMAND)
target_compile_definitions("${_targ}" PRIVATE SIM_NEED_GIT_COMMIT_ID)
endif ()
add_dependencies(${_targ} update_sim_commit)
# Create target cppcheck rule, if detected.
if (ENABLE_CPPCHECK AND cppcheck_cmd)
get_property(cppcheck_includes TARGET ${_targ} PROPERTY INCLUDE_DIRECTORIES)
get_property(cppcheck_defines TARGET ${_targ} PROPERTY COMPILE_DEFINITIONS)
list(TRANSFORM cppcheck_includes PREPEND "-I")
list(TRANSFORM cppcheck_defines PREPEND "-D")
add_custom_target("${_targ}_cppcheck"
COMMAND ${cppcheck_cmd} ${cppcheck_defines} ${cppcheck_includes} ${SIM_SOURCES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
VERBATIM
)
add_dependencies(cppcheck "${_targ}_cppcheck")
endif (ENABLE_CPPCHECK AND cppcheck_cmd)
endfunction(build_simcore _targ)
##+
## Basic template for simh executables and unit tests.
##-
## FEATURE_INT64: Use the simhi64 library (defines USE_INT64)
## FEATURE_FULL64: Use the simhz64 library (defines USE_INT64, USE_ADDR64)
## BUILDROMS: Build the hardcoded boot rooms
## FEATURE_VIDEO: Add video support
## FEATURE_DISPLAY: Add display support
##
## BESM6_SDL_HACK: A TEMPORARY feature to work around issues with BESM6 and
## SDL and SIMH video. Because it's a day ending in "y", there's going to
## be another makefile quirk.
list(APPEND ADD_SIMULATOR_OPTIONS
"FEATURE_INT64"
"FEATURE_FULL64"
"BUILDROMS"
"FEATURE_VIDEO"
"FEATURE_DISPLAY"
"NO_INSTALL"
"BESM6_SDL_HACK"
)
## TEST: The test script name that will be executed by the simulator within CTest.
## LABEL: The test name label, used to group tests, e.g., "VAX" for all of the
## VAX simulator tests. If you want to run a subset of tests, add the "-L <regexp>"
## argument to the ctest command line.
## PKG_FAMILY: The simulator family to which a simulator belongs. If not specificed,
## defaults to "default_family".
list(APPEND ADD_SIMULATOR_1ARG
"TEST"
"LABEL"
"PKG_FAMILY"
)
## DEFINES: List of extra command line manifest constants ("-D" items)
## INCLUDES: List of extra include directories
## SOURCES: List of source files
list(APPEND ADD_SIMULATOR_NARG
"DEFINES"
"INCLUDES"
"SOURCES"
)
function (simh_executable_template _targ)
cmake_parse_arguments(SIMH "${ADD_SIMULATOR_OPTIONS}" "${ADD_SIMULATOR_1ARG}" "${ADD_SIMULATOR_NARG}" ${ARGN})
if (NOT DEFINED SIMH_SOURCES)
message(FATAL_ERROR "${_targ}: No source files?")
endif (NOT DEFINED SIMH_SOURCES)
add_executable("${_targ}" "${SIMH_SOURCES}")
set_target_properties(${_targ} PROPERTIES
C_STANDARD 99
RUNTIME_OUTPUT_DIRECTORY ${SIMH_LEGACY_INSTALL}
)
target_compile_options(${_targ} PRIVATE ${EXTRA_TARGET_CFLAGS})
target_link_options(${_targ} PRIVATE ${EXTRA_TARGET_LFLAGS})
if (MINGW)
## target_compile_options(${_targ} PUBLIC "-fms-extensions")
target_link_options(${_targ} PUBLIC "-mconsole")
elseif (MSVC)
target_link_options(${_targ} PUBLIC "/SUBSYSTEM:CONSOLE")
endif ()
if (DEFINED SIMH_DEFINES)
target_compile_definitions("${_targ}" PUBLIC "${SIMH_DEFINES}")
endif (DEFINED SIMH_DEFINES)
# This is a quick cheat to make sure that all of the include paths are
# absolute paths.
if (DEFINED SIMH_INCLUDES)
set(_normalized_includes)
foreach (inc IN LISTS SIMH_INCLUDES)
if (NOT IS_ABSOLUTE "${inc}")
message(">> Fixing include for ${_targ}: ${inc} -> ${CMAKE_SOURCE_DIR}/${inc}")
get_filename_component(inc "${CMAKE_SOURCE_DIR}/${inc}" ABSOLUTE)
endif ()
list(APPEND _normalized_includes "${inc}")
endforeach ()
target_include_directories("${_targ}" PUBLIC "${_normalized_includes}")
endif ()
if (WITH_VIDEO)
if (SIMH_FEATURE_DISPLAY)
target_compile_definitions(${_targ} PUBLIC USE_DISPLAY)
endif ()
endif ()
set(SIMH_SIMLIB simhcore)
if (SIMH_FEATURE_INT64)
set(SIMH_SIMLIB simhi64)
elseif (SIMH_FEATURE_FULL64)
set(SIMH_SIMLIB simhz64)
endif ()
if (SIMH_FEATURE_VIDEO OR SIMH_FEATURE_DISPLAY)
if (NOT SIMH_BESM6_SDL_HACK)
string(APPEND SIMH_SIMLIB "_video")
else ()
string(APPEND SIMH_SIMLIB "_besm6")
endif ()
endif ()
target_link_libraries("${_targ}" PUBLIC "${SIMH_SIMLIB}")
endfunction ()
function (add_simulator _targ)
simh_executable_template(${_targ} "${ARGN}")
cmake_parse_arguments(SIMH "${ADD_SIMULATOR_OPTIONS}" "${ADD_SIMULATOR_1ARG}" "${ADD_SIMULATOR_NARG}" ${ARGN})
set(pkg_family "default_family")
if (SIMH_PKG_FAMILY)
set(pkg_family ${SIMH_PKG_FAMILY})
endif ()
set(_install_opts)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.21")
list(APPEND _install_opts RUNTIME_DEPENDENCY_SET simhRuntime)
endif ()
install(TARGETS ${_targ}
${_install_opts}
RUNTIME
COMPONENT ${pkg_family}
)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.21")
## Collect runtime dependencies. The simhRuntime install() is invoked by cpack-setup.cmake
install(IMPORTED_RUNTIME_ARTIFACTS ${_targ} COMPONENT ${pkg_family} BUNDLE COMPONENT ${pkg_family})
endif()
## Simulator-specific tests:
list(APPEND test_cmd "${_targ}" "RegisterSanityCheck")
if (DEFINED SIMH_TEST)
string(APPEND test_fname ${CMAKE_CURRENT_SOURCE_DIR} "/tests/${SIMH_TEST}_test.ini")
IF (EXISTS "${test_fname}")
list(APPEND test_cmd "${test_fname}" "-v")
ENDIF ()
endif ()
add_test(NAME "simh-${_targ}" COMMAND ${test_cmd})
if (SIMH_LABEL)
set_tests_properties("simh-${_targ}" PROPERTIES LABELS "simh-${SIMH_LABEL}")
endif ()
if (BUILD_SHARED_DEPS)
## Make sure that the tests can find the DLLs/shared objects:
file(TO_NATIVE_PATH "${SIMH_DEP_TOPDIR}/bin" native_dep_bindir)
file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}" native_binary_dir)
endif ()
## Build up test environment:
## - Simulators that link SDL2 need to use the dummy (null) drivers on tests within
## the CI/CD environment. While not STRICTLY necessary, it's a good idea.
list(APPEND test_add_env "SDL_VIDEODRIVER=dummy")
list(APPEND test_add_env "SDL_AUDIODRIVER=dummy")
if (WIN32)
if (BUILD_SHARED_DEPS)
set(test_path "PATH=${native_dep_bindir}\\\$<SEMICOLON>${native_binary_dir}\\$<SEMICOLON>")
string(REPLACE ";" "\\\$<SEMICOLON>" escaped_path "$ENV{PATH}")
string(APPEND test_path "${escaped_path}")
list(APPEND test_add_env "${test_path}")
endif ()
else ()
if (BUILD_SHARED_DEPS)
list(APPEND test_add_env "LD_LIBRARY_PATH=${native_dep_bindir}:${native_binary_dir}:\$LD_LIBRARY_PATH")
endif ()
endif ()
set_property(TEST "simh-${_targ}" PROPERTY ENVIRONMENT "${test_add_env}")
if (DONT_USE_ROMS)
target_compile_definitions(DONT_USE_INTERNAL_ROM)
elseif (SIMH_BUILDROMS)
add_dependencies(${_targ} BuildROMs)
endif ()
# Create target 'cppcheck' rule, if cppcheck detected:
if (ENABLE_CPPCHECK AND cppcheck_cmd)
get_property(cppcheck_includes TARGET ${_targ} PROPERTY INCLUDE_DIRECTORIES)
get_property(cppcheck_defines TARGET ${_targ} PROPERTY COMPILE_DEFINITIONS)
list(TRANSFORM cppcheck_includes PREPEND "-I")
list(TRANSFORM cppcheck_defines PREPEND "-D")
add_custom_target("${_targ}_cppcheck"
COMMAND ${cppcheck_cmd} ${cppcheck_defines} ${cppcheck_includes} ${SIMH_SOURCES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_dependencies(cppcheck "${_targ}_cppcheck")
endif (ENABLE_CPPCHECK AND cppcheck_cmd)
endfunction ()
function(add_unit_test _targ)
set(UNIT_TARGET "simbase-${_targ}")
set(UNIT_TEST "simbase-${_targ}")
simh_executable_template(${UNIT_TARGET} "${ARGN}")
cmake_parse_arguments(SIMH "FEATURE_INT64;FEATURE_FULL64;BUILDROMS;FEATURE_VIDEO,FEATURE_DISPLAY"
"SOURCE_DIR;LABEL"
"DEFINES;INCLUDES;SOURCES"
${ARGN})
target_link_libraries(${UNIT_TARGET} PUBLIC unittest)
add_test(NAME ${UNIT_TEST} COMMAND ${UNIT_TARGET})
set(TEST_LABEL "simbase;unit")
if (SIMH_LABEL)
list(APPEND TEST_LABEL "simbase-${SIMH_LABEL}")
endif ()
set_tests_properties(${UNIT_TEST} PROPERTIES LABELS "${TEST_LABEL}")
endfunction ()
##~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
## Now build things!
##~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
if (ENABLE_CPPCHECK AND cppcheck_cmd)
add_custom_target(cppcheck)
endif ()
build_simcore(simhcore)
build_simcore(simhi64 INT64)
build_simcore(simhz64 INT64 ADDR64)
build_simcore(simhcore_video VIDEO)
build_simcore(simhi64_video VIDEO INT64)
build_simcore(simhz64_video VIDEO INT64 ADDR64)
## Temporary hack for BESM6's breakage.
build_simcore(simhi64_besm6 VIDEO INT64 BESM6_SDL_HACK)
if (NOT DONT_USE_ROMS)
add_executable(BuildROMs sim_BuildROMs.c)
target_include_directories(BuildROMs PUBLIC "${CMAKE_SOURCE_DIR}")
target_link_libraries(BuildROMs os_features)
add_custom_command(
OUTPUT
${CMAKE_SOURCE_DIR}/VAX/vax_ka655x_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka620_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka630_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka610_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka410_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka411_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka412_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka41a_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka41d_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka42a_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka42b_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka43a_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka46a_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka47a_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka48a_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_is1000_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka410_xs_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka420_rdrz_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka420_rzrz_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka4xx_4pln_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka4xx_8pln_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka4xx_dz_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka4xx_spx_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka750_bin_new.h
${CMAKE_SOURCE_DIR}/VAX/vax_ka750_bin_old.h
${CMAKE_SOURCE_DIR}/VAX/vax_vcb02_bin.h
${CMAKE_SOURCE_DIR}/VAX/vax_vmb_exe.h
${CMAKE_SOURCE_DIR}/PDP11/pdp11_vt_lunar_rom.h
${CMAKE_SOURCE_DIR}/PDP11/pdp11_dazzle_dart_rom.h
${CMAKE_SOURCE_DIR}/PDP11/pdp11_11logo_rom.h
${CMAKE_SOURCE_DIR}/swtp6800/swtp6800/swtp_swtbugv10_bin.h
MAIN_DEPENDENCY BuildROMs
COMMAND BuildROMS
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif ()
## Front panel test.
##
## From all evidence in makefile, sim_frontpanel isn't used yet by any targets.
##
## Needs curses...
add_executable(frontpaneltest
${CMAKE_SOURCE_DIR}/frontpanel/FrontPanelTest.c
${CMAKE_SOURCE_DIR}/sim_sock.c
${CMAKE_SOURCE_DIR}/sim_frontpanel.c)
target_include_directories(frontpaneltest PUBLIC "${CMAKE_SOURCE_DIR}")
target_link_libraries(frontpaneltest PUBLIC os_features thread_lib)
if (WIN32)
target_link_libraries(frontpaneltest PUBLIC simh_network)
if (MSVC)
target_link_options(frontpaneltest PUBLIC "/SUBSYSTEM:CONSOLE")
elseif (MINGW)
target_link_options(frontpaneltest PUBLIC "-mconsole")
endif ()
endif (WIN32)