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 #4045

Merged
merged 27 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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: 7 additions & 0 deletions recipes/ignition-math/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory(source_subfolder)
10 changes: 10 additions & 0 deletions recipes/ignition-math/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sources:
"6.7.0":
url: "https://github.com/ignitionrobotics/ign-math/archive/ignition-math6_6.7.0.zip"
sha256: "5427a17de6ef9f60ee497b9a170a4e92517de9496781dac91f50cdbeb3364b22"
patches:
"6.7.0":
- base_path: "source_subfolder"
patch_file: "patches/0001-Define-time_regex-locally.patch"
- base_path: "source_subfolder"
patch_file: "patches/0002-cmake-fixes.patch"
130 changes: 130 additions & 0 deletions recipes/ignition-math/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import os

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

required_conan_version = ">=1.29.1"


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", "pkg_config"
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
exports_sources = "CMakeLists.txt", "patches/**"

_cmake = None

@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 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,
)

prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
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,
)
)

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

def build_requirements(self):
self.build_requires("ignition-cmake/2.5.0")

prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
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

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

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
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"]:
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), dll_pattern_to_remove)

def package_info(self):
version_major = tools.Version(self.version).major
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)

# cmake_find_package filename: ignition-math6-config.cmake
self.cpp_info.components["libignition-math"].libs = ["ignition-math{}".format(version_major)]
self.cpp_info.components["libignition-math"].includedirs.append("include/ignition/math{}".format(version_major))
self.cpp_info.components["libignition-math"].names["cmake_find_package"] = "ignition-math{}".format(version_major)
self.cpp_info.components["libignition-math"].names["cmake_find_package_multi"] = "ignition-math{}".format(version_major)
self.cpp_info.components["libignition-math"].names["pkg_config"] = "ignition-math{}".format(version_major)

# FIXME: create in file ignition-math6-eigen3-config.cmake
self.cpp_info.components["libignition-math-eigen3"].libs = []
self.cpp_info.components["libignition-math-eigen3"].requires = ["libignition-math", "eigen::eigen"]
self.cpp_info.components["libignition-math-eigen3"].names["cmake_find_package"] = "ignition-math{}-eigen3".format(version_major)
self.cpp_info.components["libignition-math-eigen3"].names["cmake_find_package_multi"] = "ignition-math{}-eigen3".format(version_major)
self.cpp_info.components["libignition-math-eigen3"].names["pkg_config"] = "ignition-math{}-eigen3".format(version_major)

# FIXME: create in file ignition-math6-all-config.cmake
self.cpp_info.components["libignition-math-all"].libs = []
self.cpp_info.components["libignition-math-all"].requires = ["libignition-math-eigen3"]
self.cpp_info.components["libignition-math-all"].names["cmake_find_package"] = "ignition-math{}-all".format(version_major)
self.cpp_info.components["libignition-math-all"].names["cmake_find_package_multi"] = "ignition-math{}-all".format(version_major)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
From 24a9b3284fcbf05cfec09d9cbd4de4d9977c8318 Mon Sep 17 00:00:00 2001
From: Juan Oxoby <juan@vicarious.com>
Date: Fri, 16 Oct 2020 21:28:37 -0700
Subject: [PATCH] Define time_regex locally

