cmake_minimum_required( VERSION 3.16.0 )

include(precompiled_headers)

if( COMMAND cmake_policy )
	cmake_policy( SET CMP0003 NEW )
endif()

include( CheckCXXSourceCompiles )
include( CheckFunctionExists )
include( CheckCXXCompilerFlag )
include( CheckIncludeFile )
include( CheckIncludeFiles )
include( CheckLibraryExists )
include( FindPkgConfig )

if( DEM_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE )
	option( NO_STRIP "Do not strip Release or MinSizeRel builds" )
	# At least some versions of Xcode fail if you strip with the linker
	# instead of the separate strip utility.
	if( APPLE )
		set( NO_STRIP ON )
	endif()
endif()

if( APPLE )
    option( OSX_COCOA_BACKEND "Use native Cocoa backend instead of SDL" ON )
endif()

option( ZDOOM_ENABLE_SWR "Enable software renderer" ON )
if( NOT ZDOOM_ENABLE_SWR )
	add_definitions( -DNO_SWRENDERER )
endif()

target_architecture(TARGET_ARCHITECTURE)
message(STATUS "Architecture is ${TARGET_ARCHITECTURE}")

if ( ${TARGET_ARCHITECTURE} MATCHES "arm64" )
	set (ARM64 aarch64)
endif()

# Right now only 64 bit is supported.
if( ${TARGET_ARCHITECTURE} MATCHES "x86_64" )
	set( X64 64 )
	add_definitions( -DARCH_IA32 )
endif()

if( NOT PROJECT_LIBRARIES )
	set( PROJECT_LIBRARIES "" )
endif()

add_definitions( -DTHIS_IS_GZDOOM )

if( WIN32 )

	add_definitions( -D_WIN32 )

	set( PROJECT_LIBRARIES
		psapi
		wsock32
		winmm
		dinput8
		ole32
		user32
		gdi32
		comctl32
		comdlg32
		ws2_32
		setupapi
		oleaut32
		dbghelp
		legacy_stdio_definitions )

	if( DEM_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE )
		if( DX_dxguid_LIBRARY )
			list( APPEND PROJECT_LIBRARIES "${DX_dxguid_LIBRARY}" )
		endif()
	endif()
else()
	if( APPLE )
		set( NO_GTK ON )
		set( DYN_GTK OFF )

		# Prevent inclusion of fp.h and FixMath.h from Carbon framework
		# Declarations from these files are not used but cause the following conflicts:
		#  - redefinition of 'FixedToFloat' and 'FloatToFixed' macros
		#  - redefinition of 'pi' as different kind of symbol
		add_definitions( -D__FP__ -D__FIXMATH__ )
	else()
		option( NO_GTK "Disable GTK+ dialogs (Not applicable to Windows)" )
		option( DYN_GTK "Load GTK+ at runtime instead of compile time" ON )

		# Use GTK+ for the IWAD picker, if available.
		if( NOT NO_GTK )
			pkg_check_modules( GTK3 gtk+-3.0 )
			if( GTK3_FOUND )
				if( NOT DYN_GTK )
					set( PROJECT_LIBRARIES ${PROJECT_LIBRARIES} ${GTK3_LIBRARIES} )
				endif()
				include_directories( SYSTEM ${GTK3_INCLUDE_DIRS} )
				link_directories( ${GTK3_LIBRARY_DIRS} )
			else()
				pkg_check_modules( GTK2 gtk+-2.0 )
				if( GTK2_FOUND )
					if( NOT DYN_GTK )
						set( PROJECT_LIBRARIES ${PROJECT_LIBRARIES} ${GTK2_LIBRARIES} )
					endif()
					include_directories( SYSTEM ${GTK2_INCLUDE_DIRS} )
					link_directories( ${GTK2_LIBRARY_DIRS} )
				else()
					set( NO_GTK ON )
				endif()
			endif()
		endif()
	endif()

	if ( NOT WIN32 )
		option( NO_SDL_JOYSTICK "Disable SDL joystick support (Not applicable to Windows)" OFF )
		if ( NO_SDL_JOYSTICK )
			add_definitions( -DNO_SDL_JOYSTICK=1 )
		endif()
	endif()

	if( NO_GTK )
		add_definitions( -DNO_GTK )
	elseif( DYN_GTK )
		add_definitions( -DDYN_GTK=1 )
	else()
		add_definitions( -DDYN_GTK=0 )
	endif()

	# Non-Windows version also needs SDL except native OS X backend
	if( NOT APPLE OR NOT OSX_COCOA_BACKEND )
		find_package( SDL2 REQUIRED )
		include_directories( SYSTEM "${SDL2_INCLUDE_DIR}" )
		set( PROJECT_LIBRARIES ${PROJECT_LIBRARIES} "${SDL2_LIBRARY}" )
	endif()

endif()

if( NOT NO_OPENAL )
	if ( "vcpkg-openal-soft" IN_LIST VCPKG_MANIFEST_FEATURES )
		# Statically link to OpenAL from vcpkg
		find_package( OpenAL CONFIG REQUIRED )
		list( APPEND PROJECT_LIBRARIES OpenAL::OpenAL )
	elseif ( NOT DYN_OPENAL )	# DYN_OPENAL uses local copies of the headers.
		find_package( OpenAL )
		mark_as_advanced(CLEAR OPENAL_INCLUDE_DIR)
		if( OPENAL_INCLUDE_DIR )
			include_directories( SYSTEM ${OPENAL_INCLUDE_DIR} )
			mark_as_advanced(CLEAR OPENAL_LIBRARY)
			if( OPENAL_LIBRARY )
				set( PROJECT_LIBRARIES ${OPENAL_LIBRARY} ${PROJECT_LIBRARIES} )
				if( APPLE )
					set( PROJECT_LIBRARIES ${PROJECT_LIBRARIES} "-framework AudioUnit -framework CoreAudio -framework ApplicationServices -framework AudioToolbox -framework CoreFoundation" )
				endif()
			else()
				set( NO_OPENAL ON )
			endif()
		else()
			set( NO_OPENAL ON )
		endif()
	else()
		add_definitions( -DDYN_OPENAL )
	endif()
endif()

if( NO_OPENAL )
	add_definitions( -DNO_OPENAL=1 )
endif()

# Decide on SSE setup

if( X64 )
	set( HAVE_MMX 1 )
endif( X64 )

CHECK_CXX_SOURCE_COMPILES("#include <ppl.h>
	int main() { concurrency::parallel_for(0, 1, 1, [](int) { } ); }"
	HAVE_PARALLEL_FOR)

if( NOT HAVE_PARALLEL_FOR )
	CHECK_CXX_SOURCE_COMPILES("#include <dispatch/dispatch.h>
		int main() { dispatch_apply(1, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(size_t) { }); }"
		HAVE_DISPATCH_APPLY)
endif()

# Set up flags for MSVC
if (MSVC)
	set( CMAKE_CXX_FLAGS "/MP ${CMAKE_CXX_FLAGS}" )
endif (MSVC)

# Set up flags for GCC

