diff --git a/recipes/libcpuid/all/CMakeLists.txt b/recipes/libcpuid/all/CMakeLists.txt deleted file mode 100644 index dcbf69112bb06..0000000000000 --- a/recipes/libcpuid/all/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4) -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup() - -include(GNUInstallDirs) - -if(MSVC AND BUILD_SHARED_LIBS) - set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) -endif() - -add_subdirectory(source_subfolder) diff --git a/recipes/libcpuid/all/conandata.yml b/recipes/libcpuid/all/conandata.yml index 133cbeb595d14..9f4217df40f7c 100644 --- a/recipes/libcpuid/all/conandata.yml +++ b/recipes/libcpuid/all/conandata.yml @@ -1,4 +1,7 @@ sources: + "0.6.1": + url: "https://github.com/anrieff/libcpuid/archive/v0.6.1.tar.gz" + sha256: "115f84ceb14492b5c3c4dd4110b6a41012c879e31d81fae31e8713509b88a363" "0.5.1": url: "https://github.com/anrieff/libcpuid/archive/v0.5.1.tar.gz" sha256: "36d62842ef43c749c0ba82237b10ede05b298d79a0e39ef5fd1115ba1ff8e126" @@ -6,9 +9,15 @@ sources: url: "https://github.com/anrieff/libcpuid/archive/v0.5.0.tar.gz" sha256: "49893f31475510aa0ebe2ad3a29fad95e2a592cc5f48451c95271c536f89a157" patches: + "0.6.1": + - patch_file: "patches/0.6.1-cmake-fixes.patch" + patch_description: "delete static/shared flag and enable installation on MSVC" + patch_type: "portability" "0.5.1": - patch_file: "patches/0.5.0-cmake-fixes.patch" - base_path: "source_subfolder" + patch_description: "delete static/shared flag and fix installation folder" + patch_type: "portability" "0.5.0": - patch_file: "patches/0.5.0-cmake-fixes.patch" - base_path: "source_subfolder" + patch_description: "delete static/shared flag and fix installation folder" + patch_type: "portability" diff --git a/recipes/libcpuid/all/conanfile.py b/recipes/libcpuid/all/conanfile.py index 68d83bcf3f7fc..ca1b03a0739c0 100644 --- a/recipes/libcpuid/all/conanfile.py +++ b/recipes/libcpuid/all/conanfile.py @@ -1,18 +1,18 @@ -from conans import CMake, ConanFile, tools -from conans.errors import ConanInvalidConfiguration +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout import os -required_conan_version = ">=1.43.0" - +required_conan_version = ">=1.52.0" class LibCpuidConan(ConanFile): name = "libcpuid" description = "libcpuid is a small C library for x86 CPU detection and feature extraction" - topics = ("libcpuid", "detec", "cpu", "intel", "amd", "x86_64") - license = "https://github.com/anrieff/libcpuid" - homepage = "https://github.com/anrieff/libcpuid" + license = "BSD-3-clause" url = "https://github.com/conan-io/conan-center-index" - + homepage = "https://github.com/anrieff/libcpuid" + topics = ("libcpuid", "detec", "cpu", "intel", "amd", "x86_64") settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], @@ -23,21 +23,8 @@ class LibCpuidConan(ConanFile): "fPIC": True, } - generators = "cmake" - _cmake = None - - @property - def _source_subfolder(self): - return "source_subfolder" - - @property - def _build_subfolder(self): - return "build_subfolder" - def export_sources(self): - self.copy("CMakeLists.txt") - for patch in self.conan_data.get("patches", {}).get(self.version, []): - self.copy(patch["patch_file"]) + export_conandata_patches(self) def config_options(self): if self.settings.os == "Windows": @@ -45,38 +32,47 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC - del self.settings.compiler.libcxx - del self.settings.compiler.cppstd + try: + del self.options.fPIC + except Exception: + pass + try: + del self.settings.compiler.libcxx + except Exception: + pass + try: + del self.settings.compiler.cppstd + except Exception: + pass + + def layout(self): + cmake_layout(self, src_folder="src") def validate(self): - if self.settings.arch not in ("x86", "x86_64"): - raise ConanInvalidConfiguration("libcpuid is only available for x86 and x86_64 architecture") + if self.info.settings.arch not in ("x86", "x86_64"): + raise ConanInvalidConfiguration(f"{self.ref} is only available for x86 and x86_64 architecture") def source(self): - tools.get(**self.conan_data["sources"][self.version], - destination=self._source_subfolder, strip_root=True) + get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) - def _configure_cmake(self): - if self._cmake: - return self._cmake - self._cmake = CMake(self) - self._cmake.definitions["ENABLE_DOCS"] = False - self._cmake.configure(build_folder=self._build_subfolder) - return self._cmake + def generate(self): + tc = CMakeToolchain(self) + tc.variables["ENABLE_DOCS"] = False + tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True + 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("COPYING", src=self._source_subfolder, dst="licenses") - cmake = self._configure_cmake() + copy(self, pattern="COPYING", 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", "cmake")) - tools.rmdir(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, "lib", "pkgconfig")) def package_info(self): self.cpp_info.set_property("cmake_file_name", "cpuid") @@ -85,7 +81,7 @@ def package_info(self): self.cpp_info.libs = ["cpuid"] bin_path = os.path.join(self.package_folder, "bin") - self.output.info("Appending PATH environment variable: {}".format(bin_path)) + self.output.info(f"Appending PATH environment variable: {bin_path}") self.env_info.PATH.append(bin_path) # TODO: to remove in conan v2 once cmake_find_package_* generators removed diff --git a/recipes/libcpuid/all/patches/0.6.1-cmake-fixes.patch b/recipes/libcpuid/all/patches/0.6.1-cmake-fixes.patch new file mode 100644 index 0000000000000..1501214d76b66 --- /dev/null +++ b/recipes/libcpuid/all/patches/0.6.1-cmake-fixes.patch @@ -0,0 +1,50 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 40c352d..2426b4b 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -9,22 +9,13 @@ project( + LANGUAGES C CXX ASM_MASM + VERSION ${VERSION}) + +-if(MSVC) +- set(LIBCPUID_SHARED OFF) +-else() +- set(LIBCPUID_SHARED ON) +-endif() +-option(BUILD_SHARED_LIBS "Build shared lib" ${LIBCPUID_SHARED}) +- +-option(LIBCPUID_TESTS "Enable building tests" OFF) +- + set(CMAKE_CXX_STANDARD 11) + set(CMAKE_C_STANDARD 99) + + # Global variables + list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") + +-if(UNIX) ++if(1) + include(GNUInstallDirs) + set(prefix "${CMAKE_INSTALL_PREFIX}") + set(exec_prefix "\${prefix}") +@@ -34,7 +25,7 @@ if(UNIX) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libcpuid.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libcpuid.pc" ESCAPE_QUOTES + @ONLY) + install(FILES "${PROJECT_BINARY_DIR}/libcpuid.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +-endif(UNIX) ++endif() + + # Include subdirectories + add_subdirectory(libcpuid) +diff --git a/cpuid_tool/CMakeLists.txt b/cpuid_tool/CMakeLists.txt +index b799573..eab18e4 100644 +--- a/cpuid_tool/CMakeLists.txt ++++ b/cpuid_tool/CMakeLists.txt +@@ -2,7 +2,7 @@ add_executable(cpuid_tool cpuid_tool.c) + + target_link_libraries(cpuid_tool cpuid) + +-if(WIN32) ++if(0) + install( + TARGETS cpuid_tool + CONFIGURATIONS Debug diff --git a/recipes/libcpuid/all/test_package/CMakeLists.txt b/recipes/libcpuid/all/test_package/CMakeLists.txt index bbffbda24bead..8e48ea9258177 100644 --- a/recipes/libcpuid/all/test_package/CMakeLists.txt +++ b/recipes/libcpuid/all/test_package/CMakeLists.txt @@ -1,10 +1,8 @@ -cmake_minimum_required(VERSION 3.1) -project(test_package C) - -include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") -conan_basic_setup(TARGETS) +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES C) find_package(cpuid REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.c) -target_link_libraries(${PROJECT_NAME} cpuid::cpuid) +target_link_libraries(${PROJECT_NAME} PRIVATE cpuid::cpuid) +target_compile_features(${PROJECT_NAME} PRIVATE c_std_99) diff --git a/recipes/libcpuid/all/test_package/conanfile.py b/recipes/libcpuid/all/test_package/conanfile.py index a2a865893b40b..ad37506afe612 100644 --- a/recipes/libcpuid/all/test_package/conanfile.py +++ b/recipes/libcpuid/all/test_package/conanfile.py @@ -1,10 +1,19 @@ -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", "cmake_find_package_multi" + 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) @@ -12,8 +21,8 @@ def build(self): 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") self.run("cpuid_tool --report", run_environment=True) diff --git a/recipes/libcpuid/all/test_v1_package/CMakeLists.txt b/recipes/libcpuid/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..a233d0accd60b --- /dev/null +++ b/recipes/libcpuid/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.8) + +project(test_package LANGUAGES C) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +find_package(cpuid REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} ../test_package/test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE cpuid::cpuid) +target_compile_features(${PROJECT_NAME} PRIVATE c_std_99) diff --git a/recipes/libcpuid/all/test_v1_package/conanfile.py b/recipes/libcpuid/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..348e53d7d1f67 --- /dev/null +++ b/recipes/libcpuid/all/test_v1_package/conanfile.py @@ -0,0 +1,20 @@ +from conans import ConanFile, CMake +from conan.tools.build import cross_building +import os + + +class TestPackageV1Conan(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 cross_building(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) + + self.run("cpuid_tool --report", run_environment=True) diff --git a/recipes/libcpuid/config.yml b/recipes/libcpuid/config.yml index d8b7ba4046e10..96a402a4c625f 100644 --- a/recipes/libcpuid/config.yml +++ b/recipes/libcpuid/config.yml @@ -1,4 +1,6 @@ versions: + "0.6.1": + folder: "all" "0.5.1": folder: "all" "0.5.0":