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

[symengine] conan v2 support #14872

Merged
merged 12 commits into from
Jan 28, 2023
7 changes: 0 additions & 7 deletions recipes/symengine/all/CMakeLists.txt

This file was deleted.

74 changes: 39 additions & 35 deletions recipes/symengine/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain
from conan.tools.files import (
apply_conandata_patches,
collect_libs,
copy,
get,
rm,
rmdir,
)
import os

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.54.0"


class SymengineConan(ConanFile):
Expand All @@ -12,7 +21,6 @@ class SymengineConan(ConanFile):
homepage = "https://symengine.org/"
url = "https://github.com/conan-io/conan-center-index"
exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake"
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
Expand All @@ -26,66 +34,62 @@ class SymengineConan(ConanFile):
}
short_paths = True

_cmake = None

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

@property
def _build_subfolder(self):
return "build_subfolder"

def requirements(self):
if self.options.integer_class == "boostmp":
self.requires("boost/1.79.0")
self.requires("boost/1.81.0")
else:
self.requires("gmp/6.2.1")

def source(self):
tools.get(
get(
self,
**self.conan_data["sources"][self.version],
strip_root=True,
destination=self._source_subfolder,
destination=self.source_folder,
)

def _configure_cmake(self):
if self._cmake is None:
self._cmake = CMake(self)
self._cmake.definitions["BUILD_TESTS"] = False
self._cmake.definitions["BUILD_BENCHMARKS"] = False
self._cmake.definitions["INTEGER_CLASS"] = self.options.integer_class
self._cmake.definitions["MSVC_USE_MT"] = False
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

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

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_TESTS"] = False
tc.variables["BUILD_BENCHMARKS"] = False
tc.variables["INTEGER_CLASS"] = self.options.integer_class
tc.variables["MSVC_USE_MT"] = False
tc.generate()

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

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(
self,
"LICENSE",
src=self.source_folder,
dst=os.path.join(self.package_folder, "licenses"),
)
cmake = CMake(self)
cmake.install()
# [CMAKE-MODULES-CONFIG-FILES (KB-H016)]
tools.remove_files_by_mask(self.package_folder, "*.cmake")
rm(self, "*.cmake", self.package_folder, recursive=True)
# [DEFAULT PACKAGE LAYOUT (KB-H013)]
tools.rmdir(os.path.join(self.package_folder, "CMake"))
rmdir(self, os.path.join(self.package_folder, "CMake"))

def package_info(self):
self.cpp_info.libs = ["symengine"]
if any("teuchos" in v for v in tools.collect_libs(self)):
if any("teuchos" in v for v in collect_libs(self)):
self.cpp_info.libs.append("teuchos")
if self.settings.os == "Linux":
self.cpp_info.system_libs.append("m")
self.cpp_info.names["cmake_find_package"] = "symengine"
# FIXME: symengine exports a non-namespaced `symengine` target.
self.cpp_info.names["cmake_find_package_multi"] = "symengine"
3 changes: 0 additions & 3 deletions recipes/symengine/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.1)
project(test_package CXX)

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

find_package(symengine REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
Expand Down
27 changes: 20 additions & 7 deletions recipes/symengine/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
import os


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

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["CMAKE_CXX_STANDARD"] = "11"
Copy link
Member

Choose a reason for hiding this comment

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

Usually we set it directly in the cmake file with target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) But no problem using here instead.

tc.generate()

def build(self):
cmake = CMake(self)
cmake.definitions["CMAKE_CXX_STANDARD"] = "11"
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
10 changes: 10 additions & 0 deletions recipes/symengine/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(test_package CXX)

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

find_package(symengine REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE symengine::symengine) # FIXME: Replace `symengine::symengine` with `symengine`
Copy link
Member

@uilianries uilianries Jan 27, 2023

Choose a reason for hiding this comment

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

FIXME: Replace symengine::symengine with symengine

It would need a new module in the recipe, but no problem skipping it for now.

18 changes: 18 additions & 0 deletions recipes/symengine/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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["CMAKE_CXX_STANDARD"] = "11"
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
13 changes: 13 additions & 0 deletions recipes/symengine/all/test_v1_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <symengine/constants.h>
#include <symengine/expression.h>
#include <symengine/integer.h>
#include <symengine/mul.h>

#include <iostream>

int main() {
SymEngine::Expression pi_by_12 =
SymEngine::div(SymEngine::pi, SymEngine::integer(12));
std::cout << pi_by_12 << std::endl;
return 0;
}