forked from Mirrors/wasm3
Make the source directory useable as a CMake library, plus ESP32 related cleanup (#30)
* m3_config_platforms: esp32: make the dependency on esp_system optional If the application places wasm3 into IRAM using the linker script, it can define M3_IN_IRAM flag. In this case we don't need to pull in the dependency on IDF-specific header file into m3. * cmake: make the source directory useable as a CMake library Also replace globbing with an explicit list of files, following CMake best practices. * platforms/esp32-idf: link m3 as a static library * platforms/esp32-pio: wrap the wasm3 code into a "PIO library"extensions
parent
60117db070
commit
804d14991b
@ -1,11 +1,26 @@
|
||||
file(GLOB_RECURSE M3_SOURCES "m3/*.c")
|
||||
set(idf_ver "${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}")
|
||||
|
||||
if (NOT CMAKE_BUILD_EARLY_EXPANSION)
|
||||
idf_build_get_property(build_dir BUILD_DIR)
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../../source ${build_dir}/m3)
|
||||
endif()
|
||||
|
||||
set(APP_SOURCES "main.cpp")
|
||||
|
||||
idf_component_register(SRCS ${APP_SOURCES} ${M3_SOURCES}
|
||||
INCLUDE_DIRS "")
|
||||
idf_component_register(SRCS ${APP_SOURCES}
|
||||
INCLUDE_DIRS ""
|
||||
LDFRAGMENTS linker.lf)
|
||||
|
||||
if (idf_ver STREQUAL "4.0")
|
||||
# IDF v4.0 links apps with -nostdlib, so need to explicitly list the dependencies.
|
||||
|
||||
add_library(m3_deps INTERFACE)
|
||||
target_link_libraries(m3_deps INTERFACE c m gcc)
|
||||
target_link_libraries(${COMPONENT_TARGET} PRIVATE m3 m3_deps)
|
||||
else()
|
||||
# For IDF v4.1 and later, no tricks required.
|
||||
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-error -O3 -DESP32 -Dd_m3LogOutput=false)
|
||||
target_link_libraries(${COMPONENT_TARGET} PRIVATE m3)
|
||||
endif()
|
||||
|
||||
# Disable harmless warnings
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers)
|
||||
target_compile_options(m3 PUBLIC -DM3_IN_IRAM -DESP32 -Dd_m3LogOutput=false)
|
||||
|
@ -0,0 +1,6 @@
|
||||
[mapping:wasm3]
|
||||
archive: libm3.a
|
||||
entries:
|
||||
m3_core (noflash_text)
|
||||
m3_exec (noflash_text)
|
||||
m3_compile (noflash_text)
|
@ -1 +0,0 @@
|
||||
../../../source
|
@ -0,0 +1,3 @@
|
||||
This is a placeholder for the wasm3 PIO library.
|
||||
|
||||
At the moment it simply adds the source code as a symlink, and sets some build flags.
|
@ -0,0 +1,5 @@
|
||||
{
|
||||
"build" : {
|
||||
"flags": "-DESP32 -Dd_m3LogOutput=false -O3 -Wfatal-errors -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers"
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
../../../../source
|
@ -1 +0,0 @@
|
||||
../../../source
|
@ -0,0 +1,45 @@
|
||||
set(srcs
|
||||
"m3_api_libc.c"
|
||||
"m3_api_meta_wasi.c"
|
||||
"m3_api_wasi.c"
|
||||
"m3_bind.c"
|
||||
"m3_code.c"
|
||||
"m3_compile.c"
|
||||
"m3_core.c"
|
||||
"m3_emit.c"
|
||||
"m3_env.c"
|
||||
"m3_exec.c"
|
||||
"m3_info.c"
|
||||
"m3_module.c"
|
||||
"m3_optimize.c"
|
||||
"m3_parse.c"
|
||||
)
|
||||
|
||||
add_library(m3 STATIC ${srcs})
|
||||
|
||||
target_include_directories(m3 PUBLIC .)
|
||||
|
||||
if (CMAKE_C_COMPILER_ID MATCHES "MSVC")
|
||||
# add MSVC specific flags here
|
||||
else()
|
||||
# Flags common for GCC and Clang
|
||||
|
||||
# FIXME: cast to 'void *' from smaller integer type 'i32'
|
||||
set_source_files_properties(m3_emit.c PROPERTIES COMPILE_FLAGS -Wno-int-to-pointer-cast)
|
||||
|
||||
# FIXME: comparison of integers of different signs: 'u32' and 'i32'
|
||||
set_source_files_properties(m3_env.c PROPERTIES COMPILE_FLAGS -Wno-sign-compare)
|
||||
|
||||
if (WASIENV)
|
||||
# FIXME: declaration of 'struct sigaction' will not be visible outside of this function
|
||||
target_compile_options(m3 PUBLIC -Wno-visibility)
|
||||
# FIXME incompatible pointer types passing 'u32 *' to parameter of type 'char **'
|
||||
set_source_files_properties(m3_api_meta_wasi.c PROPERTIES COMPILE_FLAGS -Wno-incompatible-pointer-types)
|
||||
endif()
|
||||
|
||||
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
# Clang specific flags here
|
||||
else()
|
||||
# GCC specific flags here
|
||||
endif()
|
||||
endif()
|
Loading…
Reference in new issue