@@ -40,11 +40,16 @@ set(UNICORN_VERSION_PATCH 0)
40
40
41
41
include (bundle_static.cmake)
42
42
43
+ # Even though we generate shared lib and static archive at the same time, we still support
44
+ # using unicorn as a subdirectory so we have to respect BUILD_SHARED_LIBS.
45
+ #
46
+ # Also we would like users to link a native cmake target, instead of a custom target for better
47
+ # compatability.
43
48
option (BUILD_SHARED_LIBS "Build shared instead of static library" ${PROJECT_IS_TOP_LEVEL} )
44
49
option (UNICORN_FUZZ "Enable fuzzing" OFF )
45
50
option (UNICORN_BUILD_TESTS "Build unicorn tests" ${PROJECT_IS_TOP_LEVEL} )
46
51
option (UNICORN_INSTALL "Enable unicorn installation" ${PROJECT_IS_TOP_LEVEL} )
47
- set (UNICORN_ARCH "x86;arm;aarch64;riscv;mips;sparc;m68k;ppc;s390x" CACHE STRING "Enabled unicorn architectures" )
52
+ set (UNICORN_ARCH "x86;arm;aarch64;riscv;mips;sparc;m68k;ppc;s390x;tricore " CACHE STRING "Enabled unicorn architectures" )
48
53
option (UNICORN_TRACER "Trace unicorn execution" OFF )
49
54
50
55
foreach (ARCH_LOOP ${UNICORN_ARCH} )
@@ -119,7 +124,7 @@ else()
119
124
string (FIND "${UC_COMPILER_VERSION} " "i686" UC_RET)
120
125
if (${UC_RET} GREATER_EQUAL "0" )
121
126
set (UNICORN_TARGET_ARCH "i386" )
122
- set (UNICORN_CFLAGS -m32)
127
+ set (UNICORN_CFLAGS -m32 - static -libgcc) # Workaround for github action bugs
123
128
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32" )
124
129
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32" )
125
130
else ()
@@ -209,6 +214,11 @@ else()
209
214
set (UNICORN_TARGET_ARCH "s390" )
210
215
break ()
211
216
endif ()
217
+ string (FIND ${UC_COMPILER_MACRO} "__tricore__" UC_RET)
218
+ if (${UC_RET} GREATER_EQUAL "0" )
219
+ set (UNICORN_TARGET_ARCH "tricore" )
220
+ break ()
221
+ endif ()
212
222
message (FATAL_ERROR "Unknown host compiler: ${CMAKE_C_COMPILER} ." )
213
223
endwhile (TRUE )
214
224
endif ()
@@ -241,6 +251,9 @@ else()
241
251
if (UNICORN_HAS_S390X)
242
252
set (EXTRA_CFLAGS "${EXTRA_CFLAGS} -DUNICORN_HAS_S390X " )
243
253
endif ()
254
+ if (UNICORN_HAS_TRICORE)
255
+ set (EXTRA_CFLAGS "${EXTRA_CFLAGS} -DUNICORN_HAS_TRICORE " )
256
+ endif ()
244
257
245
258
set (EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC" )
246
259
if (ANDROID_ABI)
@@ -282,6 +295,9 @@ else()
282
295
if (UNICORN_HAS_S390X)
283
296
set (TARGET_LIST "${TARGET_LIST} s390x-softmmu, " )
284
297
endif ()
298
+ if (UNICORN_HAS_TRICORE)
299
+ set (TARGET_LIST "${TARGET_LIST} tricore-softmmu, " )
300
+ endif ()
285
301
set (TARGET_LIST "${TARGET_LIST} " )
286
302
287
303
# GEN config-host.mak & target directories
@@ -373,6 +389,12 @@ else()
373
389
OUTPUT_FILE ${CMAKE_BINARY_DIR} /s390x-softmmu/config-target .h
374
390
)
375
391
endif ()
392
+ if (UNICORN_HAS_TRICORE)
393
+ execute_process (COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR} /qemu/scripts/create_config
394
+ INPUT_FILE ${CMAKE_BINARY_DIR} /tricore-softmmu/config-target .mak
395
+ OUTPUT_FILE ${CMAKE_BINARY_DIR} /tricore-softmmu/config-target .h
396
+ )
397
+ endif ()
376
398
add_compile_options (
377
399
${UNICORN_CFLAGS}
378
400
-I${CMAKE_CURRENT_SOURCE_DIR} /qemu/tcg/${UNICORN_TARGET_ARCH}
@@ -1034,6 +1056,36 @@ endif()
1034
1056
endif ()
1035
1057
1036
1058
1059
+ if (UNICORN_HAS_TRICORE)
1060
+ add_library (tricore-softmmu STATIC
1061
+ ${UNICORN_ARCH_COMMON}
1062
+
1063
+ qemu/target /tricore/cpu.c
1064
+ qemu/target /tricore/fpu_helper.c
1065
+ qemu/target /tricore/helper.c
1066
+ qemu/target /tricore/op_helper.c
1067
+ qemu/target /tricore/translate.c
1068
+ qemu/target /tricore/unicorn.c
1069
+ )
1070
+
1071
+ if (MSVC )
1072
+ target_compile_options (tricore-softmmu PRIVATE
1073
+ -DNEED_CPU_H
1074
+ /FItricore.h
1075
+ /I${CMAKE_CURRENT_SOURCE_DIR} /msvc /tricore-softmmu
1076
+ /I${CMAKE_CURRENT_SOURCE_DIR} /qemu/target /tricore
1077
+ )
1078
+ else ()
1079
+ target_compile_options (tricore-softmmu PRIVATE
1080
+ -DNEED_CPU_H
1081
+ -include tricore.h
1082
+ -I${CMAKE_BINARY_DIR} /tricore-softmmu
1083
+ -I${CMAKE_CURRENT_SOURCE_DIR} /qemu/target /tricore
1084
+ )
1085
+ endif ()
1086
+ endif ()
1087
+
1088
+
1037
1089
set (UNICORN_SRCS
1038
1090
uc.c
1039
1091
@@ -1093,6 +1145,7 @@ if(MSVC)
1093
1145
enable_language (ASM_MASM)
1094
1146
endif ()
1095
1147
set (UNICORN_COMMON_SRCS ${UNICORN_COMMON_SRCS} qemu/util/setjmp-wrapper-win32 .asm)
1148
+ set_property (SOURCE qemu/util/setjmp-wrapper-win32 .asm PROPERTY LANGUAGE ASM_MASM)
1096
1149
endif ()
1097
1150
else ()
1098
1151
set (UNICORN_COMMON_SRCS
@@ -1110,14 +1163,12 @@ if(NOT MSVC AND NOT ANDROID_ABI)
1110
1163
target_link_libraries (unicorn-common PRIVATE pthread)
1111
1164
endif ()
1112
1165
1166
+ add_library (unicorn ${UNICORN_SRCS} )
1167
+ # For static archive
1113
1168
if (BUILD_SHARED_LIBS )
1114
- set (UNICORN_LIB_NAME "unicorn" )
1115
- else ()
1116
- set (UNICORN_LIB_NAME "unicorn-static" ) # This static lib is useless and it's just an intermediate target
1169
+ add_library (unicorn_static STATIC ${UNICORN_SRCS} )
1117
1170
endif ()
1118
1171
1119
- add_library (${UNICORN_LIB_NAME} ${UNICORN_SRCS} )
1120
-
1121
1172
if (BUILD_SHARED_LIBS )
1122
1173
if (ANDROID_ABI)
1123
1174
file (APPEND ${CMAKE_BINARY_DIR} /adb.sh "adb push ./libunicorn.so /data/local/tmp/build/\n " )
@@ -1194,6 +1245,13 @@ if (UNICORN_HAS_S390X)
1194
1245
target_link_libraries (s390x-softmmu PRIVATE unicorn-common)
1195
1246
set (UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_s390x)
1196
1247
endif ()
1248
+ if (UNICORN_HAS_TRICORE)
1249
+ set (UNICORN_COMPILE_OPTIONS ${UNICORN_COMPILE_OPTIONS} -DUNICORN_HAS_TRICORE)
1250
+ set (UNICORN_LINK_LIBRARIES ${UNICORN_LINK_LIBRARIES} tricore-softmmu)
1251
+ set (UNICORN_SAMPLE_FILE ${UNICORN_SAMPLE_FILE} sample_tricore)
1252
+ target_link_libraries (tricore-softmmu unicorn-common)
1253
+ set (UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_tricore)
1254
+ endif ()
1197
1255
1198
1256
# Extra tests
1199
1257
set (UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_mem)
@@ -1209,10 +1267,17 @@ target_compile_options(unicorn-common PRIVATE
1209
1267
${UNICORN_COMPILE_OPTIONS}
1210
1268
)
1211
1269
1212
- target_compile_options (${UNICORN_LIB_NAME} PRIVATE
1270
+ target_compile_options (unicorn PRIVATE
1213
1271
${UNICORN_COMPILE_OPTIONS}
1214
1272
)
1215
1273
1274
+ # For static archive
1275
+ if (BUILD_SHARED_LIBS )
1276
+ target_compile_options (unicorn_static PRIVATE
1277
+ ${UNICORN_COMPILE_OPTIONS}
1278
+ )
1279
+ endif ()
1280
+
1216
1281
if (MINGW)
1217
1282
set (UNICORN_LINK_LIBRARIES ${UNICORN_LINK_LIBRARIES} pthread)
1218
1283
endif ()
@@ -1223,29 +1288,46 @@ endif()
1223
1288
1224
1289
if (MSVC )
1225
1290
if (BUILD_SHARED_LIBS )
1226
- target_compile_options (${UNICORN_LIB_NAME} PRIVATE
1291
+ target_compile_options (unicorn PRIVATE
1227
1292
-DUNICORN_SHARED
1228
1293
)
1294
+
1295
+ # For static archive
1296
+ target_link_libraries (unicorn_static PRIVATE
1297
+ ${UNICORN_LINK_LIBRARIES}
1298
+ )
1229
1299
endif ()
1230
1300
1231
- target_link_libraries (${UNICORN_LIB_NAME} PRIVATE
1301
+ target_link_libraries (unicorn PRIVATE
1232
1302
${UNICORN_LINK_LIBRARIES}
1233
1303
)
1234
1304
1235
- set_target_properties (${UNICORN_LIB_NAME} PROPERTIES
1305
+ set_target_properties (unicorn PROPERTIES
1236
1306
VERSION "${UNICORN_VERSION_MAJOR} .${UNICORN_VERSION_MINOR} "
1237
1307
)
1238
1308
else ()
1239
- target_link_libraries (${UNICORN_LIB_NAME} PRIVATE
1309
+ target_link_libraries (unicorn PRIVATE
1240
1310
${UNICORN_LINK_LIBRARIES}
1241
1311
m
1242
1312
)
1243
1313
1244
- target_link_libraries (${UNICORN_LIB_NAME} PUBLIC
1314
+ target_link_libraries (unicorn PUBLIC
1245
1315
m
1246
1316
)
1247
1317
1248
- set_target_properties (${UNICORN_LIB_NAME} PROPERTIES
1318
+ # For static archive
1319
+ if (BUILD_SHARED_LIBS )
1320
+ target_link_libraries (unicorn_static PUBLIC
1321
+ m
1322
+ )
1323
+
1324
+ target_link_libraries (unicorn_static PRIVATE
1325
+ ${UNICORN_LINK_LIBRARIES}
1326
+ m
1327
+ )
1328
+ endif ()
1329
+
1330
+ set_target_properties (unicorn PROPERTIES
1249
1331
VERSION ${UNICORN_VERSION_MAJOR}
1250
1332
SOVERSION ${UNICORN_VERSION_MAJOR}
1251
1333
)
@@ -1266,12 +1348,28 @@ else()
1266
1348
)
1267
1349
endif ()
1268
1350
1269
- target_include_directories (${UNICORN_LIB_NAME} PUBLIC
1351
+ target_include_directories (unicorn PUBLIC
1270
1352
include
1271
1353
)
1272
1354
1273
- if (NOT BUILD_SHARED_LIBS )
1274
- bundle_static_library(${UNICORN_LIB_NAME} unicorn) # Bundle our real unicorn static lib
1355
+ # For static archive
1356
+ if (BUILD_SHARED_LIBS )
1357
+ target_include_directories (unicorn_static PUBLIC
1358
+ include
1359
+ )
1360
+ endif ()
1361
+
1362
+ # Black magic for generating static archives...
1363
+ if (BUILD_SHARED_LIBS )
1364
+ if (MSVC )
1365
+ # Avoid the import lib built by MVSC clash with our archive.
1366
+ set_target_properties (unicorn PROPERTIES ARCHIVE_OUTPUT_NAME "unicorn-import" )
1367
+ endif ()
1368
+ bundle_static_library(unicorn_static unicorn_archive unicorn)
1369
+ else ()
1370
+ # Rename the "static" lib to avoid filename clash.
1371
+ set_target_properties (unicorn PROPERTIES OUTPUT_NAME "unicorn-static" )
1372
+ bundle_static_library(unicorn unicorn_archive unicorn)
1275
1373
endif ()
1276
1374
1277
1375
if (UNICORN_FUZZ)
@@ -1327,9 +1425,8 @@ if(UNICORN_INSTALL AND NOT MSVC)
1327
1425
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1328
1426
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1329
1427
)
1330
- else ()
1331
- install (FILES $<TARGET_FILE:unicorn> DESTINATION ${CMAKE_INSTALL_LIBDIR} )
1332
1428
endif ()
1429
+ install (FILES $<TARGET_FILE:unicorn_archive> DESTINATION ${CMAKE_INSTALL_LIBDIR} )
1333
1430
install (FILES ${UNICORN_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /unicorn)
1334
1431
file (WRITE ${CMAKE_BINARY_DIR} /unicorn.pc "Name: unicorn\n\
1335
1432
Description: Unicorn emulator engine\n\
0 commit comments