# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

source_set("msgs") {
  sources = [
    target_gen_dir + "/osp_messages.cc",
    target_gen_dir + "/osp_messages.h",
  ]

  public_deps = [ ":cddl_gen" ]
  deps = [
    "../../third_party/abseil",
    "../../third_party/tinycbor",
  ]

  public_configs = [
    ":cddl_gen_config",
    "../../build:openscreen_include_dirs",
  ]
}

config("cddl_gen_config") {
  include_dirs = [ "$root_gen_dir" + "/" + rebase_path("../..", "//") ]
}

action("cddl_gen") {
  script = "../../tools/cddl/cddl.py"
  sources = [ "osp_messages.cddl" ]
  outputs_src = rebase_path([
                              "osp_messages.h",
                              "osp_messages.cc",
                            ],
                            "//")
  outputs = []
  foreach(o, outputs_src) {
    outputs += [ root_gen_dir + "/" + o ]
  }

  cddl_label = "../../tools/cddl:cddl($host_toolchain)"
  cddl_path = get_label_info(cddl_label, "root_out_dir") + "/cddl"
  args =
      [
        "--cddl",

        # Path should be rebased because |root_build_dir| for current toolchain
        # may be different from |root_out_dir| of cddl built on host toolchain.
        "./" + rebase_path(cddl_path, root_build_dir),
        "--header",
        outputs_src[0],
        "--cc",
        outputs_src[1],
        "--gen-dir",
        rebase_path(root_gen_dir, root_build_dir),
        "--log",
        rebase_path("cddl.log", "//"),
      ] + rebase_path(sources, root_build_dir)

  deps = [ cddl_label ]
}

source_set("unittests") {
  testonly = true

  sources = [ "messages_unittest.cc" ]

  deps = [
    ":msgs",
    "../../third_party/googletest:gtest",
  ]
}