# -*- bazel -*-

load("@drake//tools/install:install.bzl", "install")
load("@drake//tools/skylark:cc.bzl", "cc_library")

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

cc_library(
    name = "common_robotics_utilities",
    srcs = [
        "src/common_robotics_utilities/base64_helpers.cpp",
        "src/common_robotics_utilities/conversions.cpp",
        "src/common_robotics_utilities/math.cpp",
        "src/common_robotics_utilities/serialization.cpp",
        "src/common_robotics_utilities/time_optimal_trajectory_parametrization.cpp",  # noqa
        "src/common_robotics_utilities/zlib_helpers.cpp",
    ],
    hdrs = [
        "include/common_robotics_utilities/base64_helpers.hpp",
        "include/common_robotics_utilities/color_builder.hpp",
        "include/common_robotics_utilities/conversions.hpp",
        "include/common_robotics_utilities/cru_namespace.hpp",
        "include/common_robotics_utilities/dynamic_spatial_hashed_voxel_grid.hpp",  # noqa
        "include/common_robotics_utilities/gaussian_distributions.hpp",
        "include/common_robotics_utilities/math.hpp",
        "include/common_robotics_utilities/maybe.hpp",
        "include/common_robotics_utilities/openmp_helpers.hpp",
        "include/common_robotics_utilities/parallelism.hpp",
        "include/common_robotics_utilities/path_processing.hpp",
        "include/common_robotics_utilities/print.hpp",
        "include/common_robotics_utilities/random_rotation_generator.hpp",
        "include/common_robotics_utilities/serialization.hpp",
        "include/common_robotics_utilities/simple_astar_search.hpp",
        "include/common_robotics_utilities/simple_dtw.hpp",
        "include/common_robotics_utilities/simple_graph.hpp",
        "include/common_robotics_utilities/simple_graph_search.hpp",
        "include/common_robotics_utilities/simple_hausdorff_distance.hpp",
        "include/common_robotics_utilities/simple_hierarchical_clustering.hpp",
        "include/common_robotics_utilities/simple_kmeans_clustering.hpp",
        "include/common_robotics_utilities/simple_knearest_neighbors.hpp",
        "include/common_robotics_utilities/simple_prm_planner.hpp",
        "include/common_robotics_utilities/simple_prngs.hpp",
        "include/common_robotics_utilities/simple_robot_model_interface.hpp",
        "include/common_robotics_utilities/simple_rrt_planner.hpp",
        "include/common_robotics_utilities/simple_task_planner.hpp",
        "include/common_robotics_utilities/time_optimal_trajectory_parametrization.hpp",  # noqa
        "include/common_robotics_utilities/utility.hpp",
        "include/common_robotics_utilities/voxel_grid.hpp",
        "include/common_robotics_utilities/zlib_helpers.hpp",
    ],
    includes = ["include"],
    copts = ["-w"],
    linkstatic = True,
    deps = [
        "@eigen",
        "@zlib",
    ],
    linkopts = [
        "-pthread",
    ],
)

# N.B. This test uses two threads even when OpenMP is not available.
cc_test(
    name = "hausdorff_distance_test",
    srcs = ["test/hausdorff_distance_test.cpp"],
    env = {"OMP_NUM_THREADS": "2"},
    tags = [
        "cpu:2",
        "no_kcov",
    ],
    deps = [
        ":common_robotics_utilities",
        "@eigen",
        "@gtest//:without_main",
    ],
)

cc_test(
    name = "maybe_test",
    srcs = ["test/maybe_test.cpp"],
    tags = ["no_kcov"],
    deps = [
        ":common_robotics_utilities",
        "@eigen",
        "@gtest//:without_main",
    ],
)

# N.B. This test uses two threads even when OpenMP is not available.
cc_test(
    name = "parallelism_test",
    srcs = ["test/parallelism_test.cpp"],
    env = {"OMP_NUM_THREADS": "2"},
    tags = [
        "cpu:2",
        "no_kcov",
        # Some of these tests take too long under valgrind for CI.
        "no_memcheck",
    ],
    shard_count = 4,
    timeout = "moderate",
    deps = [
        ":common_robotics_utilities",
        "@gtest//:without_main",
    ],
)

# N.B. This test uses two threads even when OpenMP is not available.
cc_test(
    name = "planning_test",
    srcs = ["test/planning_test.cpp"],
    env = {"OMP_NUM_THREADS": "2"},
    tags = [
        "cpu:2",
        "no_kcov",
    ],
    deps = [
        ":common_robotics_utilities",
        "@eigen",
        "@gtest//:without_main",
    ],
)

# N.B. The "test/print_test.cpp" is not added here, because it depends on ROS.

cc_test(
    name = "task_planning_test",
    srcs = ["test/task_planning_test.cpp"],
    tags = ["no_kcov"],
    deps = [
        ":common_robotics_utilities",
        "@gtest//:without_main",
    ],
)

cc_test(
    name = "utility_test",
    srcs = ["test/utility_test.cpp"],
    tags = ["no_kcov"],
    deps = [
        ":common_robotics_utilities",
        "@eigen",
        "@gtest//:without_main",
    ],
)

cc_test(
    name = "voxel_grid_test",
    srcs = ["test/voxel_grid_test.cpp"],
    tags = ["no_kcov"],
    deps = [
        ":common_robotics_utilities",
        "@eigen",
        "@gtest//:without_main",
    ],
)

test_suite(
    name = "test_suite",
    tests = [
        "hausdorff_distance_test",
        "maybe_test",
        "parallelism_test",
        "planning_test",
        "task_planning_test",
        "utility_test",
        "voxel_grid_test",
    ],
)

install(
    name = "install",
    docs = ["LICENSE"],
    visibility = ["//visibility:public"],
)
