Skip to content

Commit 5c59692

Browse files
3.6 version OHOS adaptation (#20826)
* 3.6 version OHOS adaptation --------- Signed-off-by: @wanghui187 <348582973@qq.com> Co-authored-by: @wanghui187 <348582973@qq.com>
1 parent c785b7a commit 5c59692

File tree

332 files changed

+28885
-177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

332 files changed

+28885
-177
lines changed

.appveyor.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: 1.0.{build}
2+
skip_tags: true
3+
skip_branch_with_pr: true
4+
image:
5+
- Visual Studio 2015
6+
environment:
7+
PYTHON: "C:\\Python27"
8+
PYTHON_VERSION: "2.7.13"
9+
PYTHON_ARCH: "32"
10+
matrix:
11+
# - build_type: windows32_cmake_test
12+
# - build_type: windows32_sln_test
13+
# - build_type: android_lua_tests
14+
# - build_type: android_cocos_new_test
15+
# - build_type: android_cpp_empty_test
16+
# - build_type: android_gen_libs
17+
18+
19+
platform:
20+
- x86
21+
22+
configuration:
23+
- Release
24+
25+
26+
branches:
27+
except:
28+
- v1
29+
- v2
30+
- v4-develop
31+
- v3-doc
32+
- v3.11_backup
33+
- v35-for-tizen
34+
35+
clone_depth: 1
36+
37+
test: off

CMakeLists.txt

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,24 @@ include(CocosBuildHelpers)
4545

4646
message(${BUILDING_STRING})
4747

48-
set(USE_WEBP_DEFAULT ON)
48+
if(OHOS)
49+
set(USE_WEBP_DEFAULT OFF)
50+
else()
51+
set(USE_WEBP_DEFAULT ON)
52+
endif()
4953
if(WINRT OR WP8)
5054
set(USE_WEBP_DEFAULT OFF)
5155
endif()
5256

5357
set(USE_PREBUILT_LIBS_DEFAULT ON)
54-
if(MINGW)
58+
if(MINGW AND NOT OHOS)
5559
set(USE_PREBUILT_LIBS_DEFAULT OFF)
5660
endif()
57-
58-
set(BUILD_CPP_TESTS_DEFAULT ON)
61+
if(OHOS)
62+
set(BUILD_CPP_TESTS_DEFAULT OFF)
63+
else()
64+
set(BUILD_CPP_TESTS_DEFAULT ON)
65+
endif()
5966
set(BUILD_LUA_LIBS_DEFAULT ON)
6067
set(BUILD_LUA_TESTS_DEFAULT ON)
6168
# TODO: fix test samples for MSVC
@@ -78,8 +85,8 @@ option(BUILD_CPP_TESTS "Build TestCpp samples" ${BUILD_CPP_TESTS_DEFAULT})
7885
option(BUILD_LUA_LIBS "Build lua libraries" ${BUILD_LUA_LIBS_DEFAULT})
7986
option(BUILD_LUA_TESTS "Build TestLua samples" ${BUILD_LUA_TESTS_DEFAULT})
8087
option(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ${USE_PREBUILT_LIBS_DEFAULT})
81-
82-
if(USE_PREBUILT_LIBS AND MINGW)
88+
89+
if(USE_PREBUILT_LIBS AND MINGW AND NOT OHOS)
8390
message(FATAL_ERROR "Prebuilt windows libs can't be used with mingw, please use packages.")
8491
endif()
8592

@@ -138,6 +145,9 @@ elseif(LINUX)
138145
elseif(ANDROID)
139146
ADD_DEFINITIONS (-DUSE_FILE32API)
140147
set(PLATFORM_FOLDER android)
148+
elseif(OHOS)
149+
ADD_DEFINITIONS (-DUSE_FILE32API)
150+
set(PLATFORM_FOLDER ohos)
141151
else()
142152
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
143153
endif()
@@ -206,6 +216,11 @@ if(LINUX OR MACOSX OR WINDOWS)
206216
endif(LINUX OR MACOSX OR WINDOWS)
207217

208218
# Freetype required on all platforms
219+
if(OHOS)
220+
set(FREETYPE_INCLUDE_DIR_ft2build ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/ohos)
221+
set(FREETYPE_INCLUDE_DIR_freetype2 ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/ohos/freetype2)
222+
set(FREETYPE_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/prebuilt/ohos/libfreetype.a)
223+
endif()
209224
cocos_find_package(Freetype FREETYPE REQUIRED)
210225

211226
# WebP required if used
@@ -215,6 +230,10 @@ endif(USE_WEBP)
215230

216231
# Chipmunk
217232
if(USE_CHIPMUNK)
233+
if(OHOS)
234+
set(CHIPMUNK_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk/include/chipmunk)
235+
set(CHIPMUNK_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk/prebuilt/ohos/libchipmunk.a)
236+
endif()
218237
cocos_find_package(Chipmunk CHIPMUNK REQUIRED)
219238
add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
220239
if(IOS OR MACOSX)
@@ -253,6 +272,10 @@ endif()
253272
message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}")
254273

