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)
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.
Related
i am trying to run a simple program using the pigpio library on my raspberry pi, with the yocto project.
I have already tried out the build with cmake and when i run it in the terminal on my pc it works. But when i try to bitbake my recipe, i get following cmake error and i cant seem to find out whats the problem and why i only get this error in bitbake and not when running cmake in the console.
| CMake Error at /home/ibschwarzfischer/yocto/poky/build-rpi3/tmp/work/cortexa53-poky-linux/blinker/1.0-r0/recipe-sysroot-native/usr/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
| Could NOT find pigpio (missing: pigpio_INCLUDE_DIR pigpio_LIBRARY
| pigpiod_if_LIBRARY pigpiod_if2_LIBRARY)
| Call Stack (most recent call first):
| /home/ibschwarzfischer/yocto/poky/build-rpi3/tmp/work/cortexa53-poky-linux/blinker/1.0-r0/recipe-sysroot-native/usr/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
| /home/ibschwarzfischer/yocto/packages/pigpio-master/util/Findpigpio.cmake:29 (find_package_handle_standard_args)
| CMakeLists.txt:12 (find_package)
My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.5)
project(blinker)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../packages/pigpio-master/util)
set(pigpio_DIR ${PROJECT_SOURCE_DIR}/../../packages/pigpio-master/cmake)
#target_include_directories(blinker PUBLIC include/pigpio)
find_package(pigpio REQUIRED)
add_executable(blinker main.c)
target_link_libraries(blinker PRIVATE pigpio)
and there is also a Findpigpio.cmake included in the pigpio library:
################################################################################
### Find the pigpio shared libraries.
################################################################################
# Find the path to the pigpio includes.
find_path(pigpio_INCLUDE_DIR
NAMES pigpio.h pigpiod_if.h pigpiod_if2.h
HINTS /usr/local/include)
# Find the pigpio libraries.
find_library(pigpio_LIBRARY
NAMES libpigpio.so
HINTS /usr/local/lib)
find_library(pigpiod_if_LIBRARY
NAMES libpigpiod_if.so
HINTS /usr/local/lib)
find_library(pigpiod_if2_LIBRARY
NAMES libpigpiod_if2.so
HINTS /usr/local/lib)
# Set the pigpio variables to plural form to make them accessible for
# the paramount cmake modules.
set(pigpio_INCLUDE_DIRS ${pigpio_INCLUDE_DIR})
set(pigpio_INCLUDES ${pigpio_INCLUDE_DIR})
# Handle REQUIRED, QUIET, and version arguments
# and set the <packagename>_FOUND variable.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(pigpio
DEFAULT_MSG
pigpio_INCLUDE_DIR pigpio_LIBRARY pigpiod_if_LIBRARY pigpiod_if2_LIBRARY)
so if anyone knows something that might help i am very happy about it!
Thanks in advance!
i tried to compile it with cmake in the terminal using cmake -S . -B out/build and then cmake --build out/build and when i ran the program in the terminal it worked and cmake didnt give me an error so i know the package is linked to the target and cmake also finds the Findpigpio.cmake.
I am trying to build a library that is dependent on GDCM. So, I've installed GDCM following instructions that were provided in INSTAL.txt file and did not have any trouble doing it. But, when I tried to use cmake to build the library that is dependent on it, I am getting following message:
CMake Error at /usr/local/lib/gdcm-3.0/GDCMTargets.cmake:37 (message):
Some (but not all) targets in this export set were already defined.
Targets Defined:
gdcmjpeg8;gdcmjpeg12;gdcmjpeg16;gdcmuuid;gdcmCommon;gdcmDICT;gdcmDSED;gdcmIOD;gdcmMSFF
Targets not yet defined:
gdcmexpat;gdcmopenjp2;gdcmcharls;gdcmzlib;socketxx;gdcmMEXD
Call Stack (most recent call first):
/usr/local/lib/gdcm-3.0/GDCMConfig.cmake:39 (include)
CMakeLists.txt:109 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/stefan/Desktop/BioClinica/bdtk/CMakeFiles/CMakeOutput.log".
See also "/home/stefan/Desktop/BioClinica/bdtk/CMakeFiles/CMakeError.log
Here is a portion of the code (from reported line GDCMConfig.make:37) from /usr/local/lib/gdcm-3.8/GDCMConfig.make file:
if(EXISTS ${SELF_DIR}/GDCMTargets.cmake)
# This is an install tree
include(${SELF_DIR}/GDCMTargets.cmake)
get_filename_component(GDCM_INCLUDE_ROOT "${SELF_DIR}/../../include/gdcm-3.0" ABSOLUTE)
set(GDCM_INCLUDE_DIRS ${GDCM_INCLUDE_ROOT})
get_filename_component(GDCM_LIB_ROOT "${SELF_DIR}/../../lib" ABSOLUTE)
set(GDCM_LIBRARY_DIRS ${GDCM_LIB_ROOT})
else()
if(EXISTS ${SELF_DIR}/GDCMExports.cmake)
# This is a build tree
set( GDCM_INCLUDE_DIRS "/home/stefan/gdcm-3.0.7/gdcm/Source/Common;/home/stefan/gdcm-3.0.7/gdcmbin/Source/Common;/home/stefan/gdcm-3.0.7/gdcm/Source/DataStructureAndEncodingDefinition;/home/stefan/gdcm-3.0.7/gdcm/Source/MediaStorageAndFileFormat;/home/stefan/gdcm-3.0.7/gdcm/Source/MessageExchangeDefinition;/home/stefan/gdcm-3.0.7/gdcm/Source/DataDictionary;/home/stefan/gdcm-3.0.7/gdcm/Source/InformationObjectDefinition")
set(GDCM_LIBRARY_DIRS "/home/stefan/gdcm-3.0.7/gdcmbin/bin/.")
include(${SELF_DIR}/GDCMExports.cmake)
else()
message(FATAL_ERROR "ooops")
endif()
endif()
I'm building a test project to learn libraries zeromq with cppmq, and I want to include both libraries as subdirectories. I currently have the following structure:
|-- CMakeLists.txt
|-- deps
| |-- cppzmq-4.3.0
| | |-- CMakeLists.txt
| | `-- rest of files
| |-- zeromq-4.3.1
| | |-- CMakeLists.txt
| | `-- rest of files
`-- main.cpp
I've tried with the following CMakeLists:
cmake_minimum_required(VERSION 3.14)
project(PruebaZeroMQ)
set(CMAKE_CXX_STANDARD 11)
add_subdirectory(deps/zeromq-4.3.1)
add_subdirectory(deps/cppzmq-4.3.0)
add_executable(PruebaZeroMQ main.cpp)
target_link_libraries(PruebaZeroMQ
libzmq
cppzmq)
When I run cmake, I get the following error:
-- Detected CPPZMQ Version - 4.3.0
-- CMake libzmq package not found, trying again with pkg-config (normal install of zeromq)
CMake Error at deps/cppzmq-4.3.0/CMakeLists.txt:20 (message):
ZeroMQ was not found, neither as a CMake package nor via pkg-config
cppmq depends on zeromq, and looks like it tries to load it using find_package, so I tried to modify CMAKE_MODULE_PATH so it could find the ZeroMQConfig.cmake file, but it fails too, with the same error:
add_subdirectory(deps/zeromq-4.3.1)
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}/deps/zeromq-4.3.1 ")
add_subdirectory(deps/cppzmq-4.3.0)
Is there a way of achieving this? I'd rather not install the libraries system-wide.
After trying to manually find_package, CMake showed the following error message:
Add the installation prefix of "ZeroMQ" to CMAKE_PREFIX_PATH or set
"ZeroMQ_DIR" to a directory containing one of the above files.
So I tried that, using:
set(ZeroMQ_DIR ${CMAKE_CURRENT_BINARY_DIR}/deps/zeromq-4.3.1)
And it worked.
I have a CMake structure:
mainproject/
mainproject/cmake/FindMyPackage.cmake
mainproject/CMakeLists.txt
plugin/
plugin/CMakeLists.txt
and in the above CMakeLists.txt I call
add_subdirectory(${LOOP_SUBDIR}/${subdir} examples/${subdir})
which add the plugin/CMakeLists.txt subdirectory outside the directory defined above.
In this second CMakeLists.txt I call FindPackage(MyPackage REQUIRED)
which give error message:
CMake Error at [...]/plugin/CMakeLists.txt:9 (find_package):
By not providing "FindMyPackage.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "MyPackage", but
CMake did not find one.
Is there any way to make it use the cmake files in the mainproject folder?
Just follow given error message, i.e. this must help:
# CMakeLists.txt
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/mainproject/cmake")
add_subdirectory(plugin)
I am trying to built a "Hello World" project with Qt 5 and cmake under MinGW.
This is the CMakeLists.txt file (taken from the on-line doc):
project(Qt5_cmake_test)
cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.1.1/5.1.1/mingw48_32")
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Find the QtWidgets library
find_package(Qt5Widgets)
# Add the source files from the current directory
aux_source_directory(. SRC_LIST)
# Tell CMake to create the executable
add_executable(${PROJECT_NAME} WIN32 ${SRC_LIST})
# Use the Widgets module from Qt5
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
The source code is the one generated automatically when creating a new project (which produces an empty window).
Configuring from the Windows command prompt with: cmake -G "MinGW Makefiles" ..\Qt5_cmake_test
I get these errors:
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeMinGWFindMake.cmake:20 (message):
sh.exe was found in your PATH, here:
C:/Program Files (x86)/Git/bin/sh.exe
For MinGW make to work correctly sh.exe must NOT be in your path.
Run cmake from a shell that does not have sh.exe in your PATH.
If you want to use a UNIX shell, then use MSYS Makefiles.
Call Stack (most recent call first):
CMakeLists.txt:8 (project)
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:C:/Users/pietro.mele/projects/tests/buildSystem_test/Qt5_cmake_test-build/CMakeFiles/2.8.11.2/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file:C:/Users/pietro.mele/projects/tests/buildSystem_test/Qt5_cmake_test-build/CMakeFiles/2.8.11.2/CMakeCXXCompiler.cma
ke
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
So it seems it is not able to find the compiler. Is there a way to let cmake find it on its own, or just giving it the CMAKE_PREFIX_PATH directory?
Do I have to manually specify all those variables in the makefile or as environment variables in Windows?
I tried both from the standard Windows command prompt and from the one provided by Qt, with the same result. Is it OK to build from the Windows command prompt, or should I do it from the MinGW's shell?
Platform:
Qt 5.1
CMake 2.8.11.2
MinGW/GCC 4.8
Windows 7
Get the git path out of your PATH before running cmake.
Here is the magic to do that:
set PATH=%PATH:C:/Program Files (x86)/Git/bin;=%
This CMakeLists.txt file works properly:
project(Qt5_cmake_test)
cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.1.1/5.1.1/mingw48_32")
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Find the Qt libraries
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
# Add the source files from the current directory
aux_source_directory(. SRC_LIST)
# Tell CMake to create the executable
add_executable(${PROJECT_NAME} WIN32 ${SRC_LIST})
# Use Qt5 modules
target_link_libraries(${PROJECT_NAME}
Qt5::Widgets
Qt5::WinMain)
The changes are:
Added find_package(Qt5Core REQUIRED).
Added Qt5::WinMain to target_link_libraries.
In some of my answer here on SO, I have described. CMake does not like sh.exe.
sh.exe was found in your PATH, here:
C:/Program Files (x86)/Git/bin/sh.exe
Solution : Rename C:/Program Files (x86)/Git/bin/sh.exe shortly.
For example:
C:/Program Files (x86)/Git/bin/shxx.exe
But do not forget when everything is built. rename properly again.