Skip to content
Closed
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
45 changes: 39 additions & 6 deletions native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if(NOT USE_XR AND NOT USE_AR_MODULE)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/predefine.cmake)
endif()
cmake_minimum_required(VERSION 3.22.1)

include(${CMAKE_CURRENT_LIST_DIR}/cmake/predefine.cmake)

################################# engine source code ##################################
set(CWD ${CMAKE_CURRENT_LIST_DIR})
Expand All @@ -13,7 +13,24 @@ set(ENGINE_NAME cocos_engine)
################################# options ############################################
# default fallback options
cc_set_if_undefined(CC_DEBUG_FORCE OFF)
cc_set_if_undefined(USE_SE_V8 ON)
cc_set_if_undefined(USE_SE_V8 OFF)
cc_set_if_undefined(USE_SE_HERMES ON)
cc_set_if_undefined(USE_V8_DEBUGGER OFF)

# Dynamically locate React Native JSI headers for Hermes support
if(USE_SE_HERMES)
execute_process(
COMMAND node -e "console.log(require('path').dirname(require.resolve('react-native/package.json')))"
OUTPUT_VARIABLE REACT_NATIVE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(REACT_NATIVE_JSI_DIR "${REACT_NATIVE_DIR}/ReactCommon/jsi")
if(EXISTS "${REACT_NATIVE_JSI_DIR}")
message(STATUS "Found React Native JSI headers at: ${REACT_NATIVE_JSI_DIR}")
else()
message(FATAL_ERROR "Hermes JSI headers not found at: ${REACT_NATIVE_JSI_DIR}")
endif()
endif()
cc_set_if_undefined(USE_SE_SM OFF)
cc_set_if_undefined(USE_SE_NAPI OFF)
cc_set_if_undefined(USE_SE_JSVM OFF)
Expand Down Expand Up @@ -3274,34 +3291,44 @@ if(USE_MODULES)
add_library(ccgeometry ${ccgeometry_SOURCE_LIST})

target_include_directories(ccmath PRIVATE
${CWD}
${CWD}/cocos
$<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}>
)
target_include_directories(ccgeometry PRIVATE
${CWD}
${CWD}/cocos
$<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}>
)
target_include_directories(ccunzip PRIVATE
${CWD}
${CWD}/external/sources/unzip
${CWD}/external/sources
${CWD}/cocos
$<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}>
)
target_include_directories(cclog PRIVATE
${CWD}
${CWD}/cocos
$<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}>
)
target_include_directories(ccfilesystem PRIVATE
${CWD}
${CWD}/cocos
${CWD}/external/sources
)
target_include_directories(ccutils PRIVATE
${CWD}
${CWD}/cocos
${CWD}/external/sources
$<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}>
)
target_include_directories(ccbindings PRIVATE
${CWD}
${CWD}/cocos
${CWD}/cocos/bindings/jswrapper
${CWD}/cocos/editor-support # TODO: refactor include path
${CWD}
${CC_EXTERNAL_INCLUDES}
$<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}>
)
target_link_libraries(ccunzip PUBLIC
${ZLIB}
Expand Down Expand Up @@ -3368,6 +3395,9 @@ if(QNX)
list(APPEND COCOS_SOURCE_LIST ${ccqnx_SOURCE_LIST})
endif()

# ── Extended module split ──────────────────────────────────────────────────
include("${CMAKE_CURRENT_LIST_DIR}/CocosModuleSplit.cmake")

add_library(${ENGINE_NAME} ${COCOS_SOURCE_LIST})

if(CMAKE_GENERATOR STREQUAL "Xcode")
Expand Down Expand Up @@ -3444,6 +3474,7 @@ function(cc_apply_definations target)
$<$<BOOL:${USE_SE_V8}>:SCRIPT_ENGINE_TYPE=2>
$<$<BOOL:${USE_SE_NAPI}>:SCRIPT_ENGINE_TYPE=5>
$<$<BOOL:${USE_SE_JSVM}>:SCRIPT_ENGINE_TYPE=6>
$<$<BOOL:${USE_SE_HERMES}>:SCRIPT_ENGINE_TYPE=7>
$<$<OR:$<CONFIG:Debug>,$<BOOL:${CC_DEBUG_FORCE}>>:CC_DEBUG=1>
$<IF:$<BOOL:${USE_ADPF}>,CC_USE_ADPF=1,CC_USE_ADPF=0>
$<IF:$<BOOL:${USE_GOOGLE_BILLING}>,CC_USE_GOOGLE_BILLING=1,CC_USE_GOOGLE_BILLING=0>
Expand Down Expand Up @@ -3553,6 +3584,8 @@ target_include_directories(${ENGINE_NAME}
${SWIG_OUTPUT_ROOT}
${SWIG_OUTPUT_ROOT}/cocos
$<$<BOOL:USE_SE_V8>:${CWD}/cocos/bindings/jswrapper>
$<$<BOOL:${USE_SE_HERMES}>:${CWD}/cocos/bindings/jswrapper>
$<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}>
PRIVATE
${CC_EXTERNAL_PRIVATE_INCLUDES}
)
Expand Down
102 changes: 102 additions & 0 deletions native/CMakeLists.txt.rej
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
diff a/native/CMakeLists.txt b/native/CMakeLists.txt (rejected hunks)
@@ -1,6 +1,6 @@
-if(NOT USE_XR AND NOT USE_AR_MODULE)
- include(${CMAKE_CURRENT_LIST_DIR}/cmake/predefine.cmake)
-endif()
+cmake_minimum_required(VERSION 3.22.1)
+
+include(${CMAKE_CURRENT_LIST_DIR}/cmake/predefine.cmake)

