Add new cmake variable:

- AX_PREBUILT_DIR: specific engine build directory relative to ADXE_ROOT, such as "-DAX_PREBUILT_DIR=build_x86"
This commit is contained in:
halx99 2022-02-20 17:07:13 +08:00
parent 694712ee9e
commit 8196eb8ac6
2 changed files with 307 additions and 8 deletions

View File

@ -1,8 +1,8 @@
#/****************************************************************************
# Copyright (c) 2013-2014 cocos2d-x.org
# Copyright (c) 2021 Bytedance Inc.
# Copyright (c) 2021-2022 Bytedance Inc.
#
# https://adxe.org
# https://adxeproject.github.io
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@ -44,15 +44,23 @@ if(NOT DEFINED BUILD_ENGINE_DONE) # to test HelloCpp into root project
if(NOT (ADXE_ROOT STREQUAL ""))
set(ADXE_ROOT_PATH "${ADXE_ROOT}")
file(TO_CMAKE_PATH ${ADXE_ROOT_PATH} ADXE_ROOT_PATH) # string(REPLACE "\\" "/" ADXE_ROOT_PATH ${ADXE_ROOT_PATH})
file(TO_CMAKE_PATH ${ADXE_ROOT_PATH} ADXE_ROOT_PATH) # string(REPLACE "\\" "/" ADXE_ROOT_PATH ${ADXE_ROOT_PATH})
message(STATUS "Using system env var ADXE_ROOT=${ADXE_ROOT}")
else()
message(FATAL_ERROR "Please run setup.py add system env var 'ADXE_ROOT' to specific the engine root")
endif()
set(CMAKE_MODULE_PATH ${ADXE_ROOT_PATH}/cmake/Modules/)
include(CocosBuildSet)
add_subdirectory(${ADXE_ROOT_PATH}/core ${ENGINE_BINARY_PATH}/adxe/core)
set(_AX_USE_PREBUILT FALSE)
if (WIN32 AND DEFINED AX_PREBUILT_DIR AND IS_DIRECTORY ${ADXE_ROOT_PATH}/${AX_PREBUILT_DIR})
set(_AX_USE_PREBUILT TRUE)
endif()
if (NOT _AX_USE_PREBUILT)
add_subdirectory(${ADXE_ROOT_PATH}/core ${ENGINE_BINARY_PATH}/adxe/core)
endif()
endif()
# record sources, headers, resources...
@ -166,7 +174,9 @@ if(APPLE)
# For code-signing, set the DEVELOPMENT_TEAM:
#set_xcode_property(${APP_NAME} DEVELOPMENT_TEAM "GRLXXXX2K9")
elseif(WINDOWS)
cocos_copy_target_dll(${APP_NAME})
if(NOT _AX_USE_PREBUILT)
cocos_copy_target_dll(${APP_NAME})
endif()
endif()
if(WINDOWS)
@ -175,3 +185,139 @@ elseif(LINUX)
cocos_get_resource_path(APP_RES_DIR ${APP_NAME})
cocos_copy_target_res(${APP_NAME} LINK_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER})
endif()
if (_AX_USE_PREBUILT) # support windows only
if(NOT ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Win32"))
set(WIN64 TRUE)
set(ARCH_ALIAS "x64")
else()
set(WIN32 TRUE)
set(ARCH_ALIAS "x86")
endif()
if (NOT AX_USE_SHARED_PREBUILT)
target_compile_definitions(${APP_NAME}
PRIVATE CC_STATIC=1
)
endif()
target_include_directories(${APP_NAME}
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/lua
PRIVATE ${ADXE_ROOT_PATH}/extensions/scripting/lua-bindings/manual
PRIVATE ${ADXE_ROOT_PATH}
PRIVATE ${ADXE_ROOT_PATH}/thirdparty
PRIVATE ${ADXE_ROOT_PATH}/extensions
PRIVATE ${ADXE_ROOT_PATH}/core
PRIVATE ${ADXE_ROOT_PATH}/core/platform
PRIVATE ${ADXE_ROOT_PATH}/core/base
PRIVATE ${ADXE_ROOT_PATH}/core/audio
PRIVATE ${ADXE_ROOT_PATH}/core/platform/win32
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/fmt/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/robin-map/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/freetype/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/glfw/include/GLFW
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/box2d/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/chipmunk/include
PRIVATE ${ADXE_ROOT_PATH}/${AX_PREBUILT_DIR}/engine/thirdparty/freetype/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/recast/..
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/bullet/.
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/webp/src/webp
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/pugixml
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/xxhash/.
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/lz4/.
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/clipper/.
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/ConvertUTF/.
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/poly2tri/..
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/astc/..
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/openal/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/ogg/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/glad/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/glfw/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/png
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/unzip/.
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/llhttp/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/lua/plainlua
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/lua/tolua/.
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/lua/lua-cjson/.
PRIVATE ${ADXE_ROOT_PATH}/extensions/cocostudio
PRIVATE ${ADXE_ROOT_PATH}/extensions/spine/runtime/include
PRIVATE ${ADXE_ROOT_PATH}/extensions/fairygui
PRIVATE ${ADXE_ROOT_PATH}/extensions/GUI
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/zlib/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/jpeg/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/openssl/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/curl/include
)
target_link_directories(${APP_NAME}
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/openssl/prebuilt/windows/${ARCH_ALIAS}
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/zlib/prebuilt/windows/${ARCH_ALIAS}
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/jpeg/prebuilt/windows/${ARCH_ALIAS}
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/curl/prebuilt/windows/${ARCH_ALIAS}
PRIVATE ${ADXE_ROOT_PATH}/${AX_PREBUILT_DIR}/lib/Debug
)
# Linking OS libs
target_link_libraries(${APP_NAME} winmm Version)
# Linking engine and thirdparty libs
target_link_libraries(${APP_NAME}
spine.lib
particle3d.lib
assets-manager.lib
cocostudio.lib
DragonBones.lib
adxe.lib
box2d.lib
chipmunk.lib
freetype.lib
libzlib.lib
recast.lib
bullet.lib
jpeg-static.lib
libcrypto.lib
libssl.lib
webp.lib
pugixml.lib
xxhash.lib
lz4.lib
clipper.lib
ConvertUTF.lib
poly2tri.lib
astc.lib
libcurl_imp.lib
OpenAL32.lib
ogg.lib
glad.lib
glfw.lib
png.lib
unzip.lib
llhttp.lib
physics-nodes.lib
)
# Copy dlls to app bin dir
# copy thirdparty dlls to target bin dir
# copy_thirdparty_dlls(${APP_NAME} $<TARGET_FILE_DIR:${APP_NAME}>)
add_custom_command(TARGET ${APP_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${ADXE_ROOT_PATH}/thirdparty/openssl/prebuilt/windows/${ARCH_ALIAS}/libcrypto-3.dll"
"${ADXE_ROOT_PATH}/thirdparty/openssl/prebuilt/windows/${ARCH_ALIAS}/libssl-3.dll"
"${ADXE_ROOT_PATH}/thirdparty/curl/prebuilt/windows/${ARCH_ALIAS}/libcurl.dll"
"${ADXE_ROOT_PATH}/thirdparty/zlib/prebuilt/windows/${ARCH_ALIAS}/zlib1.dll"
"${ADXE_ROOT_PATH}/${AX_PREBUILT_DIR}/bin/\$\(Configuration\)/OpenAL32.dll"
$<TARGET_FILE_DIR:${APP_NAME}>)
# Copy windows angle binaries
if (AX_USE_COMPAT_GL)
add_custom_command(TARGET ${APP_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${ADXE_ROOT_PATH}/thirdparty/angle/prebuilt/${ARCH_ALIAS}/libGLESv2.dll
${ADXE_ROOT_PATH}/thirdparty/angle/prebuilt/${ARCH_ALIAS}/libEGL.dll
${ADXE_ROOT_PATH}/thirdparty/angle/prebuilt/${ARCH_ALIAS}/d3dcompiler_47.dll
$<TARGET_FILE_DIR:${APP_NAME}>
)
endif()
endif()

View File

@ -22,6 +22,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# ****************************************************************************/
cmake_minimum_required(VERSION 3.10)
set(APP_NAME HelloLua)
@ -53,7 +54,15 @@ if(NOT DEFINED BUILD_ENGINE_DONE) # to test HelloLua into root project
include(CocosBuildSet)
set(AX_ENABLE_EXT_LUA ON)
add_subdirectory(${ADXE_ROOT_PATH}/core ${ENGINE_BINARY_PATH}/adxe/core)
set(_AX_USE_PREBUILT FALSE)
if (WIN32 AND DEFINED AX_PREBUILT_DIR AND IS_DIRECTORY ${ADXE_ROOT_PATH}/${AX_PREBUILT_DIR})
set(_AX_USE_PREBUILT TRUE)
endif()
if (NOT _AX_USE_PREBUILT)
add_subdirectory(${ADXE_ROOT_PATH}/core ${ENGINE_BINARY_PATH}/adxe/core)
endif()
endif()
set(RUNTIME_SRC_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/runtime-src)
@ -169,8 +178,10 @@ if(APPLE)
set_xcode_property(${APP_NAME} CODE_SIGN_IDENTITY "iPhone Developer")
endif()
elseif(WINDOWS)
cocos_copy_target_dll(${APP_NAME})
cocos_copy_lua_dlls(${APP_NAME})
if(NOT _AX_USE_PREBUILT)
cocos_copy_target_dll(${APP_NAME})
cocos_copy_lua_dlls(${APP_NAME})
endif()
endif()
# copy resource on linux or WINDOWS
if(WINDOWS)
@ -183,3 +194,145 @@ elseif(LINUX)
cocos_copy_lua_scripts(${APP_NAME} ${res_src_folders} ${APP_RES_DIR}/src )
cocos_copy_lua_scripts(${APP_NAME} ${res_script_folders} ${APP_RES_DIR}/src/cocos)
endif()
if (_AX_USE_PREBUILT) # support windows only
if(NOT ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Win32"))
set(WIN64 TRUE)
set(ARCH_ALIAS "x64")
else()
set(WIN32 TRUE)
set(ARCH_ALIAS "x86")
endif()
if (NOT AX_USE_SHARED_PREBUILT)
target_compile_definitions(${APP_NAME}
PRIVATE CC_STATIC=1
PRIVATE _USRLUASTATIC=1
)
endif()
target_include_directories(${APP_NAME}
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/lua
PRIVATE ${ADXE_ROOT_PATH}/extensions/scripting/lua-bindings/manual
PRIVATE ${ADXE_ROOT_PATH}
PRIVATE ${ADXE_ROOT_PATH}/thirdparty
PRIVATE ${ADXE_ROOT_PATH}/extensions
PRIVATE ${ADXE_ROOT_PATH}/core
PRIVATE ${ADXE_ROOT_PATH}/core/platform
PRIVATE ${ADXE_ROOT_PATH}/core/base
PRIVATE ${ADXE_ROOT_PATH}/core/audio
PRIVATE ${ADXE_ROOT_PATH}/core/platform/win32
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/fmt/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/robin-map/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/freetype/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/glfw/include/GLFW
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/box2d/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/chipmunk/include
PRIVATE ${ADXE_ROOT_PATH}/${AX_PREBUILT_DIR}/engine/thirdparty/freetype/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/recast/..
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/bullet/.
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/webp/src/webp
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/pugixml
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/xxhash/.
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/lz4/.
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/clipper/.
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/ConvertUTF/.
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/poly2tri/..
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/astc/..
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/openal/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/ogg/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/glad/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/glfw/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/png
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/unzip/.
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/llhttp/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/lua/plainlua
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/lua/tolua/.
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/lua/lua-cjson/.
PRIVATE ${ADXE_ROOT_PATH}/extensions/cocostudio
PRIVATE ${ADXE_ROOT_PATH}/extensions/spine/runtime/include
PRIVATE ${ADXE_ROOT_PATH}/extensions/fairygui
PRIVATE ${ADXE_ROOT_PATH}/extensions/GUI
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/zlib/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/jpeg/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/openssl/include
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/curl/include
)
target_link_directories(${APP_NAME}
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/openssl/prebuilt/windows/${ARCH_ALIAS}
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/zlib/prebuilt/windows/${ARCH_ALIAS}
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/jpeg/prebuilt/windows/${ARCH_ALIAS}
PRIVATE ${ADXE_ROOT_PATH}/thirdparty/curl/prebuilt/windows/${ARCH_ALIAS}
PRIVATE ${ADXE_ROOT_PATH}/${AX_PREBUILT_DIR}/lib/Debug
)
# Linking OS libs
target_link_libraries(${APP_NAME} winmm Version)
# Linking engine and thirdparty libs
target_link_libraries(${APP_NAME}
adxelua.lib
spine.lib
particle3d.lib
assets-manager.lib
cocostudio.lib
DragonBones.lib
lua-cjson.lib
tolua.lib
plainlua.lib
adxe.lib
box2d.lib
chipmunk.lib
freetype.lib
libzlib.lib
recast.lib
bullet.lib
jpeg-static.lib
libcrypto.lib
libssl.lib
webp.lib
pugixml.lib
xxhash.lib
lz4.lib
clipper.lib
ConvertUTF.lib
poly2tri.lib
astc.lib
libcurl_imp.lib
OpenAL32.lib
ogg.lib
glad.lib
glfw.lib
png.lib
unzip.lib
llhttp.lib
physics-nodes.lib
)
# Copy dlls to app bin dir
# copy thirdparty dlls to target bin dir
# copy_thirdparty_dlls(${APP_NAME} $<TARGET_FILE_DIR:${APP_NAME}>)
add_custom_command(TARGET ${APP_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${ADXE_ROOT_PATH}/thirdparty/openssl/prebuilt/windows/${ARCH_ALIAS}/libcrypto-3.dll"
"${ADXE_ROOT_PATH}/thirdparty/openssl/prebuilt/windows/${ARCH_ALIAS}/libssl-3.dll"
"${ADXE_ROOT_PATH}/thirdparty/curl/prebuilt/windows/${ARCH_ALIAS}/libcurl.dll"
"${ADXE_ROOT_PATH}/thirdparty/zlib/prebuilt/windows/${ARCH_ALIAS}/zlib1.dll"
"${ADXE_ROOT_PATH}/${AX_PREBUILT_DIR}/bin/\$\(Configuration\)/OpenAL32.dll"
"${ADXE_ROOT_PATH}/${AX_PREBUILT_DIR}/bin/\$\(Configuration\)/plainlua.dll"
$<TARGET_FILE_DIR:${APP_NAME}>)
# Copy windows angle binaries
if (AX_USE_COMPAT_GL)
add_custom_command(TARGET ${APP_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${ADXE_ROOT_PATH}/thirdparty/angle/prebuilt/${ARCH_ALIAS}/libGLESv2.dll
${ADXE_ROOT_PATH}/thirdparty/angle/prebuilt/${ARCH_ALIAS}/libEGL.dll
${ADXE_ROOT_PATH}/thirdparty/angle/prebuilt/${ARCH_ALIAS}/d3dcompiler_47.dll
$<TARGET_FILE_DIR:${APP_NAME}>
)
endif()
endif()