mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
61 lines
2.4 KiB
Python
61 lines
2.4 KiB
Python
load("@rules_cc//cc:defs.bzl", "cc_library")
|
|
|
|
def third_party_cc_lib_helper(
|
|
name,
|
|
include_root,
|
|
src_root = None,
|
|
src_excludes = [],
|
|
visibility = None):
|
|
"""
|
|
Helper for src / headers pairs that aren't directly compiled, but rather pulled into a bigger library.
|
|
|
|
Due to allwpilibs directory structure of includes and sources living next to eachother, it often is required
|
|
to make a header shim to deal with the include path, and a filegroup of the sources. This pattern is extermely
|
|
common for the thirdparty libraries that live beneath certain libraries.
|
|
|
|
This will produce a library shim with the include path stripped, and a filegroup of sources.
|
|
|
|
Params
|
|
include_root: The package relative path to the header files. This will be used to glob the files and strip the include prefix
|
|
src_root: Optional. The package relative path to the source files.
|
|
src_excludes: Optional. Used to exclude files from the src_root glob
|
|
visibilty: The visibility of header shim / source files / package files
|
|
"""
|
|
cc_library(
|
|
name = name + "-headers",
|
|
hdrs = native.glob([
|
|
include_root + "/**",
|
|
]),
|
|
includes = [include_root],
|
|
strip_include_prefix = include_root,
|
|
visibility = visibility,
|
|
)
|
|
|
|
if src_root:
|
|
native.filegroup(
|
|
name = name + "-srcs",
|
|
srcs = native.glob([src_root + "/**"], exclude = src_excludes),
|
|
visibility = visibility,
|
|
)
|
|
|
|
def wpilib_cc_library(
|
|
name,
|
|
srcs = [],
|
|
deps = [],
|
|
third_party_libraries = [],
|
|
third_party_header_only_libraries = [],
|
|
**kwargs):
|
|
"""
|
|
This function is used to ease the creation of a cc_library with helpers for handling thirdparty libraries in the standard allwpilib format.
|
|
|
|
Params:
|
|
third_party_libraries: These are helper dependencies, created by third_party_cc_lib_helper. Header shims will be added as deps and src filegroups will be added to srcs
|
|
third_party_header_only_libraries: Similar to third_party_libraries, but for shims that contain no sources
|
|
"""
|
|
cc_library(
|
|
name = name,
|
|
srcs = srcs + [lib + "-srcs" for lib in third_party_libraries],
|
|
deps = deps + [lib + "-headers" for lib in third_party_libraries + third_party_header_only_libraries],
|
|
**kwargs
|
|
)
|