################################# engine source code ##################################
set(CWD ${CMAKE_CURRENT_LIST_DIR})
@@ -13,7 +13,24 @@ set(ENGINE_NAME cocos_engine)
################################# options ############################################
# default fallback options
cc_set_if_undefined(CC_DEBUG_FORCE OFF)
-cc_set_if_undefined(USE_SE_V8 ON)
+cc_set_if_undefined(USE_SE_V8 OFF)
+cc_set_if_undefined(USE_SE_HERMES ON)
+cc_set_if_undefined(USE_V8_DEBUGGER OFF)
+
+# Dynamically locate React Native JSI headers for Hermes support
+if(USE_SE_HERMES)
+ execute_process(
+ COMMAND node -e "console.log(require('path').dirname(require.resolve('react-native/package.json')))"
+ OUTPUT_VARIABLE REACT_NATIVE_DIR
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ set(REACT_NATIVE_JSI_DIR "${REACT_NATIVE_DIR}/ReactCommon/jsi")
+ if(EXISTS "${REACT_NATIVE_JSI_DIR}")
+ message(STATUS "Found React Native JSI headers at: ${REACT_NATIVE_JSI_DIR}")
+ else()
+ message(FATAL_ERROR "Hermes JSI headers not found at: ${REACT_NATIVE_JSI_DIR}")
+ endif()
+endif()
cc_set_if_undefined(USE_SE_SM OFF)
cc_set_if_undefined(USE_SE_NAPI OFF)
cc_set_if_undefined(USE_SE_JSVM OFF)
@@ -3274,18 +3291,26 @@ if(USE_MODULES)
add_library(ccgeometry ${ccgeometry_SOURCE_LIST})

target_include_directories(ccmath PRIVATE
+ ${CWD}
${CWD}/cocos
+ $<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}>
)
target_include_directories(ccgeometry PRIVATE
+ ${CWD}
${CWD}/cocos
+ $<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}>
)
target_include_directories(ccunzip PRIVATE
+ ${CWD}
${CWD}/external/sources/unzip
${CWD}/external/sources
${CWD}/cocos
+ $<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}>
)
target_include_directories(cclog PRIVATE
+ ${CWD}
${CWD}/cocos
+ $<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}>
)
target_include_directories(ccfilesystem PRIVATE
${CWD}
@@ -3293,15 +3318,17 @@ if(USE_MODULES)
${CWD}/external/sources
)
target_include_directories(ccutils PRIVATE
+ ${CWD}
${CWD}/cocos
${CWD}/external/sources
+ $<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}>
)
target_include_directories(ccbindings PRIVATE
+ ${CWD}
${CWD}/cocos
${CWD}/cocos/bindings/jswrapper
${CWD}/cocos/editor-support # TODO: refactor include path
- ${CWD}
- ${CC_EXTERNAL_INCLUDES}
+ $<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}>
)
target_link_libraries(ccunzip PUBLIC
${ZLIB}
@@ -3368,6 +3395,9 @@ if(QNX)
list(APPEND COCOS_SOURCE_LIST ${ccqnx_SOURCE_LIST})
endif()

+# ── Extended module split ──────────────────────────────────────────────────
+include("${CMAKE_CURRENT_LIST_DIR}/CocosModuleSplit.cmake")
+
add_library(${ENGINE_NAME} ${COCOS_SOURCE_LIST})

if(CMAKE_GENERATOR STREQUAL "Xcode")
@@ -3444,6 +3474,7 @@ function(cc_apply_definations target)
$<$<BOOL:${USE_SE_V8}>:SCRIPT_ENGINE_TYPE=2>
$<$<BOOL:${USE_SE_NAPI}>:SCRIPT_ENGINE_TYPE=5>
$<$<BOOL:${USE_SE_JSVM}>:SCRIPT_ENGINE_TYPE=6>
+ $<$<BOOL:${USE_SE_HERMES}>:SCRIPT_ENGINE_TYPE=7>
$<$<OR:$<CONFIG:Debug>,$<BOOL:${CC_DEBUG_FORCE}>>:CC_DEBUG=1>
$<IF:$<BOOL:${USE_ADPF}>,CC_USE_ADPF=1,CC_USE_ADPF=0>
$<IF:$<BOOL:${USE_GOOGLE_BILLING}>,CC_USE_GOOGLE_BILLING=1,CC_USE_GOOGLE_BILLING=0>
140 changes: 140 additions & 0 deletions native/CocosModuleSplit.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# CocosModuleSplit.cmake
# Splits the Cocos4 engine into logical static libraries by subsystem.
# This makes incremental rebuilds fast and isolates breakage.
#
# Usage: include("${CMAKE_CURRENT_LIST_DIR}/CocosModuleSplit.cmake")
# Place this BEFORE: add_library(${ENGINE_NAME} ${COCOS_SOURCE_LIST})

message(STATUS "Executing extended module split...")

# ── Inject Hermes backend into ccbindings ───────────────────────────────────
if(USE_SE_HERMES)
target_sources(ccbindings PRIVATE
${CWD}/cocos/bindings/jswrapper/hermes/Class.cpp
${CWD}/cocos/bindings/jswrapper/hermes/Object.cpp
${CWD}/cocos/bindings/jswrapper/hermes/ScriptEngine.cpp
${CWD}/cocos/bindings/jswrapper/hermes/Utils.cpp
)
endif()

# ── Partition sources by directory ─────────────────────────────────────────
set(_ccrenderer_SOURCES)
set(_cc2d3d_SOURCES)
set(_ccscene_SOURCES)
set(_ccphysics_SOURCES)
set(_ccaudio_SOURCES)
set(_ccplatform_SOURCES)
set(_ccapp_SOURCES)
set(_ccmisc_SOURCES)

foreach(_src IN LISTS COCOS_SOURCE_LIST)
if(_src MATCHES "/cocos/renderer/")
list(APPEND _ccrenderer_SOURCES "${_src}")
elseif(_src MATCHES "/cocos/2d/" OR _src MATCHES "/cocos/3d/")
list(APPEND _cc2d3d_SOURCES "${_src}")
elseif(_src MATCHES "/cocos/scene/")
list(APPEND _ccscene_SOURCES "${_src}")
elseif(_src MATCHES "/cocos/physics/")
list(APPEND _ccphysics_SOURCES "${_src}")
elseif(_src MATCHES "/cocos/audio/")
list(APPEND _ccaudio_SOURCES "${_src}")
elseif(_src MATCHES "/cocos/platform/")
list(APPEND _ccplatform_SOURCES "${_src}")
elseif(_src MATCHES "/cocos/application/" OR _src MATCHES "/cocos/engine/" OR _src MATCHES "/cocos/main/")
list(APPEND _ccapp_SOURCES "${_src}")
elseif(_src MATCHES "/cocos/ui/" OR _src MATCHES "/cocos/network/" OR _src MATCHES "/cocos/editor-support/" OR _src MATCHES "/cocos/profiler/" OR _src MATCHES "/cocos/primitive/" OR _src MATCHES "/cocos/plugins/" OR _src MATCHES "/cocos/gi/" OR _src MATCHES "/cocos/storage/" OR _src MATCHES "/cocos/base/" OR _src MATCHES "/cocos/core/")
list(APPEND _ccmisc_SOURCES "${_src}")
endif()
endforeach()

# ── Remove split sources from main engine list ──────────────────────────────
if(USE_MODULES)
list(REMOVE_ITEM COCOS_SOURCE_LIST ${_ccrenderer_SOURCES})
list(REMOVE_ITEM COCOS_SOURCE_LIST ${_cc2d3d_SOURCES})
list(REMOVE_ITEM COCOS_SOURCE_LIST ${_ccscene_SOURCES})
list(REMOVE_ITEM COCOS_SOURCE_LIST ${_ccphysics_SOURCES})
list(REMOVE_ITEM COCOS_SOURCE_LIST ${_ccaudio_SOURCES})
list(REMOVE_ITEM COCOS_SOURCE_LIST ${_ccplatform_SOURCES})
list(REMOVE_ITEM COCOS_SOURCE_LIST ${_ccapp_SOURCES})
list(REMOVE_ITEM COCOS_SOURCE_LIST ${_ccmisc_SOURCES})
endif()

# ── Create split static libraries ──────────────────────────────────────────
if(USE_MODULES)
if(_ccrenderer_SOURCES)
add_library(ccrenderer STATIC ${_ccrenderer_SOURCES})
target_include_directories(ccrenderer PRIVATE ${CWD} ${CWD}/cocos ${CC_EXTERNAL_INCLUDES} ${CWD}/cocos/bindings/jswrapper
$<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}> ${CWD}/cocos/renderer ${CWD}/cocos/platform ${CWD}/cocos/renderer/core ${CWD}/cocos/editor-support ${SWIG_OUTPUT_ROOT} ${SWIG_OUTPUT_ROOT}/cocos ${CWD}/external/sources/khronos
$<$<NOT:$<BOOL:${APPLE}>>:${CWD}/external/sources/EGL>)
target_link_libraries(ccrenderer PUBLIC ccmath cclog ccgeometry ccbindings ccfilesystem)
if(ANDROID)
target_link_libraries(ccrenderer PUBLIC android_platform android log)
endif()
endif()

