Fix build issues when compiling WAMRC as a cross-compiler (#4112)
* Use CMAKE_INSTALL_BINDIR for wamrc installation * Fix wamrc build failure for 32bit non-x86 targets * Handle PIC flags by cmake in wamrc * Use dummy AOT reloc functions when building wamrc AOT reloc functions are used only when loading AOT WebAssembly modules on target, not during AOT compilation. Original code led to build issues when building wamrc as cross-compiler, using arm header on x86 build. * Add option to turn off SIMD support in wamrc
This commit is contained in:
@ -31,6 +31,13 @@ endif()
|
||||
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
|
||||
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
|
||||
|
||||
# Turn on SIMD by default, can be turned off by setting WAMR_BUILD_SIMD to 0
|
||||
if (WAMR_BUILD_SIMD EQUAL 0)
|
||||
add_definitions(-DWASM_ENABLE_SIMD=0)
|
||||
else()
|
||||
add_definitions(-DWASM_ENABLE_SIMD=1)
|
||||
endif()
|
||||
|
||||
add_definitions(-DWASM_ENABLE_INTERP=1)
|
||||
add_definitions(-DWASM_ENABLE_WAMR_COMPILER=1)
|
||||
add_definitions(-DWASM_ENABLE_BULK_MEMORY=1)
|
||||
@ -38,7 +45,6 @@ add_definitions(-DWASM_DISABLE_HW_BOUND_CHECK=1)
|
||||
add_definitions(-DWASM_ENABLE_SHARED_MEMORY=1)
|
||||
add_definitions(-DWASM_ENABLE_THREAD_MGR=1)
|
||||
add_definitions(-DWASM_ENABLE_TAIL_CALL=1)
|
||||
add_definitions(-DWASM_ENABLE_SIMD=1)
|
||||
add_definitions(-DWASM_ENABLE_REF_TYPES=1)
|
||||
add_definitions(-DWASM_ENABLE_CUSTOM_NAME_SECTION=1)
|
||||
add_definitions(-DWASM_ENABLE_AOT_STACK_FRAME=1)
|
||||
@ -132,21 +138,11 @@ endif ()
|
||||
|
||||
message ("-- Build as target ${WAMR_BUILD_TARGET}")
|
||||
|
||||
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64"
|
||||
OR WAMR_BUILD_TARGET MATCHES "AARCH64.*" OR WAMR_BUILD_TARGET MATCHES "RISCV64.*")
|
||||
if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows")
|
||||
# Add -fPIC flag if build as 64-bit
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
|
||||
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -fPIC")
|
||||
endif ()
|
||||
else ()
|
||||
add_definitions (-m32)
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
|
||||
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
|
||||
endif ()
|
||||
# Add -m32 flag if compiling on 64-bit system for 32-bit x86 target
|
||||
if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND WAMR_BUILD_TARGET STREQUAL "X86_32")
|
||||
add_definitions (-m32)
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
|
||||
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
|
||||
endif ()
|
||||
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
@ -275,6 +271,8 @@ else ()
|
||||
message ("-- Lib wasi-threads disabled")
|
||||
endif ()
|
||||
|
||||
set (WAMR_BUILD_WAMR_COMPILER 1)
|
||||
|
||||
include (${SHARED_DIR}/platform/${WAMR_BUILD_PLATFORM}/shared_platform.cmake)
|
||||
include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake)
|
||||
include (${SHARED_DIR}/utils/shared_utils.cmake)
|
||||
@ -376,7 +374,7 @@ add_library (aotclib ${IWASM_COMPL_SOURCE})
|
||||
|
||||
add_executable (wamrc main.c)
|
||||
check_pie_supported()
|
||||
set_target_properties (wamrc PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
set_target_properties (wamrc vmlib aotclib PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
set_version_info (wamrc)
|
||||
|
||||
if (LLVM_LINK_LLVM_DYLIB)
|
||||
@ -398,4 +396,5 @@ else()
|
||||
${UV_A_LIBS})
|
||||
endif()
|
||||
|
||||
install (TARGETS wamrc DESTINATION bin)
|
||||
include (GNUInstallDirs)
|
||||
install (TARGETS wamrc)
|
||||
|
||||
Reference in New Issue
Block a user