if( DEM_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE )
	if( PROFILE )
		set( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -pg" )
		set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg" )
		set( CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -pg" )
		set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -pg" )
	endif()

	if( NOT PROFILE AND NOT APPLE )
		# On OS X frame pointers are required for exception handling, at least with Clang
		set( REL_CXX_FLAGS "${REL_CXX_FLAGS} -fomit-frame-pointer" )
	endif()
	set( CMAKE_CXX_FLAGS_RELEASE "${REL_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}" )
	set( CMAKE_CXX_FLAGS_MINSIZEREL "${REL_CXX_FLAGS} ${CMAKE_CXX_FLAGS_MINSIZEREL}" )
	set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${REL_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" )

	# Support for the GCC/Clang sanitizers.
	set( WITH_ASAN 0 CACHE BOOL "Enable the Address Sanitizer")
	if( NOT CMAKE_COMPILER_IS_GNUCXX )
		set( WITH_MSAN 0 CACHE BOOL "Enable the Memory Sanitizer")
	endif( NOT CMAKE_COMPILER_IS_GNUCXX )
	set( WITH_UBSAN 0 CACHE BOOL "Enable the Undefined Behavior Sanitizer")
	if( WITH_MSAN )
		if ( WITH_ASAN OR WITH_UBSAN )
			message( SEND_ERROR "You can't use MSAN with either ASAN or UBSAN." )
		endif ( WITH_ASAN OR WITH_UBSAN )
	endif( WITH_MSAN )

	set( SANITIZER_FLAG "" )
	if( WITH_ASAN )
		set( SANITIZER_FLAG "-fsanitize=address" )
		if ( WITH_UBSAN )
			set( SANITIZER_FLAG "${SANITIZER_FLAG},undefined" )
		endif( WITH_UBSAN )
	elseif( WITH_MSAN )
		set( SANITIZER_FLAG "-fsanitize=memory" )
	elseif( WITH_UBSAN )
		set( SANITIZER_FLAG "-fsanitize=undefined" )
	endif( WITH_ASAN )

	set( CMAKE_CXX_FLAGS "${SANITIZER_FLAG} ${CMAKE_CXX_FLAGS}" )
	set( CMAKE_C_FLAGS "${SANITIZER_FLAG} ${CMAKE_C_FLAGS}" )
	set( CMAKE_EXE_LINKER_FLAGS "${SANITIZER_FLAG} ${CMAKE_EXE_LINKER_FLAGS}" )

	if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.5")
		set( CMAKE_C_FLAGS "-Wno-unused-result ${CMAKE_C_FLAGS}" )
		set( CMAKE_CXX_FLAGS "-Wno-unused-result ${CMAKE_CXX_FLAGS}" )
	endif()
	if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
		if( APPLE OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "3.6" )
			set( CMAKE_CXX_FLAGS "-Wno-inconsistent-missing-override ${CMAKE_CXX_FLAGS}" )
		endif()
	endif()
	set( CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused -Wno-unused-parameter -Wno-missing-field-initializers -ffp-contract=off ${CMAKE_C_FLAGS}" )
	set( CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused -Wno-unused-parameter -Wno-missing-field-initializers -ffp-contract=off ${CMAKE_CXX_FLAGS}" )

	if( NOT X64 AND NOT CAN_DO_MFPMATH )
		set( CMAKE_C_FLAGS "-DNO_SSE ${CMAKE_C_FLAGS}" )
		set( CMAKE_CXX_FLAGS "-DNO_SSE ${CMAKE_CXX_FLAGS}" )
	endif()

	# Remove extra warnings when using the official DirectX headers.
	# Also, TDM-GCC 4.4.0 no longer accepts glibc-style printf formats as valid,
	# which is a royal pain. The previous version I had been using was fine with them.
	# MinGW: switch to the Windows Unicode API.
	if( WIN32 )
		set( CMAKE_CXX_FLAGS "-Wno-unknown-pragmas -Wno-comment -Wno-format ${CMAKE_CXX_FLAGS}" )
		set( CMAKE_CXX_FLAGS "-D_UNICODE -DUNICODE ${CMAKE_CXX_FLAGS}" )
		set( CMAKE_CXX_FLAGS "-D_WIN32_WINNT=0x0600 ${CMAKE_CXX_FLAGS}" )
		set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -municode" )
	endif()

	# Detect FreeBSD and add flags
	if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
		set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC" )
		set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC" )
	endif()
	
	if(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
		set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -ljemalloc")
	endif()

	if( NOT NO_STRIP )
		set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s" )
		set (CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} -s" )
	endif()
endif()

# Check for thread_local keyword, it's optional at the moment

if ( NOT (cxx_thread_local IN_LIST CMAKE_CXX_COMPILE_FEATURES) )
	message( SEND_ERROR "C++ compiler doesn't support thread_local storage duration specifier" )
endif()

# Check for functions that may or may not exist.

require_stricmp()
require_strnicmp()

if( NOT MSVC )
	add_definitions( -D__forceinline=inline )
endif()

if( UNIX )
	CHECK_LIBRARY_EXISTS( rt clock_gettime "" CLOCK_GETTIME_IN_RT )
	if( NOT CLOCK_GETTIME_IN_RT )
		CHECK_FUNCTION_EXISTS( clock_gettime CLOCK_GETTIME_EXISTS )
		if( NOT CLOCK_GETTIME_EXISTS )
			message( STATUS "Could not find clock_gettime. Timing statistics will not be available." )
			add_definitions( -DNO_CLOCK_GETTIME )
		endif()
	else()
		list( APPEND PROJECT_LIBRARIES rt )
	endif()
endif()

# Flags

# Update gitinfo.h

add_custom_target( revision_check ALL
	COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_SOURCE_DIR}/tools/updaterevision/UpdateRevision.cmake" src/gitinfo.h
	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

# required libraries

set( PROJECT_LIBRARIES ${PROJECT_LIBRARIES} miniz "${BZIP2_LIBRARIES}" "${CMAKE_DL_LIBS}" "${DRPC_LIBRARIES}")
if (HAVE_VULKAN)
	list( APPEND PROJECT_LIBRARIES "zvulkan" )
endif()

list( APPEND PROJECT_LIBRARIES "zwidget" )
list( APPEND PROJECT_LIBRARIES "webp" )

# ZMUSIC

if( MSVC )
	find_package( ZMusic )
else()
	find_package( ZMusic REQUIRED )
endif()

message("Building for target architecture: ${TARGET_ARCHITECTURE}")

if( MSVC AND NOT ZMUSIC_FOUND )
	# Use prebuilt library
	set( ZMUSIC_ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../bin/windows/zmusic" )
	set( ZMUSIC_INCLUDE_DIR ${ZMUSIC_ROOT_PATH}/include )
	set( ZMUSIC_LIBRARIES zmusic )
	if( X64 )
		link_directories( ${ZMUSIC_ROOT_PATH}/64bit )
	elseif( ARM64 )
		link_directories( ${ZMUSIC_ROOT_PATH}/arm64 )
	else()
		link_directories( ${ZMUSIC_ROOT_PATH}/32bit )
	endif()
	set( ZMUSIC_FOUND TRUE )
endif()


# VPX

if( MSVC AND NOT VPX_FOUND )
	# Use prebuilt library
	set( VPX_ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../bin/Windows/vpx" )
	set( VPX_INCLUDE_DIR ${VPX_ROOT_PATH}/include )
	set( VPX_LIBRARIES libvpx )
	if ( NOT ARM64 )
		set (VPX_LIBRARIES ${VPX_LIBRARIES} libcompat-to-msvc )
	endif()
	if( ARM64 )
		link_directories( ${VPX_ROOT_PATH}/lib/arm64 )
	elseif( X64 )
		link_directories( ${VPX_ROOT_PATH}/lib/64 )
	else()
		link_directories( ${VPX_ROOT_PATH}/lib/32 )
		# Workaround for "error LNK2026: module unsafe for SAFESEH image."
		set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO" )
	endif()
	set( VPX_FOUND TRUE )
endif()

if( VPX_FOUND )
	add_definitions( "-DUSE_LIBVPX=1" )
	include_directories( SYSTEM "${VPX_INCLUDE_DIR}" )
	set( PROJECT_LIBRARIES ${PROJECT_LIBRARIES} ${VPX_LIBRARIES} )
else()
	message( SEND_ERROR "Could not find libvpx" )
endif()

include_directories( SYSTEM "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${ZMUSIC_INCLUDE_DIR}" "${DRPC_INCLUDE_DIR}")

if( ${HAVE_VM_JIT} )
	add_definitions( -DHAVE_VM_JIT )
	include_directories( SYSTEM "${ASMJIT_INCLUDE_DIR}" )
	set( PROJECT_LIBRARIES ${PROJECT_LIBRARIES} "${ASMJIT_LIBRARIES}")
endif()

# Start defining source files for ZDoom
set( PLAT_WIN32_SOURCES
	win32/i_steam.cpp
	common/platform/win32/hardware.cpp
	common/platform/win32/i_input.cpp
	common/platform/win32/i_keyboard.cpp
	common/platform/win32/i_mouse.cpp
	common/platform/win32/i_dijoy.cpp
	common/platform/win32/i_rawps2.cpp
	common/platform/win32/i_xinput.cpp
	common/platform/win32/i_main.cpp
	common/platform/win32/i_mainwindow.cpp
	common/platform/win32/i_system.cpp
	common/platform/win32/i_specialpaths.cpp
	common/platform/win32/st_start.cpp
	common/platform/win32/gl_sysfb.cpp
	common/platform/win32/base_sysfb.cpp
	common/platform/win32/win32basevideo.cpp
	common/platform/win32/win32glvideo.cpp
	)

if (HAVE_VULKAN)
	list (APPEND PLAT_WIN32_SOURCES common/platform/win32/win32vulkanvideo.cpp )
endif()

# todo: implement an actual crash catcher for ARM
# for now this is purely experimental
if (NOT ${TARGET_ARCHITECTURE} MATCHES "arm" )
	set (PLAT_WIN32_SOURCES ${PLAT_WIN32_SOURCES} common/platform/win32/i_crash.cpp )
endif()
if (MSVC AND ${TARGET_ARCHITECTURE} MATCHES "arm")
	set (PLAT_WIN32_SOURCES ${PLAT_WIN32_SOURCES} common/platform/win32/i_crash_arm.cpp )
	add_definitions( -DNO_SSE -D__ARM__ -DRAPIDJSON_ENDIAN=RAPIDJSON_LITTLEENDIAN)
endif()
	
set( PLAT_POSIX_SOURCES
	posix/i_steam.cpp
	common/platform/posix/i_system_posix.cpp )
set( PLAT_SDL_SOURCES
	common/platform/posix/sdl/crashcatcher.c
	common/platform/posix/sdl/hardware.cpp
	common/platform/posix/sdl/i_gui.cpp
	common/platform/posix/sdl/i_input.cpp
	common/platform/posix/sdl/i_joystick.cpp
	common/platform/posix/sdl/i_main.cpp
	common/platform/posix/sdl/i_system.cpp
	common/platform/posix/sdl/sdlglvideo.cpp
	common/platform/posix/sdl/st_start.cpp )
set( PLAT_UNIX_SOURCES
	common/platform/posix/unix/i_specialpaths.cpp
	common/platform/posix/unix/gtk_dialogs.cpp )
set( PLAT_OSX_SOURCES
	common/platform/posix/osx/iwadpicker_cocoa.mm
	common/platform/posix/osx/i_specialpaths.mm
	posix/osx/zdoom.icns )
set( PLAT_COCOA_SOURCES
	common/platform/posix/cocoa/i_input.mm
	common/platform/posix/cocoa/i_joystick.cpp
	common/platform/posix/cocoa/i_main.mm
	common/platform/posix/cocoa/i_system.mm
	common/platform/posix/cocoa/i_video.mm
	common/platform/posix/cocoa/st_console.mm
	common/platform/posix/cocoa/st_start.mm )

if( WIN32 )
	set( SYSTEM_SOURCES_DIR common/platform/win32 )
	set( SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} )
	set( OTHER_SYSTEM_SOURCES ${PLAT_POSIX_SOURCES} ${PLAT_SDL_SOURCES} ${PLAT_OSX_SOURCES} ${PLAT_COCOA_SOURCES} ${PLAT_UNIX_SOURCES} )

	set( SYSTEM_SOURCES ${SYSTEM_SOURCES} win32/zdoom.rc )
elseif( APPLE )
	if( OSX_COCOA_BACKEND )
		set( SYSTEM_SOURCES_DIR common/platform/posix common/platform/posix/cocoa )
		set( SYSTEM_SOURCES ${PLAT_COCOA_SOURCES} )
		set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ${PLAT_SDL_SOURCES} ${PLAT_UNIX_SOURCES} )
	else()
		set( SYSTEM_SOURCES_DIR common/platform/posix common/platform/posix/sdl )
		set( SYSTEM_SOURCES ${PLAT_SDL_SOURCES} )
		set( PLAT_OSX_SOURCES ${PLAT_OSX_SOURCES} common/platform/posix/sdl/i_system.mm )
		set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ${PLAT_COCOA_SOURCES} ${PLAT_UNIX_SOURCES} )
	endif()

	set( SYSTEM_SOURCES ${SYSTEM_SOURCES} ${PLAT_POSIX_SOURCES} ${PLAT_OSX_SOURCES} )

	set_source_files_properties( posix/osx/zdoom.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources )
	set_source_files_properties( common/platform/posix/osx/iwadpicker_cocoa.mm PROPERTIES COMPILE_FLAGS -fobjc-exceptions )
else()
	option (SYSTEMINSTALL "Set global progdir based on CMake Install Dir" OFF)

	set( SYSTEM_SOURCES_DIR common/platform/posix common/platform/posix/sdl )
	set( SYSTEM_SOURCES ${PLAT_POSIX_SOURCES} ${PLAT_SDL_SOURCES} ${PLAT_UNIX_SOURCES} )
	set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ${PLAT_OSX_SOURCES} ${PLAT_COCOA_SOURCES} )

	if ( SYSTEMINSTALL )
		add_definitions( -DPROGDIR="${CMAKE_INSTALL_PREFIX}/${INSTALL_PK3_PATH}" )
	endif()
endif()

if( HAVE_MMX )
	add_definitions( -DHAVE_MMX=1 )

	set( SYSTEM_SOURCES ${SYSTEM_SOURCES}
		common/textures/hires/hqnx_asm/hq2x_asm.cpp
		common/textures/hires/hqnx_asm/hq3x_asm.cpp
		common/textures/hires/hqnx_asm/hq4x_asm.cpp
		common/textures/hires/hqnx_asm/hqnx_asm_Image.cpp)

	if( DEM_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE )
		set_source_files_properties(
			common/textures/hires/hqnx_asm/hq2x_asm.cpp
			common/textures/hires/hqnx_asm/hq3x_asm.cpp
			common/textures/hires/hqnx_asm/hq4x_asm.cpp
			common/textures/hires/hqresize.cpp
			PROPERTIES COMPILE_FLAGS "-mmmx" )
	endif( DEM_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE )
endif( HAVE_MMX )

if( HAVE_PARALLEL_FOR )
	add_definitions( -DHAVE_PARALLEL_FOR=1 )
elseif( HAVE_DISPATCH_APPLY )
	add_definitions( -DHAVE_DISPATCH_APPLY=1 )
else()
	option( NO_OPENMP "Disable usage of OpenMP" OFF )

	if( NOT NO_OPENMP )
		include( FindOpenMP )

		if( OPENMP_FOUND )
			set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" )
			set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )
		endif( OPENMP_FOUND )
	endif( NOT NO_OPENMP )
endif()

add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xlat_parser.c ${CMAKE_CURRENT_BINARY_DIR}/xlat_parser.h
	COMMAND lemon -C${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/gamedata/xlat/xlat_parser.y
	DEPENDS lemon ${CMAKE_CURRENT_SOURCE_DIR}/gamedata/xlat/xlat_parser.y )

add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zcc-parse.c ${CMAKE_CURRENT_BINARY_DIR}/zcc-parse.h
	COMMAND lemon -C${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/frontend/zcc-parse.lemon
	DEPENDS lemon ${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/frontend/zcc-parse.lemon )

add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sc_man_scanner.h
	COMMAND re2c --no-generation-date -s -o ${CMAKE_CURRENT_BINARY_DIR}/sc_man_scanner.h ${CMAKE_CURRENT_SOURCE_DIR}/common/engine/sc_man_scanner.re
	DEPENDS re2c ${CMAKE_CURRENT_SOURCE_DIR}/common/engine/sc_man_scanner.re )

include_directories( ${CMAKE_CURRENT_BINARY_DIR} )

option( SEND_ANON_STATS "Enable sending of anonymous hardware statistics" ON )

if( NOT SEND_ANON_STATS )
	add_definitions( -DNO_SEND_STATS )
endif()

# Project files should be aware of the header files. We can GLOB these since
# there's generally a new cpp for every header so this file will get changed
file( GLOB HEADER_FILES
	console/*.h
	playsim/*.h
	playsim/bots/*.h
	playsim/fragglescript/*.h
	playsim/mapthinkers/*.h
	g_statusbar/*.h
	gamedata/*.h
	gamedata/resourcefiles/*.h
	gamedata/fonts/*.h
	gamedata/xlat/*.h
	intermission/*.h
	maploader/*.h
	menu/*.h
	sound/*.h
	sound/backend/*.h*
	posix/*.h
	r_data/*.h
	common/audio/sound/thirdparty/*.h
	common/audio/sound/*.h
	common/audio/music/*.h*
	common/2d/*.h
	common/console/*.h
	common/cutscenes/*.h
	common/utility/*.h
	common/engine/*.h
	common/menu/*.h
	common/statusbar/*.h
	common/fonts/*.h
	common/objects/*.h
	common/filesystem/include/*.h
	common/filesystem/source/*.h
	common/platform/posix/cocoa/*.h
	common/platform/posix/sdl/*.h
	common/platform/win32/*.h
	common/models/*.h
	common/textures/*.h
	common/startscreen/*.h
	common/widgets/*.h
	common/textures/hires/hqnx/*.h
	common/textures/hires/hqnx_asm/*.h
	common/textures/hires/xbr/*.h
	common/thirdparty/*.h
	common/thirdparty/rapidjson/*.h
	common/thirdparty/math/*h
	common/thirdparty/libsmackerdec/include/*.h
	common/thirdparty/utf8proc/*.h
	common/rendering/*.h
	common/rendering/gl_load/*.h
	common/rendering/gles/*.h
	common/rendering/hwrenderer/data/*.h
	common/rendering/vulkan/*.h
	common/rendering/vulkan/system/*.h
	common/rendering/vulkan/renderer/*.h
	common/rendering/vulkan/shaders/*.h
	common/rendering/vulkan/textures/*.h
	common/scripting/core/*h
	common/scripting/vm/*h
	common/scripting/jit/*h
	common/scripting/interface/*.h
	common/scripting/backend/*.h
	common/scripting/frontend/*.h

	utility/*.h
	launcher/*.h
	scripting/*.h
	scripting/backend/*.h
	scripting/decorate/*.h
	scripting/zscript/*.h
	sound/midisources/*.h
	rendering/*.h
	rendering/2d/*.h
	rendering/swrenderer/*.h
	rendering/swrenderer/textures/*.h
	rendering/swrenderer/drawers/*.h
	rendering/swrenderer/scene/*.h
	rendering/swrenderer/segments/*.h
	rendering/swrenderer/line/*.h
	rendering/swrenderer/plane/*.h
	rendering/swrenderer/things/*.h
	rendering/swrenderer/viewport/*.h
	rendering/hwrenderer/*.h
	rendering/hwrenderer/scene/*.h
	*.h
)

set ( SWRENDER_SOURCES
	rendering/swrenderer/r_swcolormaps.cpp
	rendering/swrenderer/r_swrenderer.cpp
	rendering/swrenderer/r_renderthread.cpp
	rendering/swrenderer/drawers/r_draw.cpp
	rendering/swrenderer/drawers/r_draw_pal.cpp
	rendering/swrenderer/drawers/r_draw_rgba.cpp
	rendering/swrenderer/scene/r_3dfloors.cpp
	rendering/swrenderer/scene/r_light.cpp
	rendering/swrenderer/scene/r_opaque_pass.cpp
	rendering/swrenderer/scene/r_portal.cpp
	rendering/swrenderer/scene/r_scene.cpp
	rendering/swrenderer/scene/r_translucent_pass.cpp
	rendering/swrenderer/viewport/r_drawerargs.cpp
	rendering/swrenderer/viewport/r_skydrawer.cpp
	rendering/swrenderer/viewport/r_spandrawer.cpp
	rendering/swrenderer/viewport/r_spritedrawer.cpp
	rendering/swrenderer/viewport/r_viewport.cpp
	rendering/swrenderer/viewport/r_walldrawer.cpp
	rendering/swrenderer/line/r_line.cpp
	rendering/swrenderer/line/r_farclip_line.cpp
	rendering/swrenderer/line/r_walldraw.cpp
	rendering/swrenderer/line/r_wallsetup.cpp
	rendering/swrenderer/line/r_fogboundary.cpp
	rendering/swrenderer/line/r_renderdrawsegment.cpp
	rendering/swrenderer/segments/r_clipsegment.cpp
	rendering/swrenderer/segments/r_drawsegment.cpp
	rendering/swrenderer/segments/r_portalsegment.cpp
	rendering/swrenderer/things/r_visiblesprite.cpp
	rendering/swrenderer/things/r_visiblespritelist.cpp
	rendering/swrenderer/things/r_voxel.cpp
	rendering/swrenderer/things/r_particle.cpp
	rendering/swrenderer/things/r_playersprite.cpp
	rendering/swrenderer/things/r_sprite.cpp
	rendering/swrenderer/things/r_wallsprite.cpp
	rendering/swrenderer/things/r_decal.cpp
	rendering/swrenderer/plane/r_visibleplane.cpp
	rendering/swrenderer/plane/r_visibleplanelist.cpp
	rendering/swrenderer/plane/r_skyplane.cpp
	rendering/swrenderer/plane/r_planerenderer.cpp
	rendering/swrenderer/plane/r_flatplane.cpp
	rendering/swrenderer/plane/r_slopeplane.cpp
)

# These files will be flagged as "headers" so that they appear in project files
# without being compiled.
set( NOT_COMPILED_SOURCE_FILES
	${OTHER_SYSTEM_SOURCES}
	${SWRENDER_SOURCES}
	sc_man_scanner.h
	common/engine/sc_man_scanner.re
	g_statusbar/sbarinfo_commands.cpp
	gamedata/xlat/xlat_parser.y
	xlat_parser.c
	xlat_parser.h
	common/scripting/frontend/zcc-parse.lemon
	zcc-parse.c
	zcc-parse.h
	common/platform/win32/zutil.natvis
)

set( VM_JIT_SOURCES
	common/scripting/jit/jit.cpp
	common/scripting/jit/jit_runtime.cpp
	common/scripting/jit/jit_call.cpp
	common/scripting/jit/jit_flow.cpp
	common/scripting/jit/jit_load.cpp
	common/scripting/jit/jit_math.cpp
	common/scripting/jit/jit_move.cpp
	common/scripting/jit/jit_store.cpp
)

# Enable fast math for some sources
set( FASTMATH_SOURCES
	rendering/swrenderer/r_all.cpp
	rendering/swrenderer/r_swscene.cpp
	common/textures/hires/hqnx/init.cpp
	common/textures/hires/hqnx/hq2x.cpp
	common/textures/hires/hqnx/hq3x.cpp
	common/textures/hires/hqnx/hq4x.cpp
	common/textures/hires/xbr/xbrz.cpp
	common/textures/hires/xbr/xbrz_old.cpp
	common/rendering/gl_load/gl_load.c
	rendering/hwrenderer/hw_dynlightdata.cpp
	rendering/hwrenderer/scene/hw_bsp.cpp
	rendering/hwrenderer/scene/hw_fakeflat.cpp
	rendering/hwrenderer/scene/hw_decal.cpp
	rendering/hwrenderer/scene/hw_drawinfo.cpp
	rendering/hwrenderer/scene/hw_drawlist.cpp
	rendering/hwrenderer/scene/hw_clipper.cpp
	rendering/hwrenderer/scene/hw_flats.cpp
	rendering/hwrenderer/scene/hw_portal.cpp
	rendering/hwrenderer/scene/hw_renderhacks.cpp
	rendering/hwrenderer/scene/hw_sky.cpp
	rendering/hwrenderer/scene/hw_skyportal.cpp
	rendering/hwrenderer/scene/hw_sprites.cpp
	rendering/hwrenderer/scene/hw_spritelight.cpp
	rendering/hwrenderer/scene/hw_walls.cpp
	rendering/hwrenderer/scene/hw_walls_vertex.cpp
	rendering/hwrenderer/scene/hw_weapon.cpp
	common/utility/matrix.cpp
)
	
#Vulkan stuff must go into a separate list because it needs to be disabled for some platforms
set (VULKAN_SOURCES
	common/rendering/vulkan/system/vk_renderdevice.cpp
	common/rendering/vulkan/system/vk_commandbuffer.cpp
	common/rendering/vulkan/system/vk_hwbuffer.cpp
	common/rendering/vulkan/system/vk_buffer.cpp
	common/rendering/vulkan/renderer/vk_renderstate.cpp
	common/rendering/vulkan/renderer/vk_renderpass.cpp
	common/rendering/vulkan/renderer/vk_streambuffer.cpp
	common/rendering/vulkan/renderer/vk_postprocess.cpp
	common/rendering/vulkan/renderer/vk_pprenderstate.cpp
	common/rendering/vulkan/renderer/vk_descriptorset.cpp
	common/rendering/vulkan/renderer/vk_raytrace.cpp
	common/rendering/vulkan/shaders/vk_shader.cpp
	common/rendering/vulkan/shaders/vk_ppshader.cpp
	common/rendering/vulkan/textures/vk_samplers.cpp
	common/rendering/vulkan/textures/vk_hwtexture.cpp
	common/rendering/vulkan/textures/vk_pptexture.cpp
	common/rendering/vulkan/textures/vk_imagetransition.cpp
	common/rendering/vulkan/textures/vk_renderbuffers.cpp
	common/rendering/vulkan/textures/vk_texture.cpp
	common/rendering/vulkan/textures/vk_framebuffer.cpp
)

if (HAVE_GLES2)
	set (GLES_SOURCES
		common/rendering/gles/gles_system.cpp
		common/rendering/gles/gles_renderer.cpp
		common/rendering/gles/gles_framebuffer.cpp
		common/rendering/gles/gles_renderstate.cpp
		common/rendering/gles/gles_renderbuffers.cpp
		common/rendering/gles/gles_postprocess.cpp
		common/rendering/gles/gles_postprocessstate.cpp
		common/rendering/gles/gles_buffers.cpp
		common/rendering/gles/gles_hwtexture.cpp
		common/rendering/gles/gles_shader.cpp
		common/rendering/gles/gles_shaderprogram.cpp
		common/rendering/gles/gles_samplers.cpp
		common/rendering/gles/glad/src/glad.c
	)

	list (APPEND FASTMATH_SOURCES ${GLES_SOURCES})
endif()

if (HAVE_VULKAN)
	list (APPEND FASTMATH_SOURCES ${VULKAN_SOURCES})
endif()

set (FASTMATH_SOURCES ${FASTMATH_SOURCES})

set (PCH_SOURCES
	common/thirdparty/richpresence.cpp
	am_map.cpp
	playsim/bots/b_bot.cpp
	playsim/bots/b_func.cpp
	playsim/bots/b_game.cpp
	playsim/bots/b_move.cpp
	playsim/bots/b_think.cpp
	bbannouncer.cpp
	console/c_cmds.cpp
	console/c_notifybuffer.cpp
	console/c_functions.cpp
	ct_chat.cpp
	d_iwad.cpp
	d_main.cpp
	d_defcvars.cpp
	d_anonstats.cpp
	d_net.cpp
	d_netinfo.cpp
	d_protocol.cpp
	doomstat.cpp
	g_cvars.cpp
	g_dumpinfo.cpp
	g_game.cpp
	g_hub.cpp
	g_level.cpp
	gameconfigfile.cpp
	hu_scores.cpp
	m_cheat.cpp
	m_misc.cpp
	playsim/p_acs.cpp
	playsim/p_actionfunctions.cpp
	p_conversation.cpp
	playsim/p_destructible.cpp
	playsim/p_effect.cpp
	playsim/p_enemy.cpp
	playsim/p_interaction.cpp
	playsim/p_lnspec.cpp
	playsim/p_map.cpp
	playsim/p_maputl.cpp
	playsim/p_mobj.cpp
	p_openmap.cpp
	playsim/p_pspr.cpp
	p_saveg.cpp
	p_setup.cpp
	playsim/p_spec.cpp
	p_states.cpp
	playsim/p_things.cpp
	p_tick.cpp
	playsim/p_user.cpp
	rendering/r_utility.cpp
	rendering/r_sky.cpp
	sound/s_advsound.cpp
	sound/s_sndseq.cpp
	sound/s_doomsound.cpp
	serializer_doom.cpp
	scriptutil.cpp
	st_stuff.cpp
	r_data/v_palette.cpp
	wi_stuff.cpp
	gamedata/a_keys.cpp
	gamedata/a_weapons.cpp
	gamedata/decallib.cpp
	gamedata/g_mapinfo.cpp
	gamedata/g_skill.cpp
	gamedata/gi.cpp
	gamedata/umapinfo.cpp
	gamedata/d_dehacked.cpp
	gamedata/g_doomedmap.cpp
	gamedata/info.cpp
	gamedata/keysections.cpp
	gamedata/p_terrain.cpp
	gamedata/statistics.cpp
	gamedata/teaminfo.cpp
	playsim/mapthinkers/a_decalfx.cpp
	playsim/mapthinkers/a_doors.cpp
	playsim/mapthinkers/a_lightning.cpp
	playsim/mapthinkers/a_quake.cpp
	playsim/mapthinkers/a_ceiling.cpp
	playsim/mapthinkers/a_floor.cpp
	playsim/mapthinkers/a_lights.cpp
	playsim/mapthinkers/a_lighttransfer.cpp
	playsim/mapthinkers/a_pillar.cpp
	playsim/mapthinkers/a_plats.cpp
	playsim/mapthinkers/a_pusher.cpp
	playsim/mapthinkers/a_thruster.cpp
	playsim/mapthinkers/a_scroll.cpp
	playsim/mapthinkers/dsectoreffect.cpp
	playsim/a_pickups.cpp
	playsim/a_action.cpp
	playsim/a_corona.cpp
	playsim/a_decals.cpp
	playsim/a_dynlight.cpp
	playsim/a_flashfader.cpp
	playsim/a_morph.cpp
	playsim/a_specialspot.cpp
	playsim/p_secnodes.cpp
	playsim/p_sectors.cpp
	playsim/p_sight.cpp
	playsim/p_switch.cpp
	playsim/p_tags.cpp
	playsim/p_teleport.cpp
	playsim/actorptrselect.cpp
	playsim/dthinker.cpp
	playsim/p_3dfloors.cpp
	playsim/p_3dmidtex.cpp
	playsim/p_linkedsectors.cpp
	playsim/p_trace.cpp
	playsim/po_man.cpp
	playsim/portal.cpp
	g_statusbar/hudmessages.cpp
	g_statusbar/shared_hud.cpp
	g_statusbar/sbarinfo.cpp
	g_statusbar/sbar_mugshot.cpp
	g_statusbar/shared_sbar.cpp
	rendering/2d/v_blend.cpp
	rendering/hwrenderer/hw_entrypoint.cpp
	rendering/hwrenderer/hw_vertexbuilder.cpp
	rendering/hwrenderer/doom_aabbtree.cpp
	rendering/hwrenderer/doom_levelmesh.cpp
	rendering/hwrenderer/hw_models.cpp
	rendering/hwrenderer/hw_precache.cpp
	rendering/hwrenderer/scene/hw_lighting.cpp
	rendering/hwrenderer/scene/hw_drawlistadd.cpp
	rendering/hwrenderer/scene/hw_setcolor.cpp
	maploader/edata.cpp
	maploader/specials.cpp
	maploader/maploader.cpp
	maploader/slopes.cpp
	maploader/glnodes.cpp
	maploader/udmf.cpp
	maploader/usdf.cpp
	maploader/strifedialogue.cpp
	maploader/polyobjects.cpp
	maploader/renderinfo.cpp
	maploader/compatibility.cpp
	maploader/postprocessor.cpp
	menu/doommenu.cpp
	menu/loadsavemenu.cpp
	menu/playermenu.cpp
	gamedata/textures/animations.cpp
	gamedata/textures/anim_switches.cpp
	gamedata/textures/buildloader.cpp
	gamedata/p_xlat.cpp
	gamedata/xlat/parse_xlat.cpp
	gamedata/xlat/parsecontext.cpp
	playsim/fragglescript/t_func.cpp
	playsim/fragglescript/t_load.cpp
	playsim/fragglescript/t_oper.cpp
	playsim/fragglescript/t_parse.cpp
	playsim/fragglescript/t_prepro.cpp
	playsim/fragglescript/t_script.cpp
	playsim/fragglescript/t_spec.cpp
	playsim/fragglescript/t_variable.cpp
	playsim/fragglescript/t_cmd.cpp
	intermission/intermission.cpp
	intermission/intermission_parse.cpp
	r_data/colormaps.cpp
	r_data/gldefs.cpp
	r_data/a_dynlightdata.cpp
	r_data/r_translate.cpp
	r_data/sprites.cpp
	r_data/portalgroups.cpp
	r_data/voxeldef.cpp
	r_data/r_canvastexture.cpp
	r_data/r_interpolate.cpp
	r_data/r_vanillatrans.cpp
	r_data/r_sections.cpp
	r_data/models.cpp
	scripting/vmiterators.cpp
	scripting/vmthunks.cpp
	scripting/vmthunks_actors.cpp
	scripting/thingdef.cpp
	scripting/thingdef_data.cpp
	scripting/thingdef_properties.cpp
	scripting/backend/codegen_doom.cpp
	scripting/decorate/olddecorations.cpp
	scripting/decorate/thingdef_exp.cpp
	scripting/decorate/thingdef_parse.cpp
	scripting/decorate/thingdef_states.cpp
	scripting/zscript/zcc_compile_doom.cpp
	rendering/swrenderer/textures/r_swtexture.cpp
	rendering/swrenderer/textures/warptexture.cpp
	rendering/swrenderer/textures/swcanvastexture.cpp
	events.cpp
	launcher/launcherwindow.cpp
	launcher/launcherbanner.cpp
	launcher/launcherbuttonbar.cpp
	launcher/playgamepage.cpp
	launcher/settingspage.cpp

	common/audio/sound/i_sound.cpp
	common/audio/sound/oalsound.cpp
	common/audio/sound/s_environment.cpp
	common/audio/sound/s_sound.cpp
	common/audio/sound/s_reverbedit.cpp
	common/audio/music/music_midi_base.cpp
	common/audio/music/music.cpp
	common/audio/music/i_music.cpp
	common/audio/music/i_soundfont.cpp
	common/audio/music/music_config.cpp
	common/2d/v_2ddrawer.cpp
	common/2d/v_drawtext.cpp
	common/2d/v_draw.cpp
	common/2d/wipe.cpp
	common/thirdparty/animlib.cpp
	common/thirdparty/gain_analysis.cpp
	common/thirdparty/sfmt/SFMT.cpp
	common/startscreen/startscreen.cpp
	common/startscreen/startscreen_heretic.cpp
	common/startscreen/startscreen_hexen.cpp
	common/startscreen/startscreen_strife.cpp
	common/startscreen/startscreen_generic.cpp
	common/startscreen/endoom.cpp
	common/widgets/errorwindow.cpp
	common/widgets/netstartwindow.cpp
	common/widgets/widgetresourcedata.cpp
	common/fonts/singlelumpfont.cpp
	common/fonts/singlepicfont.cpp
	common/fonts/specialfont.cpp
	common/fonts/font.cpp
	common/fonts/hexfont.cpp
	common/fonts/v_font.cpp
	common/fonts/v_text.cpp	
	common/textures/hw_ihwtexture.cpp
	common/textures/hw_material.cpp
	common/textures/bitmap.cpp
	common/textures/m_png.cpp
	common/textures/texture.cpp
	common/textures/gametexture.cpp
	common/textures/image.cpp
	common/textures/imagetexture.cpp
	common/textures/texturemanager.cpp
	common/textures/multipatchtexturebuilder.cpp
	common/textures/skyboxtexture.cpp
	common/textures/animtexture.cpp
	common/textures/v_collection.cpp
	common/textures/formats/automaptexture.cpp
	common/textures/formats/brightmaptexture.cpp
	common/textures/formats/buildtexture.cpp
	common/textures/formats/ddstexture.cpp
	common/textures/formats/flattexture.cpp
	common/textures/formats/fontchars.cpp
	common/textures/formats/imgztexture.cpp
	common/textures/formats/md5check.cpp
	common/textures/formats/multipatchtexture.cpp
	common/textures/formats/patchtexture.cpp
	common/textures/formats/pcxtexture.cpp
	common/textures/formats/pngtexture.cpp
	common/textures/formats/rawpagetexture.cpp
	common/textures/formats/startuptexture.cpp
	common/textures/formats/emptytexture.cpp
	common/textures/formats/shadertexture.cpp
	common/textures/formats/tgatexture.cpp
	common/textures/formats/stbtexture.cpp
	common/textures/formats/anmtexture.cpp
	common/textures/formats/startscreentexture.cpp
	common/textures/formats/qoitexture.cpp
	common/textures/formats/webptexture.cpp
	common/textures/hires/hqresize.cpp
	common/models/models_md3.cpp
	common/models/models_md2.cpp
	common/models/models_voxel.cpp
	common/models/models_ue1.cpp
	common/models/models_obj.cpp
	common/models/models_iqm.cpp
	common/models/model.cpp
	common/models/voxels.cpp
	common/console/c_commandline.cpp
	common/console/c_buttons.cpp
	common/console/c_bind.cpp
	common/console/c_enginecmds.cpp
	common/console/c_consolebuffer.cpp
	common/console/c_cvars.cpp
	common/console/c_dispatch.cpp
	common/console/c_commandbuffer.cpp
	common/console/c_console.cpp
	common/console/c_notifybufferbase.cpp
	common/console/c_tabcomplete.cpp
	common/console/c_expr.cpp
	common/cutscenes/playmve.cpp
	common/cutscenes/movieplayer.cpp
	common/cutscenes/screenjob.cpp
	common/utility/engineerrors.cpp
	common/utility/i_module.cpp
	common/utility/gitinfo.cpp
	common/utility/m_alloc.cpp
	common/utility/utf8.cpp
	common/utility/palette.cpp
	common/utility/memarena.cpp
	common/utility/cmdlib.cpp
	common/utility/configfile.cpp
	common/utility/i_time.cpp
	common/utility/m_argv.cpp
	common/utility/s_playlist.cpp
	common/utility/name.cpp
	common/utility/r_memory.cpp
	common/utility/writezip.cpp
	common/thirdparty/base64.cpp
	common/thirdparty/md5.cpp
 	common/thirdparty/superfasthash.cpp
	common/thirdparty/libsmackerdec/src/BitReader.cpp
	common/thirdparty/libsmackerdec/src/FileStream.cpp
	common/thirdparty/libsmackerdec/src/HuffmanVLC.cpp
	common/thirdparty/libsmackerdec/src/LogError.cpp
	common/thirdparty/libsmackerdec/src/SmackerDecoder.cpp
	common/engine/cycler.cpp
	common/engine/d_event.cpp
	common/engine/date.cpp
	common/engine/stats.cpp
	common/engine/sc_man.cpp
	common/engine/palettecontainer.cpp
	common/engine/stringtable.cpp
	common/engine/i_net.cpp
	common/engine/i_interface.cpp
	common/engine/renderstyle.cpp
	common/engine/v_colortables.cpp
	common/engine/serializer.cpp
	common/engine/m_joy.cpp
	common/engine/m_random.cpp
	common/objects/autosegs.cpp
	common/objects/dobject.cpp
	common/objects/dobjgc.cpp
	common/objects/dobjtype.cpp
	common/menu/joystickmenu.cpp
	common/menu/menu.cpp
	common/menu/messagebox.cpp
	common/menu/optionmenu.cpp
	common/menu/resolutionmenu.cpp
	common/menu/menudef.cpp
	common/menu/savegamemanager.cpp
	common/statusbar/base_sbar.cpp
	
	common/rendering/v_framebuffer.cpp
	common/rendering/v_video.cpp
	common/rendering/r_thread.cpp
	common/rendering/r_videoscale.cpp
	common/rendering/hwrenderer/hw_draw2d.cpp
	common/rendering/hwrenderer/data/hw_clock.cpp
	common/rendering/hwrenderer/data/hw_skydome.cpp
	common/rendering/hwrenderer/data/flatvertices.cpp
	common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp
	common/rendering/hwrenderer/data/hw_modelvertexbuffer.cpp
	common/rendering/hwrenderer/data/hw_cvars.cpp
	common/rendering/hwrenderer/data/hw_vrmodes.cpp
	common/rendering/hwrenderer/data/hw_lightbuffer.cpp
	common/rendering/hwrenderer/data/hw_bonebuffer.cpp
	common/rendering/hwrenderer/data/hw_aabbtree.cpp
	common/rendering/hwrenderer/data/hw_shadowmap.cpp
	common/rendering/hwrenderer/data/hw_shaderpatcher.cpp
	common/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp
	common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp
	common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp
	common/rendering/hwrenderer/postprocessing/hw_postprocessshader_ccmds.cpp
	common/rendering/gl_load/gl_interface.cpp
	common/rendering/gl/gl_renderer.cpp
	common/rendering/gl/gl_stereo3d.cpp
	common/rendering/gl/gl_framebuffer.cpp
	common/rendering/gl/gl_renderstate.cpp
	common/rendering/gl/gl_renderbuffers.cpp
	common/rendering/gl/gl_postprocess.cpp
	common/rendering/gl/gl_postprocessstate.cpp
	common/rendering/gl/gl_debug.cpp
	common/rendering/gl/gl_buffers.cpp
	common/rendering/gl/gl_hwtexture.cpp
	common/rendering/gl/gl_samplers.cpp
	common/rendering/gl/gl_shader.cpp
	common/rendering/gl/gl_shaderprogram.cpp
	common/scripting/core/maps.cpp
	common/scripting/core/dictionary.cpp
	common/scripting/core/dynarrays.cpp
	common/scripting/core/symbols.cpp
	common/scripting/core/types.cpp
	common/scripting/core/scopebarrier.cpp
	common/scripting/core/vmdisasm.cpp
	common/scripting/core/imports.cpp
	common/scripting/vm/vmexec.cpp
	common/scripting/vm/vmframe.cpp
	common/scripting/interface/stringformat.cpp
	common/scripting/interface/vmnatives.cpp
	common/scripting/frontend/ast.cpp
	common/scripting/frontend/zcc_compile.cpp
	common/scripting/frontend/zcc_parser.cpp
	common/scripting/backend/vmbuilder.cpp
	common/scripting/backend/codegen.cpp
	
	utility/nodebuilder/nodebuild.cpp
	utility/nodebuilder/nodebuild_classify_nosse2.cpp
	utility/nodebuilder/nodebuild_events.cpp
	utility/nodebuilder/nodebuild_extract.cpp
	utility/nodebuilder/nodebuild_gl.cpp
	utility/nodebuilder/nodebuild_utility.cpp
)

if( ${HAVE_VM_JIT} )
	set( PCH_SOURCES ${PCH_SOURCES} ${VM_JIT_SOURCES} )
else()
	set( NOT_COMPILED_SOURCE_FILES ${NOT_COMPILED_SOURCE_FILES} ${VM_JIT_SOURCES} )
endif()

set( GAME_SOURCES
	${HEADER_FILES}
	${NOT_COMPILED_SOURCE_FILES}
	${SYSTEM_SOURCES}
	${FASTMATH_SOURCES}
	${PCH_SOURCES}
	common/utility/x86.cpp
	common/thirdparty/strnatcmp.c
	common/thirdparty/utf8proc/utf8proc.c
	common/thirdparty/stb/stb_sprintf.c
	common/utility/zstring.cpp
	common/utility/findfile.cpp
	common/thirdparty/math/asin.c
	common/thirdparty/math/atan.c
	common/thirdparty/math/const.c
	common/thirdparty/math/cosh.c
	common/thirdparty/math/exp.c
	common/thirdparty/math/isnan.c
	common/thirdparty/math/log.c
	common/thirdparty/math/log10.c
	common/thirdparty/math/mtherr.c
	common/thirdparty/math/polevl.c
	common/thirdparty/math/pow.c
	common/thirdparty/math/powi.c
	common/thirdparty/math/sin.c
	common/thirdparty/math/sinh.c
	common/thirdparty/math/sqrt.c
	common/thirdparty/math/tan.c
	common/thirdparty/math/tanh.c
	common/thirdparty/math/fastsin.cpp

	common/filesystem/source/filesystem.cpp
	common/filesystem/source/ancientzip.cpp
	common/filesystem/source/file_7z.cpp
	common/filesystem/source/file_grp.cpp
	common/filesystem/source/file_lump.cpp
	common/filesystem/source/file_rff.cpp
	common/filesystem/source/file_wad.cpp
	common/filesystem/source/file_zip.cpp
	common/filesystem/source/file_pak.cpp
	common/filesystem/source/file_whres.cpp
	common/filesystem/source/file_ssi.cpp
	common/filesystem/source/file_hog.cpp
	common/filesystem/source/file_mvl.cpp
	common/filesystem/source/file_directory.cpp
	common/filesystem/source/resourcefile.cpp
	common/filesystem/source/files.cpp
	common/filesystem/source/files_decompress.cpp
	common/filesystem/source/fs_findfile.cpp
	common/filesystem/source/fs_stringpool.cpp
	common/filesystem/source/unicode.cpp
	common/filesystem/source/critsec.cpp

)

set( GAME_NONPCH_SOURCES ${GAME_SOURCES} )
list( REMOVE_ITEM GAME_NONPCH_SOURCES ${PCH_SOURCES} )

add_executable( zdoom WIN32 MACOSX_BUNDLE ${GAME_SOURCES} )

target_precompile_headers( zdoom PRIVATE g_pch.h )

set_source_files_properties( ${FASTMATH_SOURCES} PROPERTIES COMPILE_FLAGS ${ZD_FASTMATH_FLAG} )
set_source_files_properties( xlat/parse_xlat.cpp PROPERTIES OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/xlat_parser.c" )
set_source_files_properties( common/engine/sc_man.cpp PROPERTIES OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/sc_man_scanner.h" )
set_source_files_properties( ${NOT_COMPILED_SOURCE_FILES} PROPERTIES HEADER_FILE_ONLY TRUE )
set_source_files_properties( ${GAME_NONPCH_SOURCES} common/textures/hires/hqresize.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE )


if(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS")
	# [BL] Solaris requires these to be explicitly linked.
	set( PROJECT_LIBRARIES ${PROJECT_LIBRARIES} nsl socket)
endif()

if( UNIX )
	find_package( Backtrace )
	if(Backtrace_FOUND)
		set( PROJECT_LIBRARIES ${PROJECT_LIBRARIES} ${Backtrace_LIBRARIES} )
	endif()
endif()

target_link_libraries( zdoom ${PROJECT_LIBRARIES} lzma ${ZMUSIC_LIBRARIES} )

include_directories(
	BEFORE
	.
	common/audio/sound
	common/audio/music
	common/2d
	common/cutscenes
	common/thirdparty/libsmackerdec/include
	common/thirdparty
	common/thirdparty/stb
	common/thirdparty/utf8proc
	common/textures
	common/textures/formats
	common/textures/hires
	common/textures
	common/models
	common/filesystem/include
	common/utility
	common/console
	common/engine
	common/menu
	common/statusbar
	common/fonts
	common/objects
	common/startscreen
	common/widgets
	common/rendering
	common/rendering/hwrenderer/data
	common/rendering/gl_load
	common/rendering/gl
	common/rendering/gles
	common/rendering/gles/glad/include
	common/rendering/gles/Mali_OpenGL_ES_Emulator/include
	common/scripting/vm
	common/scripting/jit
	common/scripting/core
	common/scripting/interface
	common/scripting/frontend
	common/scripting/backend
	g_statusbar
	console
	playsim
	playsim/bots
	playsim/mapthinkers
	gamedata
	gamedata/textures
	gamedata/fonts
	rendering
	rendering/hwrenderer
	rendering/2d
	r_data
	sound
	menu
	sound/backend
	xlat
	utility
	utility/nodebuilder
	scripting
	scripting/zscript
	rendering
	launcher
	../libraries/ZVulkan/include
	../libraries/ZWidget/include
	../libraries/webp/include
	${SYSTEM_SOURCES_DIR}
)

add_dependencies( zdoom revision_check )

# Due to some quirks, we need to do this in this order
if( NOT ZDOOM_OUTPUT_OLDSTYLE )
	# RUNTIME_OUTPUT_DIRECTORY does not exist in CMake 2.4.
	# Linux distributions are slow to adopt 2.6. :(
	set_target_properties( zdoom PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ZDOOM_OUTPUT_DIR} )
	set_target_properties( zdoom PROPERTIES OUTPUT_NAME ${ZDOOM_EXE_NAME} )
else()
	set_target_properties( zdoom PROPERTIES
		RUNTIME_OUTPUT_NAME ${ZDOOM_EXE_NAME}
		RUNTIME_OUTPUT_DIRECTORY_RELEASE ${ZDOOM_OUTPUT_DIR}
		RUNTIME_OUTPUT_NAME_DEBUG ${ZDOOM_EXE_NAME}d
		RUNTIME_OUTPUT_DIRECTORY_DEBUG ${ZDOOM_OUTPUT_DIR}
		RUNTIME_OUTPUT_NAME_MINSIZEREL ${ZDOOM_EXE_NAME}msr
		RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${ZDOOM_OUTPUT_DIR}
		RUNTIME_OUTPUT_NAME_RELWITHDEBINFO ${ZDOOM_EXE_NAME}rd
		RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${ZDOOM_OUTPUT_DIR}
	)
endif()

if( MSVC )
	option( ZDOOM_GENERATE_MAPFILE "Generate .map file for debugging." OFF )
	set( LINKERSTUFF "/MANIFEST:NO" )

	if( ZDOOM_GENERATE_MAPFILE )
		set( LINKERSTUFF "${LINKERSTUFF} /MAP" )
	endif()
	set_target_properties(zdoom PROPERTIES LINK_FLAGS ${LINKERSTUFF})

	add_custom_command(TARGET zdoom POST_BUILD
		COMMAND "mt.exe" -manifest \"${CMAKE_CURRENT_SOURCE_DIR}\\common\\platform\\win32\\manifest.xml\" -outputresource:\"$<TARGET_FILE:zdoom>\"\;\#1
		COMMENT "Adding manifest..."
	)

endif()

if( NOT WIN32 AND NOT APPLE )
	FILE( WRITE ${CMAKE_CURRENT_BINARY_DIR}/link-make "if [ ! -e ${ZDOOM_OUTPUT_DIR}/${ZDOOM_EXE_NAME} ]; then ln -sf ${CMAKE_CURRENT_BINARY_DIR}/${ZDOOM_EXE_NAME} ${ZDOOM_OUTPUT_DIR}/${ZDOOM_EXE_NAME}; fi" )
	add_custom_command( TARGET zdoom POST_BUILD
		COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/link-make
		COMMAND ${CMAKE_CURRENT_BINARY_DIR}/link-make )
	IF ("${INSTALL_RPATH}" STREQUAL "")
		set_target_properties(zdoom PROPERTIES
			#allow libzmusic.so.1 library in same folder as executable at runtime
			INSTALL_RPATH "\$ORIGIN:\$ORIGIN/zmusic/build/source"
			BUILD_WITH_INSTALL_RPATH ON
		)
	endif()
endif()

add_custom_command(TARGET zdoom POST_BUILD
	COMMAND ${CMAKE_COMMAND} -E copy_if_different
	${CMAKE_SOURCE_DIR}/soundfont/gzdoom.sf2 $<TARGET_FILE_DIR:zdoom>/soundfonts/gzdoom.sf2
	COMMAND ${CMAKE_COMMAND} -E copy_if_different
	${CMAKE_SOURCE_DIR}/fm_banks/GENMIDI.GS.wopl $<TARGET_FILE_DIR:zdoom>/fm_banks/GENMIDI.GS.wopl
	COMMAND ${CMAKE_COMMAND} -E copy_if_different
	${CMAKE_SOURCE_DIR}/fm_banks/gs-by-papiezak-and-sneakernets.wopn $<TARGET_FILE_DIR:zdoom>/fm_banks/gs-by-papiezak-and-sneakernets.wopn
)

if (VCPKG_TOOLCHAIN)
	x_vcpkg_install_local_dependencies(TARGETS zdoom DESTINATION ".")
endif()

if( WIN32 )
	set( INSTALL_SOUNDFONT_PATH . CACHE STRING "Directory where soundfonts and WOPL/WOPN banks will be placed during install." )
else()
	set( INSTALL_SOUNDFONT_PATH share/games/doom CACHE STRING "Directory where soundfonts and WOPL/WOPN banks will be placed during install." )
endif()
install(DIRECTORY "${PROJECT_BINARY_DIR}/soundfonts" "${PROJECT_BINARY_DIR}/fm_banks"
		DESTINATION ${INSTALL_SOUNDFONT_PATH}
		COMPONENT "Soundfont resources")

if( DEM_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE )
	# Need to enable intrinsics for these files.
	set_property( SOURCE
		common/utility/palette.cpp
		common/utility/x86.cpp
		rendering/swrenderer/r_all.cpp
		APPEND_STRING PROPERTY COMPILE_FLAGS " ${SSE2_ENABLE}" )
endif()

if( APPLE )
	set( LINK_FRAMEWORKS "-framework Cocoa -framework IOKit -framework OpenGL")

	if( HAVE_VULKAN )
		set( LINK_FRAMEWORKS "${LINK_FRAMEWORKS} -framework QuartzCore" )
	endif()

	set_target_properties(zdoom PROPERTIES
		LINK_FLAGS "${LINK_FRAMEWORKS}"
		MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/posix/osx/zdoom-info.plist"
		XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "org.drdteam.gzdoom"
		XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "" )

	# Dymanic libraries like libvulkan.dylib or libMoltenVK.dylib will be loaded by dlopen()
	# if placed in the directory with the main executable
	set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rpath @executable_path" )
endif()

if( WIN32 )
	set( INSTALL_PATH . CACHE STRING "Directory where the executable will be placed during install." )
else()
	set( INSTALL_PATH bin CACHE STRING "Directory where the executable will be placed during install." )
endif()
install(TARGETS zdoom
		DESTINATION ${INSTALL_PATH}
		COMPONENT "Game executable")

source_group("Audio Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/sound/.+")
source_group("Game Data" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/gamedata/.+")
source_group("Game Data\\Fonts" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/gamedata/fonts/.+")
source_group("Intermission" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/intermission/.+")
source_group("Map Loader" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/maploader/.+")
source_group("Menu" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/menu/.+")
source_group("Console" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/console/.+")
source_group("Playsim" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/playsim/.+")
source_group("Playsim\\Bots" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/playsim/bots/.+")
source_group("Playsim\\FraggleScript" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/playsim/fragglescript/.+")
source_group("Playsim\\Map Thinkers" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/playsim/mapthinkers/.+")
source_group("Rendering" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/.+")
source_group("Rendering\\2D" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/2d/.+")
source_group("Rendering\\Hardware Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/gl/.+")
source_group("Rendering\\Hardware Renderer\\Scene" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/hwrenderer/scene/.+")
source_group("Rendering\\Software Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/.+")
source_group("Rendering\\Software Renderer\\Drawers" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/drawers/.+")
source_group("Rendering\\Software Renderer\\Scene" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/scene/.+")
source_group("Rendering\\Software Renderer\\Segments" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/segments/.+")
source_group("Rendering\\Software Renderer\\Line" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/line/.+")
source_group("Rendering\\Software Renderer\\Plane" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/plane/.+")
source_group("Rendering\\Software Renderer\\Things" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/things/.+")
source_group("Rendering\\Software Renderer\\Viewport" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/viewport/.+")
source_group("Render Data" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/r_data/.+")
source_group("Render Interface" FILES r_defs.h r_renderer.h r_sky.cpp r_sky.h r_state.h r_utility.cpp r_utility.h)
source_group("Platforms\\POSIX Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/posix/.+")
source_group("Platforms\\Win32 Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/win32/.+")
source_group("Scripting\\Decorate frontend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/decorate/.+")
source_group("Scripting\\ZScript frontend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/zscript/.+")
source_group("Scripting\\Compiler backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/backend/.+")
source_group("Scripting" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/.+")
source_group("Common" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/.+")
source_group("Common\\Audio" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/audio/.+")
source_group("Common\\Audio\\Sound" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/audio/sound/.+")
source_group("Common\\Audio\\Sound\\Third-party" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/audio/sound/thirdparty/.+")
source_group("Common\\Audio\\Music" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/audio/music.+")
source_group("Common\\Console" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/console/.+")
source_group("Common\\Utility" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/utility/.+")
source_group("Common\\Engine" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/engine/.+")
source_group("Common\\2D" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/2d/.+")
source_group("Common\\Cutscenes" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/cutscenes/.+")
source_group("Common\\Objects" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/objects/.+")
source_group("Common\\Menu" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/menu/.+")
source_group("Common\\Fonts" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/fonts/.+")
source_group("Common\\File System" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/filesystem/.+")
source_group("Common\\File System\\Include" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/filesystem/include/.+")
source_group("Common\\File System\\Source" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/filesystem/source/.+")
source_group("Common\\Startscreen" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/startscreen/.+")
source_group("Common\\Widgets" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/widgets/.+")
source_group("Common\\Scripting" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/.+")
source_group("Common\\Scripting\\Interface" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/interface/.+")
source_group("Common\\Scripting\\Frontend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/frontend/.+" FILES ${CMAKE_CURRENT_BINARY_DIR}/zcc-parse.c ${CMAKE_CURRENT_BINARY_DIR}/zcc-parse.h)
source_group("Common\\Scripting\\Backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/backend/.+")
source_group("Common\\Scripting\\Core" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/core/.+")
source_group("Common\\Scripting\\JIT" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/jit/.+")
source_group("Common\\Scripting\\VM" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/vm/.+")
source_group("Common\\Platforms\\Cocoa Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/posix/cocoa/.+")
source_group("Common\\Platforms\\OS X Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/posix/osx/.+")
source_group("Common\\Platforms\\Unix Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/posix/unix/.+")
source_group("Common\\Platforms\\SDL Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/posix/sdl/.+")
source_group("Common\\Platforms\\Win32 Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/win32/.+")
source_group("Common\\Rendering" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/.+")
source_group("Common\\Rendering\\Hardware Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/hwrenderer/.+")
source_group("Common\\Rendering\\Hardware Renderer\\Data" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/hwrenderer/data/.+")
source_group("Common\\Rendering\\Hardware Renderer\\Postprocessing" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/hwrenderer/postprocessing/.+")
source_group("Common\\Rendering\\OpenGL Loader" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/gl_load/.+")
source_group("Common\\Rendering\\OpenGL Backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/gl/.+")
source_group("Common\\Rendering\\GLES Backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/gles/.+")
source_group("Common\\Rendering\\Vulkan Renderer\\System" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/vulkan/system/.+")
source_group("Common\\Rendering\\Vulkan Renderer\\Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/vulkan/renderer/.+")
source_group("Common\\Rendering\\Vulkan Renderer\\Shaders" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/vulkan/shaders/.+")
source_group("Common\\Rendering\\Vulkan Renderer\\Textures" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/vulkan/textures/.+")
source_group("Common\\Models" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/models/.+")
source_group("Common\\Textures" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/.+")
source_group("Common\\Textures\\Hires" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/hires/.+")
source_group("Common\\Textures\\Hires\\HQ Resize" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/hires/hqnx/.+")
source_group("Common\\Textures\\Hires\\HQ Resize MMX version" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/hires/hqnx_asm/.+")
source_group("Common\\Textures\\Hires\\XBRZ" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/hires/xbr/.+")
source_group("Common\\Textures\\Formats" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/formats/.+")
source_group("Common\\Third Party" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/thirdparty/.+")
source_group("Common\\Third Party\\Math" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/thirdparty/math/.+")
source_group("Common\\Third Party\\RapidJSON" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/thirdparty/rapidjson/.+")
source_group("Common\\Third Party\\SFMT" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/thirdparty/sfmt/.+")
source_group("Common\\Third Party\\stb" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/thirdparty/stb/.+")
source_group("Common\\Third Party\\utf8proc" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/thirdparty/utf8proc/.+")
source_group("Utility" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/utility/.+")
source_group("Utility\\Node Builder" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/utility/nodebuilder/.+")
source_group("Utility\\Smackerdec" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/smackerdec/.+")
source_group("Utility\\Smackerdec\\Headers" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/libsmackerdec/include/.+")
source_group("Utility\\Smackerdec\\Sources" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/libsmackerdec/src/.+")
source_group("Statusbar" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/g_statusbar/.+")
source_group("Launcher" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/launcher/.+")
source_group("Versioning" FILES version.h win32/zdoom.rc)
source_group("Xlat" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/xlat/.+" FILES ${CMAKE_CURRENT_BINARY_DIR}/xlat_parser.c ${CMAKE_CURRENT_BINARY_DIR}/xlat_parser.h)
source_group("Source Files" FILES ${CMAKE_CURRENT_BINARY_DIR}/sc_man_scanner.h common/engine/sc_man_scanner.re)