---
include/ignition/math/Helpers.hh | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/ignition/math/Helpers.hh b/include/ignition/math/Helpers.hh
index 2dd5cc6..bd4d35f 100644
--- a/include/ignition/math/Helpers.hh
+++ b/include/ignition/math/Helpers.hh
@@ -870,7 +870,7 @@ namespace ignition
// The following regex takes a time string in the general format of
// "dd hh:mm:ss.nnn" where n is milliseconds, if just one number is
// provided, it is assumed to be seconds
- static const std::regex time_regex(
+ static const char* time_regex_str =
Comment on lines +18 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with creating std::regex here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent questions....

From the original author #3215 (comment)

After a lot of pain, I was able to solve the segfault error that was happening. The problem was the static initialization of a std::regex variable: https://github.com/ignitionrobotics/ign-math/blob/51eb0640a0c7454c36fef1a3007d3db37fe9165f/include/ignition/math/Helpers.hh#L873, which I solved by creating a raw static char* and using that to initialize a local static (static inside the function) std::regex variable: https://github.com/conan-io/conan-center-index/pull/3215/files#diff-e2f831892c4567a7388d8d62242576015a59f008af8dd34c946996d15f6991e9

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see what problem it fixes and how, but good to know it fixes something :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 I agree... I just didn't want to waste the time we put in so I wanted to keep it but I have no clue what this project is or does.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, works for me 👍

"^([0-9]+ ){0,1}" // day:
// Any positive integer

@@ -887,7 +887,7 @@ namespace ignition
// 0 - 9
// 00 - 59

- "(\\.[0-9]{1,3}){0,1})$"); // millisecond:
+ "(\\.[0-9]{1,3}){0,1})$"; // millisecond:
// .0 - .9
// .00 - .99
// .000 - 0.999
@@ -907,6 +907,7 @@ namespace ignition
uint64_t & numberMinutes, uint64_t & numberSeconds,
uint64_t & numberMilliseconds)
{
+ static const std::regex time_regex(time_regex_str);
std::smatch matches;

// `matches` should always be a size of 6 as there are 6 matching
--
2.17.1

34 changes: 34 additions & 0 deletions recipes/ignition-math/all/patches/0002-cmake-fixes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -39,7 +39,7 @@ ign_find_package(
########################################
# Include swig
find_package(SWIG QUIET)
-if (NOT SWIG_FOUND)
+if (1)
IGN_BUILD_WARNING("Swig is missing: Language interfaces are disabled.")
message (STATUS "Searching for swig - not found.")
else()
@@ -47,7 +47,7 @@ else()
endif()

# Include other languages if swig was found
-if (SWIG_FOUND)
+if (0)
########################################
# Include ruby
find_package(Ruby 1.9 QUIET)
@@ -74,9 +74,9 @@ ign_create_packages()
#============================================================================
# Configure documentation
#============================================================================
-configure_file(${CMAKE_SOURCE_DIR}/api.md.in ${CMAKE_BINARY_DIR}/api.md)
-configure_file(${CMAKE_SOURCE_DIR}/tutorials.md.in ${CMAKE_BINARY_DIR}/tutorials.md)
+configure_file(${PROJECT_SOURCE_DIR}/api.md.in ${PROJECT_BINARY_DIR}/api.md)
+configure_file(${PROJECT_SOURCE_DIR}/tutorials.md.in ${PROJECT_BINARY_DIR}/tutorials.md)

ign_create_docs(
- API_MAINPAGE_MD "${CMAKE_BINARY_DIR}/api.md"
- TUTORIALS_MAINPAGE_MD "${CMAKE_BINARY_DIR}/tutorials.md")
+ API_MAINPAGE_MD "${PROJECT_BINARY_DIR}/api.md"
+ TUTORIALS_MAINPAGE_MD "${PROJECT_BINARY_DIR}/tutorials.md")
21 changes: 21 additions & 0 deletions recipes/ignition-math/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.8)
project(test_package)

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

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

if(NOT IGN_MATH_MAJOR_VER)
message(FATAL_ERROR "IGN_MAJOR_MAJOR_VER not set")
endif()

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_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS ON
)
17 changes: 17 additions & 0 deletions recipes/ignition-math/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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.definitions["IGN_MATH_MAJOR_VER"] = tools.Version(self.deps_cpp_info["ignition-math"].version).major
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)
7 changes: 7 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,7 @@
#include <iostream>
#include <ignition/math/Angle.hh>

int main(int argc, char **argv)
{
ignition::math::Angle a;
}
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.7.0":
folder: all