Skip to content

Commit

Permalink
3.9 version OHOS adaptation (#20830)
Browse files Browse the repository at this point in the history
* 3.9  version OHOS adaptation

---------

Signed-off-by: @wanghui187 <[email protected]>
Co-authored-by: @wanghui187 <[email protected]>
  • Loading branch information
xqg243795168 and wanghui187 authored Dec 30, 2024
1 parent 0682832 commit 93b0a77
Show file tree
Hide file tree
Showing 340 changed files with 28,418 additions and 174 deletions.
37 changes: 37 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: 1.0.{build}
skip_tags: true
skip_branch_with_pr: true
image:
- Visual Studio 2015
environment:
PYTHON: "C:\\Python27"
PYTHON_VERSION: "2.7.13"
PYTHON_ARCH: "32"
matrix:
# - build_type: windows32_cmake_test
# - build_type: windows32_sln_test
# - build_type: android_lua_tests
# - build_type: android_cocos_new_test
# - build_type: android_cpp_empty_test
# - build_type: android_gen_libs


platform:
- x86

configuration:
- Release


branches:
except:
- v1
- v2
- v4-develop
- v3-doc
- v3.11_backup
- v35-for-tizen

clone_depth: 1

test: off
91 changes: 83 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,30 @@ include(CocosBuildHelpers)

message(${BUILDING_STRING})

set(USE_WEBP_DEFAULT ON)
if(OHOS)
set(USE_WEBP_DEFAULT OFF)
else()
set(USE_WEBP_DEFAULT ON)
endif()
if(WINRT OR WP8)
set(USE_WEBP_DEFAULT OFF)
endif()

set(USE_PREBUILT_LIBS_DEFAULT ON)
if(MINGW)
if(MINGW AND NOT OHOS)
set(USE_PREBUILT_LIBS_DEFAULT OFF)
endif()

set(BUILD_CPP_TESTS_DEFAULT ON)
set(BUILD_LUA_LIBS_DEFAULT ON)
set(BUILD_LUA_TESTS_DEFAULT ON)
set(BUILD_JS_LIBS_DEFAULT ON)
set(BUILD_JS_TESTS_DEFAULT ON)
if(OHOS)
set(BUILD_JS_LIBS_DEFAULT OFF)
set(BUILD_JS_TESTS_DEFAULT OFF)
else()
set(BUILD_JS_LIBS_DEFAULT ON)
set(BUILD_JS_TESTS_DEFAULT ON)
endif()
# TODO: fix test samples for MSVC
if(MSVC)
set(BUILD_CPP_TESTS_DEFAULT OFF)
Expand All @@ -86,8 +95,8 @@ option(BUILD_LUA_TESTS "Build TestLua samples" ${BUILD_LUA_TESTS_DEFAULT})
option(BUILD_JS_LIBS "Build js libraries" ${BUILD_JS_LIBS_DEFAULT})
option(BUILD_JS_TESTS "Build TestJS samples" ${BUILD_JS_TESTS_DEFAULT})
option(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ${USE_PREBUILT_LIBS_DEFAULT})

if(USE_PREBUILT_LIBS AND MINGW)
if(USE_PREBUILT_LIBS AND MINGW AND NOT OHOS)
message(FATAL_ERROR "Prebuilt windows libs can't be used with mingw, please use packages.")
endif()

Expand Down Expand Up @@ -146,6 +155,9 @@ elseif(LINUX)
elseif(ANDROID)
ADD_DEFINITIONS (-DUSE_FILE32API)
set(PLATFORM_FOLDER android)
elseif(OHOS)
ADD_DEFINITIONS (-DUSE_FILE32API)
set(PLATFORM_FOLDER ohos)
else()
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
endif()
Expand Down Expand Up @@ -215,6 +227,11 @@ if(LINUX OR MACOSX OR WINDOWS)
endif(LINUX OR MACOSX OR WINDOWS)

# Freetype required on all platforms
if(OHOS)
set(FREETYPE_INCLUDE_DIR_ft2build ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/ohos)
set(FREETYPE_INCLUDE_DIR_freetype2 ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/ohos/freetype2)
set(FREETYPE_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/prebuilt/ohos/libfreetype.a)
endif()
cocos_find_package(Freetype FREETYPE REQUIRED)

# WebP required if used
Expand All @@ -224,6 +241,10 @@ endif(USE_WEBP)

# Chipmunk
if(USE_CHIPMUNK)
if(OHOS)
set(CHIPMUNK_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk/include/chipmunk)
set(CHIPMUNK_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk/prebuilt/ohos/libchipmunk.a)
endif()
cocos_find_package(Chipmunk CHIPMUNK REQUIRED)
add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
if(IOS OR MACOSX)
Expand Down Expand Up @@ -296,6 +317,10 @@ endif()
message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}")

