Integrating and running OpenDDS with QTCreator - c++

I have installed the latest version of OpenDDS I followed the configuration and installation documents provided.
I can perfectly run opendds examples with the terminal.
I need to integrate OpenDDS with QT, since OpenDDS supports CMake
I have tried to load CMakeList.txt in qt for messenger_1 and messeger_2 examples I got, unknown CMake command "OPENDDS_TARGET_SOURCE"
I wasn't able to run the IShape example either.

This most probably means that CMake does not find the OpenDDS package files.
CMake reads the CMake variable CMAKE_PREFIX_PATH and extends its default package search path by this. By default Qt Creator sets that to your Qt install path (which is good since you want to use Qt), but to use OpenDDS you need to point it to its source/install path as well (see the OpenDDS CMake documentation).
You can add multiple paths to CMAKE_PREFIX_PATH, separated by ; on Windows, or : on Linux/macOS.
In Qt Creator the CMAKE_PREFIX_PATH is set up in the CMake Configuration part of the Kit. So:
Open "Options > Kits > Kits" and choose the kit you use for your project
Scroll down to CMake Configuration and click Change
Find the CMAKE_PREFIX_PATH line and change it to something like
CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX};C:\path\to\OpenDDS or if you are on Linux/macOS
CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX};/path/to/OpenDDS
You might need to close and re-open the project after that (but maybe not).

Related

I cannot use Qt with CLion

I try to make a program using Qt in CLion.
After clicking New Project in the starting window of CLion I choose Qt Widgets Executable on the left and add the following Qt CMake prefix path:
C:\Qt\6.0.3
Then I click on "create" and get the "Open Project Wizard" window. I click on "Manage toolchains..." and add a new toolchain. Next to "Environment:" I write:
C:\Qt\Tools\mingw810_64
and everything looks fine. Then I click on Ok and again on Ok and after few seconds I get the following message below:
CMake Error at CMakeLists.txt:21 (find_package):
By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5", but
CMake did not find one.
Could not find a package configuration file provided by "Qt5" with any of
the following names:
Qt5Config.cmake
qt5-config.cmake
Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
to a directory containing one of the above files. If "Qt5" provides a
separate development package or SDK, be sure it has been installed.
Please, can you help me?
(Qt is installed on my computer)
Setting Toolchains, treat qt mingw tool path as default
when you create qt project, please set qt cmake prefix path, such as "D:\Qt\6.1.2\mingw81_64\lib\cmake"
try previous version of qt.
OR
try Visual Studio IDE.

Using CMake to find dependencies in an application-specific subfolder

