From 28993946ad12a94166a5d9e7ac0ff6ba1d0ab2e1 Mon Sep 17 00:00:00 2001 From: wenyongh Date: Fri, 1 Nov 2019 00:38:45 -0500 Subject: [PATCH] Add BUILD_TARGET setting in makefile (#135) --- core/iwasm/products/darwin/CMakeLists.txt | 57 ++++++++++++----- core/iwasm/products/linux-sgx/CMakeLists.txt | 48 +++++++++----- core/iwasm/products/linux/CMakeLists.txt | 57 ++++++++++++----- core/iwasm/products/vxworks/CMakeLists.txt | 57 ++++++++++++----- .../products/zephyr/simple/CMakeLists.txt | 22 +++++++ core/iwasm/runtime/utils/wasm_vector.c | 2 +- .../runtime/vmcore-wasm/invokeNative_em64.s | 5 ++ .../runtime/vmcore-wasm/invokeNative_ia32.s | 5 ++ core/iwasm/runtime/vmcore-wasm/vmcore.cmake | 14 ++++- core/iwasm/runtime/vmcore-wasm/wasm_runtime.c | 12 ++-- core/shared-lib/include/config.h | 29 ++++++++- samples/gui/lvgl-native-ui-app/CMakeLists.txt | 18 +++--- .../linux-build/CMakeLists.txt | 59 ++++++++++++----- .../zephyr-build/CMakeLists.txt | 22 +++++++ .../vgl-native-ui-app/CMakeLists.txt | 18 +++--- .../littlevgl/vgl-wasm-runtime/CMakeLists.txt | 59 ++++++++++++----- .../zephyr-build/CMakeLists.txt | 21 +++++++ samples/littlevgl/wasm-apps/Makefile_wasm_app | 2 +- samples/simple/CMakeLists.txt | 63 ++++++++++++++----- 19 files changed, 432 insertions(+), 138 deletions(-) diff --git a/core/iwasm/products/darwin/CMakeLists.txt b/core/iwasm/products/darwin/CMakeLists.txt index a88b155a..e327f3ca 100644 --- a/core/iwasm/products/darwin/CMakeLists.txt +++ b/core/iwasm/products/darwin/CMakeLists.txt @@ -22,32 +22,59 @@ set (PLATFORM "darwin") set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") -# Enable repl mode if want to test spec cases -# add_definitions(-DWASM_ENABLE_REPL) - if (NOT ("$ENV{VALGRIND}" STREQUAL "YES")) add_definitions(-DNVALGRIND) endif () -# Currently build as 64-bit by default. -set (BUILD_AS_64BIT_SUPPORT "YES") +# Set BUILD_TARGET, currently values supported: +# "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32" +if (NOT BUILD_TARGET) + if (CMAKE_SIZEOF_VOID_P EQUAL 8) + # Build as X86_64 by default in 64-bit platform + set (BUILD_TARGET "X86_64") + else () + # Build as X86_32 by default in 32-bit platform + set (BUILD_TARGET "X86_32") + endif () +endif () + +string(TOUPPER ${BUILD_TARGET} BUILD_TARGET) + +# Add definitions for the build target +if (BUILD_TARGET STREQUAL "X86_64") + add_definitions(-DBUILD_TARGET_X86_64) +elseif (BUILD_TARGET STREQUAL "AMD_64") + add_definitions(-DBUILD_TARGET_AMD_64) +elseif (BUILD_TARGET STREQUAL "X86_32") + add_definitions(-DBUILD_TARGET_X86_32) +elseif (BUILD_TARGET STREQUAL "ARM_32") + add_definitions(-DBUILD_TARGET_ARM_32) +elseif (BUILD_TARGET STREQUAL "MIPS_32") + add_definitions(-DBUILD_TARGET_MIPS_32) +elseif (BUILD_TARGET STREQUAL "XTENSA_32") + add_definitions(-DBUILD_TARGET_XTENSA_32) +else () + message (FATAL_ERROR "-- Build target isn't set") +endif () + +message ("-- Build as target ${BUILD_TARGET}") if (CMAKE_SIZEOF_VOID_P EQUAL 8) -if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES") - # Add -fPIC flag if build as 64-bit - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") -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 () + if (BUILD_TARGET STREQUAL "X86_64" OR BUILD_TARGET STREQUAL "AMD_64") + # Add -fPIC flag if build as 64-bit + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") + set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") + 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 () endif () if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif (NOT CMAKE_BUILD_TYPE) -message ("CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE}) +message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE}) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic") diff --git a/core/iwasm/products/linux-sgx/CMakeLists.txt b/core/iwasm/products/linux-sgx/CMakeLists.txt index 4d590a8e..9f9f980e 100644 --- a/core/iwasm/products/linux-sgx/CMakeLists.txt +++ b/core/iwasm/products/linux-sgx/CMakeLists.txt @@ -28,32 +28,50 @@ add_definitions(-DOPS_UNSAFE_BUFFERS=0) add_definitions(-DWASM_ENABLE_LOG=0) add_definitions(-Dbh_printf=bh_printf_sgx) -# Enable repl mode if want to test spec cases -# add_definitions(-DWASM_ENABLE_REPL) - if (NOT ("$ENV{VALGRIND}" STREQUAL "YES")) add_definitions(-DNVALGRIND) endif () -# Currently build as 64-bit by default. -set (BUILD_AS_64BIT_SUPPORT "YES") +# Set BUILD_TARGET, currently values supported: +if (NOT BUILD_TARGET) + if (CMAKE_SIZEOF_VOID_P EQUAL 8) + # Build as X86_64 by default in 64-bit platform + set (BUILD_TARGET "X86_64") + else () + # Build as X86_32 by default in 32-bit platform + set (BUILD_TARGET "X86_32") + endif () +endif () -if (CMAKE_SIZEOF_VOID_P EQUAL 8) -if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES") - # Add -fPIC flag if build as 64-bit - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") +string(TOUPPER ${BUILD_TARGET} BUILD_TARGET) + +# Add definitions for the build target +if (BUILD_TARGET STREQUAL "X86_64") + add_definitions(-DBUILD_TARGET_X86_64) +elseif (BUILD_TARGET STREQUAL "X86_32") + add_definitions(-DBUILD_TARGET_X86_32) 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 () + message (FATAL_ERROR "-- Build target isn't set") endif () +message ("-- Build as target ${BUILD_TARGET}") + if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif (NOT CMAKE_BUILD_TYPE) -message ("CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE}) +message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE}) + +if (CMAKE_SIZEOF_VOID_P EQUAL 8) + if (BUILD_TARGET STREQUAL "X86_64") + # Add -fPIC flag if build as 64-bit + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") + set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") + 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 () +endif () set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic") diff --git a/core/iwasm/products/linux/CMakeLists.txt b/core/iwasm/products/linux/CMakeLists.txt index 6e893670..b21c4ad6 100644 --- a/core/iwasm/products/linux/CMakeLists.txt +++ b/core/iwasm/products/linux/CMakeLists.txt @@ -22,32 +22,59 @@ set (PLATFORM "linux") set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") -# Enable repl mode if want to test spec cases -# add_definitions(-DWASM_ENABLE_REPL) - if (NOT ("$ENV{VALGRIND}" STREQUAL "YES")) add_definitions(-DNVALGRIND) endif () -# Currently build as 64-bit by default. -set (BUILD_AS_64BIT_SUPPORT "YES") +# Set BUILD_TARGET, currently values supported: +# "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32" +if (NOT BUILD_TARGET) + if (CMAKE_SIZEOF_VOID_P EQUAL 8) + # Build as X86_64 by default in 64-bit platform + set (BUILD_TARGET "X86_64") + else () + # Build as X86_32 by default in 32-bit platform + set (BUILD_TARGET "X86_32") + endif () +endif () + +string(TOUPPER ${BUILD_TARGET} BUILD_TARGET) + +# Add definitions for the build target +if (BUILD_TARGET STREQUAL "X86_64") + add_definitions(-DBUILD_TARGET_X86_64) +elseif (BUILD_TARGET STREQUAL "AMD_64") + add_definitions(-DBUILD_TARGET_AMD_64) +elseif (BUILD_TARGET STREQUAL "X86_32") + add_definitions(-DBUILD_TARGET_X86_32) +elseif (BUILD_TARGET STREQUAL "ARM_32") + add_definitions(-DBUILD_TARGET_ARM_32) +elseif (BUILD_TARGET STREQUAL "MIPS_32") + add_definitions(-DBUILD_TARGET_MIPS_32) +elseif (BUILD_TARGET STREQUAL "XTENSA_32") + add_definitions(-DBUILD_TARGET_XTENSA_32) +else () + message (FATAL_ERROR "-- Build target isn't set") +endif () + +message ("-- Build as target ${BUILD_TARGET}") if (CMAKE_SIZEOF_VOID_P EQUAL 8) -if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES") - # Add -fPIC flag if build as 64-bit - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") -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 () + if (BUILD_TARGET STREQUAL "X86_64" OR BUILD_TARGET STREQUAL "AMD_64") + # Add -fPIC flag if build as 64-bit + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") + set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") + 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 () endif () if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif (NOT CMAKE_BUILD_TYPE) -message ("CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE}) +message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE}) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic") diff --git a/core/iwasm/products/vxworks/CMakeLists.txt b/core/iwasm/products/vxworks/CMakeLists.txt index d8019e98..80737f30 100644 --- a/core/iwasm/products/vxworks/CMakeLists.txt +++ b/core/iwasm/products/vxworks/CMakeLists.txt @@ -27,32 +27,59 @@ SET(CMAKE_RANLIB vx-ranlib) set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") -# Enable repl mode if want to test spec cases -# add_definitions(-DWASM_ENABLE_REPL) - if (NOT ("$ENV{VALGRIND}" STREQUAL "YES")) add_definitions(-DNVALGRIND) endif () -# Currently build as 64-bit by default. -set (BUILD_AS_64BIT_SUPPORT "YES") +# Set BUILD_TARGET, currently values supported: +# "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32" +if (NOT BUILD_TARGET) + if (CMAKE_SIZEOF_VOID_P EQUAL 8) + # Build as X86_64 by default in 64-bit platform + set (BUILD_TARGET "X86_64") + else () + # Build as X86_32 by default in 32-bit platform + set (BUILD_TARGET "X86_32") + endif () +endif () + +string(TOUPPER ${BUILD_TARGET} BUILD_TARGET) + +# Add definitions for the build target +if (BUILD_TARGET STREQUAL "X86_64") + add_definitions(-DBUILD_TARGET_X86_64) +elseif (BUILD_TARGET STREQUAL "AMD_64") + add_definitions(-DBUILD_TARGET_AMD_64) +elseif (BUILD_TARGET STREQUAL "X86_32") + add_definitions(-DBUILD_TARGET_X86_32) +elseif (BUILD_TARGET STREQUAL "ARM_32") + add_definitions(-DBUILD_TARGET_ARM_32) +elseif (BUILD_TARGET STREQUAL "MIPS_32") + add_definitions(-DBUILD_TARGET_MIPS_32) +elseif (BUILD_TARGET STREQUAL "XTENSA_32") + add_definitions(-DBUILD_TARGET_XTENSA_32) +else () + message (FATAL_ERROR "-- Build target isn't set") +endif () + +message ("-- Build as target ${BUILD_TARGET}") if (CMAKE_SIZEOF_VOID_P EQUAL 8) -if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES") - # Add -fPIC flag if build as 64-bit - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") -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 () + if (BUILD_TARGET STREQUAL "X86_64" OR BUILD_TARGET STREQUAL "AMD_64") + # Add -fPIC flag if build as 64-bit + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") + set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") + 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 () endif () if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif (NOT CMAKE_BUILD_TYPE) -message ("CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE}) +message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE}) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic") diff --git a/core/iwasm/products/zephyr/simple/CMakeLists.txt b/core/iwasm/products/zephyr/simple/CMakeLists.txt index 0363741b..a62bebf6 100644 --- a/core/iwasm/products/zephyr/simple/CMakeLists.txt +++ b/core/iwasm/products/zephyr/simple/CMakeLists.txt @@ -21,6 +21,28 @@ enable_language (ASM) add_definitions (-DNVALGRIND) +# Build as X86_32 by default, change to "ARM_32", "MIPS_32" or "XTENSA_32" +# if we want to support arm, mips or xtensa +if (NOT BUILD_TARGET) + set (BUILD_TARGET "X86_32") +endif () + +string(TOUPPER ${BUILD_TARGET} BUILD_TARGET) + +if (BUILD_TARGET STREQUAL "X86_32") + add_definitions(-DBUILD_TARGET_X86_32) +elseif (BUILD_TARGET STREQUAL "ARM_32") + add_definitions(-DBUILD_TARGET_ARM_32) +elseif (BUILD_TARGET STREQUAL "MIPS_32") + add_definitions(-DBUILD_TARGET_MIPS_32) +elseif (BUILD_TARGET STREQUAL "XTENSA_32") + add_definitions(-DBUILD_TARGET_XTENSA_32) +else () + message (FATAL_ERROR "-- Build target isn't set") +endif () + +message ("-- Build as target ${BUILD_TARGET}") + set (IWASM_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/iwasm) set (SHARED_LIB_ROOT ${IWASM_ROOT}/../shared-lib) diff --git a/core/iwasm/runtime/utils/wasm_vector.c b/core/iwasm/runtime/utils/wasm_vector.c index f04f4b3f..c3606da3 100644 --- a/core/iwasm/runtime/utils/wasm_vector.c +++ b/core/iwasm/runtime/utils/wasm_vector.c @@ -52,7 +52,7 @@ extend_vector(Vector *vector, uint32 length) } memcpy(data, vector->data, vector->size_elem * vector->max_elements); - free(vector->data); + wasm_free(vector->data); vector->data = data; vector->max_elements = length; return true; diff --git a/core/iwasm/runtime/vmcore-wasm/invokeNative_em64.s b/core/iwasm/runtime/vmcore-wasm/invokeNative_em64.s index c031f826..34bc9c27 100644 --- a/core/iwasm/runtime/vmcore-wasm/invokeNative_em64.s +++ b/core/iwasm/runtime/vmcore-wasm/invokeNative_em64.s @@ -15,9 +15,14 @@ */ .text .align 2 +#ifndef OS_MACOSX .globl invokeNative .type invokeNative, @function invokeNative: +#else +.globl _invokeNative +_invokeNative: +#endif /* end of OS_MACOSX */ /* rdi - function ptr */ /* rsi - argv */ /* rdx - n_stacks */ diff --git a/core/iwasm/runtime/vmcore-wasm/invokeNative_ia32.s b/core/iwasm/runtime/vmcore-wasm/invokeNative_ia32.s index 6c41d211..6fb66b60 100644 --- a/core/iwasm/runtime/vmcore-wasm/invokeNative_ia32.s +++ b/core/iwasm/runtime/vmcore-wasm/invokeNative_ia32.s @@ -16,9 +16,14 @@ .text .align 2 +#ifndef OS_MACOSX .globl invokeNative .type invokeNative, @function invokeNative: +#else +.globl _invokeNative +_invokeNative: +#endif /* end of OS_MACOSX */ push %ebp movl %esp, %ebp movl 16(%ebp), %ecx /* ecx = argc */ diff --git a/core/iwasm/runtime/vmcore-wasm/vmcore.cmake b/core/iwasm/runtime/vmcore-wasm/vmcore.cmake index 7af218ee..cf3d4e0b 100644 --- a/core/iwasm/runtime/vmcore-wasm/vmcore.cmake +++ b/core/iwasm/runtime/vmcore-wasm/vmcore.cmake @@ -20,10 +20,18 @@ include_directories(${VMCORE_LIB_DIR}/../include) file (GLOB_RECURSE c_source_all ${VMCORE_LIB_DIR}/*.c) list (REMOVE_ITEM c_source_all ${VMCORE_LIB_DIR}/invokeNative_general.c) -if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES") -set (source_all ${c_source_all} ${VMCORE_LIB_DIR}/invokeNative_em64.s) +if (${BUILD_TARGET} STREQUAL "X86_64" OR ${BUILD_TARGET} STREQUAL "AMD_64") + set (source_all ${c_source_all} ${VMCORE_LIB_DIR}/invokeNative_em64.s) +elseif (${BUILD_TARGET} STREQUAL "X86_32") + set (source_all ${c_source_all} ${VMCORE_LIB_DIR}/invokeNative_ia32.s) +elseif (${BUILD_TARGET} STREQUAL "ARM_32") + set (source_all ${c_source_all} ${VMCORE_LIB_DIR}/invokeNative_arm.s) +elseif (${BUILD_TARGET} STREQUAL "MIPS_32") + set (source_all ${c_source_all} ${VMCORE_LIB_DIR}/invokeNative_mips.s) +elseif (${BUILD_TARGET} STREQUAL "XTENSA_32") + set (source_all ${c_source_all} ${VMCORE_LIB_DIR}/invokeNative_xtensa.s) else () -set (source_all ${c_source_all} ${VMCORE_LIB_DIR}/invokeNative_ia32.s) + message (FATAL_ERROR "Build target isn't set") endif () set (VMCORE_LIB_SOURCE ${source_all}) diff --git a/core/iwasm/runtime/vmcore-wasm/wasm_runtime.c b/core/iwasm/runtime/vmcore-wasm/wasm_runtime.c index 77c7bb9e..cfd10ff0 100644 --- a/core/iwasm/runtime/vmcore-wasm/wasm_runtime.c +++ b/core/iwasm/runtime/vmcore-wasm/wasm_runtime.c @@ -1458,7 +1458,7 @@ word_copy(uint32 *dest, uint32 *src, unsigned num) (addr)[1] = u.parts[1]; \ } while (0) -#if !defined(__x86_64__) && !defined(__amd_64__) +#if !defined(BUILD_TARGET_X86_64) && !defined(BUILD_TARGET_AMD_64) typedef void (*GenericFunctionPointer)(); int64 invokeNative(GenericFunctionPointer f, uint32 *args, uint32 sz); @@ -1483,7 +1483,7 @@ wasm_runtime_invoke_native(void *func_ptr, WASMType *func_type, uint32 argv_buf[32], *argv1 = argv_buf, argc1, i, j = 0; uint64 size; -#if !defined(__arm__) && !defined(__mips__) +#if !defined(BUILD_TARGET_ARM_32) && !defined(BUILD_TARGET_MIPS_32) argc1 = argc + 2; #else argc1 = func_type->param_count * 2 + 2; @@ -1501,7 +1501,7 @@ wasm_runtime_invoke_native(void *func_ptr, WASMType *func_type, for (i = 0; i < sizeof(WASMModuleInstance*) / sizeof(uint32); i++) argv1[j++] = ((uint32*)&module_inst)[i]; -#if !defined(__arm__) && !defined(__mips__) +#if !defined(BUILD_TARGET_ARM_32) && !defined(BUILD_TARGET_MIPS_32) word_copy(argv1 + j, argv, argc); j += argc; #else @@ -1526,7 +1526,7 @@ wasm_runtime_invoke_native(void *func_ptr, WASMType *func_type, break; } } -#endif +#endif /* end of !defined(BUILD_TARGET_ARM_32) && !defined(BUILD_TARGET_MIPS_32) */ argc1 = j; if (func_type->result_count == 0) { @@ -1557,7 +1557,7 @@ wasm_runtime_invoke_native(void *func_ptr, WASMType *func_type, return true; } -#else /* else of !defined(__x86_64__) && !defined(__amd_64__) */ +#else /* else of !defined(BUILD_TARGET_X86_64) && !defined(BUILD_TARGET_AMD_64) */ typedef void (*GenericFunctionPointer)(); int64 invokeNative(GenericFunctionPointer f, uint64 *args, uint64 n_stacks); @@ -1675,5 +1675,5 @@ wasm_runtime_invoke_native(void *func_ptr, WASMType *func_type, return true; } -#endif /* end of !defined(__x86_64__) && !defined(__amd_64__) */ +#endif /* end of !defined(BUILD_TARGET_X86_64) && !defined(BUILD_TARGET_AMD_64) */ diff --git a/core/shared-lib/include/config.h b/core/shared-lib/include/config.h index 565db6c0..820c835a 100644 --- a/core/shared-lib/include/config.h +++ b/core/shared-lib/include/config.h @@ -16,6 +16,29 @@ #ifndef _CONFIG_H_ +#if !defined(BUILD_TARGET_X86_64) \ + && !defined(BUILD_TARGET_AMD_64) \ + && !defined(BUILD_TARGET_X86_32) \ + && !defined(BUILD_TARGET_ARM_32) \ + && !defined(BUILD_TARGET_MIPS_32) \ + && !defined(BUILD_TARGET_XTENSA_32) +#if defined(__x86_64__) || defined(__x86_64) +#define BUILD_TARGET_X86_64 +#elif defined(__amd64__) || defined(__amd64) +#define BUILD_TARGET_AMD_64 +#elif defined(__i386__) || defined(__i386) || defined(i386) +#define BUILD_TARGET_X86_32 +#elif defined(__arm__) +#define BUILD_TARGET_ARM_32 +#elif defined(__mips__) || defined(__mips) || defined(mips) +#define BUILD_TARGET_MIPS_32 +#elif defined(__XTENSA__) +#define BUILD_TARGET_XTENSA +#else +#error "Build target isn't set" +#endif +#endif + /* Memory allocator ems */ #define MEM_ALLOCATOR_EMS 0 @@ -100,7 +123,7 @@ #define APP_HEAP_SIZE_MAX (1024 * 1024) /* Default wasm stack size of each app */ -#ifdef __x86_64__ +#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) #define DEFAULT_WASM_STACK_SIZE (12 * 1024) #else #define DEFAULT_WASM_STACK_SIZE (8 * 1024) @@ -116,7 +139,6 @@ #define APP_THREAD_STACK_SIZE_MIN (2 * 1024) #define APP_THREAD_STACK_SIZE_MAX (256 * 1024) #endif -#endif /* External memory space provided by user, but not wasm memory space and app heap space */ @@ -134,3 +156,6 @@ #ifndef WASM_ENABLE_GUI #define WASM_ENABLE_GUI 0 #endif + +#endif /* end of _CONFIG_H_ */ + diff --git a/samples/gui/lvgl-native-ui-app/CMakeLists.txt b/samples/gui/lvgl-native-ui-app/CMakeLists.txt index 95550afc..ce40ffa8 100644 --- a/samples/gui/lvgl-native-ui-app/CMakeLists.txt +++ b/samples/gui/lvgl-native-ui-app/CMakeLists.txt @@ -22,15 +22,15 @@ project (lvgl_native_ui_app) set (BUILD_AS_64BIT_SUPPORT "YES") if (CMAKE_SIZEOF_VOID_P EQUAL 8) - if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES") - # Add -fPIC flag if build as 64-bit - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") - 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 () + if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES") + # Add -fPIC flag if build as 64-bit + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") + set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") + 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 () endif () set(THIRDPARTY_DIR ../../../core/iwasm/lib/3rdparty) diff --git a/samples/gui/wasm-runtime-wgl/linux-build/CMakeLists.txt b/samples/gui/wasm-runtime-wgl/linux-build/CMakeLists.txt index ce3e1cd0..002b1944 100644 --- a/samples/gui/wasm-runtime-wgl/linux-build/CMakeLists.txt +++ b/samples/gui/wasm-runtime-wgl/linux-build/CMakeLists.txt @@ -18,37 +18,64 @@ set (TARGET_PLATFORM "linux") set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") -# Enable repl mode if want to test spec cases -# add_definitions(-DWASM_ENABLE_REPL) - if (NOT ("$ENV{VALGRIND}" STREQUAL "YES")) add_definitions(-DNVALGRIND) endif () -# Currently build as 64-bit by default. -set (BUILD_AS_64BIT_SUPPORT "YES") +# Set BUILD_TARGET, currently values supported: +# "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32" +if (NOT BUILD_TARGET) + if (CMAKE_SIZEOF_VOID_P EQUAL 8) + # Build as X86_64 by default in 64-bit platform + set (BUILD_TARGET "X86_64") + else () + # Build as X86_32 by default in 32-bit platform + set (BUILD_TARGET "X86_32") + endif () +endif () + +string(TOUPPER ${BUILD_TARGET} BUILD_TARGET) + +# Add definitions for the build target +if (BUILD_TARGET STREQUAL "X86_64") + add_definitions(-DBUILD_TARGET_X86_64) +elseif (BUILD_TARGET STREQUAL "AMD_64") + add_definitions(-DBUILD_TARGET_AMD_64) +elseif (BUILD_TARGET STREQUAL "X86_32") + add_definitions(-DBUILD_TARGET_X86_32) +elseif (BUILD_TARGET STREQUAL "ARM_32") + add_definitions(-DBUILD_TARGET_ARM_32) +elseif (BUILD_TARGET STREQUAL "MIPS_32") + add_definitions(-DBUILD_TARGET_MIPS_32) +elseif (BUILD_TARGET STREQUAL "XTENSA_32") + add_definitions(-DBUILD_TARGET_XTENSA_32) +else () + message (FATAL_ERROR "-- Build target isn't set") +endif () + +message ("-- Build as target ${BUILD_TARGET}") if (CMAKE_SIZEOF_VOID_P EQUAL 8) -if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES") - # Add -fPIC flag if build as 64-bit - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") -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 () + if (BUILD_TARGET STREQUAL "X86_64" OR BUILD_TARGET STREQUAL "AMD_64") + # Add -fPIC flag if build as 64-bit + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") + set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") + 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 () endif () if (NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE Debug) endif (NOT CMAKE_BUILD_TYPE) -message ("CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE}) +message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE}) if (NOT PLATFORM) SET(PLATFORM linux) endif (NOT PLATFORM) -message ("PLATFORM = " ${PLATFORM}) +message ("-- PLATFORM = " ${PLATFORM}) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic") diff --git a/samples/gui/wasm-runtime-wgl/zephyr-build/CMakeLists.txt b/samples/gui/wasm-runtime-wgl/zephyr-build/CMakeLists.txt index c00eadee..99066ed0 100644 --- a/samples/gui/wasm-runtime-wgl/zephyr-build/CMakeLists.txt +++ b/samples/gui/wasm-runtime-wgl/zephyr-build/CMakeLists.txt @@ -27,6 +27,28 @@ zephyr_compile_definitions (-DNVALGRIND -Dattr_container_free=bh_free -DWASM_ENABLE_GUI=1) +# Build as ARM_32 by default, change to "X86_32", "MIPS_32" or "XTENSA_32" +# if we want to support x86, mips or xtensa +if (NOT BUILD_TARGET) + set (BUILD_TARGET "ARM_32") +endif () + +string(TOUPPER ${BUILD_TARGET} BUILD_TARGET) + +if (BUILD_TARGET STREQUAL "X86_32") + add_definitions(-DBUILD_TARGET_X86_32) +elseif (BUILD_TARGET STREQUAL "ARM_32") + add_definitions(-DBUILD_TARGET_ARM_32) +elseif (BUILD_TARGET STREQUAL "MIPS_32") + add_definitions(-DBUILD_TARGET_MIPS_32) +elseif (BUILD_TARGET STREQUAL "XTENSA_32") + add_definitions(-DBUILD_TARGET_XTENSA_32) +else () + message (FATAL_ERROR "-- Build target isn't set") +endif () + +message ("-- Build as target ${BUILD_TARGET}") + set (IWASM_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/core/iwasm) set (APP_MGR_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/core/app-mgr) set (SHARED_LIB_ROOT ${IWASM_ROOT}/../shared-lib) diff --git a/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt b/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt index 78f64645..5b14feb8 100644 --- a/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt +++ b/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt @@ -23,15 +23,15 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLV_CONF_INCLUDE_SIMPLE -DPLATFORM_NATIVE_L set (BUILD_AS_64BIT_SUPPORT "YES") if (CMAKE_SIZEOF_VOID_P EQUAL 8) - if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES") - # Add -fPIC flag if build as 64-bit - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") - 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 () + if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES") + # Add -fPIC flag if build as 64-bit + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") + set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") + 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 () endif () set(lv_name lvgl) diff --git a/samples/littlevgl/vgl-wasm-runtime/CMakeLists.txt b/samples/littlevgl/vgl-wasm-runtime/CMakeLists.txt index 69114070..7518688f 100644 --- a/samples/littlevgl/vgl-wasm-runtime/CMakeLists.txt +++ b/samples/littlevgl/vgl-wasm-runtime/CMakeLists.txt @@ -8,37 +8,64 @@ set (TARGET_PLATFORM "linux") set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") -# Enable repl mode if want to test spec cases -# add_definitions(-DWASM_ENABLE_REPL) - if (NOT ("$ENV{VALGRIND}" STREQUAL "YES")) add_definitions(-DNVALGRIND) endif () -# Currently build as 64-bit by default. -set (BUILD_AS_64BIT_SUPPORT "YES") +# Set BUILD_TARGET, currently values supported: +# "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32" +if (NOT BUILD_TARGET) + if (CMAKE_SIZEOF_VOID_P EQUAL 8) + # Build as X86_64 by default in 64-bit platform + set (BUILD_TARGET "X86_64") + else () + # Build as X86_32 by default in 32-bit platform + set (BUILD_TARGET "X86_32") + endif () +endif () + +string(TOUPPER ${BUILD_TARGET} BUILD_TARGET) + +# Add definitions for the build target +if (BUILD_TARGET STREQUAL "X86_64") + add_definitions(-DBUILD_TARGET_X86_64) +elseif (BUILD_TARGET STREQUAL "AMD_64") + add_definitions(-DBUILD_TARGET_AMD_64) +elseif (BUILD_TARGET STREQUAL "X86_32") + add_definitions(-DBUILD_TARGET_X86_32) +elseif (BUILD_TARGET STREQUAL "ARM_32") + add_definitions(-DBUILD_TARGET_ARM_32) +elseif (BUILD_TARGET STREQUAL "MIPS_32") + add_definitions(-DBUILD_TARGET_MIPS_32) +elseif (BUILD_TARGET STREQUAL "XTENSA_32") + add_definitions(-DBUILD_TARGET_XTENSA_32) +else () + message (FATAL_ERROR "-- Build target isn't set") +endif () + +message ("-- Build as target ${BUILD_TARGET}") if (CMAKE_SIZEOF_VOID_P EQUAL 8) -if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES") - # Add -fPIC flag if build as 64-bit - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") -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 () + if (BUILD_TARGET STREQUAL "X86_64" OR BUILD_TARGET STREQUAL "AMD_64") + # Add -fPIC flag if build as 64-bit + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") + set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") + 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 () endif () if (NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE Debug) endif (NOT CMAKE_BUILD_TYPE) -message ("CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE}) +message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE}) if (NOT PLATFORM) SET(PLATFORM linux) endif (NOT PLATFORM) -message ("PLATFORM = " ${PLATFORM}) +message ("-- PLATFORM = " ${PLATFORM}) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic") diff --git a/samples/littlevgl/vgl-wasm-runtime/zephyr-build/CMakeLists.txt b/samples/littlevgl/vgl-wasm-runtime/zephyr-build/CMakeLists.txt index a564c6aa..b59fd4a8 100644 --- a/samples/littlevgl/vgl-wasm-runtime/zephyr-build/CMakeLists.txt +++ b/samples/littlevgl/vgl-wasm-runtime/zephyr-build/CMakeLists.txt @@ -26,6 +26,27 @@ zephyr_compile_definitions (-DNVALGRIND -Dattr_container_malloc=bh_malloc -Dattr_container_free=bh_free) +# Build as ARM_32 by default, change to "X86_32", "MIPS_32" or "XTENSA_32" +# if we want to support x86, mips or xtensa +if (NOT BUILD_TARGET) + set (BUILD_TARGET "ARM_32") +endif () + +string(TOUPPER ${BUILD_TARGET} BUILD_TARGET) + +if (BUILD_TARGET STREQUAL "X86_32") + add_definitions(-DBUILD_TARGET_X86_32) +elseif (BUILD_TARGET STREQUAL "ARM_32") + add_definitions(-DBUILD_TARGET_ARM_32) +elseif (BUILD_TARGET STREQUAL "MIPS_32") + add_definitions(-DBUILD_TARGET_MIPS_32) +elseif (BUILD_TARGET STREQUAL "XTENSA_32") + add_definitions(-DBUILD_TARGET_XTENSA_32) +else () + message (FATAL_ERROR "-- Build target isn't set") +endif () + +message ("-- Build as target ${BUILD_TARGET}") set (IWASM_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/core/iwasm) set (APP_MGR_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/core/app-mgr) set (SHARED_LIB_ROOT ${IWASM_ROOT}/../shared-lib) diff --git a/samples/littlevgl/wasm-apps/Makefile_wasm_app b/samples/littlevgl/wasm-apps/Makefile_wasm_app index 225a7a87..b9003ac8 100644 --- a/samples/littlevgl/wasm-apps/Makefile_wasm_app +++ b/samples/littlevgl/wasm-apps/Makefile_wasm_app @@ -47,7 +47,7 @@ SRCS += lvgl/lv_misc/lv_task.c lvgl/lv_misc/lv_circ.c lvgl/lv_misc/lv_anim.c SRCS += lvgl/lv_misc/lv_color.c lvgl/lv_misc/lv_txt.c lvgl/lv_misc/lv_math.c SRCS += lvgl/lv_misc/lv_mem.c lvgl/lv_misc/lv_font.c lvgl/lv_misc/lv_ll.c SRCS += lvgl/lv_misc/lv_area.c lvgl/lv_misc/lv_templ.c lvgl/lv_misc/lv_ufs.c -SRCS += lvgl/lv_misc/lv_area.c lvgl/lv_misc/lv_templ.c lvgl/lv_misc/lv_gc.c +SRCS += lvgl/lv_misc/lv_gc.c SRCS += lvgl/lv_hal/lv_hal_tick.c lvgl/lv_hal/lv_hal_indev.c lvgl/lv_hal/lv_hal_disp.c SRCS += lvgl/lv_themes/lv_theme_mono.c lvgl/lv_themes/lv_theme_templ.c SRCS += lvgl/lv_themes/lv_theme_material.c lvgl/lv_themes/lv_theme.c diff --git a/samples/simple/CMakeLists.txt b/samples/simple/CMakeLists.txt index 34bc1b70..69843349 100644 --- a/samples/simple/CMakeLists.txt +++ b/samples/simple/CMakeLists.txt @@ -8,37 +8,70 @@ set (TARGET_PLATFORM "linux") set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") -# Enable repl mode if want to test spec cases -# add_definitions(-DWASM_ENABLE_REPL) - if (NOT ("$ENV{VALGRIND}" STREQUAL "YES")) add_definitions(-DNVALGRIND) endif () -# Currently build as 64-bit by default. set (BUILD_AS_64BIT_SUPPORT "YES") -if (CMAKE_SIZEOF_VOID_P EQUAL 8) -if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES") - # Add -fPIC flag if build as 64-bit - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") -else () - add_definitions (-m32) - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") - set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32") +# Set BUILD_TARGET, currently values supported: +# "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32" +if (NOT BUILD_TARGET) + if (CMAKE_SIZEOF_VOID_P EQUAL 8) + if (BUILD_AS_64BIT_SUPPORT STREQUAL "YES") + # Build as X86_64 by default in 64-bit platform + set (BUILD_TARGET "X86_64") + else () + set (BUILD_TARGET "X86_32") + endif () + else () + # Build as X86_32 by default in 32-bit platform + set (BUILD_TARGET "X86_32") + endif () endif () + +string(TOUPPER ${BUILD_TARGET} BUILD_TARGET) + +# Add definitions for the build target +if (BUILD_TARGET STREQUAL "X86_64") + add_definitions(-DBUILD_TARGET_X86_64) +elseif (BUILD_TARGET STREQUAL "AMD_64") + add_definitions(-DBUILD_TARGET_AMD_64) +elseif (BUILD_TARGET STREQUAL "X86_32") + add_definitions(-DBUILD_TARGET_X86_32) +elseif (BUILD_TARGET STREQUAL "ARM_32") + add_definitions(-DBUILD_TARGET_ARM_32) +elseif (BUILD_TARGET STREQUAL "MIPS_32") + add_definitions(-DBUILD_TARGET_MIPS_32) +elseif (BUILD_TARGET STREQUAL "XTENSA_32") + add_definitions(-DBUILD_TARGET_XTENSA_32) +else () + message (FATAL_ERROR "-- Build target isn't set") +endif () + +message ("-- Build as target ${BUILD_TARGET}") + +if (CMAKE_SIZEOF_VOID_P EQUAL 8) + if (BUILD_TARGET STREQUAL "X86_64" OR BUILD_TARGET STREQUAL "AMD_64") + # Add -fPIC flag if build as 64-bit + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") + set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") + 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 () endif () if (NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE Debug) endif (NOT CMAKE_BUILD_TYPE) -message ("CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE}) +message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE}) if (NOT PLATFORM) SET(PLATFORM linux) endif (NOT PLATFORM) -message ("PLATFORM = " ${PLATFORM}) +message ("-- PLATFORM = " ${PLATFORM}) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")