# libjpeg
if(OHOS)
set(JPEG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/include/ohos)
set(JPEG_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/prebuilt/ohos/libjpeg.a)
endif()
cocos_find_package(JPEG JPEG REQUIRED)
cocos_find_package(ZLIB ZLIB REQUIRED)

Expand All @@ -322,9 +347,47 @@ else()
add_definitions(-DMINIZIP_FROM_SYSTEM)
endif()

if(OHOS)
set(PNG_PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/ohos)
set(PNG_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/ohos/libpng.a)
endif()
cocos_find_package(PNG PNG REQUIRED)

if(OHOS)
set(TIFF_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/include/ohos)
set(TIFF_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/ohos/libtiff.a)
endif()
cocos_find_package(TIFF TIFF REQUIRED)

if(OHOS)
set(WEBSOCKETS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/include/ohos)
set(WEBSOCKETS_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/ohos/libwebsockets.a)
endif()
cocos_find_package(WEBSOCKETS WEBSOCKETS REQUIRED)

# openssl for web
if(OHOS)
set(OPENSSL_INCLUDE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/external/openssl
${CMAKE_CURRENT_SOURCE_DIR}/external/openssl/include/ohos
${CMAKE_CURRENT_SOURCE_DIR}/external/openssl/include/ohos/openssl
)
set(OPENSSL_LIBRARY
${CMAKE_CURRENT_SOURCE_DIR}/external/openssl/prebuilt/ohos/libcrypto.a
${CMAKE_CURRENT_SOURCE_DIR}/external/openssl/prebuilt/ohos/libssl.a
)
endif()
cocos_find_package(OPENSSL OPENSSL REQUIRED)

