cmake_minimum_required(VERSION 3.0)
project(piqt)
if(NOT LIBPROJECT)
	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()
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")
find_qt(${QtVersions} Core Gui Positioning)
qt_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM)
qt_add_library(${PROJECT_NAME} SHARED out_CPP)
qt_target_link_libraries(${PROJECT_NAME} pip qad_utils qad_widgets)
message(STATUS "Building ${PROJECT_NAME}")
if(LIBPROJECT)
	sdk_install("pip" "${PROJECT_NAME}" "${out_HDR}" "${out_QM}")
else()
	if(LIB)
		if(WIN32)
			install(FILES ${out_HDR} DESTINATION ${MINGW_INCLUDE}/pip)
			if(NOT "x${out_QM}" STREQUAL "x")
				qt_install(FILES ${out_QM} DESTINATION QtLang)
			endif()
			qt_install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${MINGW_LIB})
			qt_install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${MINGW_BIN})
			qt_install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION QtBin)
		else()
			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()
		if(WIN32)
			qt_install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
			qt_install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION lib)
		else()
			qt_install(TARGETS ${PROJECT_NAME} DESTINATION lib)
		endif()
		install(FILES ${out_HDR} DESTINATION include/pip)
		message(STATUS "Install ${PROJECT_NAME} to local \"bin\", \"lib\" and \"include\"")
	endif()
endif()
