From f909134900d68a644571c0d4969e94449c6050c0 Mon Sep 17 00:00:00 2001 From: toge Date: Fri, 20 Sep 2024 20:32:02 +0900 Subject: [PATCH] (#25269) fixed_math: add version 2.0.0, fix install path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixed_math: add version 2.0.0 * fix trailing spaces * fix install path * Update recipes/fixed_math/all/conanfile.py --------- Co-authored-by: Abril Rincón Blanco --- recipes/fixed_math/1.x.x/conandata.yml | 4 + recipes/fixed_math/1.x.x/conanfile.py | 143 ++++++++++++++++++ .../1.x.x/test_package/CMakeLists.txt | 8 + .../1.x.x/test_package/conanfile.py | 26 ++++ .../1.x.x/test_package/test_package.cpp | 39 +++++ recipes/fixed_math/all/conandata.yml | 6 +- recipes/fixed_math/all/conanfile.py | 112 ++++---------- .../all/test_package/CMakeLists.txt | 4 +- .../all/test_package/test_package.cpp | 50 +++--- recipes/fixed_math/config.yml | 4 +- 10 files changed, 278 insertions(+), 118 deletions(-) create mode 100644 recipes/fixed_math/1.x.x/conandata.yml create mode 100644 recipes/fixed_math/1.x.x/conanfile.py create mode 100644 recipes/fixed_math/1.x.x/test_package/CMakeLists.txt create mode 100644 recipes/fixed_math/1.x.x/test_package/conanfile.py create mode 100644 recipes/fixed_math/1.x.x/test_package/test_package.cpp diff --git a/recipes/fixed_math/1.x.x/conandata.yml b/recipes/fixed_math/1.x.x/conandata.yml new file mode 100644 index 0000000000000..3e20dff4a8b77 --- /dev/null +++ b/recipes/fixed_math/1.x.x/conandata.yml @@ -0,0 +1,4 @@ +sources: + "1.0.2": + url: "https://github.com/arturbac/fixed_math/archive/refs/tags/v1.0.2.tar.gz" + sha256: "6c87217286e3b93ce5e1fff0bbbb08a9751d04f416cd76ddd5ddd37a8c6772cf" diff --git a/recipes/fixed_math/1.x.x/conanfile.py b/recipes/fixed_math/1.x.x/conanfile.py new file mode 100644 index 0000000000000..aed8cfa5c1d05 --- /dev/null +++ b/recipes/fixed_math/1.x.x/conanfile.py @@ -0,0 +1,143 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import copy, get, rmdir, replace_in_file +from conan.tools.scm import Version +from conan.tools.layout import basic_layout +from conan.tools.env import VirtualBuildEnv +from conan.tools.microsoft import is_msvc +import os + +required_conan_version = ">=1.53.0" + +class FixedMathConan(ConanFile): + name = "fixed_math" + description = "A High-Performance C++17 Library for Fixed-Point 48.16 Arithmetic" + license = "MIT" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/arturbac/fixed_math/" + topics = ("mathematics", "fixed-point") + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "header_only": [True, False], + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "header_only": False, + "shared": False, + "fPIC": True, + } + + @property + def _min_cppstd(self): + return 17 + + @property + def _compilers_minimum_version(self): + return { + "gcc": "10", # fixed_math requires __has_builtin + "clang": "7", + "apple-clang": "12", + "Visual Studio": "16", + "msvc": "192", + } + + def config_options(self): + if self.settings.os == "Windows": + self.package_type = "static-library" + del self.options.fPIC + + def configure(self): + if self.settings.os == "Windows": + self.options.rm_safe("shared") + if self.options.header_only: + self.options.rm_safe("shared") + self.options.rm_safe("fPIC") + self.package_type = "header-library" + elif self.options.get_safe("shared"): + self.options.rm_safe("fPIC") + + def layout(self): + if self.options.header_only: + basic_layout(self, src_folder="src") + else: + cmake_layout(self, src_folder="src") + + def package_id(self): + if self.info.options.header_only: + self.info.clear() + + def validate(self): + if self.settings.compiler.cppstd: + check_min_cppstd(self, self._min_cppstd) + minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) + if minimum_version and Version(self.settings.compiler.version) < minimum_version: + raise ConanInvalidConfiguration( + f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." + ) + + def build_requirements(self): + if not self.options.header_only: + self.tool_requires("cmake/[>=3.21 <4]") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + if self.options.header_only: + return + tc = CMakeToolchain(self) + if is_msvc(self): + tc.variables["CMAKE_CXX_FLAGS"] = "/Zc:__cplusplus" + tc.generate() + venv = VirtualBuildEnv(self) + venv.generate(scope="build") + + def build(self): + if not self.options.header_only: + # fix install path (https://github.com/arturbac/fixed_math/issues/8) + replace_in_file(self, os.path.join(self.source_folder, "fixed_lib", "CMakeLists.txt"), + "${CMAKE_INSTALL_INCLUDEDIR}/fixed_math", + "${CMAKE_INSTALL_INCLUDEDIR}/fixedmath") + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + copy(self, "LICENCE", self.source_folder, os.path.join(self.package_folder, "licenses")) + if not self.options.header_only: + cmake = CMake(self) + cmake.install() + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + else: + # fix install path (https://github.com/arturbac/fixed_math/issues/8) + copy( + self, + "*.h", + os.path.join(self.source_folder, "fixed_lib", "include", "fixedmath"), + os.path.join(self.package_folder, "include", "fixedmath"), + ) + copy( + self, + "*.hpp", + os.path.join(self.source_folder, "fixed_lib", "include", "fixedmath"), + os.path.join(self.package_folder, "include", "fixedmath"), + ) + + def package_info(self): + if self.options.header_only: + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] + else: + self.cpp_info.libs = ["fixed_math"] + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.system_libs.append("m") + + self.cpp_info.set_property("cmake_file_name", "fixed_math") + self.cpp_info.set_property("cmake_target_name", "fixed_math::fixed_math") + + if is_msvc(self): + self.cpp_info.cxxflags.append("/Zc:__cplusplus") diff --git a/recipes/fixed_math/1.x.x/test_package/CMakeLists.txt b/recipes/fixed_math/1.x.x/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..d63966d4ccdd2 --- /dev/null +++ b/recipes/fixed_math/1.x.x/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) + +find_package(fixed_math REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE fixed_math::fixed_math) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/recipes/fixed_math/1.x.x/test_package/conanfile.py b/recipes/fixed_math/1.x.x/test_package/conanfile.py new file mode 100644 index 0000000000000..ef5d7042163ec --- /dev/null +++ b/recipes/fixed_math/1.x.x/test_package/conanfile.py @@ -0,0 +1,26 @@ +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 = "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 can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/fixed_math/1.x.x/test_package/test_package.cpp b/recipes/fixed_math/1.x.x/test_package/test_package.cpp new file mode 100644 index 0000000000000..9337496e2cbd5 --- /dev/null +++ b/recipes/fixed_math/1.x.x/test_package/test_package.cpp @@ -0,0 +1,39 @@ +#include + +#include "fixedmath/fixed_math.hpp" +#include "fixedmath/iostream.h" + +using fixedmath::fixed_t; +using fixedmath::operator ""_fix; + +//fixed and all functionality is constexpr so You can declare constants see features [1] +inline constexpr fixed_t foo_constant{ fixedmath::tan( 15 * fixedmath::phi/180) }; + +constexpr fixed_t my_function( fixed_t value ) { + using namespace fixedmath; + return foo_constant + sin(value) / (1.41_fix - 2*cos(value) / 4); +} + +int main() { + // converting to/from fixed_t + // construction from other arithmetic types is explicit + fixed_t val { 3.14 }; + + //- there is no implicit assignment from other types + float some_float{val}; + fixed_t some_fixed{some_float}; + + some_fixed = fixed_t{some_float}; + + //- converting to other arithmetic types coud be done with static cast and is explicit + double some_double { static_cast(some_fixed) }; + + // for constant values postfix operator _fix may be used + some_fixed = some_float * 2.45_fix; //operation with float is promoted to fixed_t + some_double = 4.15 * some_fixed; //operation with double is promoted to double + + std::cout << some_fixed << '\n'; + std::cout << some_double << '\n'; + + return 0; +} diff --git a/recipes/fixed_math/all/conandata.yml b/recipes/fixed_math/all/conandata.yml index 3e20dff4a8b77..a7ea4a2ff9968 100644 --- a/recipes/fixed_math/all/conandata.yml +++ b/recipes/fixed_math/all/conandata.yml @@ -1,4 +1,4 @@ sources: - "1.0.2": - url: "https://github.com/arturbac/fixed_math/archive/refs/tags/v1.0.2.tar.gz" - sha256: "6c87217286e3b93ce5e1fff0bbbb08a9751d04f416cd76ddd5ddd37a8c6772cf" + "2.0.0": + url: "https://github.com/arturbac/fixed_math/archive/refs/tags/v2.0.0.tar.gz" + sha256: "a02efd417592f9cb3d21fc39877aba76fe5c37b3e68b11769065202f71242f66" diff --git a/recipes/fixed_math/all/conanfile.py b/recipes/fixed_math/all/conanfile.py index 21e92751973d1..4684b16404cb7 100644 --- a/recipes/fixed_math/all/conanfile.py +++ b/recipes/fixed_math/all/conanfile.py @@ -1,11 +1,9 @@ from conan import ConanFile from conan.errors import ConanInvalidConfiguration from conan.tools.build import check_min_cppstd -from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout -from conan.tools.files import copy, get, rmdir +from conan.tools.files import copy, get from conan.tools.scm import Version from conan.tools.layout import basic_layout -from conan.tools.env import VirtualBuildEnv from conan.tools.microsoft import is_msvc import os @@ -17,58 +15,30 @@ class FixedMathConan(ConanFile): license = "MIT" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/arturbac/fixed_math/" - topics = ("mathematics", "fixed-point") - package_type = "library" + topics = ("mathematics", "fixed-point", "header-only") + package_type = "header-library" settings = "os", "arch", "compiler", "build_type" - options = { - "header_only": [True, False], - "shared": [True, False], - "fPIC": [True, False], - } - default_options = { - "header_only": False, - "shared": False, - "fPIC": True, - } + no_copy_source = True @property def _min_cppstd(self): - return 17 + return 23 @property def _compilers_minimum_version(self): return { - "gcc": "10", # fixed_math requires __has_builtin - "clang": "7", - "apple-clang": "12", - "Visual Studio": "16", - "msvc": "192", + "Visual Studio": "17", + "msvc": "193", + "gcc": "12", + "clang": "15", + "apple-clang": "16", } - def config_options(self): - if self.settings.os == "Windows": - self.package_type = "static-library" - del self.options.fPIC - - def configure(self): - if self.settings.os == "Windows": - self.options.rm_safe("shared") - if self.options.header_only: - self.options.rm_safe("shared") - self.options.rm_safe("fPIC") - self.package_type = "header-library" - elif self.options.get_safe("shared"): - self.options.rm_safe("fPIC") - def layout(self): - if self.options.header_only: - basic_layout(self, src_folder="src") - else: - cmake_layout(self, src_folder="src") + basic_layout(self, src_folder="src") def package_id(self): - if self.info.options.header_only: - self.info.clear() + self.info.clear() def validate(self): if self.settings.compiler.cppstd: @@ -79,57 +49,27 @@ def validate(self): f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." ) - def build_requirements(self): - if not self.options.header_only: - self.tool_requires("cmake/[>=3.21 <4]") - def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) - def generate(self): - if self.options.header_only: - return - tc = CMakeToolchain(self) - if is_msvc(self): - tc.variables["CMAKE_CXX_FLAGS"] = "/Zc:__cplusplus" - tc.generate() - venv = VirtualBuildEnv(self) - venv.generate(scope="build") - - def build(self): - if not self.options.header_only: - cmake = CMake(self) - cmake.configure() - cmake.build() - def package(self): copy(self, "LICENCE", self.source_folder, os.path.join(self.package_folder, "licenses")) - if not self.options.header_only: - cmake = CMake(self) - cmake.install() - rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) - else: - copy( - self, - "*.h", - os.path.join(self.source_folder, "fixed_lib", "include", "fixedmath"), - os.path.join(self.package_folder, "include", "fixed_math"), - ) - copy( - self, - "*.hpp", - os.path.join(self.source_folder, "fixed_lib", "include", "fixedmath"), - os.path.join(self.package_folder, "include", "fixed_math"), - ) + copy( + self, + "*.h", + os.path.join(self.source_folder, "fixed_lib", "include"), + os.path.join(self.package_folder, "include"), + ) + copy( + self, + "*.hpp", + os.path.join(self.source_folder, "fixed_lib", "include"), + os.path.join(self.package_folder, "include"), + ) def package_info(self): - if self.options.header_only: - self.cpp_info.bindirs = [] - self.cpp_info.libdirs = [] - else: - self.cpp_info.libs = ["fixed_math"] - if self.settings.os in ["Linux", "FreeBSD"]: - self.cpp_info.system_libs.append("m") + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] self.cpp_info.set_property("cmake_file_name", "fixed_math") self.cpp_info.set_property("cmake_target_name", "fixed_math::fixed_math") diff --git a/recipes/fixed_math/all/test_package/CMakeLists.txt b/recipes/fixed_math/all/test_package/CMakeLists.txt index d63966d4ccdd2..2b820757c217b 100644 --- a/recipes/fixed_math/all/test_package/CMakeLists.txt +++ b/recipes/fixed_math/all/test_package/CMakeLists.txt @@ -1,8 +1,8 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.20) project(test_package LANGUAGES CXX) find_package(fixed_math REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) target_link_libraries(${PROJECT_NAME} PRIVATE fixed_math::fixed_math) -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_23) diff --git a/recipes/fixed_math/all/test_package/test_package.cpp b/recipes/fixed_math/all/test_package/test_package.cpp index fe7f675d4cade..7fbb1e6d1d25b 100644 --- a/recipes/fixed_math/all/test_package/test_package.cpp +++ b/recipes/fixed_math/all/test_package/test_package.cpp @@ -1,39 +1,37 @@ -#include +#include -#include "fixed_math/fixed_math.hpp" -#include "fixed_math/iostream.h" +#include "fixedmath/fixed_math.hpp" +#include "fixedmath/iostream.h" using fixedmath::fixed_t; -using fixedmath::operator ""_fix; +using fixedmath::operator""_fix; -//fixed and all functionality is constexpr so You can declare constants see features [1] -inline constexpr fixed_t foo_constant{ fixedmath::tan( 15 * fixedmath::phi/180) }; +// fixed and all functionality is constexpr so You can declare constants see features [1] +inline constexpr fixed_t foo_constant{fixedmath::fobj::tan(15 * fixedmath::phi / 180)}; -constexpr fixed_t my_function( fixed_t value ) { - using namespace fixedmath; - return foo_constant + sin(value) / (1.41_fix - 2*cos(value) / 4); +constexpr fixed_t my_function(fixed_t value) { + using namespace fixedmath; + // You can use funcioons or function objects + return foo_constant + fobj::sin(value) / (1.41_fix - 2 * func::cos(value) / 4); } int main() { - // converting to/from fixed_t - // construction from other arithmetic types is explicit - fixed_t val { 3.14 }; + // converting to/from fixed_t + // construction from other arithmetic types is explicit + fixed_t val1{3.14}; + fixed_t val2{3u}; - //- there is no implicit assignment from other types - float some_float{val}; - fixed_t some_fixed{some_float}; + //- there is no implicit assignment from other types + float some_float{3.14f}; + fixed_t some_fixed; + some_fixed = fixed_t{some_float}; - some_fixed = fixed_t{some_float}; + //- converting to other arithmetic types coud be done with static cast and is explicit + double some_double(some_fixed); - //- converting to other arithmetic types coud be done with static cast and is explicit - double some_double { static_cast(some_fixed) }; + // for constant values postfix operator _fix may be used + some_fixed = some_float * 2.45_fix; // operation with float is promoted to fixed_t + some_double = 4.15 * some_fixed; // operation with double is promoted to double - // for constant values postfix operator _fix may be used - some_fixed = some_float * 2.45_fix; //operation with float is promoted to fixed_t - some_double = 4.15 * some_fixed; //operation with double is promoted to double - - std::cout << some_fixed << '\n'; - std::cout << some_double << '\n'; - - return 0; + std::cout << some_double << " " << my_function(some_fixed) << std::endl; } diff --git a/recipes/fixed_math/config.yml b/recipes/fixed_math/config.yml index 8457ca9a4a8cd..3a4c749874ca0 100644 --- a/recipes/fixed_math/config.yml +++ b/recipes/fixed_math/config.yml @@ -1,3 +1,5 @@ versions: - "1.0.2": + "2.0.0": folder: all + "1.0.2": + folder: 1.x.x