
macro(PRINT_LINE num_chars)
    set(_line_padding "")
    foreach(x RANGE ${num_chars})
        set(_line_padding "${_line_padding}=")
    endforeach()
    message(STATUS "${_line_padding}")
    unset(_line_padding)
endmacro()

macro(SET_MIN_PADDING padded_string input_string min_padding)
    string(LENGTH "${input_string}" num_filled_chars)
    math(EXPR char_difference "${min_padding} - ${num_filled_chars}")
    set(padding "")
    # adding the correct amount of space
    foreach(x RANGE ${char_difference})
        set(padding "${padding} ")
    endforeach()
    set(${padded_string} "${input_string}${padding}")
    # unset locals since this is a macro
    unset(num_filled_chars)
    unset(char_difference)
    unset(padding)
endmacro()

# Shows a listing of the major build configuration variables.
# Usage:
#   show_vars()
macro(SHOW_VARS)
    get_cmake_property(_variableNames VARIABLES)
    # we first find the max length of all the variable names we'd like to show_vars
    # this is just to keep things somewhat organized in the console
    set(max_key_length "0")
    foreach (_variableName ${_variableNames})
        string(REGEX MATCH "MBED_TARGET_|MBED_AVAILABLE_TARGETS.*" IS_MBED_MATCH "${_variableName}")
        if("${IS_MBED_MATCH}" STREQUAL "")
            string(REGEX MATCH "_eigen3_" IS_DEFINE_MATCH "${_variableName}")
            string(REGEX MATCH "\\/\\*" IS_FILE_CONTENTS1 "${${_variableName}}")
            string(REGEX MATCH "^# " IS_FILE_CONTENTS2 "${${_variableName}}")
            if("${IS_DEFINE_MATCH}" STREQUAL "")
                if("${IS_FILE_CONTENTS1}" STREQUAL "")
                    if("${IS_FILE_CONTENTS2}" STREQUAL "")
                        string(LENGTH "${_variableName}" this_length)
                        if(${this_length} GREATER ${max_key_length})
                            set(max_key_length ${this_length})
                        endif()
                    endif()
                endif()
            endif()
        endif()
    endforeach()
    unset(IS_FILE_CONTENTS1)
    unset(IS_FILE_CONTENTS2)
    print_line(100)
    # now we display the variables and their values, using the indent variable we just defined
    foreach (_variableName ${_variableNames})
        string(REGEX MATCH "MBED_TARGET_|MBED_AVAILABLE_TARGETS.*" IS_MBED_MATCH "${_variableName}")
        if("${IS_MBED_MATCH}" STREQUAL "")
            string(REGEX MATCH "_eigen3_" IS_DEFINE_MATCH "${_variableName}")
            string(REGEX MATCH "\\/\\*" IS_FILE_CONTENTS1 "${${_variableName}}")
            string(REGEX MATCH "^# " IS_FILE_CONTENTS2 "${${_variableName}}")
            if("${IS_DEFINE_MATCH}" STREQUAL "")
                if("${IS_FILE_CONTENTS1}" STREQUAL "")
                    if("${IS_FILE_CONTENTS2}" STREQUAL "")
                        set_min_padding(paddedVariable ${_variableName} ${max_key_length})
                        message(STATUS "${paddedVariable} =>  ${${_variableName}}")
                    endif()
                endif()
            endif()
        endif()
    endforeach()
    print_line(100)
    # unset locals since this is a macro
    unset(IS_FILE_CONTENTS1)
    unset(IS_FILE_CONTENTS2)
    unset(max_key_length)
    unset(this_length)
endmacro()
  
