#-------------------------------------------------------------------------------------------
# Copyright (c) 2022-present, SkillerRaptor <skillerraptor@protonmail.com>
#
# SPDX-License-Identifier: MIT
#-------------------------------------------------------------------------------------------

#-------------------------------------------------------------------------------------------
# Compiler Warnings
#-------------------------------------------------------------------------------------------
function(enable_warnings project_name)
		option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" ON)

		set(MSVC_WARNINGS
				/W4
				/w14242
				/w14254
				/w14263
				/w14265
				/w14287
				/we4289
				/w14296
				/w14311
				/w14545
				/w14546
				/w14547
				/w14549
				/w14555
				/w14619
				/w14640
				/w14826
				/w14905
				/w14906
				/w14928
				/permissive-)

		set(CLANG_WARNINGS
				-Wall
				-Wextra
				-Wshadow
				-Wnon-virtual-dtor
				-Wold-style-cast
				-Wcast-align
				-Wunused
				-Woverloaded-virtual
				-Wpedantic
				-Wconversion
				-Wsign-conversion
				-Wnull-dereference
				-Wdouble-promotion
				-Wformat=2)

		set(GCC_WARNINGS
				${CLANG_WARNINGS}
				-Wmisleading-indentation
				-Wduplicated-cond
				-Wduplicated-branches
				-Wlogical-op
				-Wuseless-cast)

		if (WARNINGS_AS_ERRORS)
				set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
				set(GCC_WARNINGS ${GCC_WARNINGS} -Werror)
				set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
		endif ()

		if (MSVC)
				set(PROJECT_WARNINGS ${MSVC_WARNINGS})
		elseif (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
				set(PROJECT_WARNINGS ${CLANG_WARNINGS})
		elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
				set(PROJECT_WARNINGS ${GCC_WARNINGS})
		else ()
				message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
		endif ()

		target_compile_options(
				${project_name}
				INTERFACE
				${PROJECT_WARNINGS})
endfunction()
