From cb0d0771b181930c7be4fe559f5767ea7d2f4ecd Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Tue, 25 May 2021 21:31:42 +0200 Subject: [PATCH] (#5629) add pagmo2/2.17.0 * add pagmo2/2.17.0 * move some logic in validate() --- recipes/pagmo2/all/CMakeLists.txt | 7 + recipes/pagmo2/all/conandata.yml | 4 + recipes/pagmo2/all/conanfile.py | 148 ++++++++++++++++++ .../pagmo2/all/test_package/CMakeLists.txt | 11 ++ recipes/pagmo2/all/test_package/conanfile.py | 17 ++ .../pagmo2/all/test_package/test_package.cpp | 42 +++++ recipes/pagmo2/config.yml | 3 + 7 files changed, 232 insertions(+) create mode 100644 recipes/pagmo2/all/CMakeLists.txt create mode 100644 recipes/pagmo2/all/conandata.yml create mode 100644 recipes/pagmo2/all/conanfile.py create mode 100644 recipes/pagmo2/all/test_package/CMakeLists.txt create mode 100644 recipes/pagmo2/all/test_package/conanfile.py create mode 100644 recipes/pagmo2/all/test_package/test_package.cpp create mode 100644 recipes/pagmo2/config.yml diff --git a/recipes/pagmo2/all/CMakeLists.txt b/recipes/pagmo2/all/CMakeLists.txt new file mode 100644 index 00000000000000..361b35d4c17d9a --- /dev/null +++ b/recipes/pagmo2/all/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8.11) +project(cmake_wrapper) + +include(conanbuildinfo.cmake) +conan_basic_setup() + +add_subdirectory(source_subfolder) diff --git a/recipes/pagmo2/all/conandata.yml b/recipes/pagmo2/all/conandata.yml new file mode 100644 index 00000000000000..a610a9ffc5a7b1 --- /dev/null +++ b/recipes/pagmo2/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "2.17.0": + url: "https://github.com/esa/pagmo2/archive/refs/tags/v2.17.0.tar.gz" + sha256: "1b95b036f75e6fa0b21082ab228dbd63cd18ca10d9622ac53629245e0f95c35c" diff --git a/recipes/pagmo2/all/conanfile.py b/recipes/pagmo2/all/conanfile.py new file mode 100644 index 00000000000000..4917221c688d2d --- /dev/null +++ b/recipes/pagmo2/all/conanfile.py @@ -0,0 +1,148 @@ +from conans import ConanFile, CMake, tools +from conans.errors import ConanInvalidConfiguration +import os + +required_conan_version = ">=1.33.0" + + +class Pagmo2Conan(ConanFile): + name = "pagmo2" + description = "pagmo is a C++ scientific library for massively parallel optimization." + license = ("LGPL-3.0-or-later", "GPL-3.0-or-later") + topics = ("conan", "pagmo", "optimization", "parallel-computing", "genetic-algorithm", "metaheuristics") + homepage = "https://esa.github.io/pagmo2" + url = "https://github.com/conan-io/conan-center-index" + + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + "with_eigen": [True, False], + "with_nlopt": [True, False], + "with_ipopt": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + "with_eigen": False, + "with_nlopt": False, + "with_ipopt": False, + } + + exports_sources = "CMakeLists.txt" + generators = "cmake", "cmake_find_package", "cmake_find_package_multi" + _cmake = None + + @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.options.shared: + del self.options.fPIC + + def requirements(self): + self.requires("boost/1.76.0") + self.requires("tbb/2020.3") + if self.options.with_eigen: + self.requires("eigen/3.3.9") + if self.options.with_nlopt: + self.requires("nlopt/2.7.0") + + @property + def _compilers_minimum_version(self): + return { + "Visual Studio": "15.7", + "gcc": "7", + "clang": "5.0", + "apple-clang": "9.1" + } + + @property + def _required_boost_components(self): + return ["serialization"] + + def validate(self): + if self.settings.compiler.get_safe("cppstd"): + tools.check_min_cppstd(self, 17) + + def lazy_lt_semver(v1, v2): + lv1 = [int(v) for v in v1.split(".")] + lv2 = [int(v) for v in v2.split(".")] + min_length = min(len(lv1), len(lv2)) + return lv1[:min_length] < lv2[:min_length] + + minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) + if not minimum_version: + self.output.warn("{} {} requires C++17. Your compiler is unknown. Assuming it supports C++17.".format(self.name, self.version)) + elif lazy_lt_semver(str(self.settings.compiler.version), minimum_version): + raise ConanInvalidConfiguration("{} {} requires C++17, which your compiler does not support.".format(self.name, self.version)) + + # TODO: add ipopt support + if self.options.with_ipopt: + raise ConanInvalidConfiguration("ipopt recipe not available yet in CCI") + + miss_boost_required_comp = any(getattr(self.options["boost"], "without_{}".format(boost_comp), True) for boost_comp in self._required_boost_components) + if self.options["boost"].header_only or miss_boost_required_comp: + raise ConanInvalidConfiguration("{0} requires non header-only boost with these components: {1}".format(self.name, ", ".join(self._required_boost_components))) + + def source(self): + tools.get(**self.conan_data["sources"][self.version], + destination=self._source_subfolder, strip_root=True) + + def _patch_sources(self): + # do not force MT runtime for static lib + tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"), + "if(YACMA_COMPILER_IS_MSVC AND PAGMO_BUILD_STATIC_LIBRARY)", + "if(0)") + # No warnings as errors + yacma_cmake = os.path.join(self._source_subfolder, "cmake_modules", "yacma", "YACMACompilerLinkerSettings.cmake") + tools.replace_in_file(yacma_cmake, "list(APPEND _YACMA_CXX_FLAGS_DEBUG \"-Werror\")", "") + tools.replace_in_file(yacma_cmake, "_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(/W4)", "") + tools.replace_in_file(yacma_cmake, "_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(/WX)", "") + + def _configure_cmake(self): + if self._cmake: + return self._cmake + self._cmake = CMake(self) + self._cmake.definitions["PAGMO_BUILD_TESTS"] = False + self._cmake.definitions["PAGMO_BUILD_BENCHMARKS"] = False + self._cmake.definitions["PAGMO_BUILD_TUTORIALS"] = False + self._cmake.definitions["PAGMO_WITH_EIGEN3"] = self.options.with_eigen + self._cmake.definitions["PAGMO_WITH_NLOPT"] = self.options.with_nlopt + self._cmake.definitions["PAGMO_WITH_IPOPT"] = self.options.with_ipopt + self._cmake.definitions["PAGMO_ENABLE_IPO"] = False + self._cmake.definitions["PAGMO_BUILD_STATIC_LIBRARY"] = not self.options.shared + self._cmake.configure() + return self._cmake + + def build(self): + self._patch_sources() + cmake = self._configure_cmake() + cmake.build() + + def package(self): + self.copy(pattern="COPYING.*", dst="licenses", src=self._source_subfolder) + cmake = self._configure_cmake() + cmake.install() + tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) + + def package_info(self): + self.cpp_info.filenames["cmake_find_package"] = "pagmo" + self.cpp_info.filenames["cmake_find_package_multi"] = "pagmo" + self.cpp_info.names["cmake_find_package"] = "Pagmo" + self.cpp_info.names["cmake_find_package_multi"] = "Pagmo" + self.cpp_info.components["_pagmo"].names["cmake_find_package"] = "pagmo" + self.cpp_info.components["_pagmo"].names["cmake_find_package_multi"] = "pagmo" + self.cpp_info.components["_pagmo"].libs = ["pagmo"] + self.cpp_info.components["_pagmo"].requires = ["boost::headers", "boost::serialization", "tbb::tbb"] + if self.options.with_eigen: + self.cpp_info.components["_pagmo"].requires.append("eigen::eigen") + if self.options.with_nlopt: + self.cpp_info.components["_pagmo"].requires.append("nlopt::nlopt") + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.components["_pagmo"].system_libs.append("pthread") diff --git a/recipes/pagmo2/all/test_package/CMakeLists.txt b/recipes/pagmo2/all/test_package/CMakeLists.txt new file mode 100644 index 00000000000000..e512e2207b1583 --- /dev/null +++ b/recipes/pagmo2/all/test_package/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +find_package(pagmo REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} Pagmo::pagmo) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/recipes/pagmo2/all/test_package/conanfile.py b/recipes/pagmo2/all/test_package/conanfile.py new file mode 100644 index 00000000000000..a9f777f7680ff1 --- /dev/null +++ b/recipes/pagmo2/all/test_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + 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) diff --git a/recipes/pagmo2/all/test_package/test_package.cpp b/recipes/pagmo2/all/test_package/test_package.cpp new file mode 100644 index 00000000000000..2a7861aea64472 --- /dev/null +++ b/recipes/pagmo2/all/test_package/test_package.cpp @@ -0,0 +1,42 @@ +// From first_udp_ver0.cpp in tutorials of pagmo2 + +#include +#include + +#include +#include +#include +#include + +// Our simple example problem, version 0. +struct problem_v0 { + // Implementation of the objective function. + pagmo::vector_double fitness(const pagmo::vector_double &dv) const + { + return {dv[0] * dv[3] * (dv[0] + dv[1] + dv[2]) + dv[2]}; + } + // Implementation of the box bounds. + std::pair get_bounds() const + { + return {{1., 1., 1., 1.}, {5., 5., 5., 5.}}; + } +}; + +int main() +{ + // Construct a pagmo::problem from our example problem. + pagmo::problem p{problem_v0{}}; + + // Compute the value of the objective function + // in the point (1, 2, 3, 4). + std::cout << "Value of the objfun in (1, 2, 3, 4): " << p.fitness({1, 2, 3, 4})[0] << '\n'; + + // Fetch the lower/upper bounds for the first variable. + std::cout << "Lower bounds: [" << p.get_lb()[0] << "]\n"; + std::cout << "Upper bounds: [" << p.get_ub()[0] << "]\n\n"; + + // Print p to screen. + std::cout << p << "\n"; + + return 0; +} diff --git a/recipes/pagmo2/config.yml b/recipes/pagmo2/config.yml new file mode 100644 index 00000000000000..635df83ba09192 --- /dev/null +++ b/recipes/pagmo2/config.yml @@ -0,0 +1,3 @@ +versions: + "2.17.0": + folder: all