add host detection in CMakeLists.txt (#1244)

* fix finding python path which only has python3.

* add host detection.

* add ia64, ppc, s390 host detections.
This commit is contained in:
Chen Huitao 2020-04-29 08:47:48 +08:00 committed by GitHub
parent 0d93f055b4
commit d5f088c85f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,6 +82,59 @@ if(MSVC)
string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
endif()
else()
# detect host arch.
execute_process(COMMAND ${CMAKE_C_COMPILER} -dM -E -
INPUT_FILE /dev/null
OUTPUT_VARIABLE UC_COMPILER_MACRO)
while(TRUE)
string(FIND ${UC_COMPILER_MACRO} "__x86_64__" UC_RET)
if (${UC_RET} GREATER "0")
set(UNICORN_TARGET_ARCH "i386")
break()
endif()
string(FIND ${UC_COMPILER_MACRO} "__i386__" UC_RET)
if (${UC_RET} GREATER "0")
set(UNICORN_TARGET_ARCH "i386")
break()
endif()
string(FIND ${UC_COMPILER_MACRO} "__arm__" UC_RET)
if (${UC_RET} GREATER "0")
set(UNICORN_TARGET_ARCH "arm")
break()
endif()
string(FIND ${UC_COMPILER_MACRO} "__aarch64__" UC_RET)
if (${UC_RET} GREATER "0")
set(UNICORN_TARGET_ARCH "aarch64")
break()
endif()
string(FIND ${UC_COMPILER_MACRO} "__mips__" UC_RET)
if (${UC_RET} GREATER "0")
set(UNICORN_TARGET_ARCH "mips")
break()
endif()
string(FIND ${UC_COMPILER_MACRO} "__sparc__" UC_RET)
if (${UC_RET} GREATER "0")
set(UNICORN_TARGET_ARCH "sparc")
break()
endif()
string(FIND ${UC_COMPILER_MACRO} "__ia64__" UC_RET)
if (${UC_RET} GREATER "0")
set(UNICORN_TARGET_ARCH "ia64")
break()
endif()
string(FIND ${UC_COMPILER_MACRO} "_ARCH_PPC" UC_RET)
if (${UC_RET} GREATER "0")
set(UNICORN_TARGET_ARCH "ppc")
break()
endif()
string(FIND ${UC_COMPILER_MACRO} "__s390__" UC_RET)
if (${UC_RET} GREATER "0")
set(UNICORN_TARGET_ARCH "s390")
break()
endif()
message(FATAL_ERROR "Unknown host compiler: ${CMAKE_C_COMPILER}.")
endwhile(TRUE)
# check python
find_program(PYTHON_CMD python)
if (NOT PYTHON_CMD)
@ -219,7 +272,7 @@ else()
-c -o ${CMAKE_BINARY_DIR} -b -i ${CMAKE_CURRENT_SOURCE_DIR}/qemu/qapi-schema.json
)
add_compile_options(
-I${CMAKE_CURRENT_SOURCE_DIR}/qemu/tcg/i386
-I${CMAKE_CURRENT_SOURCE_DIR}/qemu/tcg/${UNICORN_TARGET_ARCH}
-D_GNU_SOURCE
-D_FILE_OFFSET_BITS=64
-D_LARGEFILE_SOURCE