CMake include precompiled library - cmake

I'm trying to get compiled project under QTCreator with CMake under Windows, I'm wonder how to add external library and its headers to my project. I have my CMakeList.txt as follows
cmake_minimum_required(VERSION 2.8)
project(opencl_info)
add_executable(${PROJECT_NAME} "main.cpp")
include_directories(c:\\AMD APP SDK\\3.0\\include\\)
target_link_libraries(opencl_info c:\\AMD APP SDK\\3.0\\lib\\x86_64\\OpenCL.lib)
I'm getting "CL\cl.h - No such file or directory" how to include it? for now with "hardlink"?
Thank you.
Under VS15 I'm running this project and it requires to have:
"Additional Include Directories" c:\AMD APP SDK\3.0\include\
"Additional Library Directories" c:\AMD APP SDK\3.0\lib\x86_64\
"Additional Depandancies" OpenCL.lib and th eproject runs.
I need to have OpenCL.dll within my path.
So I'm looking for the same/similar behaviour for QTCreator/CMake to include headers and libraries (.lib,.dll) for my project.
Thank you.
I have more opencl platfroms (nVidia, AMD) present on my machine, per using FIND_PACKAGE(OpenCL REQUIRED) its nVidia identified instead Found OpenCL: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/lib/x64/OpenCL.lib (found version "1.2")
How to tell CMake explicitly to find and use AMD?

In CMake spaces are separators. If you want to use string with spaces, enclose it in double quotes:
"c:\\AMD APP SDK\\3.0\\include\\"

Partial success, I moved AMD APP SDK to another directory named as c:\opencl\
which is shorten with no space in path directory
I included direcotries include_directories(c:\\opencl\\include\\) and now an issue of missing "CL\cl.h - No such file or directory" is gone.

I found solution :)
cmake_minimum_required(VERSION 2.8)
project(opencl_info)
include_directories("c:\\AMD APP SDK\\3.0\\include\\")
link_directories("c:\\AMD APP SDK\\3.0\\lib\\x86_64\\")
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(opencl_info OpenCL.lib)
Thanks for help, guys!!!

Related

cmake link to macOS pre-compiled binaries at custom path

I want to link to the GLFW library using the binaries provided when downloading from the website at a custom path in my project:
include_directories(PROJECT_SOURCE_DIR/third_party/glfw/lib-arm64)
add_executable(rpg main.cpp)
target_include_directories(rpg PRIVATE ${PROJECT_SOURCE_DIR}/third_party/glad/include ${PROJECT_SOURCE_DIR}/third_party/glfw/include)
find_library(GLFW_LIB NAMES glfw3 PATHS PROJECT_SOURCE_DIR/third_party/glfw PATH_SUFFIXES lib-arm64 lib-universal lib-x86_64)
target_link_libraries(rpg PRIVATE ${GLFW_LIB})
I've tried finding both glfw and glfw3 but this fails to find the GLFW library:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
GLFW_LIB
linked by target "rpg" in directory /Users/ashley/Personal/rpg/src
How should I specify the path to link to these rather than use a globally installed version or building from source myself?
Edit
Correcting the use of find_library as per #Tsyvarev suggestion solved this. The prior update to say it still didn't work was in haste - I wasn't correctly expanding the path variable.

CMake package configuration files for upstream projects using Qt5 problems

