-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add pagmo2/2.17.0 * move some logic in validate()
- Loading branch information
Showing
7 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 2.8.11) | ||
project(cmake_wrapper) | ||
|
||
include(conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
|
||
add_subdirectory(source_subfolder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources: | ||
"2.17.0": | ||
url: "https://github.com/esa/pagmo2/archive/refs/tags/v2.17.0.tar.gz" | ||
sha256: "1b95b036f75e6fa0b21082ab228dbd63cd18ca10d9622ac53629245e0f95c35c" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", "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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// From first_udp_ver0.cpp in tutorials of pagmo2 | ||
|
||
#include <pagmo/problem.hpp> | ||
#include <pagmo/types.hpp> | ||
|
||
#include <cmath> | ||
#include <initializer_list> | ||
#include <iostream> | ||
#include <utility> | ||
|
||
// 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<pagmo::vector_double, pagmo::vector_double> 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"2.17.0": | ||
folder: all |