Skip to content
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

3.6 version OHOS adaptation #20826

Open
wants to merge 5 commits into
base: cocos2d-x-3.6-oh
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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
97 changes: 87 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,24 @@ 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)
if(OHOS)
set(BUILD_CPP_TESTS_DEFAULT OFF)
else()
set(BUILD_CPP_TESTS_DEFAULT ON)
endif()
set(BUILD_LUA_LIBS_DEFAULT ON)
set(BUILD_LUA_TESTS_DEFAULT ON)
# TODO: fix test samples for MSVC
Expand All @@ -78,8 +85,8 @@ option(BUILD_CPP_TESTS "Build TestCpp samples" ${BUILD_CPP_TESTS_DEFAULT})
option(BUILD_LUA_LIBS "Build lua libraries" ${BUILD_LUA_LIBS_DEFAULT})
option(BUILD_LUA_TESTS "Build TestLua samples" ${BUILD_LUA_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 @@ -138,6 +145,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 @@ -206,6 +216,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 @@ -215,6 +230,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 @@ -253,6 +272,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 @@ -279,9 +302,48 @@ 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)

add_subdirectory(external/flatbuffers)
Expand All @@ -294,23 +356,38 @@ add_subdirectory(external/xxhash)
set(XXHASH_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/xxhash)
set(XXHASH_LIBRARIES xxhash)

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)
add_subdirectory(tests/cpp-tests)
if(OHOS)
add_subdirectory(tests/cpp-tests)
elseif()
add_subdirectory(tests/cpp-empty-test)
add_subdirectory(tests/cpp-tests)
endif()
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(OHOS)
add_subdirectory(tests/lua-tests/project)
elseif()
add_subdirectory(tests/lua-tests/project)
add_subdirectory(tests/lua-empty-test/project)
endif()
endif(BUILD_LUA_TESTS)

endif(BUILD_LUA_LIBS)
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
88 changes: 82 additions & 6 deletions cocos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ if(BUILD_EDITOR_SPINE)
include(editor-support/spine/CMakeLists.txt)
set(COCOS_EDITOR_SUPPORT_SRC ${COCOS_EDITOR_SUPPORT_SRC} ${COCOS_SPINE_SRC})
endif(BUILD_EDITOR_SPINE)

include(../extensions/CMakeLists.txt)
if(OHOS)
include(${COCOS2DX_ROOT_PATH}/extensions/CMakeLists.txt)
else()
include(../extensions/CMakeLists.txt)
endif()

set(COCOS_SRC cocos2d.cpp
${COCOS_2D_SRC}
Expand All @@ -77,9 +80,12 @@ set(COCOS_SRC cocos2d.cpp
${COCOS_EDITOR_SUPPORT_SRC}
${COCOS_EXTENSIONS_SRC}
)

if(OHOS)
#todo: provide prebuild versions of the xx libs for all platforms
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/xxtea)
else()
include_directories(../external/xxtea)
endif()


add_library(cocos2d ${COCOS_SRC})
Expand Down Expand Up @@ -121,13 +127,83 @@ elseif(MACOSX OR APPLE)

elseif(ANDROID)
set(PLATFORM_SPECIFIC_LIBS GLESv2 log android)
elseif(OHOS)
find_library( # Sets the name of the path variable.
Drawing-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
native_drawing )
find_library( # Sets the name of the path variable.
libace-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
ace_ndk.z )
find_library( # Sets the name of the path variable.
libnapi-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
ace_napi.z )
find_library( # Sets the name of the path variable.
libuv-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
uv )
find_library( # Sets the name of the path variable.
GLES-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
GLESv3 )
find_library( # Sets the name of the path variable.
rawfile-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
rawfile.z )
find_library( # Sets the name of the path variable.
EGL-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
EGL )
set(PLATFORM_SPECIFIC_LIBS ${Drawing-lib} ${libace-lib} ${libnapi-lib} ${libuv-lib} ${GLES-lib} ${rawfile-lib} ${EGL-lib} EGL OpenSLES libc++.a)

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
)
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(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()

if(OHOS)
target_link_libraries(cocos2d
# ext_cpufeatures TBD need fixed?
ext_pvmp3dec
ext_tremolo
)
endif(OHOS)

if(LINUX)
set(glfw_other_linker_flags X11)
Expand Down
Loading