if(_cc2d3d_SOURCES)
add_library(cc2d3d STATIC ${_cc2d3d_SOURCES})
target_include_directories(cc2d3d PRIVATE ${CWD} ${CWD}/cocos ${CC_EXTERNAL_INCLUDES} ${CWD}/cocos/bindings/jswrapper
$<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}> ${CWD}/cocos/renderer ${CWD}/cocos/platform ${CWD}/cocos/renderer/core ${CWD}/cocos/editor-support ${SWIG_OUTPUT_ROOT} ${SWIG_OUTPUT_ROOT}/cocos ${CWD}/external/sources/khronos
$<$<NOT:$<BOOL:${APPLE}>>:${CWD}/external/sources/EGL>)
target_link_libraries(cc2d3d PUBLIC ccmath cclog ccgeometry ccbindings ccrenderer)
endif()

if(_ccscene_SOURCES)
add_library(ccscene STATIC ${_ccscene_SOURCES})
target_include_directories(ccscene PRIVATE ${CWD} ${CWD}/cocos ${CC_EXTERNAL_INCLUDES} ${CWD}/cocos/bindings/jswrapper
$<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}> ${CWD}/cocos/renderer ${CWD}/cocos/platform ${CWD}/cocos/renderer/core ${CWD}/cocos/editor-support ${SWIG_OUTPUT_ROOT} ${SWIG_OUTPUT_ROOT}/cocos ${CWD}/external/sources/khronos
$<$<NOT:$<BOOL:${APPLE}>>:${CWD}/external/sources/EGL>)
target_link_libraries(ccscene PUBLIC ccmath cclog cc2d3d ccrenderer ccbindings)
endif()

