tree: f387d11a85d0bb2c15ec290fd917927b33d25140 [path history] [tgz]
  1. lib_a/
  2. lib_b/
  3. BUILD.bazel
  4. lib.cpp
  5. lib.h
  6. README.md
examples/nested/README.md

Nested subpackages example

This is an example of how to use the rules in a nested subpackage that split the project in multiple libraries. Move to the parent directory and run the following command:

bazel build //nested:doxygen

Lib a

The lib_a library is in a subpackage, determined by the presence of a BUILD.bazel file. It must export a filegroup target to make the sources available to the doxygen rule.

# BUILD.bazel file in the lib_a directory
filegroup(
    name = "sources",
    srcs = glob([
        "*.h",
        "*.cpp",
    ]),
    visibility = ["//visibility:public"],
)
# BUILD.bazel file in this directory
doxygen(
    name = "doxygen",
    srcs = glob([
        "*.h",
        "*.cpp",
    ]) + ["//nested/lib_a:sources"],
    configurations = ["INPUT = nested nested/lib_a"]
    project_name = "nested",
)

Lib b

The lib_b library does not have a BUILD.bazel file, so it is not a subpackage. Its files are available to the doxygen rule from its parent directory.

# BUILD.bazel file in this directory
doxygen(
    name = "doxygen",
    srcs = glob([
        "*.h",
        "*.cpp",
        "lib_b/*.h",
        "lib_b/*.cpp",
    ]),
    configurations = ["INPUT = nested nested/lib_b"]
    project_name = "nested",
)

Putting it all together

It is possible to fuse both approaches together, with the following BUILD.bazel file:

doxygen(
    name = "doxygen",
    srcs = glob([
        "*.h",
        "*.cpp",
        "lib_b/*.h",
        "lib_b/*.cpp",
    ]) + ["//nested/lib_a:sources"],
    configurations = [
        "INPUT = nested nested/lib_a nested/lib_b",
    ],
    project_brief = "Example project for doxygen",
    project_name = "nested",
)