Skip to content

Commit 5c092ba

Browse files
authored
Fix BUILD_SHARED_LIBS for Android (#2462)
1 parent 6b964f5 commit 5c092ba

File tree

7 files changed

+39
-8
lines changed

7 files changed

+39
-8
lines changed

3rdparty/glad/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ if(BUILD_SHARED_LIBS)
1313
PUBLIC GLAD_API_CALL_EXPORT=1
1414
PRIVATE GLAD_API_CALL_EXPORT_BUILD=1
1515
)
16+
if (NOT WINDOWS AND AX_USE_GL)
17+
target_link_libraries(${target_name} EGL)
18+
endif()
1619
endif()
1720

1821
if(ANDROID)

3rdparty/lua/plainlua/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ if(WIN32)
2020
# target_link_libraries(${target_name} PRIVATE runtimeobject)
2121
# endif()
2222
else()
23-
add_library(${target_name} ${LUA_CORE})
23+
if (BUILD_SHARED_LIBS AND NOT WINRT)
24+
set(LUA_BUILD_AS_DLL FALSE)
25+
add_library(${target_name} SHARED ${LUA_CORE} ${LUA_SRC_PATH}/plainlua.def)
26+
else()
27+
add_library(${target_name} ${LUA_CORE})
28+
endif()
2429
endif()
2530

2631
target_compile_definitions(${target_name}

core/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,18 @@ endif()
456456

457457
if(ANDROID)
458458
add_subdirectory(${_AX_ROOT}/core/platform/android ${ENGINE_BINARY_PATH}/core/cpp-android)
459+
if (BUILD_SHARED_LIBS)
460+
# whole archive for jni
461+
target_link_libraries(${_AX_CORE_LIB} -Wl,--whole-archive cpp_android_spec -Wl,--no-whole-archive)
462+
if (_AX_LUA_PROJ)
463+
add_subdirectory(${_AX_ROOT}/extensions/scripting/lua-bindings/proj.android ${ENGINE_BINARY_PATH}/extensions/lua-android)
464+
target_link_libraries(${_AX_CORE_LIB} -Wl,--whole-archive lua_android_spec -Wl,--no-whole-archive)
465+
endif()
466+
467+
if (_AX_LUA_PROJ OR AX_ENABLE_EXT_LUA)
468+
target_link_libraries(${_AX_CORE_LIB} ${AX_LUA_ENGINE})
469+
endif()
470+
endif()
459471
endif()
460472

461473
if(LINUX)

core/platform/android/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ add_library(${target_name} STATIC
1818
${${target_name}_src}
1919
)
2020

21-
target_link_libraries(${target_name} ${_AX_CORE_LIB})
21+
if(NOT BUILD_SHARED_LIBS)
22+
target_link_libraries(${target_name} ${_AX_CORE_LIB})
23+
endif()
2224

2325
target_include_directories(${target_name}
2426
PRIVATE ..

templates/cpp/cmake/modules/AXGameTargetSetup.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ if(NOT ANDROID)
22
add_executable(${APP_NAME} ${APP_SOURCES})
33
else()
44
add_library(${APP_NAME} SHARED ${APP_SOURCES})
5-
# whole archive for jni
6-
target_link_libraries(${APP_NAME} -Wl,--whole-archive cpp_android_spec -Wl,--no-whole-archive)
5+
6+
# whole archive for jni when not building engine as shared libs, otherwise libaxmol.so is archived with it.
7+
if (NOT BUILD_SHARED_LIBS)
8+
target_link_libraries(${APP_NAME} -Wl,--whole-archive cpp_android_spec -Wl,--no-whole-archive)
9+
endif()
10+
711
config_android_shared_libs("dev.axmol.lib" "${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src")
812
endif()
913

templates/lua/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ set(CMAKE_MODULE_PATH
3737
${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules
3838
)
3939

40+
# Important when BUILD_SHARED_LIBS option is set to TRUE
41+
set(_AX_LUA_PROJ TRUE)
42+
4043
# NOTE: The order of the cmake module "include(AXGame...)" statements matters
4144
include(AXGameEngineSetup)
4245

templates/lua/cmake/modules/AXGameTargetSetup.cmake

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ if(NOT ANDROID)
33
else()
44
add_library(${APP_NAME} SHARED ${APP_SOURCES})
55

6-
# whole archive for jni
7-
target_link_libraries(${APP_NAME} -Wl,--whole-archive cpp_android_spec -Wl,--no-whole-archive)
8-
add_subdirectory(${_AX_ROOT}/extensions/scripting/lua-bindings/proj.android ${ENGINE_BINARY_PATH}/extensions/lua-android)
9-
target_link_libraries(${APP_NAME} -Wl,--whole-archive lua_android_spec -Wl,--no-whole-archive)
6+
# whole archive for jni when not building engine as shared libs, otherwise libaxmol.so is archived with it.
7+
if (NOT BUILD_SHARED_LIBS)
8+
target_link_libraries(${APP_NAME} -Wl,--whole-archive cpp_android_spec -Wl,--no-whole-archive)
9+
add_subdirectory(${_AX_ROOT}/extensions/scripting/lua-bindings/proj.android ${ENGINE_BINARY_PATH}/extensions/lua-android)
10+
target_link_libraries(${APP_NAME} -Wl,--whole-archive lua_android_spec -Wl,--no-whole-archive)
11+
endif()
1012

1113
config_android_shared_libs("dev.axmol.lib" "${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src")
1214
endif()

0 commit comments

Comments
 (0)