if(_ccphysics_SOURCES)
add_library(ccphysics STATIC ${_ccphysics_SOURCES})
target_include_directories(ccphysics PRIVATE ${CWD} ${CWD}/cocos ${CC_EXTERNAL_INCLUDES} ${CWD}/cocos/bindings/jswrapper
$<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}> ${CWD}/cocos/renderer ${CWD}/cocos/platform ${CWD}/cocos/renderer/core ${CWD}/cocos/editor-support ${SWIG_OUTPUT_ROOT} ${SWIG_OUTPUT_ROOT}/cocos ${CWD}/external/sources/khronos
$<$<NOT:$<BOOL:${APPLE}>>:${CWD}/external/sources/EGL>)
target_link_libraries(ccphysics PUBLIC ccmath cclog ccscene)
endif()

if(_ccaudio_SOURCES)
add_library(ccaudio STATIC ${_ccaudio_SOURCES})
target_include_directories(ccaudio PRIVATE ${CWD} ${CWD}/cocos ${CC_EXTERNAL_INCLUDES} ${CWD}/cocos/bindings/jswrapper
$<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}> ${CWD}/cocos/renderer ${CWD}/cocos/platform ${CWD}/cocos/renderer/core ${CWD}/cocos/editor-support ${SWIG_OUTPUT_ROOT} ${SWIG_OUTPUT_ROOT}/cocos ${CWD}/external/sources/khronos
$<$<NOT:$<BOOL:${APPLE}>>:${CWD}/external/sources/EGL>
${CWD}/external/sources/pvmp3dec/include ${CWD}/external/sources/pvmp3dec/src)
target_link_libraries(ccaudio PUBLIC ccmath cclog)
if(ANDROID)
target_link_libraries(ccaudio PUBLIC android_platform android log OpenSLES)
endif()
endif()

