Skip to content

Commit 8faa3f6

Browse files
committed
conanfile.py: update urdfdom
1 parent ae06eed commit 8faa3f6

File tree

8 files changed

+230
-1
lines changed

8 files changed

+230
-1
lines changed

conanfile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def requirements(self):
150150
self.requires("tinyobjloader/2.0.0-rc10")
151151
self.requires("liblzf/3.6")
152152
if "kinematics" in modules:
153-
self.requires("urdfdom/3.1.1")
153+
self.requires("urdfdom/4.0.0@cupoch")
154154
if "visualization" in modules:
155155
self.requires("glew/2.2.0")
156156
self.requires("glfw/3.3.8")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sources:
2+
"4.0.0":
3+
urdfdom:
4+
url: "https://github.com/ros/urdfdom/archive/refs/tags/4.0.0.tar.gz"
5+
sha256: "9848d106dc88dc0b907d5667c09da3ca53241fbcf17e982d8c234fe3e0d6ddcc"
6+
urdfdom_headers:
7+
url: "https://github.com/ros/urdfdom_headers/archive/refs/tags/1.1.1.zip"
8+
sha256: "dde77e3dd96ffa41e2ee0a20bddcd6ef05863e95ce0143ede77130d8cd46c644"
9+
patches:
10+
"4.0.0":
11+
- patch_file: "patches/001-optional-build-apps.patch"
12+
patch_type: "conan"
13+
patch_description: "Disable building of apps by default"
14+
- patch_file: "patches/002-use-conan-dependencies.patch"
15+
patch_type: "conan"
16+
patch_description: "Use dependencies from Conan, use merged urdfdom_headers"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import os
2+
3+
from conan import ConanFile
4+
from conan.tools.build import check_min_cppstd
5+
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
6+
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rm, rmdir
7+
from conan.tools.scm import Version
8+
9+
required_conan_version = ">=1.53.0"
10+
11+
12+
class PackageConan(ConanFile):
13+
name = "urdfdom"
14+
version = "4.0.0"
15+
description = "Data structures and parsers to access URDF files using the DOM model"
16+
license = "BSD-3-Clause"
17+
url = "https://github.com/conan-io/conan-center-index"
18+
homepage = "https://github.com/ros/urdfdom"
19+
topics = ("urdf", "ros", "robotics")
20+
package_type = "library"
21+
settings = "os", "arch", "compiler", "build_type"
22+
options = {
23+
"shared": [True, False],
24+
"fPIC": [True, False],
25+
}
26+
default_options = {
27+
"shared": False,
28+
"fPIC": True,
29+
}
30+
31+
@property
32+
def _min_cppstd(self):
33+
return 14
34+
35+
def export_sources(self):
36+
export_conandata_patches(self)
37+
38+
def config_options(self):
39+
if self.settings.os == "Windows":
40+
del self.options.fPIC
41+
42+
def configure(self):
43+
if self.options.shared:
44+
self.options.rm_safe("fPIC")
45+
46+
def layout(self):
47+
cmake_layout(self, src_folder="src")
48+
49+
def requirements(self):
50+
if Version(self.version) >= "4.0":
51+
self.requires("tinyxml2/10.0.0", transitive_headers=True, transitive_libs=True)
52+
else:
53+
self.requires("tinyxml/2.6.2", transitive_headers=True, transitive_libs=True)
54+
self.requires("console_bridge/1.0.2")
55+
56+
def validate(self):
57+
if self.settings.compiler.cppstd:
58+
check_min_cppstd(self, self._min_cppstd)
59+
60+
def source(self):
61+
# urdfdom packages its headers separately as urdfdom_headers.
62+
# There is no obvious benefit of doing the same for the Conan package,
63+
# so we simply merge the headers into the main source tree.
64+
sources = self.conan_data["sources"][self.version]
65+
get(self, **sources["urdfdom_headers"], strip_root=True,
66+
destination=os.path.join(self.source_folder, "urdf_parser"))
67+
get(self, **sources["urdfdom"], strip_root=True, destination=self.source_folder)
68+
69+
def generate(self):
70+
tc = CMakeToolchain(self)
71+
tc.variables["APPEND_PROJECT_NAME_TO_INCLUDEDIR"] = False
72+
tc.variables["BUILD_TESTING"] = False
73+
tc.variables["BUILD_APPS"] = False
74+
if not self.options.shared:
75+
tc.preprocessor_definitions["URDFDOM_STATIC"] = "1"
76+
# Need to set CMP0077 because CMake policy version is too old (3.5 as of v4.0.0)
77+
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
78+
tc.generate()
79+
CMakeDeps(self).generate()
80+
81+
def _patch_sources(self):
82+
apply_conandata_patches(self)
83+
# Do not hard-code libraries to SHARED
84+
parser_cmakelists = os.path.join(self.source_folder, "urdf_parser", "CMakeLists.txt")
85+
replace_in_file(self, parser_cmakelists, " SHARED", "")
86+
87+
def build(self):
88+
self._patch_sources()
89+
cmake = CMake(self)
90+
cmake.configure()
91+
cmake.build()
92+
93+
def package(self):
94+
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
95+
cmake = CMake(self)
96+
cmake.install()
97+
# Copy urdfdom_headers
98+
copy(self, "*",
99+
src=os.path.join(self.source_folder, "urdf_parser", "include"),
100+
dst=os.path.join(self.package_folder, "include"))
101+
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
102+
rmdir(self, os.path.join(self.package_folder, "lib", "urdfdom"))
103+
rmdir(self, os.path.join(self.package_folder, "CMake"))
104+
rmdir(self, os.path.join(self.package_folder, "share"))
105+
rm(self, "*.pdb", self.package_folder, recursive=True)
106+
107+
def package_info(self):
108+
self.cpp_info.libs = [
109+
"urdfdom_model",
110+
"urdfdom_model_state",
111+
"urdfdom_sensor",
112+
"urdfdom_world",
113+
]
114+
115+
if not self.options.shared:
116+
self.cpp_info.defines.append("URDFDOM_STATIC=1")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--- urdf_parser/CMakeLists.txt
2+
+++ urdf_parser/CMakeLists.txt
3+
@@ -81,6 +81,7 @@
4+
5+
# --------------------------------
6+
7+
+if(BUILD_APPS)
8+
add_executable(check_urdf src/check_urdf.cpp)
9+
target_include_directories(check_urdf PUBLIC include)
10+
target_link_libraries(check_urdf urdfdom_model urdfdom_world)
11+
@@ -97,6 +98,7 @@
12+
add_executable(urdf_mem_test test/memtest.cpp)
13+
target_include_directories(urdf_mem_test PUBLIC include)
14+
target_link_libraries(urdf_mem_test urdfdom_model)
15+
+endif()
16+
17+
include(CTest)
18+
if(BUILD_TESTING)
19+
@@ -104,6 +106,7 @@
20+
add_subdirectory(test)
21+
endif()
22+
23+
+if(BUILD_APPS)
24+
INSTALL(
25+
TARGETS
26+
check_urdf
27+
@@ -114,6 +117,7 @@
28+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
29+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
30+
)
31+
+endif()
32+
INSTALL(
33+
TARGETS
34+
urdfdom_model
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--- CMakeLists.txt
2+
+++ CMakeLists.txt
3+
@@ -45,11 +45,8 @@
4+
5+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
6+
7+
-find_package(tinyxml2_vendor QUIET)
8+
find_package(TinyXML2 REQUIRED)
9+
10+
-find_package(urdfdom_headers 1.0 REQUIRED)
11+
-find_package(console_bridge_vendor QUIET) # Provides console_bridge 0.4.0 on platforms without it.
12+
find_package(console_bridge REQUIRED)
13+
14+
# Control where libraries and executables are placed during the build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(test_package CXX)
3+
4+
find_package(urdfdom REQUIRED CONFIG)
5+
6+
add_executable(${PROJECT_NAME} test_package.cpp)
7+
target_link_libraries(${PROJECT_NAME} PRIVATE urdfdom::urdfdom)
8+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from conan import ConanFile
2+
from conan.tools.build import can_run
3+
from conan.tools.cmake import cmake_layout, CMake
4+
import os
5+
6+
7+
class TestPackageConan(ConanFile):
8+
settings = "os", "arch", "compiler", "build_type"
9+
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
10+
test_type = "explicit"
11+
12+
def requirements(self):
13+
self.requires(self.tested_reference_str)
14+
15+
def layout(self):
16+
cmake_layout(self)
17+
18+
def build(self):
19+
cmake = CMake(self)
20+
cmake.configure()
21+
cmake.build()
22+
23+
def test(self):
24+
if can_run(self):
25+
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
26+
self.run(bin_path, env="conanrun")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <cstdlib>
2+
#include <iostream>
3+
#include <string>
4+
5+
#include <urdf_parser/urdf_parser.h>
6+
7+
int main() {
8+
std::string test_str =
9+
"<robot name=\"test\" version=\"1.0\">"
10+
" <link name=\"l1\"/>"
11+
"</robot>";
12+
urdf::ModelInterfaceSharedPtr urdf = urdf::parseURDF(test_str);
13+
std::cout << "urdf::parseURDF() ran successfully" << std::endl;
14+
return EXIT_SUCCESS;
15+
}

0 commit comments

Comments
 (0)