255274
# libjpeg
275+
if(OHOS)
276+
set(JPEG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/include/ohos)
277+
set(JPEG_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/prebuilt/ohos/libjpeg.a)
278+
endif()
256279
cocos_find_package(JPEG JPEG REQUIRED)
257280
cocos_find_package(ZLIB ZLIB REQUIRED)
258281

@@ -279,9 +302,48 @@ else()
279302
add_definitions(-DMINIZIP_FROM_SYSTEM)
280303
endif()
281304

305+
if(OHOS)
306+
set(PNG_PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/ohos)
307+
set(PNG_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/ohos/libpng.a)
308+
endif()
282309
cocos_find_package(PNG PNG REQUIRED)
310+
311+
if(OHOS)
312+
set(TIFF_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/include/ohos)
313+
set(TIFF_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/ohos/libtiff.a)
314+
endif()
283315
cocos_find_package(TIFF TIFF REQUIRED)
316+
317+
if(OHOS)
318+
set(WEBSOCKETS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/include/ohos)
319+
set(WEBSOCKETS_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/ohos/libwebsockets.a)
320+
endif()
284321
cocos_find_package(WEBSOCKETS WEBSOCKETS REQUIRED)
322+
323+
# openssl for web
324+
if(OHOS)
325+
set(OPENSSL_INCLUDE_DIR
326+
${CMAKE_CURRENT_SOURCE_DIR}/external/openssl
327+
${CMAKE_CURRENT_SOURCE_DIR}/external/openssl/include/ohos
328+
${CMAKE_CURRENT_SOURCE_DIR}/external/openssl/include/ohos/openssl
329+
)
330+
set(OPENSSL_LIBRARY
331+
${CMAKE_CURRENT_SOURCE_DIR}/external/openssl/prebuilt/ohos/libcrypto.a
332+
${CMAKE_CURRENT_SOURCE_DIR}/external/openssl/prebuilt/ohos/libssl.a
333+
)
334+
endif()
335+
cocos_find_package(OPENSSL OPENSSL REQUIRED)
336+
337+
if(OHOS)
338+
set(CURL_INCLUDE_DIR
339+
${CMAKE_CURRENT_SOURCE_DIR}/external/curl
340+
${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include
341+
${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/ohos
342+
${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/ohos/curl
343+
)
344+
set(CURL_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/prebuilt/ohos/libcurl.a)
345+
346+
endif()
285347
cocos_find_package(CURL CURL REQUIRED)
286348

287349
add_subdirectory(external/flatbuffers)
@@ -294,23 +356,38 @@ add_subdirectory(external/xxhash)
294356
set(XXHASH_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/xxhash)
295357
set(XXHASH_LIBRARIES xxhash)
296358

359+
if(OHOS)
360+
add_subdirectory(external/ohos-specific/pvmp3dec)
361+
add_subdirectory(external/ohos-specific/tremolo)
362+
endif()
297363
# libcocos2d.a
298364
add_subdirectory(cocos)
299365

300366
# build cpp tests
301367
if(BUILD_CPP_TESTS)
302-
add_subdirectory(tests/cpp-empty-test)
303-
add_subdirectory(tests/cpp-tests)
368+
if(OHOS)
369+
add_subdirectory(tests/cpp-tests)
370+
elseif()
371+
add_subdirectory(tests/cpp-empty-test)
372+
add_subdirectory(tests/cpp-tests)
373+
endif()
304374
endif(BUILD_CPP_TESTS)
305375

306376
## Scripting
307377
if(BUILD_LUA_LIBS)
378+
if(OHOS)
379+
add_subdirectory(external/lua/luajit)
380+
endif()
308381
add_subdirectory(cocos/scripting/lua-bindings)
309382

310383
# build lua tests
311384
if(BUILD_LUA_TESTS)
312-
add_subdirectory(tests/lua-tests/project)
313-
add_subdirectory(tests/lua-empty-test/project)
385+
if(OHOS)
386+
add_subdirectory(tests/lua-tests/project)
387+
elseif()
388+
add_subdirectory(tests/lua-tests/project)
389+
add_subdirectory(tests/lua-empty-test/project)
390+
endif()
314391
endif(BUILD_LUA_TESTS)
315392

316393
endif(BUILD_LUA_LIBS)

cmake/Modules/CocosBuildHelpers.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ endfunction()
114114
#IOS = iOS
115115
#MACOSX = MacOS X
116116
#LINUX = Linux
117-
117+
#OHOS = OpenHarmonyOS
118118
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
119119
if(WINRT)
120120
set(SYSTEM_STRING "Windows RT")
@@ -139,6 +139,8 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
139139
set(APPLE TRUE)
140140
set(SYSTEM_STRING "Mac OSX")
141141
endif()
142+
elseif(OHOS)
143+
set(SYSTEM_STRING "HarmonyOS Next")
142144
endif()
143145

144146
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")

cocos/CMakeLists.txt

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ if(BUILD_EDITOR_SPINE)
5959
include(editor-support/spine/CMakeLists.txt)
6060
set(COCOS_EDITOR_SUPPORT_SRC ${COCOS_EDITOR_SUPPORT_SRC} ${COCOS_SPINE_SRC})
6161
endif(BUILD_EDITOR_SPINE)
62-
63-
include(../extensions/CMakeLists.txt)
62+
if(OHOS)
63+
include(${COCOS2DX_ROOT_PATH}/extensions/CMakeLists.txt)
64+
else()
65+
include(../extensions/CMakeLists.txt)
66+
endif()
6467

6568
set(COCOS_SRC cocos2d.cpp
6669
${COCOS_2D_SRC}
@@ -77,9 +80,12 @@ set(COCOS_SRC cocos2d.cpp
7780
${COCOS_EDITOR_SUPPORT_SRC}
7881
${COCOS_EXTENSIONS_SRC}
7982
)
80-
83+
if(OHOS)
8184
#todo: provide prebuild versions of the xx libs for all platforms
85+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/xxtea)
86+
else()
8287
include_directories(../external/xxtea)
88+
endif()
8389

8490

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

122128
elseif(ANDROID)
123129
set(PLATFORM_SPECIFIC_LIBS GLESv2 log android)
130+
elseif(OHOS)
131+
find_library( # Sets the name of the path variable.
132+
Drawing-lib
133+
# Specifies the name of the NDK library that
134+
# you want CMake to locate.
135+
native_drawing )
136+
find_library( # Sets the name of the path variable.
137+
libace-lib
138+
# Specifies the name of the NDK library that
139+
# you want CMake to locate.
140+
ace_ndk.z )
141+
find_library( # Sets the name of the path variable.
142+
libnapi-lib
143+
# Specifies the name of the NDK library that
144+
# you want CMake to locate.
145+
ace_napi.z )
146+
find_library( # Sets the name of the path variable.
147+
libuv-lib
148+
# Specifies the name of the NDK library that
149+
# you want CMake to locate.
150+
uv )
151+
find_library( # Sets the name of the path variable.
152+
GLES-lib
153+
# Specifies the name of the NDK library that
154+
# you want CMake to locate.
155+
GLESv3 )
156+
find_library( # Sets the name of the path variable.
157+
rawfile-lib
158+
# Specifies the name of the NDK library that
159+
# you want CMake to locate.
160+
rawfile.z )
161+
find_library( # Sets the name of the path variable.
162+
EGL-lib
163+
# Specifies the name of the NDK library that
164+
# you want CMake to locate.
165+
EGL )
166+
set(PLATFORM_SPECIFIC_LIBS ${Drawing-lib} ${libace-lib} ${libnapi-lib} ${libuv-lib} ${GLES-lib} ${rawfile-lib} ${EGL-lib} EGL OpenSLES libc++.a)
167+
168+
set(COCOS2DX_HEADER_PUBLIC
169+
${CLASSES_PATH}
170+
${COCOS2DX_ROOT_PATH}/cocos
171+
${COCOS2DX_ROOT_PATH}/cocos/math
172+
${COCOS2DX_ROOT_PATH}/cocos/platform
173+
${COCOS2DX_ROOT_PATH}/cocos/platform/ohos/napi/modules
174+
${COCOS2DX_ROOT_PATH}/cocos/platform/ohos
175+
${COCOS2DX_ROOT_PATH}/cocos/platform/ohos/napi/common
176+
${COCOS2DX_ROOT_PATH}/cocos/platform/ohos/napi
177+
${COCOS2DX_ROOT_PATH}/cocos/platform/ohos/napi/render
178+
)
179+
target_include_directories(cocos2d PUBLIC ${COCOS2DX_HEADER_PUBLIC})
180+
target_compile_definitions(cocos2d PUBLIC -DUSE_FILE32API -DOpenHarmony)
181+
target_compile_options(cocos2d PUBLIC -Wno-psabi)
124182
else()
125183
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
126184
endif()
127185

128-
foreach(pkg ZLIB MINIZIP JPEG PNG TIFF TinyXML2 FREETYPE WEBSOCKETS CURL FLATBUFFERS XXHASH)
129-
cocos_use_pkg(cocos2d ${pkg})
130-
endforeach()
186+
if(OHOS)
187+
foreach(pkg ZLIB MINIZIP JPEG PNG TIFF TinyXML2 FREETYPE WEBSOCKETS OPENSSL CURL FLATBUFFERS XXHASH)
188+
cocos_use_pkg(cocos2d ${pkg})
189+
endforeach()
190+
else()
191+
foreach(pkg ZLIB MINIZIP JPEG PNG TIFF TinyXML2 FREETYPE WEBSOCKETS CURL FLATBUFFERS XXHASH)
192+
cocos_use_pkg(cocos2d ${pkg})
193+
endforeach()
194+
endif()
195+
196+
if(OHOS)
197+
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)
198+
endif()
199+
200+
if(OHOS)
201+
target_link_libraries(cocos2d
202+
# ext_cpufeatures TBD need fixed?
203+
ext_pvmp3dec
204+
ext_tremolo
205+
)
206+
endif(OHOS)
131207

132208
if(LINUX)
133209
set(glfw_other_linker_flags X11)

0 commit comments

Comments
 (0)