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.11 version OHOS adaptation #20821

Merged
merged 6 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
88 changes: 83 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# THE SOFTWARE.
# ****************************************************************************/

cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.6)
# It ensures that when Find*.cmake files included from cmake's Modules dir
# include another *.cmake file with relative path, that file will be included
# also from cmake's Modules dir, to not clash with per-project files.
Expand All @@ -46,22 +46,32 @@ 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_EMPTY_TEST_DEFAULT ON)
set(BUILD_CPP_TESTS_DEFAULT ON)
set(BUILD_LUA_LIBS_DEFAULT ON)
set(BUILD_LUA_TESTS_DEFAULT ON)
if(OHOS)
set(BUILD_CPP_EMPTY_TEST_DEFAULT OFF)
set(BUILD_JS_LIBS_DEFAULT OFF)
set(BUILD_JS_TESTS_DEFAULT OFF)
else()
set(BUILD_CPP_EMPTY_TEST_DEFAULT ON)
set(BUILD_JS_LIBS_DEFAULT ON)
set(BUILD_JS_TESTS_DEFAULT ON)
endif()
# TODO: fix test samples for MSVC
if(MSVC)
set(BUILD_CPP_EMPTY_TEST_DEFAULT OFF)
Expand Down Expand Up @@ -91,7 +101,7 @@ 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 @@ -156,6 +166,9 @@ elseif(ANDROID)
set(PLATFORM_FOLDER android)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char -latomic")
elseif(OHOS)
ADD_DEFINITIONS (-DUSE_FILE32API)
set(PLATFORM_FOLDER ohos)
else()
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
endif()
Expand Down Expand Up @@ -225,6 +238,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 @@ -234,6 +252,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()
if(USE_PREBUILT_LIBS)
cocos_find_package(Chipmunk CHIPMUNK REQUIRED)
endif()
Expand Down Expand Up @@ -308,7 +330,17 @@ 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)

# libz
if(OHOS)
set(ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/zlib/include)
set(ZLIB_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/external/zlib/prebuilt/ohos/libz.a)
endif()
cocos_find_package(ZLIB ZLIB REQUIRED)

# minizip (we try to migrate to minizip from https://github.com/nmoinvaz/minizip)
Expand All @@ -334,9 +366,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
)
cocos_find_package(OPENSSL OPENSSL REQUIRED)
endif()

if(OHOS)
set(CURL_INCLUDE_DIRS
${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_LIBRARIES ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/prebuilt/ohos/libcurl.a)
endif()
cocos_find_package(CURL CURL REQUIRED)

# flatbuffers
Expand All @@ -356,6 +426,11 @@ 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)

Expand All @@ -371,12 +446,15 @@ endif(BUILD_CPP_TESTS)

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

# build lua tests
if(BUILD_LUA_TESTS)
add_subdirectory(tests/lua-tests/project)
if(!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 "OpenHarmony")
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
Expand Down
60 changes: 56 additions & 4 deletions cocos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

# this CMakeLists is to generate libcocos2d.a

cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.6)

if(WINDOWS)
ADD_DEFINITIONS(-DUNICODE -D_UNICODE)
Expand Down Expand Up @@ -62,7 +62,7 @@ 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)
include(${COCOS2DX_ROOT_PATH}/extensions/CMakeLists.txt)

set(COCOS_SRC cocos2d.cpp
${COCOS_2D_SRC}
Expand All @@ -83,8 +83,8 @@ set(COCOS_SRC cocos2d.cpp
)

#todo: provide prebuild versions of the xx libs for all platforms
include_directories(../external/xxtea)
include_directories(../external/clipper)
include_directories(${COCOS2DX_ROOT_PATH}/external/xxtea)
include_directories(${COCOS2DX_ROOT_PATH}/external/clipper)

add_library(cocos2dInternal ${COCOS_SRC})

Expand Down Expand Up @@ -130,20 +130,72 @@ elseif(ANDROID)
get_filename_component(__module_path "${CMAKE_TOOLCHAIN_FILE}" DIRECTORY)
include(${__module_path}/AndroidNdkModules.cmake)
android_ndk_import_module_cpufeatures()

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(cocos2dInternal PUBLIC ${COCOS2DX_HEADER_PUBLIC})
target_compile_definitions(cocos2dInternal PUBLIC -DUSE_FILE32API -DOpenHarmony)
target_compile_options(cocos2dInternal PUBLIC -Wno-psabi)
else()
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
endif()

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

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

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

if(OHOS)
target_link_libraries(cocos2dInternal ${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)
target_link_libraries(cocos2dInternal pvmp3dec tremolo)
endif()

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