Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignition-math: migrate to Conan v2 #18992

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions recipes/ignition-math/all/CMakeLists.txt

This file was deleted.

9 changes: 1 addition & 8 deletions recipes/ignition-math/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
sources:
"6.7.0":
url: "https://github.com/gazebosim/gz-math/archive/ignition-math6_6.7.0.tar.gz"
sha256: "e5dac5aca6a117af8bd07ebca6e4ec8255682453487bf8d706bdb0315d17d6af"
"6.10.0":
url: "https://github.com/gazebosim/gz-math/archive/ignition-math6_6.10.0.tar.gz"
sha256: "94e853e1dfba97ebec4b6152691a89af1e94660b02f4ecdf04356b763c2848bd"
patches:
"6.7.0":
- base_path: "source_subfolder"
patch_file: "patches/0001-ign-math-6.7.0-cmake-fixes.patch"
"6.10.0":
- base_path: "source_subfolder"
patch_file: "patches/0002-ign-math-6.10.0-cmake-fixes.patch"
- patch_file: "patches/0002-ign-math-6.10.0-cmake-fixes.patch"
230 changes: 120 additions & 110 deletions recipes/ignition-math/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import os
import conan.tools.files
from conans import CMake, ConanFile, tools
from conans.errors import ConanInvalidConfiguration
import textwrap

required_conan_version = ">=1.29.1"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd, cross_building
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir, save, replace_in_file
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"


class IgnitionMathConan(ConanFile):
name = "ignition-math"
description = "Math classes and functions for robot applications"
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://gazebosim.org/libs/math"
description = " Math classes and functions for robot applications"
topics = ("ignition", "math", "robotics", "gazebo")
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
generators = "cmake", "cmake_find_package_multi"
exports_sources = "CMakeLists.txt", "patches/**"

_cmake = None
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"enable_swig": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"enable_swig": True,
}

@property
def _minimum_cpp_standard(self):
Expand All @@ -30,136 +41,135 @@ def _minimum_cpp_standard(self):
def _minimum_compilers_version(self):
return {
"Visual Studio": "16",
"gcc": "7",
"msvc": "192",
"gcc": "8",
"clang": "5",
"apple-clang": "10",
}

@property
def _source_subfolder(self):
return "source_subfolder"
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:
del self.options.fPIC
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, self._minimum_cpp_standard)
min_version = self._minimum_compilers_version.get(str(self.settings.compiler))
if not min_version:
self.output.warn(
"{} recipe lacks information about the {} compiler support.".format(
self.name, self.settings.compiler
)
)
else:
if tools.Version(self.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration(
"{} requires c++17 support. The current compiler {} {} does not support it.".format(
self.name,
self.settings.compiler,
self.settings.compiler.version,
)
)
self.options.rm_safe("fPIC")

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

def requirements(self):
self.requires("eigen/3.3.9")
self.requires("doxygen/1.8.17")
self.requires("swig/4.0.2")
self.requires("ignition-cmake/2.17.1", visible=False)
self.requires("eigen/3.4.0", transitive_headers=True)
if self.options.enable_swig:
self.requires("swig/4.2.1")

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._minimum_cpp_standard)
min_version = self._minimum_compilers_version.get(str(self.settings.compiler))
if min_version and Version(self.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration(
f"{self.name} requires c++17 support. "
f"The current compiler {self.settings.compiler} {self.settings.compiler.version} does not support it.")

def build_requirements(self):
if int(tools.Version(self.version).minor) <= 8:
self.build_requires("ignition-cmake/2.5.0")
else:
self.build_requires("ignition-cmake/2.10.0")
self.tool_requires("ignition-cmake/2.17.1")
self.tool_requires("doxygen/1.9.4")
if self.options.enable_swig:
self.tool_requires("swig/4.2.1")

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_TESTING"] = False
self._cmake.configure()
return self._cmake
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
env = VirtualBuildEnv(self)
env.generate()
tc = CMakeToolchain(self)
tc.variables["BUILD_TESTING"] = False
tc.cache_variables["SKIP_SWIG"] = not self.options.enable_swig
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
apply_conandata_patches(self)
replace_in_file(self, os.path.join(self.source_folder, "src", "ruby", "CMakeLists.txt"), "${SWIG_USE_FILE}", "UseSWIG")

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
self._patch_sources()
cmake = CMake(self)
cmake.configure()
cmake.build()

def _create_cmake_module_variables(self, module_file, version):
content = textwrap.dedent(f"""\
set(ignition-math{version.major}_VERSION_MAJOR {version.major})
set(ignition-math{version.major}_VERSION_MINOR {version.minor})
set(ignition-math{version.major}_VERSION_PATCH {version.patch})
set(ignition-math{version.major}_VERSION_STRING "{version.major}.{version.minor}.{version.patch}")
set(ignition-math{version.major}_INCLUDE_DIRS "${{CMAKE_CURRENT_LIST_DIR}}/../../include/ignition/math{version.major}")
""")
save(self, module_file, content)

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "share"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
self._create_cmake_module_variables(
os.path.join(self.package_folder, self._module_file_rel_path),
tools.Version(self.version))

rmdir(self, os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
self._create_cmake_module_variables(os.path.join(self.package_folder, self._module_file_rel_path), Version(self.version))

# Remove MS runtime files
for dll_pattern_to_remove in ["concrt*.dll", "msvcp*.dll", "vcruntime*.dll"]:
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), dll_pattern_to_remove)
rm(self, dll_pattern_to_remove, os.path.join(self.package_folder, "bin"), recursive=True)

