1

I download opencl-icd from KhronosGroup and build it fine.

But it doesn't have OpenCLConfig.cmake.

So I decide to create one that my program(CMakeLists.txt) can use find_package(OpenCL) to invoke it.

Following file tree is my OpenCL dir. after I build.


# $PWD is C:/SDKs/ocl-icd

|-- OpenCLConfig.cmake
|-- bin
|   `-- OpenCL.dll
|-- include
|   `-- CL
        ... CL Headers
`-- lib
    |-- OpenCL.exp
    `-- OpenCL.lib

I create OpenCLConfig.cmake which content is:

set(OpenCL_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)
set(OpenCL_INCLUDE_DIR "${OpenCL_DIR}/include")
set(OpenCL_LIBRARIES "OpenCL")

I use find_package(OpenCL) in others CMakeLists.txt:

...
set(OpenCL_DIR "C:/SDKs/ocl-icd" CACHE PATH "OpenCL Root DIR")
find_package(OpenCL 2 REQUIRED) 
include_directories (${OpenCL_INCLUDE_DIR})
add_executable (${PROJECT_NAME} test.cc)
target_link_libraries(${OpenCL_LIBRARIES})
...

While I use cmake-gui to configure it, I got error report

CMake Error at C:/Program Files/CMake/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find OpenCL (missing: OpenCL_INCLUDE_DIR) (Required is at least
  version "2")
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindOpenCL.cmake:150 (find_package_handle_standard_args)
  CMakeLists.txt:10 (find_package)

I think that it error caused by OpenCLConfig.cmake.

How do I solved it?

update: add 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)
curlywei
  • 682
  • 10
  • 18
  • "I think that it error caused by OpenCLConfig.cmake." - The error message is clearly says, that the error is emitted by `C:/Program Files/CMake/share/cmake-3.15/Modules/FindOpenCL.cmake` script, shipped with CMake. `FindXXX.cmake` script has a precedence over `XXXConfig.cmake` one when `find_package` is used. You may disable searching for `FindXXX.cmake` script by adding `CONFIG` or `NO_MODULE` option to `find_package` call. – Tsyvarev Aug 27 '19 at 20:31
  • Hi @Tsyvarev: Thanks your reply. I add **Config** in find_package(). It looks like can entry to "C:/SDKs/ocl-icd", But still report error: – curlywei Aug 27 '19 at 20:45
  • 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 – curlywei Aug 27 '19 at 20:45
  • CMake expects `OpenCLConfigVersion.cmake` file near your `OpenCLConfig.cmake` one. This file should check version compatibility. More about behavior of this file see in the [documentation](https://cmake.org/cmake/help/latest/command/find_package.html#version-selection). – Tsyvarev Aug 27 '19 at 21:42
  • Hi @Tsyvarev: I have done. But cmake-gui still report same error – curlywei Aug 27 '19 at 21:54
  • Please, update the question with your `OpenCLConfigVersion.cmake` file content. Make sure that you have tried clean reconfiguration (with build directory cleared or, at least, with CMake cache cleared). – Tsyvarev Aug 27 '19 at 22:10
  • @Tsyvarev: OK! I will update – curlywei Aug 28 '19 at 00:36
  • On Stack Overflow we want the question to concentrate on the **single problem**. Your question would very fit for problem "How to implement version check in a config file?" ... but it contains the code (`CMakeLists.txt`) which cause **another problem** and you specify **error message** for that other problem. Could you **update the question** for the **new problem** (about version compatibility), by including `CMakeLists.txt` and, more important, the error message? After that, it would be possible to **answer** the question about new problem. – Tsyvarev Aug 28 '19 at 08:03
  • Hi @Tsyvarev: Thanks your suggestion. I will open other thread to discuss this problem. – curlywei Aug 28 '19 at 10:35
  • @Tsyvarev: Your reply ```add CONFIG to find_package() ``` is correct answer in this thread(question). So, could you post it to answer? – curlywei Aug 28 '19 at 10:37
  • Yes, splitting the question on separate questions with **well-defined problems** is a good way too. – Tsyvarev Aug 28 '19 at 11:09
  • Version problem refer to: https://stackoverflow.com/questions/57690785/cmake-how-to-implement-version-check-in-a-config-file – curlywei Aug 28 '19 at 16:01

1 Answers1

0

The error message says, that the error is emitted by the script shipped with CMake:

C:/Program Files/CMake/share/cmake-3.15/Modules/FindOpenCL.cmake

and your script (OpenCLConfig.cmake) is ignored.

The thing is that when find_package() searches the script for process the request, FindXXX.cmake script is searched first. Only if such script is absent, XXXConfig.cmake script is searched.

You may disable searching for FindXXX.cmake script by adding CONFIG or NO_MODULE option to find_package call:

find_package(OpenCL 2 REQUIRED CONFIG)

For some packages (e.g. Boost) their FindXXX.cmake script tries to "leverage" its work to XXXConfig.cmake script, if the latter script exists. But other packages (like OpenCL which you use) do not do that. I know no agreements on this leveraging.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153