# SLX - The Simple Library Extensions Library
#
# Copyright (c) 2021 William Berry
# email: wsberry@gmail.com
# github: https://github.com/wsberry
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may freely use this source code and its projects in compliance with the License.
#
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License src distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------------------------------------
# Compiler Settings
# ----------------------------------------------------------- [Settings]
macro(standard_xcode_options)

	if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
		MESSAGE(STATUS "Configuring Compiler Settings for Xcode...")
	else()
		return()
	endif()

    # I M P O R T A N T  ! ! !
	# 
	#   Defaulting to  'C++ 17'. Your compiler may or may not support this setting.
	#
    SET(CPP_VERSION_TO_COMPILE_TO 17) 
	
	if (NOT DEFINED CMAKE_CXX_STANDARD)
		SET(CMAKE_CXX_STANDARD ${CPP_VERSION_TO_COMPILE_TO})
	else()
		if (CMAKE_CXX_STANDARD LESS ${CPP_VERSION_TO_COMPILE_TO})
			MESSAGE(FATAL_ERROR "CMAKE_CXX_STANDARD is less than ${CPP_VERSION_TO_COMPILE_TO}, please specify at least SET(CMAKE_CXX_STANDARD ${CPP_VERSION_TO_COMPILE_TO})")
		endif()
	endif()

	# SET your warnings here:
	# Warning form is: '/wd{warning number}'
	#
	LIST(APPEND warnings "-Werror -Wall -Wextra")

	if (NOT CONFIGURED)

		SET(CONFIGURED ON)

		# CXX
		#
		SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${warnings}"
				CACHE STRING "Flags used by the compiler during all build types." FORCE)

		# C
		#
		SET(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} ${warnings}"
				CACHE STRING "Flags used by the compiler during all build types." FORCE)

	endif()

	SET(CMAKE_CXX_STANDARD ${CPP_VERSION_TO_COMPILE_TO})
    SET(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT ${CPP_VERSION_TO_COMPILE_TO})
	SET(CMAKE_CXX_STANDARD_REQUIRED ON)
	SET(CMAKE_CXX_EXTENSIONS OFF)
	
	# Simplify and force build outputs to _debug and _release
	#
    SET(CMAKE_CONFIGURATION_TYPES "_debug;_release" CACHE STRING "" FORCE)
    
    if (NOT DEFINED CXX_RTTI)
        option(CXX_RTTI "Enable or disable C++ RTTI." ON)
    endif()
	
	# Common Deaults (i.e. defaults people want most of the time):
	#
   SET(CMAKE_DEBUG_POSTFIX   "d")
   
    add_definitions (
	        -DPLATFORM_OSX

			# Xcode is little endian
			#
			-DENDIAN_IS_LITTLE

			# My assuption is that all C++ projects will generally include the 'fmt library.
			#
			#    If using C++ 20 then use 'std::format'.
			#
			#    https://github.com/fmtlib/fmt
			#
			-DFMT_HEADER_ONLY
	)
	
	# Platform Specific Library Groupings
	#
    # set(platform_libraries_group)
	
endmacro(standard_xcode_options)