if(OHOS)
set(CURL_INCLUDE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/external/curl
${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include
${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/ohos
${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/ohos/curl
)
set(CURL_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/prebuilt/ohos/libcurl.a)
endif()
cocos_find_package(CURL CURL REQUIRED)

# flatbuffers
Expand All @@ -344,23 +407,35 @@ if(USE_PREBUILT_LIBS)
else()
cocos_find_package(xxhash xxhash REQUIRED)
endif()

if(OHOS)
add_subdirectory(external/ohos-specific/pvmp3dec)
add_subdirectory(external/ohos-specific/tremolo)
endif()
# libcocos2d.a
add_subdirectory(cocos)

# build cpp tests
if(BUILD_CPP_TESTS)
add_subdirectory(tests/cpp-empty-test)
if(NOT OHOS)
add_subdirectory(tests/cpp-empty-test)
endif()
add_subdirectory(tests/cpp-tests)
endif(BUILD_CPP_TESTS)

## Scripting
if(BUILD_LUA_LIBS)
if(OHOS)
add_subdirectory(external/lua/luajit)
endif()
add_subdirectory(cocos/scripting/lua-bindings)

# build lua tests
if(BUILD_LUA_TESTS)
add_subdirectory(tests/lua-tests/project)
add_subdirectory(tests/lua-empty-test/project)
if(NOT OHOS)
add_subdirectory(tests/lua-empty-test/project)
endif()
endif(BUILD_LUA_TESTS)

endif(BUILD_LUA_LIBS)
Expand Down
4 changes: 3 additions & 1 deletion cmake/Modules/CocosBuildHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ endfunction()
#IOS = iOS
#MACOSX = MacOS X
#LINUX = Linux

#OHOS = OpenHarmonyOS
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if(WINRT)
set(SYSTEM_STRING "Windows RT")
Expand All @@ -139,6 +139,8 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(APPLE TRUE)
set(SYSTEM_STRING "Mac OSX")
endif()
elseif(OHOS)
set(SYSTEM_STRING "HarmonyOS Next")
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
Expand Down
61 changes: 58 additions & 3 deletions cocos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,75 @@ elseif(MACOSX OR APPLE)

elseif(ANDROID)
set(PLATFORM_SPECIFIC_LIBS GLESv2 log android)

elseif(OHOS)
FIND_LIBRARY(Drawing-lib native_drawing)
FIND_LIBRARY(libace-lib ace_ndk.z)
FIND_LIBRARY(libnapi-lib ace_napi.z)
FIND_LIBRARY(GLES-lib GLESv3)
FIND_LIBRARY(libuv-lib uv)
FIND_LIBRARY(rawfile-lib rawfile.z)
FIND_LIBRARY(EGL-lib EGL)
FIND_LIBRARY(OpenSl-lib OpenSLES)
find_library( hilog-lib hilog_ndk.z )

set(PLATFORM_SPECIFIC_LIBS
${Drawing-lib}
${libace-lib}
${libnapi-lib}
${GLES-lib}
${libuv-lib}
${rawfile-lib}
${EGL-lib}
${OpenSl-lib}
${hilog-lib}
)

set(COCOS2DX_HEADER_PUBLIC
${CLASSES_PATH}
${COCOS2DX_ROOT_PATH}/cocos
${COCOS2DX_ROOT_PATH}/cocos/math
${COCOS2DX_ROOT_PATH}/cocos/platform
${COCOS2DX_ROOT_PATH}/cocos/platform/ohos/napi/modules
${COCOS2DX_ROOT_PATH}/cocos/platform/ohos
${COCOS2DX_ROOT_PATH}/cocos/platform/ohos/napi/common
${COCOS2DX_ROOT_PATH}/cocos/platform/ohos/napi
${COCOS2DX_ROOT_PATH}/cocos/platform/ohos/napi/render
${COCOS2DX_ROOT_PATH}/external/ohos-specific/tremolo
${COCOS2DX_ROOT_PATH}/external/ohos-specific/pvmp3dec/include
${COCOS2DX_ROOT_PATH}/external/ohos-specific/pvmp3dec/src
)
target_include_directories(cocos2d PUBLIC ${COCOS2DX_HEADER_PUBLIC})
target_compile_definitions(cocos2d PUBLIC -DUSE_FILE32API -DOpenHarmony)
target_compile_options(cocos2d PUBLIC -Wno-psabi)
else()
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
endif()

foreach(pkg ZLIB MINIZIP JPEG PNG TIFF TinyXML2 FREETYPE WEBSOCKETS CURL FLATBUFFERS XXHASH)
cocos_use_pkg(cocos2d ${pkg})
endforeach()
if(OHOS)
foreach(pkg ZLIB MINIZIP JPEG PNG TIFF TinyXML2 FREETYPE WEBSOCKETS OPENSSL CURL FLATBUFFERS XXHASH)
cocos_use_pkg(cocos2d ${pkg})
endforeach()
else()
foreach(pkg ZLIB MINIZIP JPEG PNG TIFF TinyXML2 FREETYPE WEBSOCKETS CURL FLATBUFFERS XXHASH)
cocos_use_pkg(cocos2d ${pkg})
endforeach()
endif()

if(LINUX)
set(glfw_other_linker_flags X11)
endif(LINUX)

if (OHOS)
target_link_libraries(cocos2d ${Drawing-lib} ${libace-lib} ${GLES-lib} ${libnapi-lib} ${libuv-lib} ${rawfile-lib} ${EGL-lib} ${hilog-lib} libohaudio.so libavplayer.so libnative_window.so libnative_buffer.so)
endif()

target_link_libraries(cocos2d ${PLATFORM_SPECIFIC_LIBS} ${glfw_other_linker_flags})

if(OHOS)
target_link_libraries(cocos2d pvmp3dec tremolo)
endif()

if(USE_WEBP)
add_definitions(-DCC_USE_WEBP=1)
cocos_use_pkg(cocos2d WEBP)
Expand Down
Loading

0 comments on commit 93b0a77

Please sign in to comment.