@@ -40,11 +40,16 @@ set(UNICORN_VERSION_PATCH 0)
4040
4141include (bundle_static.cmake)
4242
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.
4348option (BUILD_SHARED_LIBS "Build shared instead of static library" ${PROJECT_IS_TOP_LEVEL} )
4449option (UNICORN_FUZZ "Enable fuzzing" OFF )
4550option (UNICORN_BUILD_TESTS "Build unicorn tests" ${PROJECT_IS_TOP_LEVEL} )
4651option (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" )
4853option (UNICORN_TRACER "Trace unicorn execution" OFF )
4954
5055foreach (ARCH_LOOP ${UNICORN_ARCH} )
@@ -119,7 +124,7 @@ else()
119124 string (FIND "${UC_COMPILER_VERSION} " "i686" UC_RET)
120125 if (${UC_RET} GREATER_EQUAL "0" )
121126 set (UNICORN_TARGET_ARCH "i386" )
122- set (UNICORN_CFLAGS -m32)
127+ set (UNICORN_CFLAGS -m32 - static -libgcc) # Workaround for github action bugs
123128 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32" )
124129 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32" )
125130 else ()
@@ -209,6 +214,11 @@ else()
209214 set (UNICORN_TARGET_ARCH "s390" )
210215 break ()
211216 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 ()
212222 message (FATAL_ERROR "Unknown host compiler: ${CMAKE_C_COMPILER} ." )
213223 endwhile (TRUE )
214224 endif ()
@@ -241,6 +251,9 @@ else()
241251 if (UNICORN_HAS_S390X)
242252 set (EXTRA_CFLAGS "${EXTRA_CFLAGS} -DUNICORN_HAS_S390X " )
243253 endif ()
254+ if (UNICORN_HAS_TRICORE)
255+ set (EXTRA_CFLAGS "${EXTRA_CFLAGS} -DUNICORN_HAS_TRICORE " )
256+ endif ()
244257
245258 set (EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC" )
246259 if (ANDROID_ABI)
@@ -282,6 +295,9 @@ else()
282295 if (UNICORN_HAS_S390X)
283296 set (TARGET_LIST "${TARGET_LIST} s390x-softmmu, " )
284297 endif ()
298+ if (UNICORN_HAS_TRICORE)
299+ set (TARGET_LIST "${TARGET_LIST} tricore-softmmu, " )
300+ endif ()
285301 set (TARGET_LIST "${TARGET_LIST} " )
286302
287303 # GEN config-host.mak & target directories
@@ -373,6 +389,12 @@ else()
373389 OUTPUT_FILE ${CMAKE_BINARY_DIR} /s390x-softmmu/config-target .h
374390 )
375391 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 ()
376398 add_compile_options (
377399 ${UNICORN_CFLAGS}
378400 -I${CMAKE_CURRENT_SOURCE_DIR} /qemu/tcg/${UNICORN_TARGET_ARCH}
@@ -1034,6 +1056,36 @@ endif()
10341056endif ()
10351057
10361058
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+
10371089set (UNICORN_SRCS
10381090 uc.c
10391091
@@ -1093,6 +1145,7 @@ if(MSVC)
10931145 enable_language (ASM_MASM)
10941146 endif ()
10951147 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)
10961149 endif ()
10971150else ()
10981151 set (UNICORN_COMMON_SRCS
@@ -1110,14 +1163,12 @@ if(NOT MSVC AND NOT ANDROID_ABI)
11101163 target_link_libraries (unicorn-common PRIVATE pthread)
11111164endif ()
11121165
1166+ add_library (unicorn ${UNICORN_SRCS} )
1167+ # For static archive
11131168if (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} )
11171170endif ()
11181171
1119- add_library (${UNICORN_LIB_NAME} ${UNICORN_SRCS} )
1120-
11211172if (BUILD_SHARED_LIBS )
11221173 if (ANDROID_ABI)
11231174 file (APPEND ${CMAKE_BINARY_DIR} /adb.sh "adb push ./libunicorn.so /data/local/tmp/build/\n " )
@@ -1194,6 +1245,13 @@ if (UNICORN_HAS_S390X)
11941245 target_link_libraries (s390x-softmmu PRIVATE unicorn-common)
11951246 set (UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_s390x)
11961247endif ()
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 ()
11971255
11981256# Extra tests
11991257set (UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_mem)
@@ -1209,10 +1267,17 @@ target_compile_options(unicorn-common PRIVATE
12091267 ${UNICORN_COMPILE_OPTIONS}
12101268)
12111269
1212- target_compile_options (${UNICORN_LIB_NAME} PRIVATE
1270+ target_compile_options (unicorn PRIVATE
12131271 ${UNICORN_COMPILE_OPTIONS}
12141272)
12151273
1274+ # For static archive
1275+ if (BUILD_SHARED_LIBS )
1276+ target_compile_options (unicorn_static PRIVATE
1277+ ${UNICORN_COMPILE_OPTIONS}
1278+ )
1279+ endif ()
1280+
12161281if (MINGW)
12171282 set (UNICORN_LINK_LIBRARIES ${UNICORN_LINK_LIBRARIES} pthread)
12181283endif ()
@@ -1223,29 +1288,46 @@ endif()
12231288
12241289if (MSVC )
12251290 if (BUILD_SHARED_LIBS )
1226- target_compile_options (${UNICORN_LIB_NAME} PRIVATE
1291+ target_compile_options (unicorn PRIVATE
12271292 -DUNICORN_SHARED
12281293 )
1294+
1295+ # For static archive
1296+ target_link_libraries (unicorn_static PRIVATE
1297+ ${UNICORN_LINK_LIBRARIES}
1298+ )
12291299 endif ()
12301300
1231- target_link_libraries (${UNICORN_LIB_NAME} PRIVATE
1301+ target_link_libraries (unicorn PRIVATE
12321302 ${UNICORN_LINK_LIBRARIES}
12331303 )
12341304
1235- set_target_properties (${UNICORN_LIB_NAME} PROPERTIES
1305+ set_target_properties (unicorn PROPERTIES
12361306 VERSION "${UNICORN_VERSION_MAJOR} .${UNICORN_VERSION_MINOR} "
12371307 )
12381308else ()
1239- target_link_libraries (${UNICORN_LIB_NAME} PRIVATE
1309+ target_link_libraries (unicorn PRIVATE
12401310 ${UNICORN_LINK_LIBRARIES}
12411311 m
12421312 )
12431313
1244- target_link_libraries (${UNICORN_LIB_NAME} PUBLIC
1314+ target_link_libraries (unicorn PUBLIC
12451315 m
12461316 )
12471317
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
12491331 VERSION ${UNICORN_VERSION_MAJOR}
12501332 SOVERSION ${UNICORN_VERSION_MAJOR}
12511333 )
@@ -1266,12 +1348,28 @@ else()
12661348 )
12671349endif ()
12681350
1269- target_include_directories (${UNICORN_LIB_NAME} PUBLIC
1351+ target_include_directories (unicorn PUBLIC
12701352 include
12711353)
12721354
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)
12751373endif ()
12761374
12771375if (UNICORN_FUZZ)
@@ -1327,9 +1425,8 @@ if(UNICORN_INSTALL AND NOT MSVC)
13271425 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
13281426 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
13291427 )
1330- else ()
1331- install (FILES $<TARGET_FILE:unicorn> DESTINATION ${CMAKE_INSTALL_LIBDIR} )
13321428 endif ()
1429+ install (FILES $<TARGET_FILE:unicorn_archive> DESTINATION ${CMAKE_INSTALL_LIBDIR} )
13331430 install (FILES ${UNICORN_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /unicorn)
13341431 file (WRITE ${CMAKE_BINARY_DIR} /unicorn.pc "Name: unicorn\n\
13351432Description: Unicorn emulator engine\n\
0 commit comments