Skip to content

Add Support for OpenHarmony. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ now build the library executing the command bellow:
```bash
cmake --build build/linux
```

## OpenHarmony

At the project root directory, run:

```bash
cmake -S ./ohos -B ./build/ohos -DOHOS_STL=c++_shared -DOHOS_ARCH=arm64-v8a -DOHOS_PLATFORM=OHOS -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/path/to/native/build/cmake/ohos.toolchain.cmake
```

now build the library executing the command bellow:

```bash
cmake --build build/ohos
```

## Windows References

* Build to Windows using CMake and Ninja Generator: https://dmerej.info/blog/post/cmake-visual-studio-and-the-command-line/
Expand Down
38 changes: 38 additions & 0 deletions ohos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
cmake_minimum_required(VERSION 3.10)

include("${CMAKE_CURRENT_SOURCE_DIR}/../cxx/quickjs.cmake")

set(PROJECT_NAME "quickjs_c_bridge")
project(${PROJECT_NAME} LANGUAGES CXX C)

set(PLUGIN_NAME "${PROJECT_NAME}_plugin")


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -DOHOS_STL=c++_static -DDEBUGGER_SERVER_PORT=${DEBUGGER_SERVER_PORT}")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=incompatible-pointer-types-discards-qualifiers")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-int-conversion")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-variable")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-but-set-variable")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-maybe-uninitialized")

add_library(${PLUGIN_NAME} SHARED
${QUICK_JS_LIB_DIR}/cutils.c
${QUICK_JS_LIB_DIR}/libregexp.c
${QUICK_JS_LIB_DIR}/libunicode.c
${QUICK_JS_LIB_DIR}/quickjs.c
"${CXX_LIB_DIR}/libfastdev_quickjs_runtime.cpp"
)

target_compile_options("${PLUGIN_NAME}" PRIVATE "-fPIC")

target_compile_options(${PLUGIN_NAME} PRIVATE "-DCONFIG_VERSION=\"${QUICKJS_VERSION}\"")

target_compile_features(${PLUGIN_NAME} PUBLIC cxx_std_17)
set_target_properties(${PLUGIN_NAME} PROPERTIES
CXX_VISIBILITY_PRESET hidden)
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
target_include_directories(${PLUGIN_NAME} INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/include")

#target_link_libraries(${PLUGIN_NAME} PRIVATE quickjs)
set_property(TARGET ${PLUGIN_NAME} PROPERTY POSITION_INDEPENDENT_CODE 1)