# -*- python -*-

load(
    "@drake//tools:install.bzl",
    "cmake_config",
    "install",
    "install_cmake_config",
)

package(default_visibility = ["//visibility:public"])

# Lets other packages inspect the CMake code, e.g., for the version number.
filegroup(
    name = "cmakelists_with_version",
    srcs = ["octomap/CMakeLists.txt"],
)

# Generates octomath library
cc_library(
    name = "octomath",
    srcs = glob([
        "octomap/src/math/*.cpp",
    ]),
    hdrs = glob([
        "octomap/include/octomap/math/*.h*",
    ]),
    includes = ["octomap/include"],
)

# Generates the library exported to users.  The explicitly listed srcs= matches
# upstream's explicitly listed sources.  The globbed hdrs= matches upstream's
# explicitly globbed headers.
cc_library(
    name = "octomap",
    srcs = [
        "octomap/src/AbstractOcTree.cpp",
        "octomap/src/AbstractOccupancyOcTree.cpp",
        "octomap/src/ColorOcTree.cpp",
        "octomap/src/CountingOcTree.cpp",
        "octomap/src/OcTree.cpp",
        "octomap/src/OcTreeLUT.cpp",
        "octomap/src/OcTreeNode.cpp",
        "octomap/src/OcTreeStamped.cpp",
        "octomap/src/Pointcloud.cpp",
        "octomap/src/ScanGraph.cpp",
    ],
    hdrs = glob([
        "octomap/include/octomap/*.h*",
    ]),
    includes = ["octomap/include"],
    deps = [":octomath"],
)

cmake_config(
    package = "octomap",
    script = "@drake//tools:octomap-create-cps.py",
    version_file = ":cmakelists_with_version",
)

# Creates rule :install_cmake_config.
install_cmake_config(package = "octomap")

install(
    name = "install",
    targets = [
        ":octomap",
        ":octomath",
    ],
    hdr_dest = "include",
    hdr_strip_prefix = ["octomap/include"],
    guess_hdrs = "PACKAGE",
    docs = ["octomap/LICENSE.txt"],
    doc_dest = "share/doc",
    deps = [":install_cmake_config"],
)
