project(kx_utils)
cmake_minimum_required(VERSION 2.6)
if (NOT LIBPROJECT)
	find_package(PIP REQUIRED)
endif ()
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${PIP_INCLUDES})

option(KX_PULT "Build kx_pult" 1)

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(CPPS_UTILS "kx_coeffs.cpp")
set(HDRS_UTILS "kx_coeffs.h" "kx_protocol_x.h")
if (DEFINED ENV{QNX_HOST})
	add_library(kx_utils STATIC ${CPPS_UTILS})
else ()
	add_library(kx_utils SHARED ${CPPS_UTILS})
endif ()
target_link_libraries(kx_utils ${PIP_LIBRARY})

if (NOT DEFINED ENV{QNX_HOST})
	if (KX_PULT)
		find_package(Qt4 REQUIRED)
		include_directories(${QT_INCLUDES})
		set(CPPS "kx_pult.cpp" "kx_pult.h" "kx_pult.ui" "main_kx_pult.cpp")
		set(MOCS "kx_pult.h")
		file(GLOB UIS "*.ui")
		file(GLOB RES "*.qrc")
		qt4_wrap_cpp(CMOCS ${MOCS} OPTIONS -nw)
		qt4_wrap_ui(CUIS ${UIS})
		qt4_add_resources(RESS ${RES})
		add_executable(kx_pult WIN32 ${CPPS} ${CMOCS} ${CUIS} ${RESS})
		set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${PIP_LIBRARY} qad_graphic qad_utils qad_widgets kx_utils)
		find_package(OpenGL REQUIRED)
		list(APPEND LIBS ${OPENGL_LIBRARIES})
		target_link_libraries(kx_pult ${LIBS})
	endif ()
endif ()

if (DEFINED LIB)
	set(LIB 1)
	if (${WIN32})
		find_package(MinGW REQUIRED)
		set(CMAKE_INSTALL_PREFIX ${MINGW_DIR})
		install(FILES ${HDRS_UTILS} DESTINATION ${MINGW_INCLUDE})
		install(TARGETS kx_utils DESTINATION ${MINGW_LIB})
	else ()
		set(CMAKE_INSTALL_PREFIX /usr)
		install(FILES ${HDRS_UTILS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
		install(TARGETS kx_utils DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
	endif ()
else ()
	install(TARGETS kx_utils DESTINATION bin)
endif ()

if (NOT DEFINED ENV{QNX_HOST})
	if (KX_PULT)
		install(TARGETS kx_pult DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
	endif ()
endif ()
