# ----------------------------------------------------------------------------
# Detect GNU version:
# ----------------------------------------------------------------------------
IF(CMAKE_COMPILER_IS_GNUCXX)
	execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
		          OUTPUT_VARIABLE CMAKE_MRPT_GCC_VERSION_FULL
		          OUTPUT_STRIP_TRAILING_WHITESPACE)

	string(FIND ${CMAKE_MRPT_GCC_VERSION_FULL} "." MRPT_GCC_HAS_DOT)
	if (${MRPT_GCC_HAS_DOT} EQUAL -1)
		execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpfullversion
	                OUTPUT_VARIABLE CMAKE_MRPT_GCC_VERSION_FULL
	                OUTPUT_STRIP_TRAILING_WHITESPACE)
	endif()

	# Output in CMAKE_MRPT_GCC_VERSION_FULL: "X.Y"
	#  Look for the version number
	STRING(REGEX MATCH "[0-9]+.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_MRPT_GCC_VERSION_FULL}")

	# Split the three parts:
	STRING(REGEX MATCHALL "[0-9]+" CMAKE_MRPT_GCC_VERSIONS "${CMAKE_GCC_REGEX_VERSION}")

	LIST(GET CMAKE_MRPT_GCC_VERSIONS 0 CMAKE_MRPT_GCC_VERSION_MAJOR)
	LIST(GET CMAKE_MRPT_GCC_VERSIONS 1 CMAKE_MRPT_GCC_VERSION_MINOR)

	SET(CMAKE_MRPT_GCC_VERSION ${CMAKE_MRPT_GCC_VERSION_MAJOR}${CMAKE_MRPT_GCC_VERSION_MINOR})

	IF($ENV{VERBOSE})
		MESSAGE(STATUS "gcc -dumpversion: ${CMAKE_MRPT_GCC_VERSION_FULL}  -> Major=${CMAKE_MRPT_GCC_VERSION_MAJOR} Minor=${CMAKE_MRPT_GCC_VERSION_MINOR}")
	ENDIF($ENV{VERBOSE})

	# impose minimum gcc version - 5.3
	IF (${CMAKE_MRPT_GCC_VERSION_MAJOR} LESS 5 OR (${CMAKE_MRPT_GCC_VERSION_MAJOR} EQUAL 5 AND ${CMAKE_MRPT_GCC_VERSION_MINOR} LESS 3))
		MESSAGE(FATAL_ERROR "Current gcc version (${CMAKE_MRPT_GCC_VERSION_FULL} is less than version 5.3, the required minimum. Exiting.")
	ENDIF()

ENDIF(CMAKE_COMPILER_IS_GNUCXX)
