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

libcpuid: add version 0.6.1 and support conan v2 #13358

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions recipes/libcpuid/all/CMakeLists.txt

This file was deleted.

13 changes: 11 additions & 2 deletions recipes/libcpuid/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
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"
"0.5.0":
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"
84 changes: 40 additions & 44 deletions recipes/libcpuid/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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],
Expand All @@ -23,60 +23,56 @@ 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":
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
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")
Expand All @@ -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
Expand Down
50 changes: 50 additions & 0 deletions recipes/libcpuid/all/patches/0.6.1-cmake-fixes.patch
Original file line number Diff line number Diff line change
@@ -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
10 changes: 4 additions & 6 deletions recipes/libcpuid/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 14 additions & 5 deletions recipes/libcpuid/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
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)
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.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")

self.run("cpuid_tool --report", run_environment=True)
12 changes: 12 additions & 0 deletions recipes/libcpuid/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 20 additions & 0 deletions recipes/libcpuid/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions recipes/libcpuid/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"0.6.1":
folder: "all"
"0.5.1":
folder: "all"
"0.5.0":
Expand Down