Skip to content

Commit

Permalink
(conan-io#18720) flint: migrate to Conan v2
Browse files Browse the repository at this point in the history
* flint: migrate to Conan v2

* flint: bump deps

* flint: add version 2.9.0

Generated and committed by [Conan Center Bot](https://github.com/qchateau/conan-center-bot)
Find more updatable recipes in the [GitHub Pages](https://qchateau.github.io/conan-center-bot/)

* flint: set correct pthreads4w file name, bump deps

* flint: conandata hashes have changed

* flint: add versions, simplify patching

* flint: fix MSVC pthread linking

---------

Co-authored-by: Quentin Chateau via Conan Center Bot <quentin.chateau@gmail.com>
  • Loading branch information
valgur and qchateau committed Jan 1, 2024
1 parent 1a7fdec commit 3bcb2f1
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 200 deletions.
7 changes: 0 additions & 7 deletions recipes/flint/all/CMakeLists.txt

This file was deleted.

24 changes: 13 additions & 11 deletions recipes/flint/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
sources:
"2.8.1":
url: "https://github.com/wbhart/flint2/archive/refs/tags/v2.8.1.tar.gz"
sha256: "93c4d6acd46d7a4357a2abe313e5f0625fa7e94a1a0e53048f9066f55a7acd49"
"3.0.1":
url: "https://github.com/flintlib/flint/releases/download/v3.0.1/flint-3.0.1.tar.xz"
sha256: "de9ada43c94a69de2e78a5241dc183a1c1ece11e45fe565da7272cf8ed818dd6"
"2.9.0":
url: "https://github.com/wbhart/flint2/archive/v2.9.0.tar.gz"
sha256: "624e0fc343b27a156c0e3bb48d2a644a1ac387aa66217f6753c03a02c80bbf6f"
"2.8.5":
url: "https://github.com/wbhart/flint2/archive/refs/tags/v2.8.5.tar.gz"
sha256: "4d5377e7432e67b0f34f95059a01d243ef29208da86ba3e812d312d323db0d8e"
"2.7.1":
url: "https://github.com/wbhart/flint2/archive/refs/tags/v2.7.1.tar.gz"
sha256: "bcadc2252e61092a9b3a3198b337e20abeac56078eaa19793ab99ff7a987efb7"
sha256: "80f1b7240f1ee5d15952c33cb0aa27b6395993fe897bc279ad984f4fc2743bd4"
patches:
"2.8.1":
- patch_file: "patches/0001-cmake-2.8.1.patch"
base_path: "source_subfolder"
"2.9.0":
- patch_file: "patches/0002-msvc-alloca.patch"
"2.8.5":
- patch_file: "patches/0002-msvc-alloca.patch"
base_path: "source_subfolder"
"2.7.1":
- patch_file: "patches/0001-cmake.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-msvc-alloca.patch"
base_path: "source_subfolder"
107 changes: 62 additions & 45 deletions recipes/flint/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import os

from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.53.0"


class FlintConan(ConanFile):
name = "flint"
description = "FLINT (Fast Library for Number Theory)"
license = "LGPL-2.1-or-later"
topics = ("math", "numerical")
homepage = "https://www.flintlib.org"
url = "https://github.com/conan-io/conan-center-index"
exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake"
homepage = "https://www.flintlib.org"
topics = ("math", "numerical")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -24,68 +29,80 @@ class FlintConan(ConanFile):
"fPIC": True,
}

_cmake = None

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

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

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 layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("gmp/6.2.1")
self.requires("mpfr/4.1.0")
if self.settings.compiler == "Visual Studio":
self.requires("gmp/6.3.0", transitive_headers=True, transitive_libs=True)
self.requires("mpfr/4.2.1", transitive_headers=True, transitive_libs=True)
if is_msvc(self):
self.requires("pthreads4w/3.0.0")

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

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

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_TESTING"] = False
self._cmake.definitions["BUILD_DOCS"] = False
self._cmake.definitions["WITH_NTL"] = False
def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["BUILD_TESTING"] = False
tc.cache_variables["BUILD_DOCS"] = False
tc.cache_variables["WITH_NTL"] = False
# IPO/LTO breaks clang builds
self._cmake.definitions["IPO_SUPPORTED"] = False
tc.cache_variables["IPO_SUPPORTED"] = False
# No BLAS yet
self._cmake.definitions["CMAKE_DISABLE_FIND_PACKAGE_CBLAS"] = True
tc.cache_variables["CMAKE_DISABLE_FIND_PACKAGE_CBLAS"] = True
# handle run in a cross-build
if tools.cross_building(self):
self._cmake.definitions["FLINT_USES_POPCNT_EXITCODE"] = "1"
self._cmake.definitions["FLINT_USES_POPCNT_EXITCODE__TRYRUN_OUTPUT"] = ""
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
if cross_building(self):
tc.cache_variables["FLINT_USES_POPCNT_EXITCODE"] = "1"
tc.cache_variables["FLINT_USES_POPCNT_EXITCODE__TRYRUN_OUTPUT"] = ""
tc.generate()

deps = CMakeDeps(self)
if Version(self.version) <= "3.0.1":
deps.set_property("pthreads4w", "cmake_file_name", "PThreads")
else:
# https://github.com/flintlib/flint/commit/c6cc1078cb55903b0853fb1b6dc660887842dadf
deps.set_property("pthreads4w", "cmake_file_name", "PThreads4W")
deps.set_property("pthreads4w", "cmake_target_name", "PThreads4W::PThreads4W")
deps.generate()

def _patch_sources(self):
apply_conandata_patches(self)
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "MPFR_", "mpfr_")

def build(self):
self._patch_sources()
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",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder)
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "libflint"
self.cpp_info.names["cmake_find_package_multi"] = "libflint"
self.cpp_info.set_property("cmake_file_name", "libflint")
self.cpp_info.set_property("cmake_target_name", "libflint::libflint")

if self.settings.os in ("FreeBSD", "Linux"):
self.cpp_info.system_libs = ["pthread", "m"]

self.cpp_info.includedirs.append(os.path.join("include", "flint"))
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.libs = ["flint"]

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["cmake_find_package"] = "libflint"
self.cpp_info.names["cmake_find_package_multi"] = "libflint"
63 changes: 0 additions & 63 deletions recipes/flint/all/patches/0001-cmake-2.8.1.patch

This file was deleted.

63 changes: 0 additions & 63 deletions recipes/flint/all/patches/0001-cmake.patch

This file was deleted.

5 changes: 1 addition & 4 deletions recipes/flint/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)
cmake_minimum_required(VERSION 3.15)
project(test_package CXX)

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

find_package(libflint REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
Expand Down
21 changes: 15 additions & 6 deletions recipes/flint/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os

from conans import ConanFile, CMake, tools

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

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

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
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.bindir, "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/flint/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
17 changes: 17 additions & 0 deletions recipes/flint/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os

from conans import ConanFile, CMake, tools

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
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):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
Loading

0 comments on commit 3bcb2f1

Please sign in to comment.