diff --git a/recipes/level-zero/all/conandata.yml b/recipes/level-zero/all/conandata.yml new file mode 100644 index 0000000000000..239ec80fcfb55 --- /dev/null +++ b/recipes/level-zero/all/conandata.yml @@ -0,0 +1,9 @@ +sources: + "1.17.39": + url: "https://github.com/oneapi-src/level-zero/archive/refs/tags/v1.17.39.tar.gz" + sha256: "70473c7262eee80dbe7c17974684ba9d3e34efc15ecba919b85e3cea7b1e180e" +patches: + "1.17.39": + - patch_file: "patches/1.17.39/001-patch-remove-qspectre.patch" + patch_description: "Removed /Qspectre" + patch_type: "portability" \ No newline at end of file diff --git a/recipes/level-zero/all/conanfile.py b/recipes/level-zero/all/conanfile.py new file mode 100644 index 0000000000000..6f86996442e8c --- /dev/null +++ b/recipes/level-zero/all/conanfile.py @@ -0,0 +1,93 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.env import VirtualBuildEnv +from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps +from conan.tools.files import get, apply_conandata_patches, copy, export_conandata_patches, rmdir +from conan.tools.build import check_min_cppstd +from conan.tools.scm import Version +import os + + +class LevelZeroConan(ConanFile): + name = "level-zero" + license = "MIT" + homepage = "https://github.com/oneapi-src/level-zero" + url = "https://github.com/conan-io/conan-center-index" + description = "OneAPI Level Zero Specification Headers and Loader" + topics = ("api-headers", "loader", "level-zero", "oneapi") + package_type = "shared-library" + + # Binary configuration + settings = "os", "arch", "compiler", "build_type" + + @property + def _min_cppstd(self): + return 14 + + @property + def _compilers_minimum_version(self): + return { + "apple-clang": "10", + "clang": "7", + "gcc": "7", + "msvc": "190", + "Visual Studio": "15", + } + + def requirements(self): + self.requires("spdlog/1.14.1") + + def source(self): + version_data = self.conan_data["sources"][self.version] + get(self, **version_data, strip_root=True) + + def export_sources(self): + export_conandata_patches(self) + + def layout(self): + cmake_layout(self, src_folder="src") + + def generate(self): + deps = CMakeDeps(self) + deps.generate() + + toolchain = CMakeToolchain(self) + toolchain.generate() + + def validate(self): + if self.settings.os == "Macos": + raise ConanInvalidConfiguration("This recipe doesn't prepared for macOS.") + if self.settings.os == "Windows": + if self.settings.get_safe("subsystem") == "uwp": + raise ConanInvalidConfiguration(f"{self.ref} does not support UWP on Windows.") + 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(self): + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + cmake = CMake(self) + cmake.install() + copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + + def package_info(self): + self.cpp_info.components["ze-loader"].libs = ["ze_loader"] + self.cpp_info.components["ze-loader"].includedirs = ["include", "include/level_zero"] + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.components["ze-loader"].system_libs = ["pthread"] + elif self.settings.os == "Windows": + self.cpp_info.components["ze-loader"].system_libs = ["cfgmgr32"] + self.cpp_info.components["ze-loader"].set_property("pkg_config_name", "libze_loader") + self.cpp_info.components["level-zero"].requires = ["ze-loader"] + self.cpp_info.components["level-zero"].set_property("pkg_config_name", "level-zero") + diff --git a/recipes/level-zero/all/patches/1.17.39/001-patch-remove-qspectre.patch b/recipes/level-zero/all/patches/1.17.39/001-patch-remove-qspectre.patch new file mode 100644 index 0000000000000..997ca7a844e96 --- /dev/null +++ b/recipes/level-zero/all/patches/1.17.39/001-patch-remove-qspectre.patch @@ -0,0 +1,17 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index ac2ab9f..5282757 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -132,12 +132,6 @@ if(MSVC) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DYNAMICBASE") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /guard:cf") + # enable Spectre Mitigation, not supported by clang-cl +- if((NOT CMAKE_CXX_COMPILER_ID STREQUAL Clang) AND (NOT CMAKE_CXX_COMPILER_ID STREQUAL IntelLLVM)) +- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qspectre") +- endif() +- if((NOT CMAKE_C_COMPILER_ID STREQUAL Clang) AND NOT (CMAKE_C_COMPILER_ID STREQUAL IntelLLVM)) +- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Qspectre") +- endif() + endif() + + #CXX compiler support diff --git a/recipes/level-zero/all/test_package/CMakeLists.txt b/recipes/level-zero/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..6b92e033f045a --- /dev/null +++ b/recipes/level-zero/all/test_package/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.2.0) +project(test_package LANGUAGES CXX) + +find_package(level-zero CONFIG REQUIRED) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE level-zero::level-zero) + +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) \ No newline at end of file diff --git a/recipes/level-zero/all/test_package/conanfile.py b/recipes/level-zero/all/test_package/conanfile.py new file mode 100644 index 0000000000000..0ac491f64a94f --- /dev/null +++ b/recipes/level-zero/all/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, CMakeDeps, CMakeToolchain, cmake_layout +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/level-zero/all/test_package/test_package.cpp b/recipes/level-zero/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..50cc7683ea557 --- /dev/null +++ b/recipes/level-zero/all/test_package/test_package.cpp @@ -0,0 +1,6 @@ +#include "ze_api.h" + +int main() { + zeInit(0); + return 0; +} diff --git a/recipes/level-zero/config.yml b/recipes/level-zero/config.yml new file mode 100644 index 0000000000000..6cac94c96d3b8 --- /dev/null +++ b/recipes/level-zero/config.yml @@ -0,0 +1,3 @@ +versions: + "1.17.39": + folder: "all"