#*******************************************************************************
#**  This file is part of Pecunia.                                           ***
#**                                                                          ***
#**  Copyright (C) 2017, 2018, 2019, 2020, 2021, 2023                        ***
#**  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.13 FATAL_ERROR)
project(pecunia-unit-tests)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

find_package(Qt5 REQUIRED COMPONENTS Test)

macro(addQTest testName)
	set(Test_Project_Name "${testName}-tests")
	set(Test_File_Name "${testName}-unit-tests")

	add_executable(${Test_Project_Name} ${Test_File_Name}.cpp)
	# Adds the includes for the auto-generated files.
	target_include_directories(${Test_Project_Name}
		PRIVATE
			$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>/..
			$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>/../external
			$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>/../external/pecunia
	)
	target_link_libraries(${Test_Project_Name} PRIVATE pecunia)
	target_link_libraries(${Test_Project_Name} PRIVATE Qt5::Test)
	add_test(
		NAME ${Test_Project_Name}
		COMMAND "${testName}-tests"
		WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
	)
	configure_file(
		"${CMAKE_SOURCE_DIR}/src/project.vcxproj.user.in"
		${PROJECT_BINARY_DIR}/${Test_Project_Name}.vcxproj.user @ONLY
	)

	unset(Test_Project_Name)
	unset(Test_File_Name)
endmacro(addQTest)

addQTest(algorithm)
addQTest(codes)
addQTest(conversion)
addQTest(FloatingPoint)
addQTest(math)
addQTest(money)
addQTest(range)
addQTest(rounders-currency)
addQTest(rounders-floating-point)
