
function(GET_SYSTEM_NAME RETURN_SYSTEM_NAME)
  if(WIN32)
    set(SYSTEM_NAME "Windows" )
  elseif(APPLE)
    execute_process(COMMAND sw_vers -productName RESULT_VARIABLE COMMAND_RESULT OUTPUT_VARIABLE PRODUCT_NAME )
    string(STRIP ${PRODUCT_NAME} PRODUCT_NAME )
    execute_process(COMMAND sw_vers -productVersion RESULT_VARIABLE COMMAND_RESULT OUTPUT_VARIABLE PRODUCT_VERSION )
    string(STRIP ${PRODUCT_VERSION} PRODUCT_VERSION )
    string(REPLACE " " "-" SYSTEM_NAME "${PRODUCT_NAME} ${PRODUCT_VERSION}" )
  elseif(UNIX)
    find_program(LSB lsb_release DOC "Distribution information tool")
    mark_as_advanced(LSB)
    if(LSB)
      execute_process(COMMAND ${LSB} -i
        RESULT_VARIABLE RETFLAG
        OUTPUT_VARIABLE DISTINFO
        ERROR_VARIABLE ERRDISTINFO
        OUTPUT_STRIP_TRAILING_WHITESPACE
      )
      if (NOT RETFLAG)
        string(SUBSTRING ${DISTINFO} 16 -1 SYSTEM_NAME)
      endif()
    endif()
    if (NOT SYSTEM_NAME)
      execute_process(COMMAND cat /etc/issue RESULT_VARIABLE COMMAND_RESULT OUTPUT_VARIABLE COMMAND_OUTPUT ERROR_VARIABLE ERROR_OUTPUT)
      if (COMMAND_RESULT EQUAL 0)
        if (NOT COMMAND_OUTPUT MATCHES "^\\\\")
          string(REGEX MATCH "^[^\\]*" COMMAND_OUTPUT ${COMMAND_OUTPUT} )
          string(STRIP ${COMMAND_OUTPUT} COMMAND_OUTPUT )
          string(REPLACE " " "-" SYSTEM_NAME ${COMMAND_OUTPUT} )
        endif()
      endif()
    endif()
    if(NOT SYSTEM_NAME)
      execute_process(COMMAND cat /etc/os-release RESULT_VARIABLE COMMAND_RESULT OUTPUT_VARIABLE COMMAND_OUTPUT ERROR_VARIABLE ERROR_OUTPUT)
      if (COMMAND_RESULT EQUAL 0)
        string(REGEX MATCH "^NAME=\\\"([^\\\"]*)" NAME_OUTPUT ${COMMAND_OUTPUT})
        string(REPLACE " " "-" SYSTEM_NAME ${CMAKE_MATCH_1})
      endif()
    endif()
    if (NOT SYSTEM_NAME)
      set(SYSTEM_NAME Unix-Based)
    endif()
  else()
    message( FATAL_ERROR "Don't yet know this system." )
  endif()

  string(REPLACE "\n" "_" SYSTEM_NAME ${SYSTEM_NAME})

  set(${RETURN_SYSTEM_NAME} ${SYSTEM_NAME} PARENT_SCOPE)
endfunction()

function(DEBIAN_BASED _RESULT)
  set(_DEBIAN_BASED FALSE)
  string(FIND ${LIBCELLML_SYSTEM} "Ubuntu" INDEX)
  if(INDEX EQUAL 0)
    set(_DEBIAN_BASED TRUE)
  elseif(EXISTS "/etc/debian_version")
    set(_DEBIAN_BASED TRUE)
  endif()
  set(${_RESULT} ${_DEBIAN_BASED} PARENT_SCOPE)
endfunction()

function(REDHAT_BASED _RESULT)
  set(_REDHAT_BASED FALSE)
  if(EXISTS "/etc/redhat-release")
    set(_REDHAT_BASED TRUE)
  elseif(EXISTS "/etc/centos-release")
    set(_REDHAT_BASED TRUE)
  endif()
  set(${_RESULT} ${_REDHAT_BASED} PARENT_SCOPE)
endfunction()
