Skip to content

Commit

Permalink
sleef: migrate to Conan v2
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Jul 20, 2023
1 parent d7da970 commit 13175fa
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 71 deletions.
7 changes: 0 additions & 7 deletions recipes/sleef/all/CMakeLists.txt

This file was deleted.

105 changes: 50 additions & 55 deletions recipes/sleef/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
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.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rmdir

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,73 +27,65 @@ 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"
)

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):
tc = CMakeToolchain(self)
tc.variables["BUILD_STATIC_TEST_BINS"] = False
tc.variables["ENABLE_LTO"] = False
tc.variables["BUILD_LIBM"] = True
tc.variables["BUILD_DFT"] = False
tc.variables["BUILD_QUAD"] = False
tc.variables["BUILD_GNUABI_LIBS"] = False
tc.variables["BUILD_TESTS"] = False
tc.variables["BUILD_INLINE_HEADERS"] = False
tc.variables["SLEEF_TEST_ALL_IUT"] = False
tc.variables["SLEEF_SHOW_CONFIG"] = True
tc.variables["SLEEF_SHOW_ERROR_LOG"] = False
tc.variables["ENFORCE_TESTER"] = False
tc.variables["ENFORCE_TESTER3"] = False
tc.variables["ENABLE_ALTDIV"] = False
tc.variables["ENABLE_ALTSQRT"] = False
tc.variables["DISABLE_FFTW"] = True
tc.generate()
tc = CMakeDeps(self)
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"))

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"]
Expand Down
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"
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)

0 comments on commit 13175fa

Please sign in to comment.