include_guard(GLOBAL)

macro(ixm_dict_noop dict)
  if (NOT TARGET ${dict})
    return()
  endif()
endmacro()

function (ixm_dict_create dict)
  if (NOT TARGET ${dict})
    add_library(${dict} INTERFACE IMPORTED)
  endif()
endfunction()

function (ixm_dict_filepath result path ext)
  if (NOT path MATCHES ".+[.]${ext}")
    set(path "${path}.${ext}")
  endif()
  if (NOT IS_ABSOLUTE "${path}")
    get_filename_component(path "${path}" ABSOLUTE
      BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
  endif()
  set(${result} "${path}" PARENT_SCOPE)
endfunction()

function (ixm_dict_codes)
  if (DEFINED CACHE{+C0})
    return()
  endif()
  string(ASCII 194 133 newline)
  string(ASCII 194 134 index)
  string(ASCII 192 invalid)
  string(ASCII 31 unit-separator)
  string(ASCII 30 record-separator)
  set(+NEL ${newline} CACHE INTERNAL "C1 New Line Control Code")
  set(+IDX ${index} CACHE INTERNAL "C1 Carriage Return Control Code")
  set(+RS ${record-separator} CACHE INTERNAL "C0 Record Separator Control Code")
  set(+US ${unit-separator} CACHE INTERNAL "C0 Unit Separator Control Code")
  set(+C0 ${invalid} CACHE INTERNAL "Internal IXM Use Only")
  mark_as_advanced(FORCE +NEL)
  mark_as_advanced(FORCE +IDX)
  mark_as_advanced(FORCE +RS)
  mark_as_advanced(FORCE +US)
  mark_as_advanced(FORCE +C0)
endfunction()

ixm_dict_codes()
