# 'winssr' executable

set(CMAKE_AUTOMOC ON)

find_package(Threads REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(AVFormat REQUIRED)
find_package(AVCodec REQUIRED)
find_package(AVUtil REQUIRED)
find_package(SWScale REQUIRED)

if(WITH_TRANSLATIONS)
	find_package(Qt6 6.2 COMPONENTS Core Gui Widgets REQUIRED)
else()
	find_package(Qt6 6.2 COMPONENTS Core Gui Widgets REQUIRED)
endif()

set(sources
AV/Input/AudioMixer.cpp
AV/Input/AudioMixer.h
AV/Input/WindowsInput.cpp
AV/Input/WindowsInput.h
AV/Input/WASAPIInput.cpp
AV/Input/WASAPIInput.h
	AV/Output/AudioEncoder.cpp
	AV/Output/AudioEncoder.h
	AV/Output/BaseEncoder.cpp
	AV/Output/BaseEncoder.h
	AV/Output/Muxer.cpp
	AV/Output/Muxer.h
	AV/Output/OutputManager.cpp
	AV/Output/OutputManager.h
	AV/Output/OutputSettings.h
	AV/Output/SyncDiagram.cpp
	AV/Output/SyncDiagram.h
	AV/Output/Synchronizer.cpp
	AV/Output/Synchronizer.h
	AV/Output/VideoEncoder.cpp
	AV/Output/VideoEncoder.h
	AV/Output/X264Presets.cpp
	AV/Output/X264Presets.h
	AV/AVWrapper.cpp
	AV/AVWrapper.h
	AV/FastResampler.cpp
	AV/FastResampler.h
	AV/FastResampler_FirFilter.h
	AV/FastResampler_FirFilter_Fallback.cpp
	AV/FastScaler.cpp
	AV/FastScaler.h
	AV/FastScaler_Convert.h
	AV/FastScaler_Convert_Fallback.cpp
	AV/FastScaler_Scale.h
	AV/FastScaler_Scale_Fallback.cpp
	AV/FastScaler_Scale_Generic.cpp
	AV/FastScaler_Scale_Generic.h
	AV/SampleCast.h
	AV/SourceSink.cpp
	AV/SourceSink.h
	common/CommandLineOptions.cpp
	common/CommandLineOptions.h
	common/CPUFeatures.cpp
	common/CPUFeatures.h
	common/Dialogs.cpp
	common/Dialogs.h
	common/EnumStrings.h
	common/LockFreeMessageQueue.h
	common/Logger.cpp
	common/Logger.h
	common/MutexDataPair.h
	common/QueueBuffer.h
	common/ScreenScaling.cpp
	common/ScreenScaling.h
	common/TempBuffer.h
	GUI/AudioPreviewer.cpp
	GUI/AudioPreviewer.h
	GUI/DialogRecordSchedule.cpp
	GUI/DialogRecordSchedule.h
	GUI/ElidedLabel.cpp
	GUI/ElidedLabel.h
	GUI/HiddenScrollArea.cpp
	GUI/HiddenScrollArea.h
	GUI/HotkeyListener.h
	GUI/HotkeyListener.cpp
	GUI/Icons.cpp
	GUI/Icons.h
	GUI/MainWindow.cpp
	GUI/MainWindow.h
	GUI/PageDone.cpp
	GUI/PageDone.h
	GUI/PageInput.cpp
	GUI/PageInput.h
	GUI/PageOutput.cpp
	GUI/PageOutput.h
	GUI/PageRecord.cpp
	GUI/PageRecord.h
	GUI/PageWelcome.cpp
	GUI/PageWelcome.h
	GUI/ProfileBox.cpp
	GUI/ProfileBox.h
	GUI/VideoPreviewer.cpp
	GUI/VideoPreviewer.h
	GUI/WidgetRack.cpp
	GUI/WidgetRack.h
	Benchmark.cpp
	Benchmark.h
	Global.h
	Main.cpp
)

if(ENABLE_X86_ASM)

	list(APPEND sources
		AV/FastResampler_FirFilter_SSE2.cpp
		AV/FastScaler_Convert_SSSE3.cpp
		AV/FastScaler_Scale_SSSE3.cpp
	)

	set_source_files_properties(
		AV/FastResampler_FirFilter_SSE2.cpp
		PROPERTIES COMPILE_OPTIONS "-msse2"
	)

	set_source_files_properties(
		AV/FastScaler_Convert_SSSE3.cpp
		AV/FastScaler_Scale_SSSE3.cpp
		PROPERTIES COMPILE_OPTIONS "-mssse3"
	)

endif()

set(res_input
	../data/resources/resources.qrc
)

qt6_add_resources(res_output ${res_input})
set(QT_LIBS
	Qt6::Core
	Qt6::Gui
	Qt6::Widgets
)

set_property(SOURCE ${res_output} PROPERTY SKIP_AUTOMOC ON)

string(REPLACE "\\" "/" WINSSR_ICON_PATH "${CMAKE_SOURCE_DIR}/data/icons/winssr.ico")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/winssr.rc.in ${CMAKE_CURRENT_BINARY_DIR}/winssr.rc @ONLY)

add_executable(winssr WIN32
	${sources}
	${res_output}
	${CMAKE_CURRENT_BINARY_DIR}/winssr.rc
)

target_include_directories(winssr PRIVATE
	${AVFORMAT_INCLUDE_DIRS}
	${AVCODEC_INCLUDE_DIRS}
	${AVUTIL_INCLUDE_DIRS}
	${SWSCALE_INCLUDE_DIRS}
	${CMAKE_CURRENT_SOURCE_DIR}
	${CMAKE_CURRENT_SOURCE_DIR}/AV
	${CMAKE_CURRENT_SOURCE_DIR}/AV/Input
	${CMAKE_CURRENT_SOURCE_DIR}/AV/Output
	${CMAKE_CURRENT_SOURCE_DIR}/common
	${CMAKE_CURRENT_SOURCE_DIR}/GUI
)

target_link_libraries(winssr PRIVATE
	${AVFORMAT_LIBRARIES}
	${AVCODEC_LIBRARIES}
	${AVUTIL_LIBRARIES}
	${SWSCALE_LIBRARIES}
	${QT_LIBS}
	${CMAKE_THREAD_LIBS_INIT}
	d3d11
	dxgi
	dxguid
	gdi32
	user32
	ole32
	uuid
	avrt
)

target_compile_definitions(winssr PRIVATE
	SSR_USE_X86_ASM=$<BOOL:${ENABLE_X86_ASM}>
	SSR_USE_FFMPEG_VERSIONS=$<BOOL:${ENABLE_FFMPEG_VERSIONS}>
	SSR_VERSION="${PROJECT_VERSION}"
	UNICODE
	_UNICODE
	NOMINMAX
	WIN32_LEAN_AND_MEAN
)

install(TARGETS winssr RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
