Skip to content

Commit

Permalink
Update bazel files
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <michael@openrobotics.org>
  • Loading branch information
mjcarroll committed Feb 16, 2023
1 parent 09d69f4 commit 1255925
Show file tree
Hide file tree
Showing 16 changed files with 483 additions and 149 deletions.
151 changes: 151 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_ROOT",
"GZ_VISIBILITY",
"gz_configure_header",
"gz_export_header",
"gz_include_header",
)
load("@gz//bazel/skylark:gz_py.bzl", "gz_py_binary")

package(
default_visibility = GZ_VISIBILITY,
features = GZ_FEATURES,
)

licenses(["notice"]) # Apache-2.0

exports_files(["LICENSE"])

gz_configure_header(
name = "config",
src = "include/sdf/config.hh.in",
cmakelists = ["CMakeLists.txt"],
defines = {
"CMAKE_INSTALL_FULL_DATAROOTDIR": "",
},
package = "sdformat",
)

gz_py_binary(
name = "embed_sdf",
srcs = ["sdf/embedSdf.py"],
)

genrule(
name = "embed_sdf_genrule",
srcs = glob([
"sdf/**/*.sdf",
"sdf/**/*.convert",
]),
outs = ["EmbeddedSdf.cc"],
cmd = "$(execpath :embed_sdf) --output-file $@ --sdf-root ./sdformat/sdf --input-files $(SRCS)", # noqa
tools = [":embed_sdf"],
)

public_headers_no_gen = glob([
"include/sdf/*.h",
"include/sdf/*.hh",
])

private_headers = glob(["src/*.hh"])

sources = glob(
["src/*.cc"],
exclude = [
"src/*_TEST.cc",
"src/gz.cc",
],
)

gz_export_header(
name = "include/sdf/Export.hh",
export_base = "GZ_SDFORMAT",
lib_name = "sdf",
visibility = ["//visibility:private"],
)

gz_include_header(
name = "sdformat_hh_genrule",
out = "include/sdformat.hh",
hdrs = public_headers_no_gen + [
"include/sdf/config.hh",
"include/sdf/Export.hh",
],
)

public_headers = public_headers_no_gen + [
"include/sdf/Export.hh",
"include/sdf/config.hh",
"include/sdformat.hh",
]

cc_library(
name = "urdf",
srcs = [
"src/urdf/urdf_parser/joint.cpp",
"src/urdf/urdf_parser/link.cpp",
"src/urdf/urdf_parser/model.cpp",
"src/urdf/urdf_parser/pose.cpp",
"src/urdf/urdf_parser/twist.cpp",
"src/urdf/urdf_parser/urdf_model_state.cpp",
"src/urdf/urdf_parser/urdf_sensor.cpp",
"src/urdf/urdf_parser/world.cpp",
],
hdrs = glob(
["src/urdf/**/*.h"],
),
copts = ["-Wno-unknown-pragmas"],
includes = ["src/urdf"],
deps = [
"@tinyxml2",
],
)

cc_library(
name = "sdformat",
srcs = sources + private_headers + ["EmbeddedSdf.cc"],
hdrs = public_headers,
includes = [
"include",
"src",
],
defines = [
'SDF_SHARE_PATH=\\".\\"',
'SDF_VERSION_PATH=\\"sdformat\\"',
],
deps = [
":urdf",
GZ_ROOT + "math",
GZ_ROOT + "utils",
"@tinyxml2",
],
)

test_sources = glob(
["src/*_TEST.cc"],
exclude = ["src/gz_TEST.cc"],
)

[cc_test(
name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
srcs = [src],
data = [
"sdf",
GZ_ROOT + "sdformat/test:integration",
GZ_ROOT + "sdformat/test:sdf",
],
env = {
"GZ_BAZEL": "1",
"GZ_BAZEL_PATH": "sdformat",
},
deps = [
":sdformat",
GZ_ROOT + "sdformat/test:test_utils",
"@gtest",
"@gtest//:gtest_main",
],
) for src in test_sources]

exports_files(["sdf"])
5 changes: 5 additions & 0 deletions include/sdf/config.hh.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@

#cmakedefine SDFORMAT_DISABLE_CONSOLE_LOGFILE 1

#ifndef SDF_SHARE_PATH
#define SDF_SHARE_PATH "${CMAKE_INSTALL_FULL_DATAROOTDIR}/"
#endif

#ifndef SDF_VERSION_PATH
#define SDF_VERSION_PATH "${CMAKE_INSTALL_FULL_DATAROOTDIR}/sdformat${SDF_MAJOR_VERSION}/${SDF_PKG_VERSION}"
#endif

#endif // #ifndef SDF_CONFIG_HH_
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ if (BUILD_TESTING)
XmlUtils.cc)
endif()

if (TARGET UNIT_gz_TEST)
target_compile_definitions(UNIT_gz_TEST PRIVATE
-DGZ_PATH="${GZ_PROGRAM}"
-DGZ_CONFIG_PATH="${CMAKE_BINARY_DIR}/test/conf"
-DGZ_TEST_LIBRARY_PATH="${PROJECT_BINARY_DIR}/src")
endif()

if (TARGET UNIT_FrameSemantics_TEST)
target_sources(UNIT_FrameSemantics_TEST PRIVATE FrameSemantics.cc Utils.cc)
target_link_libraries(UNIT_FrameSemantics_TEST TINYXML2::TINYXML2)
Expand Down
13 changes: 11 additions & 2 deletions src/SDF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ inline namespace SDF_VERSION_NAMESPACE
// returns the version string when possible.
std::string SDF::version = SDF_VERSION; // NOLINT(runtime/string)

std::string sdfSharePath()
{
#ifdef SDF_SHARE_PATH
if (std::string(SDF_SHARE_PATH) != "/")
return SDF_SHARE_PATH;
#endif
return "";
}

/////////////////////////////////////////////////
void setFindCallback(std::function<std::string(const std::string &)> _cb)
{
Expand Down Expand Up @@ -98,14 +107,14 @@ std::string findFile(const std::string &_filename, bool _searchLocalPath,
}

// Next check the install path.
std::string path = sdf::filesystem::append(SDF_SHARE_PATH, filename);
std::string path = sdf::filesystem::append(sdfSharePath(), filename);
if (sdf::filesystem::exists(path))
{
return path;
}

// Next check the versioned install path.
path = sdf::filesystem::append(SDF_SHARE_PATH,
path = sdf::filesystem::append(sdfSharePath(),
"sdformat" SDF_MAJOR_VERSION_STR,
sdf::SDF::Version(), filename);
if (sdf::filesystem::exists(path))
Expand Down
Loading

0 comments on commit 1255925

Please sign in to comment.