include(../scripts/qt.cmake)

find_qt_libs(${mgl_qt_major} ${mgl_qt_version} OFF ON ${mgl_qt_components})
set(mgl_json_libs ${MGL_QT_LIBS})

find_qt_libs(${mgl_qt_major} ${mgl_qt_version} OFF ON ${mgl_qt_components_wk})
if(MGL_HAVE_QT)
	list(APPEND mgl_json_libs ${MGL_QT_LIBS})
else(MGL_HAVE_QT)
	message("Couldn't find Qt${mgl_qt_major} WebKitWidgets or Network library. JSON sample disabled.")
	set(enable-json-sample OFF CACHE BOOL "Enable JSON sample (WebKit variant is the default)." FORCE)
endif(MGL_HAVE_QT)

if(enable-json-sample)
	find_qt_libs(${mgl_qt_major} ${mgl_qt_version} OFF ON ${mgl_qt_components_we})
	if(MGL_HAVE_QT)
		list(APPEND mgl_json_libs ${MGL_QT_LIBS})
		set(enable-json-sample-we ON CACHE BOOL "Enable JSON sample (WebEngine variant)." FORCE)
		set(mgl_qt_def MGL_USE_QT5_WE)
	else(MGL_HAVE_QT)
		message("Couldn't find Qt${mgl_qt_major} WebEngineWidgets. Disabling...")
		set(enable-json-sample-we OFF CACHE BOOL "Enable JSON sample (WebEngine variant)." FORCE)
	endif(MGL_HAVE_QT)

	set(json_src Backend.cpp MainWindow.cpp MainWindow.ui)
	set(json_moc_hdr Backend.hpp MainWindow.hpp)
	include_directories(${MathGL2_BINARY_DIR}/json)

	if(DEFINED mgl_qt_def)
		add_executable(MglForJsTestBench ${json_src} ${json_moc_hdr})
		target_link_libraries(MglForJsTestBench mgl-qt ${mgl_json_libs})
		target_compile_definitions(MglForJsTestBench PUBLIC MGL_USE_QT${mgl_qt_major} ${mgl_qt_def})
	endif(DEFINED mgl_qt_def)
endif(enable-json-sample)
