0

我为 opencl-icd 自定义 CMake 包配置文件OpenCLConfig.cmake

参考Create CMake XXConfig.cmake let other cmake project invoke

现在,我遇到一个问题:如何在配置文件中实现版本检查。

我在OpenCLConfig.cmake旁边创建OpenCLConfigVersion.cmake,其内容是:

#OpenCLConfigVersion.cmake

set(OpenCL_VERSION 2.2)
set(OpenCL_VERSION_MAJOR 2)
set(OpenCL_VERSION_MINOR 2)
SET(OpenCV_VERSION_PATCH 0)
SET(OpenCV_VERSION_TWEAK 0)

当我在其他 CMakeLists.txt 中调用它的 opencl-icd 时,

那是find_package(OpenCL config)

我收到了这个错误:

CMake Error at CMakeLists.txt:10 (find_package): Could not find a 
configuration file for package "OpenCL" that is compatible with requested 
version "2". The following configuration files were considered but not 
accepted: C:/SDKs/ocl-icd/OpenCLConfig.cmake, version: unknown 

我已经在我的 CMakeLists.txt中设置OpenCL_DIR了。"C:/SDKs/ocl-icd"

我自定义的 OpenCLConfig.cmake内容是

set(OpenCL_FOUND TRUE)
set(OpenCL_ROOT_DIR "C:/SDKs/ocl-icd")

set(OpenCL_VERSION 2.2)
set(OpenCL_VERSION_MAJOR 2)
set(OpenCL_VERSION_MINOR 2)
SET(OpenCV_VERSION_PATCH 0)
SET(OpenCV_VERSION_TWEAK 0)

find_path(OpenCL_INCLUDE_DIR NAMES CL/cl.h PATHS "${OpenCL_ROOT_DIR}/include")
set(OpenCL_INCLUDE_DIRS "${OpenCL_INCLUDE_DIR}")
find_library(OpenCL_LIBRARY NAMES OpenCL.lib PATHS "${OpenCL_ROOT_DIR}/lib") 
set(OpenCL_LIBRARIES ${OpenCL_LIBRARY})

如何处理版本问题。

4

1 回答 1

0

我已经解决了。

我参考OpenCVConfig-version.cmake写我的OpenCLConfigVersion.cmake

#OpenCLConfigVersion.cmake

set(OpenCL_VERSION 2.2)
set(PACKAGE_VERSION ${OpenCL_VERSION})

set(PACKAGE_VERSION_EXACT False)
set(PACKAGE_VERSION_COMPATIBLE False)

if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
  set(PACKAGE_VERSION_EXACT True)
  set(PACKAGE_VERSION_COMPATIBLE True)
endif()

if(PACKAGE_FIND_VERSION_MAJOR EQUAL 2
   AND PACKAGE_FIND_VERSION VERSION_LESS PACKAGE_VERSION)
  set(PACKAGE_VERSION_COMPATIBLE True)
endif()

修改后可以正常使用。

于 2019-08-28T16:03:38.643 回答