
include(CPUNameTest)

# ----------------------------------------------- #
# Current platform id                             #
# ----------------------------------------------- #

macro(unknown_platform)
  message(WARNING "Unknown system: ${CMAKE_SYSTEM}")
  set(buildTarget "unknown")
endmacro()

message(STATUS "SYSTEM_IS_64: ${SYSTEM_IS_64}")
message(STATUS "SYSTEM_IS_32: ${SYSTEM_IS_32}")
message(STATUS "SYSTEM_IS_X86_64: ${SYSTEM_IS_X86_64}")
message(STATUS "SYSTEM_IS_X86: ${SYSTEM_IS_X86}")

if(WIN32)
	if(SYSTEM_IS_64)
		set(buildTarget "win64")
	else()
		set(buildTarget "win32")
	endif()
elseif(UNIX)
	if(APPLE)
		if(SYSTEM_IS_64 AND SYSTEM_IS_X86)
			set(buildTarget "darwin_universal")
		elseif(NOT SYSTEM_IS_64 AND SYSTEM_IS_X86)
			set(buildTarget "darwin_universal")
		elseif(SYSTEM_IS_PPC)
			set(buildTarget "darwin_universal")
		else()
			unknown_platform()
		endif()
	elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
		if(SYSTEM_IS_X86 AND SYSTEM_IS_64)
			set(buildTarget "linux_x64")
		elseif(SYSTEM_IS_X86 AND NOT SYSTEM_IS_64)
			set(buildTarget "linux_x86")
		elseif(SYSTEM_IS_PPC AND SYSTEM_IS_64)
			unknown_platform()
		elseif(SYSTEM_IS_PPC AND NOT SYSTEM_IS_64)
			unknown_platform()
		else()
			unknown_platform()
		endif()
	elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
		if(SYSTEM_IS_X86 AND SYSTEM_IS_64)
            set(buildTarget "freebsd_x64")
		elseif(SYSTEM_IS_X86 AND NOT SYSTEM_IS_64)
			set(buildTarget "freebsd_x86")
		else()
			unknown_platform()
		endif()
	else()
		unknown_platform()
	endif()
else()
	unknown_platform()
endif()