I am working on a larger C++ library that is using CMake and depends on Qt.
We moved from Qt4 to Qt5 and now I encounter a problem when using our lib
in an upstream project. As a minimal working example demonstrating the problem please have a look at this repo:
https://github.com/philthiel/cmake_qt5_upstream
It contains two separate CMake projects:
MyLIB: a tiny library that uses QString from Qt5::Core.
It generates and installs package configuration files
MyLIBConfig.cmake, MyLIBConfigVersion.cmake, and MyLIBTargets.cmake
in order to be searchable by CMake find_package()
MyAPP: a tiny executable depending on MyLIB
The project uses find_package(MyLIB) and creates an executable that uses MyLIB
The problem is that CMake gives me the following error message when configuring the MyAPP project:
CMake Error at CMakeLists.txt:11 (add_executable):
Target "MyAPP" links to target "Qt5::Core" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?
The reason for this behaviour is that in the automatically generated MyLIBTargets.cmake file the INTERFACE_LINK_LIBRARIES entry for Qt5 Core is the Qt5::Core symbol. Using Qt4, the absolute path to the Qt core lib was specified here.
Now, I simply can resolve this by using
find_package(Qt5Core 5.X REQUIRED)
in the MyAPP project.
However, I would like to know if this is the intended/generic way to go, i.e. requesting upstream projects of our lib to search for the required transitive Qt5 dependencies themselves, or if I probably misuse CMake here and need to change my configuration procedure?
The CMake docu on package file generation
https://cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html
mentions that macros can be provided by the package configuration files to upstream. Maybe this would be the correct place to search for imported targets like Qt5 and break upstream configuration runs when these dependencies are not found?
Best,
Philipp
[edit of the edit] Full Source Example
You need to deliver a CMake config file for your project, and probably the ConfigFile should be generated via CMake itself (because you cannot know for shure where the user will install your software).
Tip, use the ECM cmake modules to ease the creation of that:
find_package(ECM REQUIRED NO_MODULE)
include(CMakePackageConfigHelpers)
ecm_setup_version(${PROJECT_VERSION}
VARIABLE_PREFIX ATCORE
VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/atcore_version.h"
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5AtCoreConfigVersion.cmake"
SOVERSION 1
)
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/KF5AtCoreConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/KF5AtCoreConfig.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)
and the KF5AtCoreConfig.cmake.in:
#PACKAGE_INIT#
find_dependency(Qt5Widgets "#REQUIRED_QT_VERSION#")
find_dependency(Qt5SerialPort "#REQUIRED_QT_VERSION#")
find_dependency(KF5Solid "#KF5_DEP_VERSION#")
include("${CMAKE_CURRENT_LIST_DIR}/KF5AtCoreTargets.cmake")
This will generate the correct FindYourSortware.cmake with all your dependencies.
[edit] Better explanation on what's going on.
If you are providing a library that will use Qt, and that would also need to find the Qt5 library before compilling the user's source, you need to provide yourself a FindYourLibrary.cmake code, that would call
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Whatever)
Now, if it's your executable that needs to be linked, use the Components instead of the way you are doing it now.
find_package(Qt5 REQUIRED COMPONENTS Core)
then you link your library with
target_link_libraries(YourTarget Qt5::Core)

GLEW with CMakeLists

I have the following CMakeLists to include glew into my project. Compiling the project works fine but when I run the project I get an error saying that the program can't find glew32.dll. Any ideas why?? Thanks for answers!
set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/external/glew-1.12.0")
set(CMAKE_LIBRARY_PATH "${CMAKE_SOURCE_DIR}/external/glew-1.12.0/lib/Release/Win32/")
find_package(GLEW REQUIRED)
if(GLEW_FOUND)
message("GLEW Found!")
include_directories(${GLEW_INCLUDE_DIRS})
link_libraries(${GLEW_LIBRARIES})
add_definitions(${GLEW_DEFINITIONS})
else(GLEW_FOUND)
message(FATAL_ERROR "GLEW NOT Found")
endif(GLEW_FOUND)
add_executable(Project ${CODE})
target_link_libraries(Project ${GLEW_LIBRARIES})
You need to have the directory where glew32.dll can be found in your environment's PATH variable. If you're using MSVC set the Environment textbox in your property pages of your application:
PATH=<dir-of-glew32.dll>;%PATH%
If you're running from shell, issue the same command on the command line.
Another option is to use GLEW as a static library. In that case you will not need glew32.dll, the entire glew library will be linked into your program. Check out the GLEW github repository and study the script cmake-testbuild.sh about how to use GLEW as a static library.
Please note, that the GLEW github repository does not contain certain generated files. If you can't run make extensions on your platform, use this repository: glew-with-extensions which already contains the generated files.

