project(qglview)
cmake_minimum_required(VERSION 2.6)
find_package(Qt4 REQUIRED)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${QT_INCLUDES})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")

set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${QT_QTXML_LIBRARY} qad_widgets qad_utils)
find_package(OpenGL REQUIRED)
list(APPEND LIBS ${OPENGL_LIBRARIES})

file(GLOB MOCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h")
file(GLOB CPPS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
file(GLOB UIS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.ui")
file(GLOB RES "*.qrc")
list(REMOVE_ITEM CPPS "main.cpp" "qglview_window.cpp")
list(REMOVE_ITEM MOCS "qglview_window.h")
list(REMOVE_ITEM UIS "qglview_window.ui")
qt4_wrap_cpp(CMOCS ${MOCS} OPTIONS -nw)
qt4_wrap_ui(CUIS ${UIS})
qt4_add_resources(CRES ${RES})
add_library(qglview SHARED ${CPPS} ${CMOCS} ${CUIS} ${CRES})
target_link_libraries(qglview ${LIBS})
if (DEFINED LIB)
	set(LIB 1)
	if (${WIN32})
		find_package(MinGW REQUIRED)
		set(CMAKE_INSTALL_PREFIX ${MINGW_DIR})
		install(FILES ${MOCS} DESTINATION ${MINGW_INCLUDE})
		install(TARGETS qglview DESTINATION ${MINGW_LIB})
	else ()
		set(CMAKE_INSTALL_PREFIX /usr)
		install(FILES ${MOCS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
		install(TARGETS qglview DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
	endif ()
else ()
	install(TARGETS qglview DESTINATION bin)
endif ()

qt4_wrap_cpp(CMOCS_TEST "qglview_window.h" OPTIONS -nw)
qt4_wrap_ui(CUIS_TEST "qglview_window.ui")
add_executable(qglview_test "main.cpp" "qglview_window.cpp" ${CMOCS_TEST} ${CUIS_TEST} ${CRES})
target_link_libraries(qglview_test ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${QT_QTXML_LIBRARY} qglview qad_widgets qad_utils)