In spite of many years of coding large-scale C++ applications, I do not understand how find_package is supposed to work in a medium-size CMake project, ASSUMING that I want to build the source to dependent packages myself and not simply rely on large systems like opencv, pcl or boost being installed somewhere in a system folder. I can't can't believe that I'm the only person in the world who has shipped multiple OpenCV and other open-source apps, has worked with meta-build systems like NAnt and SCons on major game projects, yet can't understand the most basic things about how CMake works or find a tutorial answering these questions.
In the past, I have essentially hacked around not understaning find_package by setting all the foo_DIR values by hand as CMake complains until I get a working folder.
I would like to run through a simple example which I'm working on right now, and dearly hope someone can explain what I'm doing so wrong.
Firstly, some assumptions:
I want to build everything for both MacOS and Windows, ideally via CMakeGUI. MacOS should build XCodeProjects and Windows should build Visual Studio Solutions.
Where there are dependencies, I want to compile them myself, so I have debug symbols and can modify the dependency source (or at least debug into it.)
No installation of pre-built binaries into system folders, i.e. no use of sudo port install opencv/pcl, etc on mac.
I have multiple projects, and prefer to keep a project and its dependencies in a single folder.
For the purposes of a concrete example, suppose I am building this project, although it's an arbitrary choice to illustrate the process and confusion I suffer:
https://github.com/krips89/opendetection
This lists dependencies, which I have intentionally reordered here so that I can take them in order, as follows:
find_package(OpenCV REQUIRED)
find_package(Eigen REQUIRED)
find_package(Boost 1.40 COMPONENTS program_options REQUIRED )
find_package(PCL REQUIRED)
find_package(VTK REQUIRED)
I would like to have all of these dependencies downloaded and configured in a single path (let's say c:\src on Windows, and ~\src on Mac for simplicity), NOT in a system path. Assume that the actual folder is a sub-folder for this project, and no a sub-folder for all projects. This should also allow for side-by-side installation of multiple projects on the same computer.
Taking this one step at a time:
(1) I clone openCV from https://github.com/opencv/opencv, sync to tag 3.1, configure into the folder opencv_build folder, build and install into opencv_install. I've done this so many times it's pretty straightforward.
(2) As above, but for eigen (although building for eigen doesn't actually do anything s it's a template library. I install to a folder eigen_install
Taking directory shows a series of folders for downloaded dependencies. I have assumed a convention where , and are source repos, and their following _build folders are the "WHere to build the binaries" folders in CMakeGui.
$ ls
boost_1_40_0 opencv opendetection_build
eigen opencv-build opendetection_data
eigen_build opencv_contrib pcl
eigen_install opendetection
All good so far, now let's try to configure opendetection and generate a solution into opendetection_build, and find pendetection's dependencies from within the ~/src folder, that is for the first two dependencies, I hope to find opencv and eigen in the opencv-build and eigen-build folders.
OpenCV immediately fails, as expected, saying:
Could not find a package configuration file provided by "OpenCV" with any of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set "OpenCV_DIR" to a directory containing one of the above files. If "OpenCV" provides a separate development package or SDK, be sure it has been installed.
That's good, because I want to explicitly tell CMake to look for dependent packages under my ~/src folder. Question: Is the use of CMAKE_PREFIX_PATH=/users/foo/src the recommended way to accomplish what I want - looking for all sub-packages under a specific path?
Following this, CMake finds OpenCV (good), and sets OpenCV_DIR = /Users/foo/src/opencv-build.
Question: Given that I have made an "install" to opencv-install (using CMAKE_INSTALL_PREFIX and building the Install Target Of OpenCV, shouldn't it find OpenCV in the opencv-install folder not opencv-build?
Moving on to eigen, I have configured and built eigen, and installed it to ~/src/eigen-install, which since it is a subfolder of CMAKE_PREFIX_PATH (~/src) I might expect to be found. But it doesn't seem to be. Can somebody explain to me what I'm not understanding? Particularly given that Eigen in a template library, and that there are at least three folders (eigen, eigen_build and eigen_install) under CMAKE_PREFIX_PATH which I would have thought CMake would find something in, I assume I must be doing something wrong here. I KNOW from past experience, I can set EIGEN_INCLUDE_DIR by hand in CMakeGUI by hand, and continue hacking forth, but that just seems wrong.
I'm more than willing to write up a web page explaining this for future people as dumb as me if one does not already exist, although I can't understand how use of CMake for basic project configuration and generation is apparently so obvious to everyone but so opaque for me. I have actually been using CMake for some years, usually by just manually setting Boost_INCLUDE_Dir, Foo_INCLUDE_PATH etc manually, but clearly this is not the right solution. Generally, after spending a couple of days fighting through the various packages to generate a solution by manually setting INCLUDE PATHS, LIBRARY PATHS and other options, I just deal with the solution and don't touch CMake again. But I would love to understand what I'm missing about find_package for my (surely not uncommon) use case of wanting to control my project dependencies rather than just using sudo port install * and installing random versions of projects to my global system folders.
As error message says, CMAKE_PREFIX_PATH should be set to installation prefix of the package. E.g., if the package has been built using CMake, this is CMAKE_INSTALL_PREFIX variable's value, if the package has been build using Autotools, this is value of --prefix option used for configure it, and so on.
CMake doesn't search every directory under CMAKE_PREFIX_PATH. That is why specifying it as /users/foo/src is useless if you have the package installed at /users/foo/src/eigen-install.
Instead, you may install all 3d-party packages into /users/foo/src/install, and use that path as CMAKE_PREFIX_PATH in your main project.

Ubuntu CMake what path to add to CMAKE_MODULE_PATH

My OS is Ubuntu. I would like to change from QT4 to QT5 in my project. The native package though is 4.x version in Ubuntu right now.
I have downloaded the Linux installer from QT homepage and installed QT5.4 under /opt/Qt/5.4/
This path is not found by
find_package (Qt5 REQUIRED)
I tried adding
set(CMAKE_MODULE_PATH "/opt/QT/5.4;${CMAKE_MODULE_PATH}")
to my CMAKELIST.txt but that does not help.
Where do I have to link, or am I using the wrong syntax?
Some edits after hint with calling:
cmake -DCMAKE_PREFIX_PATH=/opt/QT/5.4/gcc_64/ ../src/
I also have deleted the CMAKE_MODULE_PATH variable.
I still get the same error:
CMake Error at CMakeLists.txt:3 (find_package):
Found package configuration file:
/usr/lib/x86_64-linux-gnu/cmake/Qt5/Qt5Config.cmake
but it set Qt5_FOUND to FALSE so package "Qt5" is considered to be NOT
FOUND. Reason given by package:
The Qt5 package requires at least one component
I dont know why this is happening after reading https://blogs.kde.org/2008/12/12/how-get-cmake-find-what-you-want-it
. There it is stated, that the path will be searched before the default search directories. The path I used seems to be right now:
/opt/QT/5.4/gcc_64/
Adding subfolder gcc_64 must be right, as this subfolder has "lib", "include" ect as subfolders.
I remeber that I have called also
sudo apt-get install QT5-default
some time ago. This did not help, I needed the installer from QT. Although I removed qt5-default again to prevent cmake from finding the wrong package configuration file, the same error appears.
See discussion below, moved to here:
Cmake and QT5 - Include only takes one argument
You have to use the variable CMAKE_PREFIX_PATH, i.e. invoke
cmake -DCMAKE_PREFIX_PATH=/opt/QT/5.4 <path_to_source>
at the root of your build tree. Then you can use find_package(Qt5 ...) etc. See also the Qt5 cmake docs.
Rough distinction within you focus:
CMAKE_MODULE_PATH is for "general" inclusion of files and "FindXXX.cmake" files in find_package(... MODULE).
CMAKE_PREFIX_PATH has a special meaning in the context of find_package(... CONFIG).
After addition of new content
this is a new error and thus should require a new question. if you had that error before you'd have already found the Qt5 config.cmake file :-)
anyways, as the error tells you
The Qt5 package requires at least one component
you need to specify a component of the Qt5 package. As the cmake docs say, you need to use the find_package(Qt5 REQUIRED COMPONENTS Widgets Core ...) interface so that cmake (better: the logic of Qt5 FindQt5.cmake) knows what to look for. that will give you the targets Qt5::Widgets etc to use/link against.
i dont know if the syntax find_package(Qt5Widgets REQUIRED) works, could be equivalent.

Issue with ItkVtkGlue

I'm trying to run this example: http://www.itk.org/Wiki/ITK/Examples/IO/ImageFileReader
But, get the following when I "configure" in CMake:
CMake Error at CMakeLists.txt:11 (find_package):
By not providing "FindItkVtkGlue.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"ItkVtkGlue", but CMake did not find one.
Could not find a package configuration file provided by "ItkVtkGlue" with
any of the following names:
ItkVtkGlueConfig.cmake
itkvtkglue-config.cmake
Add the installation prefix of "ItkVtkGlue" to CMAKE_PREFIX_PATH or set
"ItkVtkGlue_DIR" to a directory containing one of the above files. If
"ItkVtkGlue" provides a separate development package or SDK, be sure it has
been installed.
It seems I need "ItkVtkGlue"? Where can I download it? And, what should I do to combine it with the program?
VtkGlue is a module within ITK, which by default is not built. You need to enable this module with cmake when you build ITK. Also, before you do this, you need to download and build VTK (which is very similar to building ITK). Assuming you are on a unix-like system, have VTK installed, have a src and bin folder for ITK, and are sitting in the bin folder, I would do:
$ ccmake ../src -DModule_ItkVtkGlue=ON
The last option turns the ItkVtkGlue module on by default. You can also do this in the curses GUI without passing this option: press t to get the advanced options, use the arrow keys to scroll down to Module_ItkVtkGlue, and, once there, use the enter key to toggle this option ON. Finally, configure, configure, configure, generate as usual, and then:
$ make
$ sudo make install
Many of the examples on the ITK Wiki use VtkGlue. You can see how to format your CMakeLists.txt file by looking at any of those.

Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH

I don't know a lot about cmake, I'm trying to build a client using cmake and Qt. Getting the following error:
CMake Error at alethzero/CMakeLists.txt:26 (find_package): By not
providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"Qt5Widgets", but CMake did not find one.
Could not find a package configuration file provided by "Qt5Widgets"
with any of the following names:
Qt5WidgetsConfig.cmake
qt5widgets-config.cmake
Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or
set "Qt5Widgets_DIR" to a directory containing one of the above
files. If "Qt5Widgets" provides a separate development package or
SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
As far as I understand, I need to add the QT path to CMake. How do I do it? I have Qt installed in /home/user/Programs. All the explanations I find are "just do this or that". I need the exact Terminal commands so I can just learn how to do it in the future.
Thanks!
UPDATE: export CMAKE_PREFIX_PATH=/home/user/Programs did not help me.
Well, here you have a solution for Windows: How to find qt5 CMake module on windows
set (CMAKE_PREFIX_PATH "C:\\Qt\\Qt5.0.1\\5.0.1\\msvc2010\\")
For your environment, I think you will have to change the path where Qt is located...
Maybe this will help you:
https://github.com/Cockatrice/Cockatrice/issues/205
This is documented:
http://doc.qt.io/qt-5/cmake-manual.html
The easiest way to use CMake is to set the CMAKE_PREFIX_PATH
environment variable to the install prefix of Qt 5
Do this
export CMAKE_PREFIX_PATH=/home/user/Programs/<other_stuff>
where references the compiler etc, so that this complete path is valid:
/home/user/Programs/<other_stuff>/bin/qmake*
I needed this on my macOS after Qt installation with brew install qt5:
export CMAKE_PREFIX_PATH=/usr/local/Cellar/qt5/5.7.0/
For ubuntu:
cmake -DCMAKE_PREFIX_PATH=/home/ryan/Qt/5.11.2/gcc_64 ..
/home/ryan/Qt/ is the Qt installation root path
at an Ubuntu 16.04.4 LTS desktop the solution was
cmake .. -DMAKE_PREFIX_PATH=/usr/include/x86_64-linux-gnu/qt5