function(cmcs_variable_exists_or_error_impl)
    cmcs_create_function_variable_prefix(_VAR_PREFIX)
    cmake_parse_arguments("${_VAR_PREFIX}" "" "PREFIX" "VARIABLE_NAMES" ${ARGN})
    foreach(_variable IN LISTS _cmcs_eoe_impl_VARIABLE_NAMES)
        if(DEFINED ${_VAR_PREFIX}_PREFIX AND NOT ${${_VAR_PREFIX}_PREFIX} MATCHES "^[\\\t ]+$") 
            # Variables are prefixed 
            if(NOT DEFINED ${${_VAR_PREFIX}_PREFIX}_${_variable} OR ${${_VAR_PREFIX}_PREFIX}_${_variable} MATCHES "^[\\\t ]+$")
                message(${CMakeCS_MSG_ERROR_TYPE} "Function call requires parameter ${_variable}! (prefixed)")
            endif()
        else() 
            # Variables are not prefixed 
            if(NOT DEFINED ${_variable} OR "x${_variable}x" STREQUAL "xx")
                message(${CMakeCS_MSG_ERROR_TYPE} "Function call requires parameter ${_variable}!")
            endif()
        endif()
    endforeach()
endfunction()

function(cmcs_variable_exists_or_error)
    cmcs_create_function_variable_prefix(_VAR_PREFIX)
    cmake_parse_arguments(PARSE_ARGV 0 "${_VAR_PREFIX}" "" "PREFIX" "VARIABLE_NAMES" )
    cmcs_variable_exists_or_error_impl(PREFIX "${_VAR_PREFIX}" VARIABLE_NAMES "VARIABLE_NAMES")
    cmcs_variable_exists_or_error_impl(PREFIX ${${_VAR_PREFIX}_PREFIX} VARIABLE_NAMES ${${_VAR_PREFIX}_VARIABLE_NAMES})
endfunction()

macro(cmcs_variable_exists_or_default_impl)
    cmcs_variable_exists_or_error_impl(PREFIX ${${_VAR_PREFIX}_PREFIX} VARIABLE_NAMES "VARIABLE;DEFAULT")
    if(DEFINED ${_VAR_PREFIX}_PREFIX) 
        # Variable is prefixed 
        if(NOT DEFINED ${${_VAR_PREFIX}_PREFIX}_${${_VAR_PREFIX}_VARIABLE})
            set( ${${_VAR_PREFIX}_PREFIX}_${${_VAR_PREFIX}_VARIABLE} ${${${_VAR_PREFIX}_PREFIX}_${${_VAR_PREFIX}_DEFAULT}})
            message(TRACE "Variable: ${${_VAR_PREFIX}_PREFIX}_${${_VAR_PREFIX}_VARIABLE} set to default value!")
        endif()
        cmcs_return_variables(${${_VAR_PREFIX}_PREFIX}_${${_VAR_PREFIX}_VARIABLE})
    else() 
        # Variable is not prefixed 
        if(NOT DEFINED ${${_VAR_PREFIX}_VARIABLE})
            set( ${${_VAR_PREFIX}_VARIABLE} ${${_VAR_PREFIX}_DEFAULT})
            message(TRACE "Variable: ${${_VAR_PREFIX}_VARIABLE} set to default value!")
        endif()
        cmcs_return_variables(${${_VAR_PREFIX}_VARIABLE})
    endif()
endmacro()

function(cmcs_variable_exists_or_default)
    cmcs_create_function_variable_prefix(_VAR_PREFIX)
    set(${_VAR_PREFIX}_PASS_DEFAULT_TO_PARENT)
    cmake_parse_arguments(PARSE_ARGV 0 "${_VAR_PREFIX}" "" "PREFIX;VARIABLE;DEFAULT" "")
    cmcs_trace_variables(_VAR_PREFIX ${_VAR_PREFIX}_PREFIX ${_VAR_PREFIX}_VARIABLE ${_VAR_PREFIX}_DEFAULT) 
    cmcs_variable_exists_or_default_impl(PREFIX ${${_VAR_PREFIX}_PREFIX} VARIABLE ${${_VAR_PREFIX}_VARIABLE} DEFAULT ${${_VAR_PREFIX}_DEFAULT})
    cmcs_trace_variables(${${_VAR_PREFIX}_VARIABLE}) 
endfunction()

