include(GenerateExportHeader)

if(MSVC)
	add_definitions(-DMGL_LIB_MSVC -DMGL_WIDGETS_DLL)
endif(MSVC)

set(MGL_WND_SRC)
set(MGL_WND_INC)
set(MGL_WND_LIB)

if(QT_ENABLED)
        add_subdirectory( qt5 )
        add_subdirectory( qt6 )
        add_subdirectory( qt4 )

        if(TARGET mgl-qt)
                get_target_property(mgl_qt_major mgl-qt mgl_qt_major)
                get_target_property(mgl_qt_version mgl-qt mgl_qt_version)
                get_target_property(mgl_qt_components mgl-qt mgl_qt_components)
                get_target_property(mgl_qt_components_wk mgl-qt mgl_qt_components_wk)
                get_target_property(mgl_qt_components_we mgl-qt mgl_qt_components_we)
                set(mgl_qt_major ${mgl_qt_major} PARENT_SCOPE)
                set(mgl_qt_version ${mgl_qt_version} PARENT_SCOPE)
                set(mgl_qt_components ${mgl_qt_components} PARENT_SCOPE)
                set(mgl_qt_components_wk ${mgl_qt_components_wk} PARENT_SCOPE)
                set(mgl_qt_components_we ${mgl_qt_components_we} PARENT_SCOPE)
        else(TARGET mgl-qt)
                message(SEND_ERROR "No Qt of any version found!")
        endif(TARGET mgl-qt)
endif(QT_ENABLED)


if(MGL_HAVE_FLTK)
	set(MGL_FLTK_SRC fltk.cpp  image.cpp  image.h ../include/mgl2/fltk.h ../include/mgl2/Fl_MathGL.h)
	list(APPEND MGL_WND_SRC ${MGL_FLTK_SRC})
	list(APPEND MGL_WND_INC ${FLTK_INCLUDE_DIR})
	list(APPEND MGL_WND_LIB ${FLTK_LIBRARIES})
	mgl_add_lib(fltk ${MGL_FLTK_SRC})
	target_include_directories(mgl-fltk SYSTEM PUBLIC ${FLTK_INCLUDE_DIR})
	target_include_directories(mgl-fltk-static SYSTEM PUBLIC ${FLTK_INCLUDE_DIR})
	target_link_libraries(mgl-fltk mgl ${FLTK_LIBRARIES})
	target_link_libraries(mgl-fltk-static mgl-static ${FLTK_LIBRARIES})
endif(MGL_HAVE_FLTK)

if(MGL_HAVE_GLUT)
	mgl_add_lib(glut glut.cpp ../include/mgl2/glut.h)
	target_include_directories(mgl-glut SYSTEM PUBLIC ${GLUT_INCLUDE_DIR})
	target_include_directories(mgl-glut-static SYSTEM PUBLIC ${GLUT_INCLUDE_DIR})
	target_link_libraries(mgl-glut mgl ${GLUT_LIBRARIES} ${OPENGL_LIBRARIES})
	target_link_libraries(mgl-glut-static mgl-static ${GLUT_LIBRARIES} ${OPENGL_LIBRARIES})
endif(MGL_HAVE_GLUT)

if(MGL_HAVE_WX)
	set(MGL_WX_SRC wx.cpp ../include/mgl2/wx.h)
	list(APPEND MGL_WND_SRC ${MGL_WX_SRC})
	list(APPEND MGL_WND_LIB ${wxWidgets_LIBRARIES})
	mgl_add_lib(wx ${MGL_WX_SRC})
	include(${wxWidgets_USE_FILE})
	target_link_libraries(mgl-wx mgl ${wxWidgets_LIBRARIES})
	target_link_libraries(mgl-wx-static mgl-static ${wxWidgets_LIBRARIES})
endif(MGL_HAVE_WX)

if(MGL_HAVE_FLTK OR MGL_HAVE_WX OR TARGET mgl-qt)
	if(TARGET mgl-qt)
                include(../scripts/qt.cmake)
                if(MGL_HAVE_WX)
            		include(${wxWidgets_USE_FILE})
                endif(MGL_HAVE_WX)
                find_qt_libs(${mgl_qt_major} ${mgl_qt_version} ON ON ${mgl_qt_components})
                mgl_add_lib(wnd ${MGL_QT_FILES} ${MGL_WND_SRC})
                target_include_directories(mgl-wnd SYSTEM PUBLIC ${MGL_WND_INC})
                target_include_directories(mgl-wnd-static SYSTEM PUBLIC ${MGL_WND_INC})
                target_link_libraries(mgl-wnd mgl ${MGL_WND_LIB} ${MGL_QT_LIBS})
                target_link_libraries(mgl-wnd-static mgl-static ${MGL_WND_LIB} ${MGL_QT_LIBS})
	else(TARGET mgl-qt)
                if(MGL_HAVE_WX)
            		include(${wxWidgets_USE_FILE})
                endif(MGL_HAVE_WX)
                mgl_add_lib(wnd ${MGL_WND_SRC})
                target_include_directories(mgl-wnd SYSTEM PUBLIC ${MGL_WND_INC})
                target_include_directories(mgl-wnd-static SYSTEM PUBLIC ${MGL_WND_INC})
                target_link_libraries(mgl-wnd mgl ${MGL_WND_LIB})
                target_link_libraries(mgl-wnd-static mgl-static ${MGL_WND_LIB})
	endif(TARGET mgl-qt)
endif(MGL_HAVE_FLTK OR MGL_HAVE_WX OR TARGET mgl-qt)


mgl_po_src(fltk.cpp ../include/mgl2/fltk.h ../include/mgl2/Fl_MathGL.h glut.cpp ../include/mgl2/glut.h wx.cpp ../include/mgl2/wx.h qt.cpp ../include/mgl2/qt.h  ../include/mgl2/qmathgl.h)
