aboutsummaryrefslogtreecommitdiff
path: root/Win32Cleanup.cmake
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-10-23 14:09:55 +0200
committerPřemysl Eric Janouch <p@janouch.name>2021-10-23 18:01:30 +0200
commit3a087ad581f2e15451bfc12d8ad520422a92f4a8 (patch)
tree443ed750abaabe7bb2db0b8292313136c930561a /Win32Cleanup.cmake
parent4305c603e900173339f0e801c3ab8a55c7141c85 (diff)
downloadlogdiag-3a087ad581f2e15451bfc12d8ad520422a92f4a8.tar.gz
logdiag-3a087ad581f2e15451bfc12d8ad520422a92f4a8.tar.xz
logdiag-3a087ad581f2e15451bfc12d8ad520422a92f4a8.zip
Remove unnecessary DLLs from Windows builds
This saves 20 MiB and 4 MiB of libraries in MSYS2 and bundle builds respectively, in total, without any adverse effects. The MSYS2 build remains bloated, due to the Adwaita icon theme. Bump minimum CMake version to avoid a bug.
Diffstat (limited to 'Win32Cleanup.cmake')
-rw-r--r--Win32Cleanup.cmake37
1 files changed, 37 insertions, 0 deletions
diff --git a/Win32Cleanup.cmake b/Win32Cleanup.cmake
new file mode 100644
index 0000000..be53ef8
--- /dev/null
+++ b/Win32Cleanup.cmake
@@ -0,0 +1,37 @@
+# To be run from cmake_install.cmake, eradicates all unreferenced libraries.
+# CMake 3.9.6 has a parsing bug with ENCODING UTF-8.
+cmake_minimum_required (VERSION 3.10)
+
+# CPack runs this almost without any CMake variables at all
+# (cmStateSnapshot::SetDefaultDefinitions(), CMAKE_INSTALL_PREFIX, [DESTDIR])
+set (installdir "${CMAKE_INSTALL_PREFIX}")
+if (NOT installdir OR installdir MATCHES "^/usr(/|$)")
+ return ()
+endif ()
+
+# The function is recursive and CMake has tragic scoping behaviour;
+# environment variables are truly global there, in the absence of a cache
+unset (ENV{seen})
+function (expand path)
+ set (seen $ENV{seen})
+ if (path IN_LIST seen OR NOT EXISTS "${path}")
+ return ()
+ endif ()
+
+ set (ENV{seen} "$ENV{seen};${path}")
+ file (STRINGS "${path}" strings REGEX "[.][Dd][Ll][Ll]$" ENCODING UTF-8)
+ foreach (string ${strings})
+ string (REGEX MATCH "[-.+_a-zA-Z0-9]+$" word "${string}")
+ expand ("${installdir}/${word}")
+ endforeach ()
+endfunction ()
+
+file (GLOB roots LIST_DIRECTORIES false "${installdir}/*.[Ee][Xx][Ee]"
+ "${installdir}/lib/gdk-pixbuf-2.0/2.10.0/loaders/*.[Dd][Ll][Ll]")
+foreach (binary ${roots})
+ expand ("${binary}")
+endforeach ()
+
+file (GLOB libraries LIST_DIRECTORIES false "${installdir}/*.[Dd][Ll][Ll]")
+list (REMOVE_ITEM libraries $ENV{seen})
+file (REMOVE ${libraries})