Skip to content

opencl-icd-loader: add 2022.05.18 + conan v2 support #13697

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

Merged
merged 6 commits into from
Oct 25, 2022
Merged
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
7 changes: 0 additions & 7 deletions recipes/opencl-icd-loader/all/CMakeLists.txt

This file was deleted.

15 changes: 10 additions & 5 deletions recipes/opencl-icd-loader/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
sources:
"2022.09.30":
url: "https://github.com/KhronosGroup/OpenCL-ICD-Loader/archive/refs/tags/v2022.09.30.tar.gz"
sha256: "e9522fb736627dd4feae2a9c467a864e7d25bb715f808de8a04eea5a7d394b74"
"2022.05.18":
url: "https://github.com/KhronosGroup/OpenCL-ICD-Loader/archive/refs/tags/v2022.05.18.tar.gz"
sha256: "71f70bba797a501b13b6b0905dc852f3fd6e264d74ce294f2df98d29914c4303"
"2022.01.04":
url: "https://github.com/KhronosGroup/OpenCL-ICD-Loader/archive/v2022.01.04.tar.gz"
sha256: "9f21d958af68c1b625a03c2befddd79da95d610614ddab6c291f26f01a947dd8"
Expand All @@ -10,8 +16,7 @@ sources:
sha256: "e7a0c161376bfb46b869e292d4593a64f4ff7b358837494a5f2d765d9a2af683"
patches:
"2020.06.16":
- base_path: "source_subfolder"
patch_file: "patches/2020.06.16/0001-xcode-missing-includes.patch"
# patch_type: portability
# source: https://github.com/KhronosGroup/OpenCL-ICD-Loader/pull/131
# description: Add missing includes (needed for new Xcode versions)
- patch_file: "patches/2020.06.16/0001-xcode-missing-includes.patch"
patch_description: "Add missing includes (needed for new Xcode versions)"
patch_type: "portability"
patch_source: "https://github.com/KhronosGroup/OpenCL-ICD-Loader/pull/131"
108 changes: 66 additions & 42 deletions recipes/opencl-icd-loader/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
import os

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.52.0"


class OpenclIcdLoaderConan(ConanFile):
name = "opencl-icd-loader"
description = "OpenCL ICD Loader."
license = "Apache-2.0"
topics = ("opencl-icd-loader", "opencl", "khronos", "parallel", "icd-loader")
topics = ("opencl", "khronos", "parallel", "icd-loader")
homepage = "https://github.com/KhronosGroup/OpenCL-ICD-Loader"
url = "https://github.com/conan-io/conan-center-index"

settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False], "disable_openclon12": [True, False]}
default_options = {"shared": False, "fPIC": True, "disable_openclon12": False}

generators = "cmake"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"
options = {
"shared": [True, False],
"fPIC": [True, False],
"disable_openclon12": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"disable_openclon12": False,
}

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":
Expand All @@ -35,49 +38,70 @@ def config_options(self):

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx
try:
del self.options.fPIC
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass
try:
del self.settings.compiler.libcxx
except Exception:
pass

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("opencl-headers/{}".format(self.version))
self.requires(f"opencl-headers/{self.version}", transitive_headers=True)

def source(self):
tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["OPENCL_ICD_LOADER_HEADERS_DIR"] = ";".join(self.deps_cpp_info["opencl-headers"].include_paths)
if self.settings.compiler == "Visual Studio":
self._cmake.definitions["USE_DYNAMIC_VCXX_RUNTIME"] = str(self.settings.compiler.runtime).startswith("MD")
self._cmake.definitions["OPENCL_ICD_LOADER_PIC"] = self.options.get_safe("fPIC", True)
self._cmake.definitions["OPENCL_ICD_LOADER_BUILD_TESTING"] = False
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["OPENCL_ICD_LOADER_HEADERS_DIR"] = ";".join(self.deps_cpp_info["opencl-headers"].include_paths)
if is_msvc(self):
tc.variables["USE_DYNAMIC_VCXX_RUNTIME"] = not is_msvc_static_runtime(self)
tc.variables["OPENCL_ICD_LOADER_PIC"] = self.options.get_safe("fPIC", True)
tc.variables["OPENCL_ICD_LOADER_BUILD_TESTING"] = False
if self.settings.os == "Windows":
self._cmake.definitions["OPENCL_ICD_LOADER_DISABLE_OPENCLON12"] = self.options.disable_openclon12
self._cmake.configure()
return self._cmake

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
tc.variables["OPENCL_ICD_LOADER_DISABLE_OPENCLON12"] = self.options.disable_openclon12
# Honor BUILD_SHARED_LIBS from conan_toolchain (see https://github.com/conan-io/conan/issues/11840)
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
tc.generate()

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "both")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why cmake_find_mode:both is required here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.cpp_info.set_property("cmake_module_file_name", "OpenCL")
self.cpp_info.set_property("cmake_file_name", "OpenCLICDLoader")
self.cpp_info.set_property("cmake_target_name", "OpenCL::OpenCL")
self.cpp_info.includedirs = []
self.cpp_info.libs = ["OpenCL"]
if not self.options.shared:
if self.settings.os == "Linux":
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["dl", "pthread"]
elif self.settings.os == "Windows":
self.cpp_info.system_libs = ["cfgmgr32", "runtimeobject"]

# TODO: to remove in conan v2
self.cpp_info.filenames["cmake_find_package"] = "OpenCL"
self.cpp_info.filenames["cmake_find_package_multi"] = "OpenCLICDLoader"
self.cpp_info.names["cmake_find_package"] = "OpenCL"
self.cpp_info.names["cmake_find_package_multi"] = "OpenCL"
7 changes: 3 additions & 4 deletions recipes/opencl-icd-loader/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)
project(test_package C)
project(test_package LANGUAGES C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(OpenCLICDLoader REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE OpenCL::OpenCL)
19 changes: 14 additions & 5 deletions recipes/opencl-icd-loader/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, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

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")
8 changes: 8 additions & 0 deletions recipes/opencl-icd-loader/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.1)
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/opencl-icd-loader/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):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
4 changes: 4 additions & 0 deletions recipes/opencl-icd-loader/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
versions:
"2022.09.30":
folder: all
"2022.05.18":
folder: all
"2022.01.04":
folder: all
"2021.04.29":
Expand Down