diff --git a/recipes/ignition-math/all/CMakeLists.txt b/recipes/ignition-math/all/CMakeLists.txt new file mode 100644 index 0000000000000..e4233e81e86f0 --- /dev/null +++ b/recipes/ignition-math/all/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.1) +project(cmake_wrapper) + +include(conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(source_subfolder) diff --git a/recipes/ignition-math/all/conandata.yml b/recipes/ignition-math/all/conandata.yml new file mode 100644 index 0000000000000..32a44e67a2ccb --- /dev/null +++ b/recipes/ignition-math/all/conandata.yml @@ -0,0 +1,10 @@ +sources: + "6.6.0": + url: "https://github.com/ignitionrobotics/ign-math/archive/ignition-math6_6.6.0.zip" + sha256: "7c29a8fa49edba1cff8e6a6194ae74942a103eefc3504b3afb63de54d7a510e9" +patches: + "6.6.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" diff --git a/recipes/ignition-math/all/conanfile.py b/recipes/ignition-math/all/conanfile.py new file mode 100644 index 0000000000000..4ae417a0006a7 --- /dev/null +++ b/recipes/ignition-math/all/conanfile.py @@ -0,0 +1,143 @@ +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", "pkg_config" + 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" + + @property + def _cmake_source_subfolder(self): + return "cmake_source_subfolder" + + @property + def _cmake_build_subfolder(self): + return "cmake_build_subfolder" + + @property + def _cmake_prefix_subfolder(self): + return "cmake_prefix_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, + ) + + 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.7") + + def build_requirements(self): + self.build_requires("pkgconf/1.7.3") + self.build_requires("ignition-cmake/2.5.0") + + def _configure_cmake(self): + if self._cmake is not None: + return self._cmake + self._cmake = CMake(self) + self._cmake.verbose = True + self._cmake.definitions["BUILD_TESTING"] = False + # self._cmake.definitions["CMAKE_PREFIX_PATH"] = os.path.join(self.build_folder, self._cmake_prefix_subfolder) + 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) diff --git a/recipes/ignition-math/all/patches/0001-Define-time_regex-locally.patch b/recipes/ignition-math/all/patches/0001-Define-time_regex-locally.patch new file mode 100644 index 0000000000000..8bc14e3ce6170 --- /dev/null +++ b/recipes/ignition-math/all/patches/0001-Define-time_regex-locally.patch @@ -0,0 +1,42 @@ +From 24a9b3284fcbf05cfec09d9cbd4de4d9977c8318 Mon Sep 17 00:00:00 2001 +From: Juan Oxoby +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 = + "^([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 + diff --git a/recipes/ignition-math/all/patches/0002-cmake-fixes.patch b/recipes/ignition-math/all/patches/0002-cmake-fixes.patch new file mode 100644 index 0000000000000..274699ec54ea0 --- /dev/null +++ b/recipes/ignition-math/all/patches/0002-cmake-fixes.patch @@ -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") diff --git a/recipes/ignition-math/all/test_package/CMakeLists.txt b/recipes/ignition-math/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..4aae31035db70 --- /dev/null +++ b/recipes/ignition-math/all/test_package/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.10.2) +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 +) diff --git a/recipes/ignition-math/all/test_package/conanfile.py b/recipes/ignition-math/all/test_package/conanfile.py new file mode 100644 index 0000000000000..315a95800ba91 --- /dev/null +++ b/recipes/ignition-math/all/test_package/conanfile.py @@ -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) diff --git a/recipes/ignition-math/all/test_package/test_package.cpp b/recipes/ignition-math/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..abd858b56a1c9 --- /dev/null +++ b/recipes/ignition-math/all/test_package/test_package.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2019 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 +#include + +int main(int argc, char **argv) +{ + // Create an angle. + ignition::math::Angle a; + + // A default constructed angle should be zero. + std::cout << "The angle 'a' should be zero: " << a << std::endl; + a = ignition::math::Angle::Pi; + + // Output the angle in radians and degrees. + std::cout << "Pi in radians: " << a << std::endl; + std::cout << "Pi in degrees: " << a.Degree() << std::endl; + + // The Angle class overloads the +=, and many other, math operators. + a += ignition::math::Angle::HalfPi; + std::cout << "Pi + PI/2 in radians: " << a << std::endl; + std::cout << "Normalized to the range -Pi and Pi: " + << a.Normalized() << std::endl; +} diff --git a/recipes/ignition-math/config.yml b/recipes/ignition-math/config.yml new file mode 100644 index 0000000000000..bebb41bc4d100 --- /dev/null +++ b/recipes/ignition-math/config.yml @@ -0,0 +1,3 @@ +versions: + "6.6.0": + folder: all