Skip to content

Commit

Permalink
conanfile.py: update urdfdom
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Feb 25, 2024
1 parent ae06eed commit 8faa3f6
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def requirements(self):
self.requires("tinyobjloader/2.0.0-rc10")
self.requires("liblzf/3.6")
if "kinematics" in modules:
self.requires("urdfdom/3.1.1")
self.requires("urdfdom/4.0.0@cupoch")
if "visualization" in modules:
self.requires("glew/2.2.0")
self.requires("glfw/3.3.8")
Expand Down
16 changes: 16 additions & 0 deletions third_party/conan-recipes/urdfdom/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
sources:
"4.0.0":
urdfdom:
url: "https://github.com/ros/urdfdom/archive/refs/tags/4.0.0.tar.gz"
sha256: "9848d106dc88dc0b907d5667c09da3ca53241fbcf17e982d8c234fe3e0d6ddcc"
urdfdom_headers:
url: "https://github.com/ros/urdfdom_headers/archive/refs/tags/1.1.1.zip"
sha256: "dde77e3dd96ffa41e2ee0a20bddcd6ef05863e95ce0143ede77130d8cd46c644"
patches:
"4.0.0":
- patch_file: "patches/001-optional-build-apps.patch"
patch_type: "conan"
patch_description: "Disable building of apps by default"
- patch_file: "patches/002-use-conan-dependencies.patch"
patch_type: "conan"
patch_description: "Use dependencies from Conan, use merged urdfdom_headers"
116 changes: 116 additions & 0 deletions third_party/conan-recipes/urdfdom/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import os

from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rm, rmdir
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"


class PackageConan(ConanFile):
name = "urdfdom"
version = "4.0.0"
description = "Data structures and parsers to access URDF files using the DOM model"
license = "BSD-3-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/ros/urdfdom"
topics = ("urdf", "ros", "robotics")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

@property
def _min_cppstd(self):
return 14

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
if Version(self.version) >= "4.0":
self.requires("tinyxml2/10.0.0", transitive_headers=True, transitive_libs=True)
else:
self.requires("tinyxml/2.6.2", transitive_headers=True, transitive_libs=True)
self.requires("console_bridge/1.0.2")

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)

def source(self):
# urdfdom packages its headers separately as urdfdom_headers.
# There is no obvious benefit of doing the same for the Conan package,
# so we simply merge the headers into the main source tree.
sources = self.conan_data["sources"][self.version]
get(self, **sources["urdfdom_headers"], strip_root=True,
destination=os.path.join(self.source_folder, "urdf_parser"))
get(self, **sources["urdfdom"], strip_root=True, destination=self.source_folder)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["APPEND_PROJECT_NAME_TO_INCLUDEDIR"] = False
tc.variables["BUILD_TESTING"] = False
tc.variables["BUILD_APPS"] = False
if not self.options.shared:
tc.preprocessor_definitions["URDFDOM_STATIC"] = "1"
# Need to set CMP0077 because CMake policy version is too old (3.5 as of v4.0.0)
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
tc.generate()
CMakeDeps(self).generate()

def _patch_sources(self):
apply_conandata_patches(self)
# Do not hard-code libraries to SHARED
parser_cmakelists = os.path.join(self.source_folder, "urdf_parser", "CMakeLists.txt")
replace_in_file(self, parser_cmakelists, " SHARED", "")

def build(self):
self._patch_sources()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
# Copy urdfdom_headers
copy(self, "*",
src=os.path.join(self.source_folder, "urdf_parser", "include"),
dst=os.path.join(self.package_folder, "include"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "urdfdom"))
rmdir(self, os.path.join(self.package_folder, "CMake"))
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.pdb", self.package_folder, recursive=True)

def package_info(self):
self.cpp_info.libs = [
"urdfdom_model",
"urdfdom_model_state",
"urdfdom_sensor",
"urdfdom_world",
]

if not self.options.shared:
self.cpp_info.defines.append("URDFDOM_STATIC=1")
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--- urdf_parser/CMakeLists.txt
+++ urdf_parser/CMakeLists.txt
@@ -81,6 +81,7 @@

# --------------------------------

+if(BUILD_APPS)
add_executable(check_urdf src/check_urdf.cpp)
target_include_directories(check_urdf PUBLIC include)
target_link_libraries(check_urdf urdfdom_model urdfdom_world)
@@ -97,6 +98,7 @@
add_executable(urdf_mem_test test/memtest.cpp)
target_include_directories(urdf_mem_test PUBLIC include)
target_link_libraries(urdf_mem_test urdfdom_model)
+endif()

include(CTest)
if(BUILD_TESTING)
@@ -104,6 +106,7 @@
add_subdirectory(test)
endif()

+if(BUILD_APPS)
INSTALL(
TARGETS
check_urdf
@@ -114,6 +117,7 @@
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
+endif()
INSTALL(
TARGETS
urdfdom_model
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -45,11 +45,8 @@

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

-find_package(tinyxml2_vendor QUIET)
find_package(TinyXML2 REQUIRED)

-find_package(urdfdom_headers 1.0 REQUIRED)
-find_package(console_bridge_vendor QUIET) # Provides console_bridge 0.4.0 on platforms without it.
find_package(console_bridge REQUIRED)

# Control where libraries and executables are placed during the build
8 changes: 8 additions & 0 deletions third_party/conan-recipes/urdfdom/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package CXX)

find_package(urdfdom REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE urdfdom::urdfdom)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
26 changes: 26 additions & 0 deletions third_party/conan-recipes/urdfdom/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
15 changes: 15 additions & 0 deletions third_party/conan-recipes/urdfdom/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <cstdlib>
#include <iostream>
#include <string>

#include <urdf_parser/urdf_parser.h>

int main() {
std::string test_str =
"<robot name=\"test\" version=\"1.0\">"
" <link name=\"l1\"/>"
"</robot>";
urdf::ModelInterfaceSharedPtr urdf = urdf::parseURDF(test_str);
std::cout << "urdf::parseURDF() ran successfully" << std::endl;
return EXIT_SUCCESS;
}

0 comments on commit 8faa3f6

Please sign in to comment.