From 54dab0cca6cbbe06bc4f1e488e5e4badae1460c7 Mon Sep 17 00:00:00 2001 From: Andrey Filipenkov Date: Sun, 31 Aug 2025 13:12:13 +0300 Subject: [PATCH] [cmake][android] symlink external libs instead of copying them saves some disk space, Gradle will package actual files anyway --- CMakeLists.txt | 4 +--- cmake_modules/VCMIUtils.cmake | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff4aabf30..93dd9ed7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -736,9 +736,7 @@ if(ANDROID) if(ANDROID_STL MATCHES "_shared$") set(stlLibName "${CMAKE_SHARED_LIBRARY_PREFIX}${ANDROID_STL}${CMAKE_SHARED_LIBRARY_SUFFIX}") - install(FILES "${CMAKE_SYSROOT}/usr/lib/${ANDROID_SYSROOT_LIB_SUBDIR}/${stlLibName}" - DESTINATION ${LIB_DIR} - ) + vcmi_install_libs_symlink("${CMAKE_SYSROOT}/usr/lib/${ANDROID_SYSROOT_LIB_SUBDIR}/${stlLibName}") endif() else() install(DIRECTORY config DESTINATION ${DATA_DIR}) diff --git a/cmake_modules/VCMIUtils.cmake b/cmake_modules/VCMIUtils.cmake index bf5e1e590..4f4fedf29 100644 --- a/cmake_modules/VCMIUtils.cmake +++ b/cmake_modules/VCMIUtils.cmake @@ -118,6 +118,18 @@ function(vcmi_print_git_commit_hash) endfunction() +# install(FILES) of shared libs but using symlink instead of copying +function(vcmi_install_libs_symlink libs) + install(CODE " + foreach(lib ${libs}) + cmake_path(GET lib FILENAME filename) + file(CREATE_LINK \${lib} \"\${CMAKE_INSTALL_PREFIX}/${LIB_DIR}/\${filename}\" + COPY_ON_ERROR SYMBOLIC + ) + endforeach() + ") +endfunction() + # install dependencies from Conan, CONAN_RUNTIME_LIBS_FILE is set in conanfile.py function(vcmi_install_conan_deps) if(NOT USING_CONAN) @@ -125,7 +137,11 @@ function(vcmi_install_conan_deps) endif() file(STRINGS "${CONAN_RUNTIME_LIBS_FILE}" runtimeLibs) - install(FILES ${runtimeLibs} DESTINATION ${LIB_DIR}) + if(ANDROID) + vcmi_install_libs_symlink("${runtimeLibs}") + else() + install(FILES ${runtimeLibs} DESTINATION ${LIB_DIR}) + endif() endfunction() function(vcmi_deploy_qt deployQtToolName deployQtOptions)