cmake_minimum_required(VERSION 3.0)
project(qglview)
if (IBPROJECT)
	include(SDKMacros)
else()
	option(LIB "System install" 0)
	option(DEBUG "Build with -g3" 0)
	option(DESIGNER_PLUGINS "Build qt designer plugins" 1)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall")
	if (DEBUG)
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
	endif()
endif()
if (MINGW)
	find_package(MinGW REQUIRED)
endif()
find_package(QAD REQUIRED)
find_package(OpenGL REQUIRED)
include_directories(${QAD_INCLUDES})
find_qt(${QtVersions} Core Gui OpenGL Xml)
qt_sources(SRC)
qt_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM)
qt_add_library(${PROJECT_NAME} SHARED out_CPP)
qt_target_link_libraries(${PROJECT_NAME} qad_utils qad_widgets ${OPENGL_LIBRARIES})
qt_target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "Building ${PROJECT_NAME}")
if (LIBPROJECT)
	sdk_install("qad" "${PROJECT_NAME}" "${out_HDR}" "${out_QM}")
else()
	if (LIB)
		if (WIN32)
			qt_install(FILES ${H} DESTINATION ${MINGW_INCLUDE}/qad)
			qt_install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${MINGW_LIB})
			qt_install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${MINGW_BIN})
			qt_install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION QtBin)
		else()
			qt_install(FILES ${H} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/qad)
			qt_install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
		endif()
		message(STATUS "Install ${PROJECT_NAME} to system \"${CMAKE_INSTALL_PREFIX}\"")
	else()
		if(WIN32)
			qt_install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
			qt_install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION lib)
		else()
			qt_install(TARGETS ${PROJECT_NAME} DESTINATION lib)
		endif()
		qt_install(FILES ${H} DESTINATION include/qad)
		message(STATUS "Install ${PROJECT_NAME} to local \"bin\", \"lib\" and \"include\"")
	endif()
endif()
foreach(_v ${_QT_VERSIONS_})
	set(MULTILIB_qglview_SUFFIX_Qt${_v} ${_v})
	set(MULTILIB_qglview_SUFFIX_Qt${_v} ${_v} PARENT_SCOPE)
endforeach()
list(APPEND QT_MULTILIB_LIST qglview)
if (NOT DEFINED ANDROID_PLATFORM)
	if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/plugin")
		add_subdirectory(plugin)
	endif()
endif()

qt_sources(test_SRC DIR "qglview_test")
qt_wrap(${test_SRC} CPPS test_CPP)
qt_add_executable(qglview_test test_CPP)
qt_target_link_libraries(qglview_test ${PROJECT_NAME})