Error with Ogre and CMake

I installed Ogre3D 1.8.1 (the source package) on Ubuntu 12.04 and everything went fine (I managed to run some samples on the Ogre interface). However, I hit a problem while I was compiling an external project (that one) that needed the OpenCV, ArUco and Ogre librarys. When I run the CMake of the project, I receive the following:
CMake Error at CMakeLists.txt:46 (find_package):
By not providing "FindOGRE.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OGRE", but
CMake did not find one.
Could not find a package configuration file provided by "OGRE" with any of
the following names:
OGREConfig.cmake
ogre-config.cmake
Add the installation prefix of "OGRE" to CMAKE_PREFIX_PATH or set
"OGRE_DIR" to a directory containing one of the above files. If "OGRE"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
I know where the FindOGRE.cmake is, it's in the /usr/local/lib/OGRE/cmake, but I don't know how to say to CMake to look for that folder and fix this problem.
You just need to use the -D command line option along with the CMAKE_MODULE_PATH variable:
cmake . -DCMAKE_MODULE_PATH=/usr/local/lib/OGRE/cmake
Just for the record, an alternative solution would be to add the module path directly in the CMakeLists.txt. For example (tested on Debian 9):
set(CMAKE_MODULE_PATH "/usr/share/OGRE/cmake/modules/;${CMAKE_MODULE_PATH}")
Just make sure to add the line before find_package is called.
For me, it only works to set the following in CMakeLists.txt before find_package:
set(OGRE_DIR /usr/share/OGRE/build/sdk/CMake)
Note that the CMake directory is the one containing OGREConfig.cmake. For some reason, my CMake ignores CMAKE_MODULE_PATH.
Maybe, of some help for someone
For me, this solution work on manjaro:
set(CMAKE_MODULE_PATH "/usr/lib/OGRE/cmake;${CMAKE_MODULE_PATH}")
find_package(OGRE QUIET)
if (OGRE_FOUND)
include_directories( ${ogre_INCLUDE_DIR})
link_directories(${OGRE_LIBRARIES})
message(STATUS "OGRE: FOUND")
else()
message(STATUS "OGRE: NOT FOUND")
endif()

Error in CMake path

I'm trying to build the Visual Studio project for a kinect demo thing, rgbddemo. According to the instructions on the page, I need to set the PATH variable to include QMAKE from QT. I did that, but I keep getting this error:
CMake Error at CMakeLists.txt:1 (QT4_WRAP_CPP):
Unknown CMake command "QT4_WRAP_CPP".
From what I could gather from google, it's a problem with CMake knowing where something from QT is. The page I linked above also mentions that you can set the path for QMAKE within CMake, but I don't know how to do that. Does anyone have any suggestions? Thanks.
You could try inserting the line
FIND_PACKAGE(Qt4)
into the top-level CMakeLists.txt file after the line
INCLUDE("${nestk_BINARY_DIR}/UseNestk.cmake")
That should cause it to try to find qmake for you. I'm not sure why they don't have that though, but then I'm not that familiar with cmake.
I think this lines in your CMakeLists.txt file can help you.
find_package(Qt4 Required)
include(${QT_USE_FILE}) #contains path to Qt header
#...
qt4_wrap_cpp(MOC_SOURCES ${MY_HEADERS}) #invoking moc
add_library(MY_LIB ${SOURCES} ${MOC_SOURCES}) #building lib
target_link_libraries(MY_LIB ${QT_LIBRARIES})
qt4_add_resources(MY_QT_RSC ${RESOURCES}) #if you want to compile from resource files
add_library(MY_LIB_2 ${MY_QT_RSC} {SOURCES})