aboutsummaryrefslogtreecommitdiff
path: root/cpack/fakeroot_fix.cmake
diff options
context:
space:
mode:
authorspicyjpeg <88942473+spicyjpeg@users.noreply.github.com>2021-09-12 19:39:02 +0200
committerspicyjpeg <88942473+spicyjpeg@users.noreply.github.com>2021-09-12 19:39:02 +0200
commitc6548f077282f871bc22bd05595d3a1139f50a80 (patch)
treeb5771fabdfd86fa2e2076ee08029d358c92f017d /cpack/fakeroot_fix.cmake
parentffa679d4d24b891cb59aba10946368f2ec00c391 (diff)
downloadpsn00bsdk-c6548f077282f871bc22bd05595d3a1139f50a80.tar.gz
Added preliminary files for CMake/CPack support
Diffstat (limited to 'cpack/fakeroot_fix.cmake')
-rw-r--r--cpack/fakeroot_fix.cmake32
1 files changed, 32 insertions, 0 deletions
diff --git a/cpack/fakeroot_fix.cmake b/cpack/fakeroot_fix.cmake
new file mode 100644
index 0000000..e34baa0
--- /dev/null
+++ b/cpack/fakeroot_fix.cmake
@@ -0,0 +1,32 @@
+# This script works around a bug in CPack's DEB/RPM generator, which causes
+# files installed by subprojects (not by the main CMake script) to end up in
+# packages alongside the "real" installation directory. It probably happens due
+# to CMake running under fakeroot (when invoked by CPack to prepare the files
+# to be packaged) and referencing absolute paths, which would explain why the
+# entire build directory tree is replicated inside the packages. What this
+# script does is simply finding and deleting all directories that do not match
+# the installation prefix before CPack generates the package.
+
+cmake_minimum_required(VERSION 3.21)
+
+set(_prefix ${CPACK_TEMPORARY_INSTALL_DIRECTORY}${CPACK_PACKAGING_INSTALL_PREFIX})
+
+file(
+ GLOB_RECURSE _entries
+ LIST_DIRECTORIES ON
+ ${CPACK_TEMPORARY_INSTALL_DIRECTORY}/*
+)
+
+foreach(_entry IN LISTS _entries)
+ # Skip the entry if it (or its parent directory) has already been deleted.
+ if(NOT EXISTS ${_entry})
+ continue()
+ endif()
+
+ # Delete anything whose path doesn't start with the expected prefix.
+ string(FIND ${_entry} ${_prefix} _index)
+ if(NOT _index EQUAL 0)
+ message(NOTICE "Deleting unneeded entry from package: ${_entry}")
+ file(REMOVE_RECURSE ${_entry})
+ endif()
+endforeach()