if(_ccplatform_SOURCES)
add_library(ccplatform STATIC ${_ccplatform_SOURCES})
target_include_directories(ccplatform PRIVATE ${CWD} ${CWD}/cocos ${CC_EXTERNAL_INCLUDES} ${CWD}/cocos/bindings/jswrapper
$<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}> ${CWD}/cocos/renderer ${CWD}/cocos/platform ${CWD}/cocos/renderer/core ${CWD}/cocos/editor-support ${SWIG_OUTPUT_ROOT} ${SWIG_OUTPUT_ROOT}/cocos ${CWD}/external/sources/khronos
$<$<NOT:$<BOOL:${APPLE}>>:${CWD}/external/sources/EGL>)
target_link_libraries(ccplatform PUBLIC ccmath cclog ccbindings ccfilesystem)
if(ANDROID)
target_link_libraries(ccplatform PUBLIC cocos_jni)
endif()
endif()

if(_ccapp_SOURCES)
add_library(ccapp STATIC ${_ccapp_SOURCES})
target_include_directories(ccapp PRIVATE ${CWD} ${CWD}/cocos ${CC_EXTERNAL_INCLUDES} ${CWD}/cocos/bindings/jswrapper
$<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}> ${CWD}/cocos/renderer ${CWD}/cocos/platform ${CWD}/cocos/renderer/core ${CWD}/cocos/editor-support ${SWIG_OUTPUT_ROOT} ${SWIG_OUTPUT_ROOT}/cocos ${CWD}/external/sources/khronos
$<$<NOT:$<BOOL:${APPLE}>>:${CWD}/external/sources/EGL>)
target_link_libraries(ccapp PUBLIC
ccmath cclog cc2d3d ccrenderer ccscene ccphysics ccaudio ccplatform ccbindings ccfilesystem
)
endif()

if(_ccmisc_SOURCES)
add_library(ccmisc STATIC ${_ccmisc_SOURCES})
target_include_directories(ccmisc PRIVATE ${CWD} ${CWD}/cocos ${CC_EXTERNAL_INCLUDES} ${CWD}/cocos/bindings/jswrapper
$<$<BOOL:${USE_SE_HERMES}>:${REACT_NATIVE_JSI_DIR}> ${CWD}/cocos/renderer ${CWD}/cocos/platform ${CWD}/cocos/renderer/core ${CWD}/cocos/editor-support ${CWD}/cocos/bindings/jswrapper ${SWIG_OUTPUT_ROOT} ${SWIG_OUTPUT_ROOT}/cocos ${CWD}/external/sources/khronos
$<$<NOT:$<BOOL:${APPLE}>>:${CWD}/external/sources/EGL>
${CWD}/external/android/${ANDROID_ABI}/include/freetype)
target_link_libraries(ccmisc PUBLIC ccmath cclog ccfilesystem ccbindings freetype)
endif()
endif()
Loading
Loading