CMAKE_MINIMUM_REQUIRED(VERSION 3.10)

SET(TARGET_ARCH_REGEX "^.*-march[= ]([^ ]+).*$")
STRING(REGEX MATCH "${TARGET_ARCH_REGEX}" TARGET_ARCH_MATCH "${CMAKE_C_FLAGS}" "${CMAKE_CXX_FLAGS}")
IF(TARGET_ARCH_MATCH)
    STRING(REGEX REPLACE "${TARGET_ARCH_REGEX}" "\\1" TARGET_ARCH "${CMAKE_C_FLAGS}" "${CMAKE_CXX_FLAGS}")
ELSE()
    SET(TARGET_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR})
ENDIF()

IF((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"))
	SET(COMPILER_CLANG			ON)
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
	SET(COMPILER_GCC			ON)
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
	SET(COMPILER_MSVC			ON)
ENDIF()

IF(("${TARGET_ARCH}" STREQUAL "x86") OR ("${TARGET_ARCH}" STREQUAL "IA32"))
	SET(ARCH_IA32				ON)
ELSEIF(("${TARGET_ARCH}" STREQUAL "x86_64") OR ("${TARGET_ARCH}" STREQUAL "AMD64"))
	SET(ARCH_AMD64				ON)
ELSEIF(("${TARGET_ARCH}" STREQUAL "armv7") OR ("${TARGET_ARCH}" STREQUAL "armv8") OR ("${TARGET_ARCH}" STREQUAL "arm"))
	SET(ARCH_ARM				ON)
ELSEIF(("${TARGET_ARCH}" STREQUAL "aarch64") OR ("${TARGET_ARCH}" STREQUAL "ARM64"))
	SET(ARCH_ARM64				ON)
ENDIF()

IF(${CMAKE_SYSTEM_NAME} STREQUAL "Windows" OR ${CMAKE_SYSTEM_NAME} STREQUAL "MSYS")
	SET(PLATFORM_WINDOWS		ON)
ENDIF()
IF(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsStore")
	SET(PLATFORM_UWP			ON)
ENDIF()
IF(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
	SET(PLATFORM_ANDROID		ON)
ENDIF()
IF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
	SET(PLATFORM_MACOS			ON)
ENDIF()
IF(${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
	SET(PLATFORM_IOS			ON)
ENDIF()
IF((${CMAKE_SYSTEM_NAME} STREQUAL "Linux") OR (${CMAKE_SYSTEM_NAME} STREQUAL "UNIX"))
	SET(PLATFORM_LINUX			ON)
ENDIF()