cmake_minimum_required(VERSION 3.14.4)

message(STATUS "Using CMake ${CMAKE_VERSION}")

include(cmake/add_files.cmake)
include(cmake/create_source_groups.cmake)
include(cmake/version.cmake)

# Project ----------------------------------------------------------------------

# Product identity — anything that depends on the product/project name is defined
# here so it lives in a single place and can change in the future. These values
# feed the build targets in src/CMakeLists.txt and the Windows version resource
# (see cmake/version.rc.in).
set(PRODUCT_NAME "DotaFactory")            # internal name and executable base name
set(PRODUCT_DISPLAY_NAME "Dota Factory")   # human-readable product / file description
set(PRODUCT_COMPANY "TODO: company")       # placeholder
set(PRODUCT_COPYRIGHT "TODO: copyright")   # placeholder

project(${PRODUCT_NAME})

set(CMAKE_BUILD_TYPE_INIT "Release")


# Qt ---------------------------------------------------------------------------

find_package(Qt5 COMPONENTS Widgets Network Multimedia Charts Svg REQUIRED)

if(Qt5Widgets_FOUND)
	message(STATUS "Found Qt ${Qt5Widgets_VERSION_STRING}")

	# FIX: Qt was built with -reduce-relocations
	if (Qt5_POSITION_INDEPENDENT_CODE)
		SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
	endif()
endif()


# Setup ---------------------------------------------------------------------------

get_filename_component(QT_BINARY_DIR "${QT_MOC_EXECUTABLE}" PATH)
set(QT_PLUGINS_DIR "${QT_BINARY_DIR}/../plugins")

function(COPY_QT_BINARIES TARGET_DIR IS_DEBUG)
	set(SUFFIX "")
	if (IS_DEBUG)
		set(SUFFIX "d")
	endif()

	set(CONFIGURATION "Release")
	if (IS_DEBUG)
		set(CONFIGURATION "Debug")
	endif()

	if(CMAKE_CL_64)
		set(BITS "64")
	else()
		set(BITS "32")
	endif()
	
	configure_file("${QT_BINARY_DIR}/Qt5Charts${SUFFIX}.dll" "${TARGET_DIR}/Qt5Charts${SUFFIX}.dll" COPYONLY)
	configure_file("${QT_BINARY_DIR}/Qt5Core${SUFFIX}.dll" "${TARGET_DIR}/Qt5Core${SUFFIX}.dll" COPYONLY)
	configure_file("${QT_BINARY_DIR}/Qt5Gui${SUFFIX}.dll" "${TARGET_DIR}/Qt5Gui${SUFFIX}.dll" COPYONLY)
	configure_file("${QT_BINARY_DIR}/Qt5Network${SUFFIX}.dll" "${TARGET_DIR}/Qt5Network${SUFFIX}.dll" COPYONLY)
	configure_file("${QT_BINARY_DIR}/Qt5Widgets${SUFFIX}.dll" "${TARGET_DIR}/Qt5Widgets${SUFFIX}.dll" COPYONLY)
	configure_file("${QT_BINARY_DIR}/Qt5Multimedia${SUFFIX}.dll" "${TARGET_DIR}/Qt5Multimedia${SUFFIX}.dll" COPYONLY)
	configure_file("${QT_BINARY_DIR}/Qt5Svg${SUFFIX}.dll" "${TARGET_DIR}/Qt5Svg${SUFFIX}.dll" COPYONLY)
endfunction(COPY_QT_BINARIES)


# Src ----------------------------------------------------------------------

find_package(OpenGL REQUIRED)

add_subdirectory(src)

