axmol/cmake/Modules/AXLinkHelpers.cmake

235 lines
9.8 KiB
CMake
Raw Normal View History

include(AXPlatform)
2022-05-19 10:54:42 +08:00
if(NOT CMAKE_GENERATOR MATCHES "Ninja")
2022-08-19 19:52:10 +08:00
set(BUILD_CONFIG_DIR "\$\(Configuration\)/")
else()
set(BUILD_CONFIG_DIR "")
2022-05-19 10:54:42 +08:00
endif()
2022-08-11 15:41:10 +08:00
function(ax_link_cxx_prebuilt APP_NAME AX_ROOT_DIR AX_PREBUILT_DIR)
2023-03-04 15:38:39 +08:00
load_cache("${AX_ROOT_DIR}/${AX_PREBUILT_DIR}" EXCLUDE thirdparty_LIB_DEPENDS)
2023-02-24 19:33:26 +08:00
2023-08-25 16:57:38 +08:00
message(STATUS "AX_USE_ANGLE=${AX_USE_ANGLE}")
2023-02-24 19:33:26 +08:00
message(STATUS "AX_ENABLE_MSEDGE_WEBVIEW2=${AX_ENABLE_MSEDGE_WEBVIEW2}")
message(STATUS "AX_ENABLE_MFMEDIA=${AX_ENABLE_MFMEDIA}")
message(STATUS "AX_ENABLE_EXT_IMGUI=${AX_ENABLE_EXT_IMGUI}")
message(STATUS "AX_ENABLE_EXT_FAIRYGUI=${AX_ENABLE_EXT_FAIRYGUI}")
message(STATUS "AX_ENABLE_EXT_LIVE2D=${AX_ENABLE_EXT_LIVE2D}")
message(STATUS "AX_ENABLE_EXT_GUI=${AX_ENABLE_EXT_GUI}")
message(STATUS "AX_ENABLE_EXT_ASSETMANAGER=${AX_ENABLE_EXT_ASSETMANAGER}")
message(STATUS "AX_ENABLE_EXT_PARTICLE3D=${AX_ENABLE_EXT_PARTICLE3D}")
message(STATUS "AX_ENABLE_EXT_PHYSICS_NODE=${AX_ENABLE_EXT_PHYSICS_NODE}")
message(STATUS "AX_ENABLE_EXT_SPINE=${AX_ENABLE_EXT_SPINE}")
message(STATUS "AX_ENABLE_EXT_EFFEKSEER=${AX_ENABLE_EXT_EFFEKSEER}")
message(STATUS "AX_ENABLE_EXT_LUA=${AX_ENABLE_EXT_LUA}")
2023-08-25 16:57:38 +08:00
ax_config_pred(${APP_NAME} AX_USE_ANGLE)
2023-02-24 19:33:26 +08:00
ax_config_pred(${APP_NAME} AX_ENABLE_MFMEDIA)
ax_config_pred(${APP_NAME} AX_ENABLE_MSEDGE_WEBVIEW2)
2022-05-19 10:54:42 +08:00
if (NOT AX_USE_SHARED_PREBUILT)
target_compile_definitions(${APP_NAME}
2022-07-16 10:43:05 +08:00
PRIVATE AX_STATIC=1
2022-05-19 10:54:42 +08:00
)
endif()
target_include_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/thirdparty/lua
PRIVATE ${AX_ROOT_DIR}/extensions/scripting/lua-bindings/manual
PRIVATE ${AX_ROOT_DIR}
PRIVATE ${AX_ROOT_DIR}/thirdparty
PRIVATE ${AX_ROOT_DIR}/extensions
PRIVATE ${AX_ROOT_DIR}/core
PRIVATE ${AX_ROOT_DIR}/core/platform
PRIVATE ${AX_ROOT_DIR}/core/base
PRIVATE ${AX_ROOT_DIR}/core/audio
PRIVATE ${AX_ROOT_DIR}/core/platform/win32
PRIVATE ${AX_ROOT_DIR}/thirdparty/fmt/include
PRIVATE ${AX_ROOT_DIR}/thirdparty/robin-map/include
PRIVATE ${AX_ROOT_DIR}/thirdparty/freetype/include
PRIVATE ${AX_ROOT_DIR}/thirdparty/glfw/include/GLFW
PRIVATE ${AX_ROOT_DIR}/thirdparty/box2d/include
PRIVATE ${AX_ROOT_DIR}/thirdparty/chipmunk/include
PRIVATE ${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/engine/thirdparty/freetype/include
PRIVATE ${AX_ROOT_DIR}/thirdparty/webp/src/webp
PRIVATE ${AX_ROOT_DIR}/thirdparty/pugixml
2022-08-19 19:52:10 +08:00
PRIVATE ${AX_ROOT_DIR}/thirdparty/xxhash
PRIVATE ${AX_ROOT_DIR}/thirdparty/ConvertUTF
2022-05-19 10:54:42 +08:00
PRIVATE ${AX_ROOT_DIR}/thirdparty/openal/include
PRIVATE ${AX_ROOT_DIR}/thirdparty/ogg/include
PRIVATE ${AX_ROOT_DIR}/thirdparty/glad/include
PRIVATE ${AX_ROOT_DIR}/thirdparty/glfw/include
PRIVATE ${AX_ROOT_DIR}/thirdparty/png
PRIVATE ${AX_ROOT_DIR}/thirdparty/unzip/.
PRIVATE ${AX_ROOT_DIR}/thirdparty/llhttp/include
PRIVATE ${AX_ROOT_DIR}/thirdparty/lua/plainlua
PRIVATE ${AX_ROOT_DIR}/thirdparty/lua/tolua/.
PRIVATE ${AX_ROOT_DIR}/thirdparty/lua/lua-cjson/.
PRIVATE ${AX_ROOT_DIR}/extensions/cocostudio
PRIVATE ${AX_ROOT_DIR}/extensions/spine/runtime/include
PRIVATE ${AX_ROOT_DIR}/extensions/fairygui
PRIVATE ${AX_ROOT_DIR}/extensions/GUI
PRIVATE ${AX_ROOT_DIR}/thirdparty/zlib/include
2022-08-19 10:12:06 +08:00
PRIVATE ${AX_ROOT_DIR}/thirdparty/jpeg-turbo/include
2022-05-19 10:54:42 +08:00
PRIVATE ${AX_ROOT_DIR}/thirdparty/openssl/include
PRIVATE ${AX_ROOT_DIR}/thirdparty/curl/include
)
2022-08-19 19:52:10 +08:00
SET (CONFIGURATION_SUBFOLDER "")
2022-05-19 10:54:42 +08:00
target_link_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/thirdparty/openssl/prebuilt/${platform_name}/${ARCH_ALIAS}
PRIVATE ${AX_ROOT_DIR}/thirdparty/zlib/prebuilt/${platform_name}/${ARCH_ALIAS}
PRIVATE ${AX_ROOT_DIR}/thirdparty/jpeg-turbo/prebuilt/${platform_name}/${ARCH_ALIAS}
PRIVATE ${AX_ROOT_DIR}/thirdparty/curl/prebuilt/${platform_name}/${ARCH_ALIAS}
2022-08-19 19:52:10 +08:00
PRIVATE ${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/lib # cmake will auto add suffix '/$(Configuration)', refer to https://github.com/Kitware/CMake/blob/master/Source/cmVisualStudio10TargetGenerator.cxx#L4145
2022-05-19 10:54:42 +08:00
)
# Linking platform libs
2022-11-17 21:26:17 +08:00
if (WINDOWS)
target_link_libraries(${APP_NAME} winmm Version)
else()
target_link_libraries(${APP_NAME} X11 fontconfig glib-2.0 gtk-3 gobject-2.0)
2022-11-17 21:26:17 +08:00
endif()
2022-05-19 10:54:42 +08:00
# Linking engine and thirdparty libs
2022-11-17 21:26:17 +08:00
set(LIBS
2022-08-11 15:41:10 +08:00
spine
particle3d
assets-manager
cocostudio
DragonBones
2022-10-01 16:24:52 +08:00
axmol
2022-08-11 15:41:10 +08:00
box2d
chipmunk
freetype
recast
bullet
webp
pugixml
xxhash
2023-07-02 01:08:04 +08:00
fastlz
2022-09-02 10:36:25 +08:00
clipper2
2022-08-11 15:41:10 +08:00
ConvertUTF
poly2tri
2023-05-10 13:45:40 +08:00
astcenc
2022-08-11 15:41:10 +08:00
ogg
glad
glfw
png
unzip
llhttp
physics-nodes
2022-05-19 10:54:42 +08:00
)
2023-02-24 19:33:26 +08:00
if (AX_ENABLE_EXT_IMGUI)
list(APPEND LIBS "ImGui")
endif()
2022-11-17 21:26:17 +08:00
if (WINDOWS)
target_link_libraries(${APP_NAME}
${LIBS}
zlib
jpeg-static
libcrypto
libssl
libcurl_imp
OpenAL32
)
else()
target_link_libraries(${APP_NAME}
${LIBS}
z
jpeg
curl
ssl
crypto
2022-11-17 21:26:17 +08:00
openal
)
endif()
2022-05-19 10:54:42 +08:00
# Copy dlls to app bin dir
2022-11-17 21:26:17 +08:00
if(WINDOWS)
set(ssl_dll_suffix "")
if(WIN64)
set(ssl_dll_suffix "-${ARCH_ALIAS}")
endif()
2022-05-19 10:54:42 +08:00
add_custom_command(TARGET ${APP_NAME} POST_BUILD
2022-11-17 21:26:17 +08:00
COMMAND ${CMAKE_COMMAND} -E copy_if_different
2023-06-20 20:48:52 +08:00
"${AX_ROOT_DIR}/thirdparty/openssl/prebuilt/${platform_name}/${ARCH_ALIAS}/libcrypto-3${ssl_dll_suffix}.dll"
"${AX_ROOT_DIR}/thirdparty/openssl/prebuilt/${platform_name}/${ARCH_ALIAS}/libssl-3${ssl_dll_suffix}.dll"
"${AX_ROOT_DIR}/thirdparty/curl/prebuilt/${platform_name}/${ARCH_ALIAS}/libcurl.dll"
"${AX_ROOT_DIR}/thirdparty/zlib/prebuilt/${platform_name}/${ARCH_ALIAS}/zlib1.dll"
2022-11-17 21:26:17 +08:00
"${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/bin/${BUILD_CONFIG_DIR}OpenAL32.dll"
$<TARGET_FILE_DIR:${APP_NAME}>)
2022-05-19 10:54:42 +08:00
2023-01-06 18:38:16 +08:00
if (BUILD_SHARED_LIBS)
add_custom_command(TARGET ${ax_target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/bin/${BUILD_CONFIG_DIR}glad.dll"
"${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/bin/${BUILD_CONFIG_DIR}glfw.dll"
"${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/bin/${BUILD_CONFIG_DIR}pugixml.dll"
"${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/bin/${BUILD_CONFIG_DIR}freetype.dll"
"${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/bin/${BUILD_CONFIG_DIR}axmol.dll"
"${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/bin/${BUILD_CONFIG_DIR}cocostudio.dll"
"${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/bin/${BUILD_CONFIG_DIR}GUI.dll"
"${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/bin/${BUILD_CONFIG_DIR}particle3d.dll"
"${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/bin/${BUILD_CONFIG_DIR}physics-nodes.dll"
"${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/bin/${BUILD_CONFIG_DIR}spine.dll"
"${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/bin/${BUILD_CONFIG_DIR}assets-manager.dll"
$<TARGET_FILE_DIR:${APP_NAME}>)
endif()
2022-11-17 21:26:17 +08:00
# Copy windows angle binaries
2023-08-25 16:57:38 +08:00
if (AX_USE_ANGLE)
2022-11-16 17:03:39 +08:00
add_custom_command(TARGET ${APP_NAME} POST_BUILD
2022-11-17 21:26:17 +08:00
COMMAND ${CMAKE_COMMAND} -E copy_if_different
2023-06-20 20:48:52 +08:00
${AX_ROOT_DIR}/thirdparty/angle/prebuilt/${platform_name}/${ARCH_ALIAS}/libGLESv2.dll
${AX_ROOT_DIR}/thirdparty/angle/prebuilt/${platform_name}/${ARCH_ALIAS}/libEGL.dll
${AX_ROOT_DIR}/thirdparty/angle/prebuilt/${platform_name}/${ARCH_ALIAS}/d3dcompiler_47.dll
2022-05-19 10:54:42 +08:00
$<TARGET_FILE_DIR:${APP_NAME}>
)
2022-11-17 21:26:17 +08:00
endif()
if (AX_ENABLE_MSEDGE_WEBVIEW2)
if(CMAKE_GENERATOR MATCHES "Ninja")
2022-11-17 21:26:17 +08:00
target_link_libraries(${APP_NAME} ${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/packages/Microsoft.Web.WebView2/build/native/${ARCH_ALIAS}/WebView2Loader.dll.lib)
target_include_directories(${APP_NAME} PRIVATE ${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/packages/Microsoft.Web.WebView2/build/native/include)
add_custom_command(TARGET ${APP_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/packages/Microsoft.Web.WebView2/build/native/${ARCH_ALIAS}/WebView2Loader.dll"
$<TARGET_FILE_DIR:${APP_NAME}>
)
2022-11-17 21:26:17 +08:00
else()
target_link_libraries(${APP_NAME} ${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/packages/Microsoft.Web.WebView2/build/native/Microsoft.Web.WebView2.targets)
endif()
2022-05-19 10:54:42 +08:00
endif()
endif()
2022-08-11 15:41:10 +08:00
endfunction(ax_link_cxx_prebuilt)
2022-05-19 10:54:42 +08:00
2022-08-11 15:41:10 +08:00
function(ax_link_lua_prebuilt APP_NAME AX_ROOT_DIR AX_PREBUILT_DIR)
2022-05-19 10:54:42 +08:00
if (NOT AX_USE_SHARED_PREBUILT)
target_compile_definitions(${APP_NAME}
PRIVATE _USRLUASTATIC=1
)
endif()
2022-08-08 18:02:17 +08:00
target_link_libraries(${APP_NAME} axlua lua-cjson tolua plainlua)
ax_link_cxx_prebuilt(${APP_NAME} ${AX_ROOT_DIR} ${AX_PREBUILT_DIR})
2022-11-17 21:26:17 +08:00
if (WINDOWS)
if(MSVC)
add_custom_command(TARGET ${APP_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/bin/${BUILD_CONFIG_DIR}plainlua.dll"
$<TARGET_FILE_DIR:${APP_NAME}>)
else()
add_custom_command(TARGET ${APP_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/bin/$<CONFIG>/plainlua.dll"
$<TARGET_FILE_DIR:${APP_NAME}>)
endif()
2022-11-17 21:26:17 +08:00
endif()
2022-08-11 15:41:10 +08:00
endfunction(ax_link_lua_prebuilt)