commit b192afc2fdbcd9e2417776a68724cad01326d4ee
Author: James Le Cuirot <chewi@gentoo.org>
Date:   Sun Dec 21 22:28:33 2025 +0000

    Add BUILD_NONFREE option so legally sensitive content can be omitted

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -63,9 +63,14 @@ if(CMAKE_CROSSCOMPILING)
 endif()
 
 # Recursive function to place PK3 archive source files into a hierarchy of source file in the IDE
-function( assort_pk3_source_folder FOLDER_NAME PK3_DIR )
+function( assort_pk3_source_folder FOLDER_NAME )
 	# Assort source files into folders in the IDE
-	file(GLOB PK3_SRCS ${PK3_DIR}/*) # Create list of all files in this folder
+	# Create wildcard patterns for all directories
+	set(PK3_PATTERNS)
+	foreach(PK3_DIR ${ARGN})
+		list(APPEND PK3_PATTERNS "${PK3_DIR}/*")
+	endforeach()
+	file(GLOB PK3_SRCS ${PK3_PATTERNS}) # Create list of all files in these folders
 	foreach(PK3_SRC ${PK3_SRCS})
 		# If there are subfolders, recurse into them
 		if(IS_DIRECTORY ${PK3_SRC})
@@ -85,25 +90,30 @@ if( PK3_QUIET_ZIPDIR )
 	set( PK3_ZIPDIR_OPTIONS "-q" )
 endif()
 
-# Simplify pk3 building, add_pk3(filename srcdirectory)
-function( add_pk3 PK3_NAME PK3_DIR )
+# Simplify pk3 building, add_pk3(filename srcdirectory [srcdirectory2 ...])
+function( add_pk3 PK3_NAME )
 	# Generate target name. Just use "pk3" for main pk3 target.
 	string( REPLACE "." "_" PK3_TARGET ${PK3_NAME} )
 
 	if( NOT ZDOOM_OUTPUT_OLDSTYLE )
 		add_custom_command( OUTPUT ${ZDOOM_OUTPUT_DIR}/${PK3_NAME}
-			COMMAND zipdir -udf ${PK3_ZIPDIR_OPTIONS} ${ZDOOM_OUTPUT_DIR}/${PK3_NAME} ${PK3_DIR}
+			COMMAND zipdir -udf ${PK3_ZIPDIR_OPTIONS} ${ZDOOM_OUTPUT_DIR}/${PK3_NAME} ${ARGN}
 			COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ZDOOM_OUTPUT_DIR}/${PK3_NAME} $<TARGET_FILE_DIR:zdoom>/${PK3_NAME}
 			DEPENDS zipdir )
 	else()
 		add_custom_command( OUTPUT ${ZDOOM_OUTPUT_DIR}/${PK3_NAME}
-			COMMAND zipdir -udf ${PK3_ZIPDIR_OPTIONS} ${ZDOOM_OUTPUT_DIR}/${PK3_NAME} ${PK3_DIR}
+			COMMAND zipdir -udf ${PK3_ZIPDIR_OPTIONS} ${ZDOOM_OUTPUT_DIR}/${PK3_NAME} ${ARGN}
 			DEPENDS zipdir )
 	endif()
 	# Create a list of source files for this PK3, for use in the IDE
 	# Phase 1: Create a list of all source files for this PK3 archive, except
 	#  for a couple of strife image file names that confuse CMake.
-	file(GLOB_RECURSE PK3_SRCS ${PK3_DIR}/*)
+	# Create wildcard patterns for all directories
+	set(PK3_PATTERNS)
+	foreach(PK3_DIR ${ARGN})
+		list(APPEND PK3_PATTERNS "${PK3_DIR}/*")
+	endforeach()
+	file(GLOB_RECURSE PK3_SRCS ${PK3_PATTERNS})
 	# Exclude from the source list some files with brackets in the
 	# file names here, because they confuse CMake.
 	# This only affects the list of source files shown in the IDE.
@@ -126,7 +136,7 @@ function( add_pk3 PK3_NAME PK3_DIR )
 		DEPENDS ${ZDOOM_OUTPUT_DIR}/${PK3_NAME}
 		SOURCES ${PK3_SRCS})
 	# Phase 3: Assign source files to a nice folder structure in the IDE
-	assort_pk3_source_folder("Source Files" ${PK3_DIR})
+	assort_pk3_source_folder("Source Files" ${ARGN})
 	# Phase 4: Add the resulting PK3 to the install target.
 	if( WIN32 )
 		set( INSTALL_PK3_PATH . CACHE STRING "Directory where zdoom.pk3 will be placed during install." )
@@ -404,6 +414,7 @@ install(DIRECTORY docs/
 		COMPONENT "Documentation")
 
 option( DYN_OPENAL "Dynamically load OpenAL" ON )
+option( BUILD_NONFREE "Build non-free assets used by commercial games" ON )
 
 add_subdirectory( libraries/lzma )
 add_subdirectory( libraries/miniz )
--- a/wadsrc_bm/CMakeLists.txt
+++ b/wadsrc_bm/CMakeLists.txt
@@ -1 +1,3 @@
-add_pk3(brightmaps.pk3 ${CMAKE_CURRENT_SOURCE_DIR}/static)
+if( BUILD_NONFREE )
+	add_pk3(brightmaps.pk3 ${CMAKE_CURRENT_SOURCE_DIR}/static)
+endif()
--- a/wadsrc_extra/CMakeLists.txt
+++ b/wadsrc_extra/CMakeLists.txt
@@ -1 +1 @@
-add_pk3(game_support.pk3 ${CMAKE_CURRENT_SOURCE_DIR}/static)
+add_pk3(game_support.pk3 ${CMAKE_CURRENT_SOURCE_DIR}/static $<$<BOOL:${BUILD_NONFREE}>:${CMAKE_CURRENT_SOURCE_DIR}/nonfree>)
--- a/wadsrc_widepix/CMakeLists.txt
+++ b/wadsrc_widepix/CMakeLists.txt
@@ -1 +1,3 @@
-add_pk3(game_widescreen_gfx.pk3 ${CMAKE_CURRENT_SOURCE_DIR}/static)
+if( BUILD_NONFREE )
+	add_pk3(game_widescreen_gfx.pk3 ${CMAKE_CURRENT_SOURCE_DIR}/static)
+endif()
