project(qglview)
cmake_minimum_required(VERSION 2.6)
cmake_policy(SET CMP0017 OLD)
if (IBPROJECT)
	include(SDKMacros)
else()
	option(LIB "System install" 0)
	option(DEBUG "Build with -g3" 0)
	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})
file(GLOB SRC "*.h" "*.cpp" "*.ui" "*.qrc" "lang/*.ts")
find_qt(Qt4 Core Gui OpenGL Xml)
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})
message(STATUS "Building ${PROJECT_NAME}")
if (LIBPROJECT)
	sdk_install("qad" "${PROJECT_NAME}" "${H}")
else()
	if (LIB)
		if (WIN32)
			set(CMAKE_INSTALL_PREFIX ${MINGW_DIR})
			install(FILES ${H} DESTINATION ${MINGW_INCLUDE}/qad)
			install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_LIB})
			install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_BIN})
			get_filename_component(QTDIR ${QT_QMAKE_EXECUTABLE} PATH)
			install(TARGETS ${PROJECT_NAME} DESTINATION ${QTDIR})
		else()
			if(APPLE)
				set(CMAKE_INSTALL_PREFIX /usr/local)
			else()
				set(CMAKE_INSTALL_PREFIX /usr)
			endif()
			install(FILES ${H} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/qad)
			install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
		endif()
		message(STATUS "Install ${PROJECT_NAME} to system \"${CMAKE_INSTALL_PREFIX}\"")
	else()
		install(TARGETS ${PROJECT_NAME} DESTINATION bin)
		message(STATUS "Install ${PROJECT_NAME} to local \"bin\"")
	endif()
endif()

qt4_wrap_cpp(CMOCS_TEST "qglview_window.h" OPTIONS -nw)
qt4_wrap_ui(CUIS_TEST "qglview_window.ui")
qt_add_executable(qglview_test "main.cpp" "qglview_window.cpp" ${CMOCS_TEST} ${CUIS_TEST} ${CRES})
qt_target_link_libraries(qglview_test ${PROJECT_NAME} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})
