project(piqt_utils)
cmake_minimum_required(VERSION 2.6)
if (NOT ${LIBPROJECT})
	find_package(PIP REQUIRED)
endif ()
find_package(Qt4 REQUIRED)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${PIP_INCLUDES} ${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}")

file(GLOB CPPS_UTILS "piqt_*.cpp" "ccm.cpp")
file(GLOB HDRS_UTILS "piqt_*.h")
file(GLOB UIS_UTILS "piqt_*.ui")
qt4_wrap_cpp(CMOCS_UTILS ${HDRS_UTILS} OPTIONS -nw)
qt4_wrap_ui(CUIS_UTILS ${UIS_UTILS})
if (DEFINED ENV{QNX_HOST})
	add_library(piqt_utils STATIC ${CPPS_UTILS} ${CMOCS_UTILS} ${CUIS_UTILS})
else ()
	add_library(piqt_utils SHARED ${CPPS_UTILS} ${CMOCS_UTILS} ${CUIS_UTILS})
endif ()
target_link_libraries(piqt_utils ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${PIP_LIBRARY} qad_utils qad_widgets qad_blockview)

if (NOT DEFINED ENV{QNX_HOST})
	set(CPPS "pidumper.cpp" "pidumper_main.cpp")
	set(MOCS "pidumper.h")
	set(UIS "pidumper.ui")
	file(GLOB RES "*.qrc")
	qt4_wrap_cpp(CMOCS ${MOCS} OPTIONS -nw)
	qt4_wrap_ui(CUIS ${UIS})
	qt4_add_resources(RESS ${RES})
	add_executable(pidumper ${CPPS} ${CMOCS} ${CUIS} ${RESS})
	set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${PIP_LIBRARY} qad_widgets piqt_utils)
	target_link_libraries(pidumper ${LIBS})

	set(ICPPS "piintrospector.cpp" "piintrospector_main.cpp")
	set(IMOCS "piintrospector.h")
	set(IUIS "piintrospector.ui")
	file(GLOB IRES "*.qrc")
	qt4_wrap_cpp(ICMOCS ${IMOCS} OPTIONS -nw)
	qt4_wrap_ui(ICUIS ${IUIS})
	qt4_add_resources(IRESS ${IRES})
	add_executable(piintrospector ${ICPPS} ${ICMOCS} ${ICUIS} ${IRESS})
	set(ILIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${PIP_LIBRARY} qad_widgets)
	target_link_libraries(piintrospector ${LIBS})

	add_executable(piconnectionedit "piconnedit_main.cpp" ${RESS})
	target_link_libraries(piconnectionedit ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${PIP_LIBRARY} piqt_utils)
endif ()

if (DEFINED LIB)
	set(LIB true)
	if (${WIN32})
		find_package(MinGW REQUIRED)
		set(CMAKE_INSTALL_PREFIX ${MINGW_DIR})
		install(FILES ${HDRS_UTILS} DESTINATION ${MINGW_INCLUDE})
		install(TARGETS piqt_utils DESTINATION ${MINGW_LIB})
		get_filename_component(QTDIR ${QT_QMAKE_EXECUTABLE} PATH)
		install(TARGETS piqt_utils DESTINATION ${QTDIR})
	else ()
		set(CMAKE_INSTALL_PREFIX /usr)
		install(FILES ${HDRS_UTILS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
		install(TARGETS piqt_utils DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
	endif ()
else ()
	install(TARGETS piqt_utils DESTINATION bin)
endif ()

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