cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
cmake_policy(SET CMP0072 NEW) #  FindOpenGL prefers GLVND by default
project(QAD)
set(QAD_MAJOR    2)
set(QAD_MINOR    32)
set(QAD_REVISION 0)
set(QAD_SUFFIX   )
set(QAD_COMPANY  SHS)
set(QAD_DOMAIN   org.SHS)

if ("x${CMAKE_MODULE_PATH}" STREQUAL "x")
	set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
endif()

include(SHSTKMacros)
include(QtWraps)
shstk_begin_project(QAD)
include(SHSTKQtMacros)

shstk_qt_founded(QtVersions)
foreach(_v ${_QT_VERSIONS_})
	#message("Qt ${_v} -> ${QtVersions}")
	option(Qt${_v} "Build for Qt${_v}" ON)
endforeach()

if (NOT DEFINED ANDROID_PLATFORM)
	find_package(OpenGL REQUIRED)
endif()
#include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

option(UTILS "Build various utils" ${_plugins_default_})
option(DESIGNER_PLUGINS "Build Qt designer plugins" ${_plugins_default_})
option(HAS_GL "Build with OpenGL" ${_plugins_default_})

macro(qad_library NAME _MODULES _LIBS)
	shstk_qad_project(qad_${NAME} FALSE "QAD" "${_MODULES}" "${_LIBS}" ${ARGN})
	shstk_qad_install("qad" FALSE qad_${NAME} "${out_HDR}" "out_QM")
endmacro()

macro(qad_application NAME _MODULES _LIBS)
	shstk_qad_project(${NAME} TRUE "QAD" "${_MODULES}" "${_LIBS}" ${ARGN})
	shstk_qad_install("qad" TRUE ${NAME} "" "out_QM")
endmacro()

macro(qad_plugin NAME _MODULES _LIBS)
	shstk_qad_plugin(qad_${NAME} "${_MODULES}" "qad_${NAME};${_LIBS}")
endmacro()

shstk_install(qad FALSE "" "${QAD_VERSION_FILE}")
file(GLOB CMAKES "cmake/*.cmake" "cmake/*.in")
install(FILES ${CMAKES} DESTINATION ${CMAKE_ROOT}/Modules)

add_subdirectory(libs)
if (UTILS)
	add_subdirectory(utils)
endif()

message("----------QAD----------")
message(" Build for ${QtVersions}")
message(" Version: ${QAD_VERSION} ")
message(" Linkage: ${QAD_LIB_TYPE_MSG}")
message(" Type   : ${QAD_BUILD_TYPE}")
if (NOT LOCAL)
	message(" Install: \"${CMAKE_INSTALL_PREFIX}\"")
else()
	if(NOT PIP_FREERTOS)
		message(" Install: local \"bin\", \"lib\" and \"include\"")
	endif()
endif()
message("")
print_list("${_qt_libs}" " Libraries:" "  * ")
if (NOT "x${_qt_plugs}" STREQUAL "x")
	message("")
	print_list("${_qt_plugs}" " Plugins:" "  * ")
endif()
if (NOT "x${_qt_apps}" STREQUAL "x")
	message("")
	print_list("${_qt_apps}" " Applications:" "  * ")
endif()
message("-----------------------")

shstk_copy_to_parent()
