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

Add ignition-math #3215

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 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
4 changes: 4 additions & 0 deletions recipes/ignition-math/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"6.6.0":
url: "https://github.com/ignitionrobotics/ign-math/archive/ignition-math6_6.6.0.zip"
sha256: "7c29a8fa49edba1cff8e6a6194ae74942a103eefc3504b3afb63de54d7a510e9"
118 changes: 118 additions & 0 deletions recipes/ignition-math/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import glob
import os

from conans import CMake, ConanFile, tools
from conans.errors import ConanInvalidConfiguration


class IgnitionMathConan(ConanFile):
name = "ignition-math"
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://ignitionrobotics.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"

@property
def _minimum_cpp_standard(self):
return 17

@property
def _minimum_compilers_version(self):
return {
"Visual Studio": "16",
"gcc": "7",
"clang": "5",
"apple-clang": "10",
}

@property
def _source_subfolder(self):
return "source_subfolder"

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

def configure(self):
if self.settings.get_safe("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,
)
)

def source(self):
tools.get(**self.conan_data["sources"][self.version])
version_major = self.version.split(".")[0]
os.rename(
"ign-math-ignition-math{}_{}".format(version_major, self.version),
self._source_subfolder,
)

def requirements(self):
self.requires("eigen/3.3.7")

def _configure_cmake(self):
self.cmake = CMake(self)
self.cmake.definitions["BUILD_TESTING"] = False
self.cmake.definitions["BUILD_SHARED_LIBS"] = self.options.shared
self.cmake.configure(source_folder=self._source_subfolder)

def build(self):
self._install_ign_cmake()
self._configure_cmake()
self.cmake.build()

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
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"))

# Remove MS runtime files
for dll_pattern_to_remove in ["concrt*.dll", "msvcp*.dll", "vcruntime*.dll"]:
for dll_to_remove in glob.glob(os.path.join(self.package_folder, "bin", dll_pattern_to_remove)):
os.remove(dll_to_remove)

def package_info(self):
version_major = self.version.split(".")[0]
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.names["cmake_find_package"] = "ignition-math{}".format(
version_major
)
self.cpp_info.names["cmake_find_package_multi"] = "ignition-math{}".format(
version_major
)
self.cpp_info.includedirs = ["include/ignition/math{}".format(version_major)]
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)

def _install_ign_cmake(self):
# Get and build ign-cmake. This is just a set of cmake macros used by all the ignition
# packages.
# TODO: find a way of using an ign-make Conan package as a
# build_requirement
self.run(
"git clone --depth=1 https://github.com/ignitionrobotics/ign-cmake.git --branch ignition-cmake2_2.5.0"
)
cmake = CMake(self)
cmake.configure(source_folder="ign-cmake", build_folder="build_ign-cmake")
cmake.build()
cmake.install()
13 changes: 13 additions & 0 deletions recipes/ignition-math/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.10.2)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

set(IGN_MATH_MAJOR_VER 6)

find_package(ignition-math${IGN_MATH_MAJOR_VER} REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ignition-math${IGN_MATH_MAJOR_VER}::ignition-math${IGN_MATH_MAJOR_VER})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)
16 changes: 16 additions & 0 deletions recipes/ignition-math/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from conans import ConanFile, CMake, tools
import os

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

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

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
80 changes: 80 additions & 0 deletions recipes/ignition-math/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <iostream>
#include <ignition/math.hh>

int main(int argc, char **argv)
{
// Create a triangle with the following vertices:
// 1: x = -1, y = 0
// 2: x = 0, y = 1
// 3: x = 1, y = 0
ignition::math::Triangled tri(
ignition::math::Vector2d(-1, 0),
ignition::math::Vector2d(0, 1),
ignition::math::Vector2d(1, 0));

// The individual vertices are accessible through the [] operator
std::cout << "Vertex 1: " << tri[0] << "\n"
<< "Vertex 2: " << tri[1] << "\n"
<< "Vertex 3: " << tri[2] << "\n";

// Each side of the triangle is also accessible via the Side function
std::cout << "Side 1: " << tri.Side(0) << "\n"
<< "Side 2: " << tri.Side(1) << "\n"
<< "Side 3: " << tri.Side(2) << "\n";

// It's also possible to set each vertex individually.
tri.Set(0, ignition::math::Vector2d(-10, 0));
tri.Set(1, ignition::math::Vector2d(0, 20));
tri.Set(2, ignition::math::Vector2d(10, 2));

// Or set all the vertices at once.
tri.Set(ignition::math::Vector2d(-1, 0),
ignition::math::Vector2d(0, 1),
ignition::math::Vector2d(1, 0));

// You can get the perimeter length and area of the triangle
std::cout << "Perimeter=" << tri.Perimeter()
<< " Area=" << tri.Area() << "\n";

// The Contains functions check if a line or point is inside the triangle
if (tri.Contains(ignition::math::Vector2d(0, 0.5)))
std::cout << "Triangle contains the point 0, 0.5\n";
else
std::cout << "Triangle does not contain the point 0, 0.5\n";

// The Intersect function check if a line segment intersects the triangle.
// It also returns the points of intersection
ignition::math::Vector2d pt1, pt2;
if (tri.Intersects(ignition::math::Line2d(-2, 0.5, 2, 0.5), pt1, pt2))
{
std::cout << "A line from (-2, 0.5) to (2, 0.5) intersects "
<< "the triangle at the\nfollowing points:\n"
<< "\t Pt1=" << pt1 << "\n"
<< "\t Pt2=" << pt2 << "\n";
}
else
{
std::cout << "A line from (-2, 0.5) to (2, 0.5) does not intersect "
<< "the triangle\n";
}

// There are more functions in Triangle. Take a look at the API;
// http://ignitionrobotics.org/libraries/ign_mat/api
}
3 changes: 3 additions & 0 deletions recipes/ignition-math/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"6.6.0":
folder: all