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

sleef: migrate to Conan v2 #18721

Merged
merged 13 commits into from
Feb 26, 2024
7 changes: 0 additions & 7 deletions recipes/sleef/all/CMakeLists.txt

This file was deleted.

3 changes: 3 additions & 0 deletions recipes/sleef/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"3.6":
url: "https://github.com/shibatch/sleef/archive/3.6.tar.gz"
sha256: "de4f3d992cf2183a872cd397f517c1defcd3ee6cafa2ce5fa36963bd7e562446"
"3.5.1":
url: "https://github.com/shibatch/sleef/archive/3.5.1.tar.gz"
sha256: "415ee9b1bcc5816989d3d4d92afd0cd3f9ee89cbd5a33eb008e69751e40438ab"
135 changes: 79 additions & 56 deletions recipes/sleef/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.32.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import cross_building
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import copy, get, rmdir
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"


class SleefConan(ConanFile):
name = "sleef"
description = "SLEEF is a library that implements vectorized versions " \
"of C standard math functions."
description = "SLEEF is a library that implements vectorized versions of C standard math functions."
license = "BSL-1.0"
topics = ("conan", "sleef", "vectorization", "simd")
homepage = "https://sleef.org"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://sleef.org"
topics = ("vectorization", "simd")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -24,75 +30,92 @@ class SleefConan(ConanFile):
"fPIC": True,
}

short_paths = True

exports_sources = "CMakeLists.txt"
generators = "cmake"
_cmake = None

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

@property
def _build_subfolder(self):
return "build_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
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

def layout(self):
cmake_layout(self, src_folder="src")

def validate(self):
if self.settings.os == "Windows" and self.options.shared:
raise ConanInvalidConfiguration("shared sleef not supported on Windows, it produces runtime errors")
raise ConanInvalidConfiguration(
"shared sleef not supported on Windows, it produces runtime errors"
)
if self.settings.compiler == "apple-clang":
if cross_building(self):
# Fails with "No rule to make target `/bin/mkrename'"
Copy link
Member

Choose a reason for hiding this comment

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

Confirmed that it does not work in 3.6 too.

# https://github.com/shibatch/sleef/issues/308
raise ConanInvalidConfiguration(f"{self.ref} does not support cross-building with apple-clang")
if Version(self.version) < "3.6" and self.settings.arch == "armv8":
# clang: error: the clang compiler does not support '-march=armv7-a'
# clang: warning: argument unused during compilation: '-mfpu=vfpv4' [-Wunused-command-line-argument]
# clang: warning: argument unused during compilation: '-arch arm64' [-Wunused-command-line-argument]
# clang: warning: argument unused during compilation: '-mmacosx-version-min=11.0' [-Wunused-command-line-argument]
raise ConanInvalidConfiguration(f"{self.ref} does not support Mac M1. Please, use {self.name} version >=3.6.")

def build_requirements(self):
if Version(self.version) >= "3.6":
self.tool_requires("cmake/[>=3.18 <4]")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
os.rename(self.name + "-" + self.version, self._source_subfolder)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_STATIC_TEST_BINS"] = False
self._cmake.definitions["ENABLE_LTO"] = False
self._cmake.definitions["BUILD_LIBM"] = True
self._cmake.definitions["BUILD_DFT"] = False
self._cmake.definitions["BUILD_QUAD"] = False
self._cmake.definitions["BUILD_GNUABI_LIBS"] = False
self._cmake.definitions["BUILD_TESTS"] = False
self._cmake.definitions["BUILD_INLINE_HEADERS"] = False
self._cmake.definitions["SLEEF_TEST_ALL_IUT"] = False
self._cmake.definitions["SLEEF_SHOW_CONFIG"] = True
self._cmake.definitions["SLEEF_SHOW_ERROR_LOG"] = False
self._cmake.definitions["ENFORCE_TESTER"] = False
self._cmake.definitions["ENFORCE_TESTER3"] = False
self._cmake.definitions["ENABLE_ALTDIV"] = False
self._cmake.definitions["ENABLE_ALTSQRT"] = False
self._cmake.definitions["DISABLE_FFTW"] = True
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
VirtualBuildEnv(self).generate()

tc = CMakeToolchain(self)
tc.cache_variables["BUILD_SHARED_LIBS"] = self.options.shared
if Version(self.version) >= "3.6":
Copy link
Member

Choose a reason for hiding this comment

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

Some options changed in 3.6, including for testing. Please, check in the new release.

tc.cache_variables["SLEEF_BUILD_STATIC_TEST_BINS"] = False
tc.cache_variables["SLEEF_BUILD_LIBM"] = True
tc.cache_variables["SLEEF_BUILD_DFT"] = False
tc.cache_variables["SLEEF_BUILD_QUAD"] = False
tc.cache_variables["SLEEF_BUILD_GNUABI_LIBS"] = False
tc.cache_variables["SLEEF_BUILD_SCALAR_LIB"] = False
tc.cache_variables["SLEEF_BUILD_TESTS"] = False
tc.cache_variables["SLEEF_BUILD_INLINE_HEADERS"] = False
tc.cache_variables["SLEEF_SHOW_CONFIG"] = True
tc.cache_variables["SLEEF_SHOW_ERROR_LOG"] = False
tc.cache_variables["SLEEF_ENABLE_ALTDIV"] = False
tc.cache_variables["SLEEF_ENABLE_ALTSQRT"] = False
tc.cache_variables["SLEEF_DISABLE_FFTW"] = True
tc.cache_variables["SLEEF_DISABLE_MPFR"] = True
tc.cache_variables["SLEEF_DISABLE_SSL"] = True
tc.cache_variables["SLEEF_ENABLE_CUDA"] = False
tc.cache_variables["SLEEF_ENABLE_CXX"] = False
else:
tc.cache_variables["BUILD_DFT"] = False
tc.cache_variables["BUILD_GNUABI_LIBS"] = False
tc.cache_variables["BUILD_TESTS"] = False
tc.cache_variables["DISABLE_FFTW"] = True
tc.generate()

def build(self):
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE.txt",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder)
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "dummy"))

def package_info(self):
self.cpp_info.names["pkg_config"] = "sleef"
self.cpp_info.set_property("pkg_config_name", "sleef")
self.cpp_info.libs = ["sleef"]
if self.settings.os == "Windows" and not self.options.shared:
self.cpp_info.defines = ["SLEEF_STATIC_LIBS"]
if self.settings.os == "Linux":
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["m"]
7 changes: 3 additions & 4 deletions recipes/sleef/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(sleef REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE sleef::sleef)
19 changes: 14 additions & 5 deletions recipes/sleef/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake"
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.settings):
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/sleef/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/sleef/all/test_v1_package/conanfile.py
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)
2 changes: 2 additions & 0 deletions recipes/sleef/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
versions:
"3.6":
folder: all
"3.5.1":
folder: all
Loading