@staticmethod
def _create_cmake_module_variables(module_file, version):
content = textwrap.dedent("""\
set(ignition-math{major}_VERSION_MAJOR {major})
set(ignition-math{major}_VERSION_MINOR {minor})
set(ignition-math{major}_VERSION_PATCH {patch})
set(ignition-math{major}_VERSION_STRING "{major}.{minor}.{patch}")
set(ignition-math{major}_INCLUDE_DIRS "${{CMAKE_CURRENT_LIST_DIR}}/../../include/ignition/math{major}")
""".format(major=version.major, minor=version.minor, patch=version.patch))
tools.save(module_file, content)
@property
def _module_file_rel_dir(self):
return os.path.join("lib", "cmake")

@property
def _module_file_rel_path(self):
return os.path.join(self._module_file_rel_dir, f"conan-official-{self.name}-variables.cmake")

def package_info(self):
version_major = tools.Version(self.version).major
version_major = str(Version(self.version).major)
lib_name = f"ignition-math{version_major}"

# Based on https://github.com/gazebosim/gz-math/blob/ignition-math6_6.10.0/examples/CMakeLists.txt
self.cpp_info.set_property("cmake_file_name", lib_name)
self.cpp_info.set_property("cmake_target_name", f"{lib_name}::{lib_name}")

main_component = self.cpp_info.components[lib_name]
main_component.libs = [lib_name]
main_component.includedirs.append(os.path.join("include", "ignition", "math" + version_major))
main_component.requires = ["eigen::eigen"]
if self.options.enable_swig:
main_component.requires.append("swig::swig")

eigen3_component = self.cpp_info.components["eigen3"]
eigen3_component.includedirs.append(os.path.join("include", "ignition", "math" + version_major))
eigen3_component.requires = ["eigen::eigen"]

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["cmake_find_package"] = lib_name
self.cpp_info.names["cmake_find_package_multi"] = lib_name
self.cpp_info.names["cmake_paths"] = lib_name

self.cpp_info.components[lib_name].names["cmake_find_package"] = lib_name
self.cpp_info.components[lib_name].names["cmake_find_package_multi"] = lib_name
self.cpp_info.components[lib_name].names["cmake_paths"] = lib_name
self.cpp_info.components[lib_name].libs = [lib_name]
self.cpp_info.components[lib_name].includedirs.append(os.path.join("include", "ignition", "math"+version_major))
self.cpp_info.components[lib_name].requires = ["swig::swig", "eigen::eigen", "doxygen::doxygen"]

self.cpp_info.components[lib_name].builddirs = [self._module_file_rel_dir]
self.cpp_info.components[lib_name].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components[lib_name].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.components[lib_name].build_modules["cmake_paths"] = [self._module_file_rel_path]

self.cpp_info.components["eigen3"].names["cmake_find_package"] = "eigen3"
self.cpp_info.components["eigen3"].names["cmake_find_package_multi"] = "eigen3"
self.cpp_info.components["eigen3"].names["cmake_paths"] = "eigen3"
self.cpp_info.components["eigen3"].includedirs.append(os.path.join("include", "ignition", "math"+version_major))
self.cpp_info.components["eigen3"].requires = ["eigen::eigen"]

self.cpp_info.components["eigen3"].builddirs = [self._module_file_rel_dir]
self.cpp_info.components["eigen3"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components["eigen3"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.components["eigen3"].build_modules["cmake_paths"] = [self._module_file_rel_path]

def validate(self):
if self.settings.os == "Macos" and self.settings.arch == "armv8":
raise ConanInvalidConfiguration("sorry, M1 builds are not currently supported, give up!")

@property
def _module_file_rel_dir(self):
return os.path.join("lib", "cmake")

@property
def _module_file_rel_path(self):
return os.path.join(self._module_file_rel_dir, f"conan-official-{self.name}-variables.cmake")

main_component.names["cmake_find_package"] = lib_name
main_component.names["cmake_find_package_multi"] = lib_name
main_component.names["cmake_paths"] = lib_name
main_component.builddirs = [self._module_file_rel_dir]
main_component.build_modules["cmake_find_package"] = [self._module_file_rel_path]
main_component.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
main_component.build_modules["cmake_paths"] = [self._module_file_rel_path]
eigen3_component.names["cmake_find_package"] = "eigen3"
eigen3_component.names["cmake_find_package_multi"] = "eigen3"
eigen3_component.names["cmake_paths"] = "eigen3"
eigen3_component.builddirs = [self._module_file_rel_dir]
eigen3_component.build_modules["cmake_find_package"] = [self._module_file_rel_path]
eigen3_component.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
eigen3_component.build_modules["cmake_paths"] = [self._module_file_rel_path]

This file was deleted.

7 changes: 2 additions & 5 deletions recipes/ignition-math/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
cmake_minimum_required(VERSION 3.8)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

set(IGN_MATH_MAJOR_VER "" CACHE STRING "Version of igition-math")

Expand Down
Loading