CMAKE_MINIMUM_REQUIRED(VERSION 3.8)


# Check if the target system is supported

FUNCTION(IS_SUPPORTED)

	SET(COMPOSITE_SYSTEM ${CMAKE_SYSTEM}-${CMAKE_SYSTEM_PROCESSOR})

	IF(UNIX OR CYGWIN)

		MESSAGE(STATUS "System ${COMPOSITE_SYSTEM} is supported")

	ELSE(UNIX OR CYGWIN)

		MESSAGE(FATAL_ERROR "System ${COMPOSITE_SYSTEM} is not supported")

	ENDIF(UNIX OR CYGWIN)

ENDFUNCTION(IS_SUPPORTED)


# Print detected host system information

FUNCTION(DESCRIBE_HOST)

	MESSAGE(STATUS "Host system: ${CMAKE_HOST_SYSTEM}")

	MESSAGE(STATUS "Host processor: ${CMAKE_HOST_SYSTEM_PROCESSOR}")

ENDFUNCTION(DESCRIBE_HOST)


# Print detected target system information

FUNCTION(DESCRIBE_TARGET)

	MESSAGE(STATUS "Target system: ${CMAKE_SYSTEM}")

	MESSAGE(STATUS "Target processor: ${CMAKE_SYSTEM_PROCESSOR}")

ENDFUNCTION(DESCRIBE_TARGET)


# Create file listing

FUNCTION(LIST_FILES GLOB_EXPRESSION RETVAL)

	FILE(GLOB RESULT LIST_DIRECTORIES FALSE ${GLOB_EXPRESSION})

	SET(${RETVAL} ${RESULT} PARENT_SCOPE)

ENDFUNCTION(LIST_FILES)


# Store variable listing to a file

FUNCTION(LIST_VARIABLES TO_FILE)

	GET_PROPERTY(OPTS DIRECTORY ./ PROPERTY VARIABLES)

	FOREACH(OPT ${OPTS})

		GET_PROPERTY(P VARIABLE PROPERTY ${OPT})

		FILE(APPEND ${TO_FILE} "${OPT}: ${P}\n")

	ENDFOREACH(OPT)

ENDFUNCTION(LIST_VARIABLES)
