From 0d3493beb2df1689a8994eab14b4c7035ed8afa3 Mon Sep 17 00:00:00 2001
From: Zalewa <zalewapl@gmail.com>
Date: Sat, 3 May 2025 18:58:20 +0200
Subject: [PATCH] makesourcepackages: keep the dir layout in Wadseeker's source
 archive

Wadseeker's source code is in src/wadseeker when in the repository,
but the source packager would pull it up to the top-dir of the archive.
This change in the layout changes the relative paths between the files.
Coupled with how CMAKE_SOURCE_DIR is used, it forces the use of the
root CMakeLists.txt to combine the interdependent projects together,
making it difficult to create standalone tools that would include
Wadseeker as a dependency project and would live in repo's
subdirectories.

After the layout change, the compile scripts should be able to assume
that the relative directory paths will be stable, no matter if the whole
repository is available or just its exported subset. Remove references
to CMAKE_SOURCE_DIR in Wadseeker's recipe and use relative paths
instead.
---
 releasescripts/CMakeLists.wadseeker.txt |  6 ++++++
 releasescripts/makesourcepackages.sh    | 15 ++++++++++-----
 src/wadseeker/CMakeLists.txt            | 16 ++++------------
 3 files changed, 20 insertions(+), 17 deletions(-)
 create mode 100644 releasescripts/CMakeLists.wadseeker.txt

diff --git a/releasescripts/CMakeLists.wadseeker.txt b/releasescripts/CMakeLists.wadseeker.txt
new file mode 100644
index 00000000..7024867f
--- /dev/null
+++ b/releasescripts/CMakeLists.wadseeker.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 3.5...4.0)
+if(CMAKE_VERSION VERSION_LESS 3.12)
+	cmake_policy(VERSION ${CMAKE_VERSION})
+endif()
+project(Wadseeker)
+add_subdirectory(src/wadseeker)
diff --git a/releasescripts/makesourcepackages.sh b/releasescripts/makesourcepackages.sh
index 67df3889..a752c8f6 100755
--- a/releasescripts/makesourcepackages.sh
+++ b/releasescripts/makesourcepackages.sh
@@ -149,13 +149,18 @@ if ! tar -c "$doomseekerArchiveName" --owner=doomseeker --group=doomseeker | xz
 	echo 'Failed to create Doomseeker archive!' >&2
 	Error=1
 else
+	echo 'Laying out Wadseeker source...'
+	mkdir -p "$wadseekerArchiveName/src/"
+	cp -r "$doomseekerArchiveName/src/wadseeker" "$wadseekerArchiveName/src/"
+	echo 'Adding top-level CMakeLists.txt'
+	cp CMakeLists.wadseeker.txt "$wadseekerArchiveName/"
 	echo 'Adding licence and dependencies for independent building...'
-	cp "$doomseekerArchiveName/LICENSE" "$doomseekerArchiveName/src/wadseeker"
-	cp -r "$doomseekerArchiveName/cmake" "$doomseekerArchiveName/src/wadseeker"
-	cp -r "$doomseekerArchiveName/dependencies" "$doomseekerArchiveName/src/wadseeker"
+	cp "$doomseekerArchiveName/LICENSE" "$wadseekerArchiveName/"
+	cp -r "$doomseekerArchiveName/cmake" "$wadseekerArchiveName/"
+	cp -r "$doomseekerArchiveName/dependencies" "$wadseekerArchiveName/"
 
 	echo 'Creating Wadseeker archive...'
-	if ! tar -cC "$doomseekerArchiveName/src" wadseeker --transform "s,^wadseeker,$wadseekerArchiveName," --owner=doomseeker --group=doomseeker | xz -9 > "$wadseekerArchiveName.tar.xz"; then
+	if ! tar -c "$wadseekerArchiveName" --owner=doomseeker --group=doomseeker | xz -9 > "$wadseekerArchiveName.tar.xz"; then
 		echo 'Failed to create Wadseeker archive!' >&2
 		Error=1
 	fi
@@ -165,6 +170,6 @@ if ! sign_archive "$doomseekerArchiveName.tar.xz" || ! sign_archive "$wadseekerA
 	Error=1
 fi
 
-rm -rf "$doomseekerArchiveName"
+rm -rf "$doomseekerArchiveName" "$wadseekerArchiveName"
 
 exit "$Error"
diff --git a/src/wadseeker/CMakeLists.txt b/src/wadseeker/CMakeLists.txt
index 8ce00d59..cc949abf 100644
--- a/src/wadseeker/CMakeLists.txt
+++ b/src/wadseeker/CMakeLists.txt
@@ -46,7 +46,7 @@ set(CXX_STANDARD_REQUIRED ON)
 
 add_subdirectory(lzma)
 
-include(${CMAKE_SOURCE_DIR}/cmake/Modules/Macros.cmake)
+include(../../cmake/Modules/Macros.cmake)
 
 find_package(${Qt_PACKAGE} COMPONENTS Core)
 
@@ -65,8 +65,6 @@ if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
 		option(FORCE_INTERNAL_ZLIB "Use internal zlib" OFF)
 		option(FORCE_INTERNAL_BZIP2 "Use internal bzip2" OFF)
 
-		include(${CMAKE_SOURCE_DIR}/cmake/Modules/Macros.cmake)
-
 		if(NOT FORCE_INTERNAL_ZLIB)
 			find_package_ZLIB()
 		endif()
@@ -245,15 +243,9 @@ elseif(WIN32)
 		ARCHIVE DESTINATION ./lib COMPONENT wadseeker
 		INCLUDES DESTINATION ${CMAKE_INSTALL_PREFIX}/include
 	)
-	# License files.
-	set(LICENSE_FILES
-		LICENSE
-	)
-	foreach (LICFILE ${LICENSE_FILES})
-		install(FILES "${CMAKE_SOURCE_DIR}/${LICFILE}" DESTINATION .
-			COMPONENT wadseeker
-			RENAME "${LICFILE}.txt")
-	endforeach(LICFILE)
+	install(FILES "../../LICENSE" DESTINATION .
+		COMPONENT wadseeker
+		RENAME "LICENSE.txt")
 endif()
 
 install(SCRIPT InstallHeaders.cmake COMPONENT wadseeker-dev)
-- 
2.25.1

