cmake_minimum_required(VERSION 3.0)
project(qcd_utils)
set(_QCD_MAJOR    1)
set(_QCD_MINOR    0)
set(_QCD_REVISION 0)
set(_QCD_SUFFIX   "")
set(_QCD_COMPANY  SHS)
set(_QCD_DOMAIN   org.SHS)
if(NOT DEFINED BUILD_NUMBER)
	set(BUILD_NUMBER 9999)
endif()
if (NOT LIBPROJECT)
	find_package(PIP REQUIRED)
	option(LIB "System install" 0)
	if (CMAKE_BUILD_TYPE MATCHES Debug)
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -Wall")
		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3 -Wall")
	else()
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall")
		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wall")
	endif()
	include(DeployMacros)
endif()
set_version(${PROJECT_NAME}
	MAJOR    ${_QCD_MAJOR}
	MINOR    ${_QCD_MINOR}
	REVISION ${_QCD_REVISION}
	BUILD    "${BUILD_NUMBER}"
	SUFFIX   "${_QCD_SUFFIX}")

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)
set_deploy_property(${PROJECT_NAME} SHARED
		LABEL 		${PROJECT_NAME}
		FULLNAME 	"${_QCD_DOMAIN}.${PROJECT_NAME}"
		COMPANY 	${_QCD_COMPANY}
		INFO 		"QCD library")
make_rc(${PROJECT_NAME} out_RC)
qt_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM)
qt_add_library(${PROJECT_NAME} SHARED out_CPP ${out_RC})
qt_target_link_libraries(${PROJECT_NAME} pip qad_utils qad_widgets qad_graphic cd_utils piqt)
message(STATUS "Building ${PROJECT_NAME}")

set(QCD_UTILS_UTILS 1)
if(LIBPROJECT)
	sdk_install("" "${PROJECT_NAME}" "${out_HDR}" "${out_QM}")
	set(QCD_UTILS_UTILS ${UTILS})
else()
	if(LIB)
		if(WIN32)
			install(FILES ${out_HDR} DESTINATION ${MINGW_INCLUDE})
			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)
			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)
		message(STATUS "Install ${PROJECT_NAME} to local \"bin\", \"lib\" and \"include\"")
	endif()
endif()

if(QCD_UTILS_UTILS)
	add_subdirectory(pult)
endif()
