axmol/cmake/Modules/AXLinkHelpers.cmake

371 lines
14 KiB
CMake
Raw Normal View History

2024-03-23 00:51:46 +08:00
include(${_AX_ROOT}/1k/platforms.cmake)
2024-01-19 20:33:40 +08:00
_1k_deprecated_32bit(axmol 2.2.0)
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)
# stupid: exclude CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG to avoid cmake generate
# .vcxproj with incorrect debug msvc runtime, should be /MDd but got /MD
2023-10-16 20:24:59 +08:00
set(GLSLCC_OUT_DIR_PROJ "${GLSLCC_OUT_DIR}")
load_cache("${AX_ROOT_DIR}/${AX_PREBUILT_DIR}" EXCLUDE thirdparty_LIB_DEPENDS CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG)
2023-10-16 20:24:59 +08:00
set(GLSLCC_OUT_DIR_ENGINE ${GLSLCC_OUT_DIR})
set(GLSLCC_OUT_DIR "${GLSLCC_OUT_DIR_PROJ}" CACHE STRING "" FORCE)
unset(GLSLCC_OUT_DIR_PROJ)
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_INSPECTOR=${AX_ENABLE_EXT_INSPECTOR}")
2023-02-24 19:33:26 +08:00
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}")
2024-01-05 05:35:05 +08:00
message(STATUS "AX_ENABLE_EXT_DRAWNODEEX=${AX_ENABLE_EXT_DRAWNODEEX}")
2023-02-24 19:33:26 +08:00
2023-10-11 00:27:46 +08:00
# compile defines can't inherit when link prebuits, so need add manually
target_compile_definitions(${APP_NAME}
PRIVATE AX_GLES_PROFILE=${AX_GLES_PROFILE}
PRIVATE OPENSSL_SUPPRESS_DEPRECATED=1
PRIVATE NOUNCRYPT=1
PRIVATE P2T_STATIC_EXPORTS=1
PRIVATE BT_USE_SSE_IN_API=1
PRIVATE CP_USE_DOUBLES=0
PRIVATE CP_USE_CGTYPES=0
)
ax_config_pred(${APP_NAME} AX_USE_ALSOFT)
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)
if (AX_ISA_SIMD MATCHES "sse")
target_compile_definitions(${APP_NAME} PRIVATE AX_USE_SSE=1)
endif()
if (BUILD_SHARED_LIBS)
target_compile_definitions(${APP_NAME} PRIVATE AX_DLLIMPORT=1)
2022-05-19 10:54:42 +08:00
endif()
target_include_directories(${APP_NAME}
2024-03-19 21:33:02 +08:00
PRIVATE ${AX_ROOT_DIR}/3rdparty/lua
PRIVATE ${AX_ROOT_DIR}/extensions/scripting
2022-05-19 10:54:42 +08:00
PRIVATE ${AX_ROOT_DIR}/extensions/scripting/lua-bindings/manual
PRIVATE ${AX_ROOT_DIR}
2024-03-19 21:33:02 +08:00
PRIVATE ${AX_ROOT_DIR}/3rdparty
2022-05-19 10:54:42 +08:00
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
2024-03-19 21:33:02 +08:00
PRIVATE ${AX_ROOT_DIR}/3rdparty/fmt/include
PRIVATE ${AX_ROOT_DIR}/3rdparty/robin-map/include
PRIVATE ${AX_ROOT_DIR}/3rdparty/freetype/include
PRIVATE ${AX_ROOT_DIR}/3rdparty/glfw/include/GLFW
PRIVATE ${AX_ROOT_DIR}/3rdparty/box2d/include
PRIVATE ${AX_ROOT_DIR}/3rdparty/chipmunk/include
PRIVATE ${AX_ROOT_DIR}/${AX_PREBUILT_DIR}/engine/3rdparty/freetype/include
PRIVATE ${AX_ROOT_DIR}/3rdparty/webp/src/webp
PRIVATE ${AX_ROOT_DIR}/3rdparty/pugixml
PRIVATE ${AX_ROOT_DIR}/3rdparty/xxhash
PRIVATE ${AX_ROOT_DIR}/3rdparty/ConvertUTF
PRIVATE ${AX_ROOT_DIR}/3rdparty/openal/include
PRIVATE ${AX_ROOT_DIR}/3rdparty/ogg/include
PRIVATE ${AX_ROOT_DIR}/3rdparty/glad/include
PRIVATE ${AX_ROOT_DIR}/3rdparty/glfw/include
PRIVATE ${AX_ROOT_DIR}/3rdparty/png
PRIVATE ${AX_ROOT_DIR}/3rdparty/unzip/.
PRIVATE ${AX_ROOT_DIR}/3rdparty/llhttp/include
PRIVATE ${AX_ROOT_DIR}/3rdparty/lua/plainlua
PRIVATE ${AX_ROOT_DIR}/3rdparty/lua/tolua/.
PRIVATE ${AX_ROOT_DIR}/3rdparty/lua/lua-cjson/.
2024-03-24 05:20:59 +08:00
PRIVATE ${AX_ROOT_DIR}/3rdparty/zlib/_x/include
PRIVATE ${AX_ROOT_DIR}/3rdparty/jpeg-turbo/_x/include
PRIVATE ${AX_ROOT_DIR}/3rdparty/openssl/_x/include
PRIVATE ${AX_ROOT_DIR}/3rdparty/curl/_x/include
2024-03-19 21:33:02 +08:00
PRIVATE ${AX_ROOT_DIR}/3rdparty/yasio
2022-05-19 10:54:42 +08:00
)
2022-08-19 19:52:10 +08:00
SET (CONFIGURATION_SUBFOLDER "")
2022-05-19 10:54:42 +08:00
target_link_directories(${APP_NAME}
2024-03-24 05:20:59 +08:00
PRIVATE ${AX_ROOT_DIR}/3rdparty/openssl/_x/lib/${PLATFORM_NAME}/${ARCH_ALIAS}
PRIVATE ${AX_ROOT_DIR}/3rdparty/zlib/_x/lib/${PLATFORM_NAME}/${ARCH_ALIAS}
PRIVATE ${AX_ROOT_DIR}/3rdparty/jpeg-turbo/_x/lib/${PLATFORM_NAME}/${ARCH_ALIAS}
PRIVATE ${AX_ROOT_DIR}/3rdparty/curl/_x/lib/${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()
2023-11-19 09:38:12 +08:00
target_link_libraries(${APP_NAME} X11 fontconfig)
2022-11-17 21:26:17 +08:00
endif()
2022-05-19 10:54:42 +08:00
2024-03-19 21:33:02 +08:00
# Linking engine and 3rdparty libs
2022-11-17 21:26:17 +08:00
set(LIBS
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
simdjson
2022-08-11 15:41:10 +08:00
physics-nodes
yasio
websocket-parser
2022-05-19 10:54:42 +08:00
)
2023-12-31 22:32:32 +08:00
if (AX_ENABLE_EXT_DRAGONBONES)
list(APPEND LIBS "cocostudio")
target_include_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/extensions/DragonBones/src
)
2023-12-31 22:32:32 +08:00
endif()
if(AX_ENABLE_EXT_COCOSTUDIO)
list(APPEND LIBS "DragonBones")
target_include_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/extensions/cocostudio/src
)
2023-12-31 22:32:32 +08:00
endif()
if(AX_ENABLE_EXT_ASSETMANAGER)
list(APPEND LIBS "assets-manager")
target_include_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/extensions/assets-manager/src
)
2023-12-31 22:32:32 +08:00
endif()
if(AX_ENABLE_EXT_PARTICLE3D)
list(APPEND LIBS "particle3d")
target_include_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/extensions/Particle3D/src
)
2023-12-31 22:32:32 +08:00
endif()
if(AX_ENABLE_EXT_SPINE)
list(APPEND LIBS "spine")
target_include_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/extensions/spine/runtime/include
PRIVATE ${AX_ROOT_DIR}/extensions/spine/src
)
2023-12-31 22:32:32 +08:00
endif()
2023-02-24 19:33:26 +08:00
if (AX_ENABLE_EXT_IMGUI)
list(APPEND LIBS "ImGui")
target_include_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/extensions/ImGui/src
PRIVATE ${AX_ROOT_DIR}/extensions/ImGui/src/ImGui/imgui
)
2023-02-24 19:33:26 +08:00
endif()
if (AX_ENABLE_EXT_INSPECTOR)
list(APPEND LIBS "Inspector")
target_include_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/extensions/Inspector/src
)
endif()
2023-12-31 22:32:32 +08:00
if (AX_ENABLE_EXT_SDFGEN)
list(APPEND LIBS "SDFGen")
target_include_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/extensions/SDFGen/src
)
2023-12-31 22:32:32 +08:00
endif()
2024-01-05 05:35:05 +08:00
if (AX_ENABLE_EXT_DRAWNODEEX)
list(APPEND LIBS "DrawNodeEx")
target_include_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/extensions/DrawNodeEx/src
)
2024-01-05 05:35:05 +08:00
endif()
if (AX_ENABLE_EXT_GUI)
list(APPEND LIBS "GUI")
target_include_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/extensions/GUI/src
)
endif()
if (AX_ENABLE_EXT_FAIRYGUI)
list(APPEND LIBS "fairygui")
target_include_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/extensions/fairygui/src
)
endif()
if (AX_ENABLE_EXT_LIVE2D)
list(APPEND LIBS "Live2D")
target_include_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/extensions/Live2D/Framework/src
)
endif()
if (AX_ENABLE_EXT_EFFEKSEER)
list(APPEND LIBS "EffekseerForCocos2d-x")
target_include_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/extensions/Effekseer
)
endif()
if (AX_ENABLE_EXT_PHYSICS_NODE)
list(APPEND LIBS "physics-nodes")
target_include_directories(${APP_NAME}
PRIVATE ${AX_ROOT_DIR}/extensions/physics-nodes/src
)
endif()
2022-11-17 21:26:17 +08:00
if (WINDOWS)
target_link_libraries(${APP_NAME}
${LIBS}
zlib
jpeg-static
libcrypto
libssl
libcurl_imp
)
if (AX_ENABLE_AUDIO)
target_link_libraries(${APP_NAME}
OpenAL32
)
endif()
2022-11-17 21:26:17 +08:00
else()
target_link_libraries(${APP_NAME}
${LIBS}
z
jpeg
curl
ssl
crypto
2022-11-17 21:26:17 +08:00
)
if (AX_ENABLE_AUDIO)
target_link_libraries(${APP_NAME}
openal
)
endif()
2022-11-17 21:26:17 +08:00
endif()
2022-05-19 10:54:42 +08:00
2024-02-20 05:37:28 +08:00
target_link_libraries(${APP_NAME} debug fmtd optimized fmt)
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
2024-03-24 05:20:59 +08:00
"${AX_ROOT_DIR}/3rdparty/openssl/_x/lib/${PLATFORM_NAME}/${ARCH_ALIAS}/libcrypto-3${ssl_dll_suffix}.dll"
"${AX_ROOT_DIR}/3rdparty/openssl/_x/lib/${PLATFORM_NAME}/${ARCH_ALIAS}/libssl-3${ssl_dll_suffix}.dll"
"${AX_ROOT_DIR}/3rdparty/curl/_x/lib/${PLATFORM_NAME}/${ARCH_ALIAS}/libcurl.dll"
"${AX_ROOT_DIR}/3rdparty/zlib/_x/lib/${PLATFORM_NAME}/${ARCH_ALIAS}/zlib1.dll"
2022-11-17 21:26:17 +08:00
$<TARGET_FILE_DIR:${APP_NAME}>)
2022-05-19 10:54:42 +08:00
if (AX_ENABLE_AUDIO)
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}OpenAL32.dll"
$<TARGET_FILE_DIR:${APP_NAME}>)
endif()
2023-01-06 18:38:16 +08:00
if (BUILD_SHARED_LIBS)
2024-02-19 14:48:03 +08:00
add_custom_command(TARGET ${APP_NAME} POST_BUILD
2023-01-06 18:38:16 +08:00
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
if (AX_GLES_PROFILE)
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
2024-03-24 05:20:59 +08:00
${AX_ROOT_DIR}/3rdparty/angle/_x/lib/${PLATFORM_NAME}/${ARCH_ALIAS}/libGLESv2.dll
${AX_ROOT_DIR}/3rdparty/angle/_x/lib/${PLATFORM_NAME}/${ARCH_ALIAS}/libEGL.dll
${AX_ROOT_DIR}/3rdparty/angle/_x/lib/${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()
2023-10-16 20:24:59 +08:00
# prebuilt, need copy axslc folder to target output directory
get_target_property(rt_output ${APP_NAME} RUNTIME_OUTPUT_DIRECTORY)
ax_sync_target_res(${APP_NAME} LINK_TO "${rt_output}/${CMAKE_CFG_INTDIR}/axslc" FOLDERS ${GLSLCC_OUT_DIR_ENGINE} SYNC_TARGET_ID axslc-builtin)
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)
2023-10-11 21:42:01 +08:00
if (NOT BUILD_SHARED_LIBS)
2022-05-19 10:54:42 +08:00
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)