project(piqt_utils)
cmake_minimum_required(VERSION 2.6)
cmake_policy(SET CMP0017 OLD)
if(LIBPROJECT)
	include(PIPMacros)
	include(SDKMacros)
else()
	find_package(PIP REQUIRED)
	option(LIB "System install" 0)
	option(DEBUG "Build with -g3" 0)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall")
	if(DEBUG)
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
	endif()
endif()
set(LIBTYPE SHARED)
if(DEFINED ENV{QNX_HOST})
	set(LIBTYPE STATIC)
endif()
find_package(QAD REQUIRED)
list(APPEND QT_MULTILIB_LIST ${PROJECT_NAME})
set(QT_MULTILIB_LIST ${QT_MULTILIB_LIST} PARENT_SCOPE)
include_directories(${PIP_INCLUDES} ${QAD_INCLUDES})
file(GLOB SRC "*.h" "*.cpp" "*.ui" "*.qrc" "lang/*.ts")
pip_code_model(CCM "../pip/src_main/io/piiodevice.h" "../pip/src_main/io/pipacketextractor.h" OPTIONS "-DPIP_EXPORT" "-Es")
find_qt(${QtVersions} Core Gui)
qt_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM)
qt_add_library(${PROJECT_NAME} ${LIBTYPE} out_CPP CCM)
qt_target_link_libraries(${PROJECT_NAME} pip qad_utils qad_widgets qad_blockview)
message(STATUS "Building ${PROJECT_NAME}")

if (LIBPROJECT)
	foreach(_v ${_QT_VERSIONS_})
		if (LOCAL_FOUND${_v})
			add_dependencies(piqt_utils${_v} pip_cmg)
		endif()
	endforeach()
endif()

if (NOT DEFINED ENV{QNX_HOST})
	add_subdirectory(piconnedit)
	add_subdirectory(pidumper)
	add_subdirectory(piintrospector)
endif()

if(LIBPROJECT)
	sdk_install("pip" "${PROJECT_NAME}" "${out_HDR}")
else()
	if(LIB)
		if(WIN32)
			set(CMAKE_INSTALL_PREFIX ${MINGW_DIR})
			install(FILES ${out_HDR} DESTINATION ${MINGW_INCLUDE}/pip)
			qt_install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_LIB})
			qt_install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_BIN})
			qt_install(TARGETS ${PROJECT_NAME} DESTINATION QtBin)
		else()
			if(APPLE)
				set(CMAKE_INSTALL_PREFIX /usr/local)
			else()
				set(CMAKE_INSTALL_PREFIX /usr)
			endif()
			install(FILES ${out_HDR} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/pip)
			qt_install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
		endif()
		message(STATUS "Install ${PROJECT_NAME} to system \"${CMAKE_INSTALL_PREFIX}\"")
	else()
		qt_install(TARGETS ${PROJECT_NAME} DESTINATION bin)
		message(STATUS "Install ${PROJECT_NAME} to local \"bin\"")
	endif()
endif()
