function(load_hardware_version BOARD_HEADER_FILE BOARD_NAME BOARD_VERSION)
  message(STATUS "Search for board name ${BOARD_NAME} in header file")
  if(EXISTS ${BOARD_HEADER_FILE})
    file(STRINGS ${BOARD_HEADER_FILE} ConfigContents)
    foreach(Line ${ConfigContents})
      string(REGEX MATCH "^#define.*" NameAndValue ${Line})
        
      if(NOT NameAndValue STREQUAL "")
        string(REGEX MATCH "^#define +([0-9a-zA-Z_]+) +([0-9]+)" Tmp ${NameAndValue})
        set(Name ${CMAKE_MATCH_1})
        set(Version ${CMAKE_MATCH_2})
        if(Name STREQUAL BOARD_NAME)
          message(STATUS "Found ${Name} (it has indeed version ${Version})")
          break()
        endif()
      endif()
    endforeach()
  else()
    message(STATUS "The file ${BOARD_HEADER_FILE} does not exist")
  endif()
  set(${BOARD_VERSION} "${Version}" PARENT_SCOPE)
endfunction()

function(load_board_name BOARD_HEADER_FILE BOARD_NAME BOARD_VERSION)
  message(STATUS "Search for board version ${BOARD_VERSION} in header file")
  if(EXISTS ${BOARD_HEADER_FILE})
    file(STRINGS ${BOARD_HEADER_FILE} ConfigContents)
    foreach(Line ${ConfigContents})
      string(REGEX MATCH "^#define.*" NameAndValue ${Line})
        
      if(NOT NameAndValue STREQUAL "")
        string(REGEX MATCH "^#define +([0-9a-zA-Z_]+) +([0-9]+)" Tmp ${NameAndValue})
        set(Name ${CMAKE_MATCH_1})
        set(Version ${CMAKE_MATCH_2})
        if(Version STREQUAL BOARD_VERSION) 
          message(STATUS "Found ${Name} (it has indeed version ${Version})")
          break()
        endif()
      endif()
    endforeach()
  else()
    message(STATUS "The file ${BOARD_HEADER_FILE} does not exist")
  endif()
  set(${BOARD_NAME} "${Name}" PARENT_SCOPE)
endfunction()
