#*******************************************************************************
#**  This file is part of Dux Rei Nummariae.                                 ***
#**                                                                          ***
#**  Copyright (C) 2017, 2018, 2019, 2020, 2021                              ***
#**  John Schneiderman <Licensing _AT_ Schneiderman _DOT_ me>                ***
#**                                                                          ***
#**  This program is free software: you can redistribute it and/or modify it ***
#**  under the terms of the GNU Affero General Public License as published   ***
#**  by the Free Software Foundation, either version 3 of the License, or    ***
#**  (at your option) any later version.                                     ***
#**                                                                          ***
#**  This program is distributed in the hope that it will be useful, but     ***
#**  WITHOUT ANY WARRANTY; without even the implied warranty of              ***
#**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                    ***
#**  See the GNU Affero General Public License for more details.             ***
#**                                                                          ***
#**  You should have received a copy of the GNU Affero General Public License***
#**  along with this program. If not, see <http://www.gnu.org/licenses/>.    ***
#*******************************************************************************
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project (DuxReiNummariae
	VERSION 0.4.1
	DESCRIPTION "A simple & powerful budgeting application."
	LANGUAGES CXX
)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX "d")
set(${PROJECT_NAME}_COPYRIGHT_YEARS "\"2017 - 2021\"")

set(
	${PROJECT_NAME}_OPEN_EXCHANGE_RATES_API_KEY
	""
	CACHE
	STRING
	"The application API key for Open Exchange Rates"
)
option(${PROJECT_NAME}_ENABLE_TESTS "Enables compiling and executing tests." OFF)

if ("" STREQUAL "${${PROJECT_NAME}_OPEN_EXCHANGE_RATES_API_KEY}")
	message(WARNING "The Open Exchange Rates API key is empty.")
endif ("" STREQUAL "${${PROJECT_NAME}_OPEN_EXCHANGE_RATES_API_KEY}")

if (${PROJECT_NAME}_ENABLE_TESTS)
	include(CTest)
	enable_testing()
endif ()

# Allow for packagers to supply the name of the library directory.
if (DEFINED LIB_INSTALL_DIR)
	message(STATUS "Using supplied library directory installation path.")
	set (${PROJECT_NAME}_LIBRARY_INSTALL_DIR ${LIB_INSTALL_DIR})
else ()
	if (EXISTS "${CMAKE_INSTALL_PREFIX}/lib32/" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
		set (${PROJECT_NAME}_LIBRARY_INSTALL_DIR lib32)
	elseif (EXISTS "${CMAKE_INSTALL_PREFIX}/lib64/" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
		set (${PROJECT_NAME}_LIBRARY_INSTALL_DIR lib64)
	else ()
		set (${PROJECT_NAME}_LIBRARY_INSTALL_DIR lib)
	endif (EXISTS "${CMAKE_INSTALL_PREFIX}/lib32/" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
endif ()

if (WIN32)
	add_compile_options("/fp:strict")
	add_compile_options("/W4")
	add_compile_options("/utf-8")
	add_compile_options("/WX")
	# Justification: The code is meant to be compiled as a single collection. When this changes,
	# make the templated member variables unique ptrs.
	add_compile_options("/wd4251")
	# Justification: Using some C++17 features.
	add_compile_options("/Wv:18")
	# Justification: Using pagrmas from other compilers.
	add_compile_options("/wd4068")
elseif (APPLE)
	add_compile_options("-Wall")
	# Justification: Using pagrmas from other compilers.
	add_compile_options("-Wno-unknown-pragmas")
elseif (UNIX)
	add_compile_options("-Wall")
	add_compile_options("-Wextra")
	add_compile_options("-Wpedantic")
	add_compile_options("-Wconversion")
	add_compile_options("-Wfloat-equal")
	add_compile_options("-Wsuggest-override")
# 	add_compile_options("-Wduplicated-branches")
# 	add_compile_options("-Wduplicated-cond")
	add_compile_options("-Wshadow")
	add_compile_options("-Wundef")
# 	add_compile_options("-Wextra-semi")
	add_compile_options("-Wlogical-op")
	add_compile_options("-Werror")
	# Justification no-attributes: fails for enum class types with Qt specified type.
	add_compile_options("-Wno-attributes")
else ()
	message(WARNING "No additional warning checks are enabled.")
endif ()

add_subdirectory(src)
