#*******************************************************************************
#**  This file is part of Pecunia.                                           ***
#**                                                                          ***
#**  Copyright (C) 2017, 2018, 2019, 2020, 2021, 2023, 2024                  ***
#**  John Schneiderman <Licencing _AT_ Schneiderman _DOT_ me>                ***
#**                                                                          ***
#**  This program is free software: you can redistribute it and/or modify it ***
#**  under the terms of the GNU Lesser 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 Lesser General Public License for more details.             ***
#**                                                                          ***
#**  You should have received a copy of the GNU Lesser General Public License***
#**  along with this program. If not, see <http://www.gnu.org/licenses/>.    ***
#*******************************************************************************
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(Pecunia
	VERSION 0.7.0
	DESCRIPTION "Library for working with currencies using the ISO-4217 standard and a fixed unit size."
	LANGUAGES CXX
)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX "d")

if (EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
	message(STATUS "Enabling Conan.io support.")
	include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
	conan_basic_setup()
endif (EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")

option(${PROJECT_NAME}_BUILD_SHARED_LIBRARY "Enables building as a shared library, else static." ON)


if (${PROJECT_NAME}_BUILD_SHARED_LIBRARY)
	set(${PROJECT_NAME}_LIBRARY_TYPE "SHARED")
else ()
	set(${PROJECT_NAME}_LIBRARY_TYPE "STATIC")
endif (${PROJECT_NAME}_BUILD_SHARED_LIBRARY)

option(${PROJECT_NAME}_ENABLE_TESTS "Enables building and executing tests." OFF)

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

set(
	${PROJECT_NAME}_SUB_MINOR_DIGITS
	2u
	CACHE
	STRING
	"Sets the extra number of digits to have after the minor unit."
)
set(
	${PROJECT_NAME}_MINOR_UNIT_TYPE
	std::uint16_t
	CACHE
	STRING
	"Sets the type used for the minor unit."
)
set(
	${PROJECT_NAME}_UNIT_STORAGE_TYPE
	std::int64_t
	CACHE
	STRING
	"Sets the type used for the money amount storage unit."
)
set(
	${PROJECT_NAME}_FLOATING_POINT_TYPE
	double
	CACHE
	STRING
	"Sets the type used for floating point operations."
)
set(
	${PROJECT_NAME}_FLOATING_POINT_PRECISION
	2u
	CACHE
	STRING
	"Sets the extra number of digit precision during floating point operations."
)
set(
	${PROJECT_NAME}_DEFAULT_ROUNDING_DIGITS
	3u
	CACHE
	STRING
	"Sets the number of digits during rounding operations to use as a default."
)

if (UNIX)
	set(
		${PROJECT_NAME}_LOCALE
		"C.UTF-8"
		CACHE
		STRING
		"Sets the default locale used when setting up the library."
	)
else ()
	set(
		${PROJECT_NAME}_LOCALE
		"en_US.UTF-8"
		CACHE
		STRING
		"Sets the default locale used when setting up the library."
	)
endif ()
set(${PROJECT_NAME}_COPYRIGHT_YEARS "\"2017 - 2024\"")
set(
	${PROJECT_NAME}_DESCRIPTION
	"A C++ library for working with currencies using the ISO-4217 standard and a fixed unit size."
)
set(${PROJECT_NAME}_HOMEPAGE_URL "http://www.schneiderman.me/pages/pecunia.html")

# 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 (DEFINED LIB_INSTALL_DIR)

if (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
	add_compile_options("-Wall")
	add_compile_options("-Wcast-qual")
	add_compile_options("-Wconversion")
	add_compile_options("-Wdangling-else")
	add_compile_options("-Wdeprecated")
	add_compile_options("-Wdeprecated-declarations")
	add_compile_options("-Wduplicated-branches")
	add_compile_options("-Wduplicated-cond")
	add_compile_options("-Werror")
	add_compile_options("-Wextra")
	add_compile_options("-Wextra-semi")
	add_compile_options("-Wfloat-equal")
	add_compile_options("-Winit-self")
	add_compile_options("-Wlogical-op")
	add_compile_options("-Wmissing-declarations")
	add_compile_options("-Wpedantic")
	add_compile_options("-Wshadow")
	add_compile_options("-Wsign-conversion")
	add_compile_options("-Wsuggest-override")
	add_compile_options("-Wundef")
	add_compile_options("-Wuninitialized")
	add_compile_options("-Wunused-macros")
	# Justification: caused by the interaction between forward declarations and definitions of
	# enum classes.
	add_compile_options("-Wno-attributes")
	add_compile_options("-fconcepts-diagnostics-depth=5")
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
	message(WARNING "Compilations options not set.")
	set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE)
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
	add_compile_options("/permissive-")
	add_compile_options("/fp:strict")
	add_compile_options("/W4")
	add_compile_options("/utf-8")
	add_compile_options("/WX")
endif()

add_subdirectory(src)

set(CPACK_PACKAGE_HOMEPAGE_URL "${${PROJECT_NAME}_HOMEPAGE_URL}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README")
set(CPACK_PACKAGE_CHECKSUM SHA256)
include(CPack)
