project(qad_widgets)
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 "qpiconsole.h" "spinslider.h"
			"colorbutton.h" "chardialog.h" "shortcuts.h"
			"qipedit.h" "clineedit.h" "ecombobox.h"
			"qpointedit.h" "qrectedit.h" "iconedlabel.h"
			"qcodeedit.h" "qvariantedit.h")
set(CPPS "qpiconsole.cpp" "spinslider.cpp" "colorbutton.cpp"
			"chardialog.cpp" "shortcuts.cpp" "qipedit.cpp"
			"clineedit.cpp" "ecombobox.cpp" "qpointedit.cpp"
			"qrectedit.cpp" "qcodeedit.cpp" "qvariantedit.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_widgets SHARED ${CPPS} ${CUIS} ${CMOCS} ${CRES})
set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})
target_link_libraries(qad_widgets ${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_widgets DESTINATION ${MINGW_LIB})
		get_filename_component(QTDIR ${QT_QMAKE_EXECUTABLE} PATH)
		install(TARGETS qad_widgets DESTINATION ${QTDIR})
	else ()
		set(CMAKE_INSTALL_PREFIX /usr)
		install(FILES ${MOCS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
		install(TARGETS qad_widgets DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
	endif ()
else ()
	install(TARGETS qad_widgets DESTINATION bin)
endif ()
