set(COMPILER_NAME "?")
set(COMPILER_VERSION 0)

# detect the compiler and its version
# Note: on some platforms (OS X), CMAKE_COMPILER_IS_GNUCXX is true
# even when CLANG is used, therefore the Clang test is done first
if(CMAKE_CXX_COMPILER MATCHES ".*clang[+][+]" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
	set(COMPILER_NAME "clang")
	execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE CLANG_VERSION_OUTPUT)
	string(REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" COMPILER_VERSION "${CLANG_VERSION_OUTPUT}")
elseif(CMAKE_COMPILER_IS_GNUCXX)
	set(COMPILER_NAME "gcc")
	execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpversion" OUTPUT_VARIABLE GCC_VERSION_OUTPUT)
	string(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" COMPILER_VERSION "${GCC_VERSION_OUTPUT}")
	
	#execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE GCC_COMPILER_VERSION)
	#string(REGEX MATCHALL ".*(tdm[64]*-[1-9]).*" SFML_COMPILER_GCC_TDM "${GCC_COMPILER_VERSION}")
	#execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpmachine" OUTPUT_VARIABLE GCC_MACHINE)
	#string(STRIP "${GCC_MACHINE}" GCC_MACHINE)
	#if(${GCC_MACHINE} MATCHES ".*w64.*")
	#	set(SFML_COMPILER_GCC_W64 1)
	#endif()
elseif(MSVC)
	set(COMPILER_NAME "msvc")

	if(MSVC_VERSION EQUAL 1200)
		set(COMPILER_VERSION 6)
	elseif(MSVC_VERSION EQUAL 1300)
		set(COMPILER_VERSION 7)
	elseif(MSVC_VERSION EQUAL 1310)
		set(COMPILER_VERSION 7.1)
	elseif(MSVC_VERSION EQUAL 1400)
		set(COMPILER_VERSION 8)
	elseif(MSVC_VERSION EQUAL 1500)
		set(COMPILER_VERSION 9)
	elseif(MSVC_VERSION EQUAL 1600)
		set(COMPILER_VERSION 10)
	elseif(MSVC_VERSION EQUAL 1700)
		set(COMPILER_VERSION 11)
	elseif(MSVC_VERSION EQUAL 1800)
		set(COMPILER_VERSION 12)
	endif()
else()
	message(FATAL_ERROR "Unsupported compiler")
	return()
endif()

message(STATUS "Compiler detected as ${COMPILER_NAME} ${COMPILER_VERSION}")