
function(list_union VAR_NAME LIST1 LIST2)
	list(LENGTH "${LIST1}" LIST1_LEN)
	list(LENGTH "${LIST2}" LIST2_LEN)
	if(${LIST1_LEN} GREATER ${LIST2_LEN})
		set(ANS "${${LIST1}}")
		foreach(EL IN LISTS "${LIST2}")
			if(NOT "${EL}" IN_LIST "${LIST1}")
				list(APPEND ANS "${EL}")
			endif()
		endforeach()
	else()
		set(ANS "${${LIST2}}")
		foreach(EL IN LISTS "${LIST1}")
			if(NOT "${EL}" IN_LIST "${LIST2}")
				list(APPEND ANS "${EL}")
			endif()
		endforeach()
	endif()
	set(${VAR_NAME} "${ANS}" PARENT_SCOPE)
endfunction()

function(list_diff VAR_NAME LIST1 LIST2)
	set(ANS)
#	message(STATUS "Diff: ${LIST1} - ${LIST2}")
	foreach(EL IN LISTS "${LIST1}")
		if(NOT "${EL}" IN_LIST "${LIST2}")
#			message(STATUS "Diff: appending element ${EL}")
			list(APPEND ANS "${EL}")
#			if("${EL}" STREQUAL "_VARIABLE_NAMES_AFTER")
#				message(STATUS "Diff: Appending ${EL}")
#				message(STATUS "LIST2: "${LIST2}")
#			endif()
		else()
#			if("${EL}" STREQUAL "_VARIABLE_NAMES_AFTER")
#				message(STATUS "Diff: NOT Appending ${EL}")
#			endif()
		endif()
	endforeach()
	set(${VAR_NAME} "${ANS}" PARENT_SCOPE)
endfunction()

function(list_intersect VAR_NAME LIST1 LIST2)

	list(LENGTH "${LIST1}" LIST1_LEN)
	list(LENGTH "${LIST2}" LIST2_LEN)
	set(ANS)
	if(${LIST1_LEN} GREATER ${LIST2_LEN})
		foreach(EL IN LISTS "${LIST2}")
			if("${EL}" IN_LIST "${LIST1}")
				list(APPEND ANS "${EL}")
			endif()
		endforeach()
	else()
		foreach(EL IN LISTS "${LIST1}")
			if("${EL}" IN_LIST "${LIST2}")
				list(APPEND ANS "${EL}")
			endif()
		endforeach()
	endif()
	set(${VAR_NAME} "${ANS}" PARENT_SCOPE)
endfunction()


