Skip to content

Commit

Permalink
[tools] Link ignition-math statically
Browse files Browse the repository at this point in the history
It was an oddball in terms of being a shared library.

TBD This is breaking change, in that it's no longer exported for downstream
projects to build against.
  • Loading branch information
jwnimmer-tri committed Aug 18, 2021
1 parent 1df1c47 commit ec1f2cf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
1 change: 0 additions & 1 deletion tools/install/libdrake/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ cc_library(
":vtk_deps",
":x11_deps",
"//common:drake_marker_shared_library",
"@ignition_math",
"@lcm",
"@spdlog",
"@tinyxml2",
Expand Down
6 changes: 0 additions & 6 deletions tools/install/libdrake/drake.cps
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
"Hints": ["@prefix@/lib/cmake/fmt"],
"X-CMake-Find-Args": ["CONFIG"]
},
"ignition-math6": {
"Version": "6.4",
"Hints": ["@prefix@/lib/cmake/ignition-math6"],
"X-CMake-Find-Args": ["CONFIG"]
},
"lcm": {
"Version": "1.4",
"Hints": ["@prefix@/lib/cmake/lcm"],
Expand Down Expand Up @@ -52,7 +47,6 @@
":drake-marker",
"Eigen3:Eigen",
"fmt:fmt-header-only",
"ignition-math6:ignition-math6",
"lcm:lcm",
"optitrack:optitrack-lcmtypes-cpp",
"spdlog:spdlog",
Expand Down
46 changes: 39 additions & 7 deletions tools/workspace/ignition_math/package.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ load(
"@drake//tools/workspace:check_lists_consistency.bzl",
"check_lists_consistency",
)
load(
"@drake//third_party:com_github_bazelbuild_rules_cc/whole_archive.bzl",
"cc_whole_archive_library",
)
load(
"@drake//tools/install:install.bzl",
"cmake_config",
Expand Down Expand Up @@ -169,11 +173,13 @@ public_headers = public_headers_no_gen + [
"include/ignition/math.hh",
]

# Generates the library exported to users. The explicitly listed srcs= matches
# upstream's explicitly listed sources plus private headers. The explicitly
# listed hdrs= matches upstream's public headers.
cc_binary(
name = "libdrake_ignition_math.so",
# Generates the library. The explicitly listed srcs= matches upstream's
# explicitly listed sources plus private headers. The explicitly listed
# hdrs= matches upstream's public headers.
# TODO(jwnimmer-tri) On 2021-12-01 when the ":ignition_math" target is removed,
# we should rename this to `name = "ignition_math"`, i.e., take over its name.
cc_library(
name = "ignition_math_static",
srcs = [
"src/Angle.cc",
"src/AxisAlignedBox.cc",
Expand All @@ -200,15 +206,35 @@ cc_binary(
"src/Vector3Stats.cc",
] + private_headers + public_headers,
copts = [
"-fvisibility-inlines-hidden",
# TODO(jwnimmer-tri) Ideally, we should use hidden visibility for the
# private builds of our dependencies.
"-w",
],
linkstatic = True,
includes = ["include"],
)

# TODO(jwnimmer-tri) On 2021-12-01 when the ":ignition_math" target is removed,
# we should also remove this target.
cc_whole_archive_library(
name = "ignition_math_static_whole_archive",
deps = [":ignition_math_static"],
visibility = ["//visibility:private"],
)

# TODO(jwnimmer-tri) On 2021-12-01 when the ":ignition_math" target is removed,
# we should also remove this target.
cc_binary(
name = "libdrake_ignition_math.so",
deps = [
":ignition_math_static_whole_archive",
],
linkopts = select({
":linux": ["-Wl,-soname,libdrake_ignition_math.so"],
"//conditions:default": [],
}),
linkshared = 1,
linkstatic = 1,
visibility = [],
)

Expand All @@ -217,11 +243,15 @@ cc_library(
srcs = ["libdrake_ignition_math.so"],
hdrs = public_headers,
includes = ["include"],
visibility = ["//visibility:public"],
deprecation = "DRAKE DEPRECATED: The @ignition_math external is becoming private to Drake. The shared library will no longer be available nor installed from Drake on or after 2021-12-01.", # noqa
)

# TODO(jwnimmer-tri) On 2021-12-01 when the ":ignition_math" target is removed,
# we should also remove this constant.
CMAKE_PACKAGE = "ignition-math%d" % (PROJECT_MAJOR)

# TODO(jwnimmer-tri) On 2021-12-01 when the ":ignition_math" target is removed,
# we should also remove this target. Be sure to remove the *-cps.py file, also.
cmake_config(
package = CMAKE_PACKAGE,
script = "@drake//tools/workspace/ignition_math:package-create-cps.py",
Expand All @@ -231,6 +261,8 @@ cmake_config(
# Creates rule :install_cmake_config.
install_cmake_config(package = CMAKE_PACKAGE)

# TODO(jwnimmer-tri) On 2021-12-01 when the ":ignition_math" target is removed,
# this target should remove all of its attributes other than "name" and "docs".
install(
name = "install",
workspace = CMAKE_PACKAGE,
Expand Down
2 changes: 1 addition & 1 deletion tools/workspace/sdformat/package.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ cc_library(
linkstatic = 1,
deps = [
":urdfdom",
"@ignition_math",
"@ignition_math//:ignition_math_static",
"@ignition_utils",
"@tinyxml2",
],
Expand Down

0 comments on commit ec1f2cf

Please sign in to comment.