project(qad_utils)
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(MOCS "qpiconfig.h" "qpiconfigwidget.h" "qpievaluator.h"
			"qpiconfignewdialog.h" "qpiconfigvaluewidget.h"
			"session_manager.h" "chunkstream.h")
set(CPPS "qpiconfig.cpp" "qpiconfigwidget.cpp" "qpievaluator.cpp"
			"qpiconfignewdialog.cpp" "qpiconfigvaluewidget.cpp"
			"session_manager.cpp" "chunkstream.cpp")
file(GLOB UIS "./*.ui")
file(GLOB RES "./*.qrc")
qt4_wrap_ui(CUIS ${UIS})
qt4_wrap_cpp(CMOCS ${MOCS} OPTIONS -nw)
qt4_add_resources(CRES ${RES})
add_library(qad_utils SHARED ${CPPS} ${CUIS} ${CMOCS} ${CRES})
set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} qad_widgets)
target_link_libraries(qad_utils ${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 qad_utils DESTINATION ${MINGW_LIB})
		get_filename_component(QTDIR ${QT_QMAKE_EXECUTABLE} PATH)
		install(TARGETS qad_utils DESTINATION ${QTDIR})
	else ()
		set(CMAKE_INSTALL_PREFIX /usr)
		install(FILES ${MOCS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
		install(TARGETS qad_utils DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
	endif ()
else ()
	install(TARGETS qad_utils DESTINATION bin)
endif ()
