CMake file cannot locate Qt charts module - c++

I'm trying to start writing my Qt project inside JetBrains' Clion but I need to link some libraries in my Cmake file first. There's no problem when trying to find packages like Qt5Core, Qt5Widgets, Qt5Gui but when it come to finding Qt5Charts an error is thrown:
By not providing "FindQt5Charts.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file
provided by "Qt5Charts", but CMake did not find one.
Could not find a package configuration file provided by "Qt5Charts"
with any of the following names:
Qt5ChartsConfig.cmake
qt5charts-config.cmake
Add the installation prefix of "Qt5Charts" to CMAKE_PREFIX_PATH or
set "Qt5Charts_DIR" to a directory containing one of the above
files. If "Qt5Charts" provides a separate development package or
SDK, be sure it has been installed.
This is my CMake file right now.
All packages are installed via the Qt's Linux(ubuntu) maintanence tool.
Any ideas how to help Cmake find the Charts module ?

Using the following and see if it helps:
sudo apt install libqt5charts5-dev
Src: https://stackoverflow.com/a/46765025

Typically when including Qt5 in a project I use the follow basic script for CMake, though I should note I haven't tested this on Linux.
cmake_minimum_required(VERSION 3.10.0 FATAL_ERROR)
project(<YOUR_PROJECT_NAME>)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Charts)
# set your project sources and headers
set(project_sources src/blah.cpp)
set(project_headers include/headers/blah.h)
# wrap your qt based classes with qmoc
qt5_wrap_cpp(project_source_moc ${project_headers})
# add your build target
add_executable(${PROJECT_NAME} ${project_sources} ${project_headers} ${project_source_moc})
# link to Qt5
target_link_libraries(${PROJECT_NAME}
PUBLIC
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::Charts)
# require C++ 14
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14)
When configuring your project via cmake, you just need to pass in the path to you qt5 installation directory (cmake variable name is Qt5_DIR) that contains the Qt5Config.cmake file and then cmake should be able to find the rest of the components that you request.
Also double check that Qt5Charts was installed, not sure if it's installed by default.

Maybe try this?
sudo apt install libqt5charts5-dev

Related

How can I use mbedtls in CMake?

I'm trying to use mbedtls in my CMakelists.txt file. I used the vcpkg package manager to install mbedtls: vcpkg install mbedtls
I added my find_package() statement before add_executable() but despite adding -DCMAKE_TOOLCHAIN_FILE=/bin/vcpkg/scripts/buildsystems/vcpkg.cmake to my CLion CMake options, CLion does not find mbedtls.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.22)
project(mbedtls_ssl_server)
set(CMAKE_CXX_STANDARD 20)
find_package(mbedtls REQUIRED)
add_executable(mbedtls_ssl_server
main.cpp)
target_link_libraries(mbedtls_ssl_server mbedtls::mbedtls)
The error message is:
CMake Error at /bin/vcpkg/scripts/buildsystems/vcpkg.cmake:838 (_find_package):
By not providing "Findmbedtls.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "mbedtls", but
CMake did not find one.
Could not find a package configuration file provided by "mbedtls" with any
of the following names:
mbedtlsConfig.cmake
mbedtls-config.cmake
Add the installation prefix of "mbedtls" to CMAKE_PREFIX_PATH or set
"mbedtls_DIR" to a directory containing one of the above files. If
"mbedtls" provides a separate development package or SDK, be sure it has
been installed.
I also tried running sudo apt install libmbedtls-dev on Ubuntu but that didn't help either, the previous error persists.
I had the same error and i had to set the variable MbedTLS_DIR in CMakelists.txt.
Exemple for MacOS:
set(MbedTLS_DIR /opt/homebrew/Cellar/mbedtls/3.3.0/cmake/) # <-- Here
find_package(MbedTLS REQUIRED )
target_link_libraries(${target_lib} PUBLIC MbedTLS::mbedtls)
This point on folder that contain MbedTLSConfig.cmake

AUTOMOC set to true makes fail cmake build

I'm at the very first day of Qt + Cmake and Conan, trying to make things work. I'm not using qmake because I'll integrate everything into a bigger project using cmake.
By following QT's tutorial, I figured out that I need to compile QT macros, and for that there's a useful AUTOMOC CMake property, as suggested here.
The point is that it's making me fail cmake builds.
My conanfile.txt:
[requires]
qt/5.15.2
[generators]
cmake
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
project(qttest)
set(CMAKE_CXX_STANDARD 20)
set_target_properties(${PROJECT_NAME} PROPERTIES AUTOMOC TRUE)
set (PROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
with the following output:
CMake Warning (dev) in CMakeLists.txt:
AUTOGEN: No valid Qt version found for target qttest. AUTOMOC disabled.
Consider adding:
find_package(Qt<QTVERSION> COMPONENTS Core)
to your CMakeLists.txt file.
This warning is for project developers. Use -Wno-dev to suppress it.
ouch, but adding the find doesn't make things better:
CMake Warning at CMakeLists.txt:6 (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
Actually the project compiles, Qt is there in its conan dir:
matteo#MacBook-Pro-de-matteo 96a68a791abfc7a246f2bc28aa2f6fc210be0f9f % cd ~/.conan/data/qt
matteo#MacBook-Pro-de-matteo qt % ls
5.15.2 6.2.2
matteo#MacBook-Pro-de-matteo qt %
how could I enable it, or make things easier to compile it along with cmake?
You need to tell CMake, where to find Qt.
So, as CMake suggests by itself:
find_package(Qt5 COMPONENTS Core)
for the most basic stuff, you might want to add some of the other components later.
Depending on the system you are working on and your Qt installation, you need to tell CMake where to search for the package configuration files (second error message). CMake has some default directories, where it looks for these files, but obviously, there is none. On Linux, this can be solved by installing Qt with a package manager (this will install the CMake config files to one of the Qt default locations). If you are on Windows or if you installed Qt to a different location, this can be solved by providing the path with the PREFIX_PATH-variable.
cmake -B $BUILD_DIR -S $SOURCE_DIR -DCMAKE_PREFIX_PATH=$QT_INSTALL_PATH/5.15.2/$ARCHITECTURE $OTHER_OPTIONS
(You can have different versions installed in the same installation path, that's why Qt adds an other folder with the version number. And you can have different compilers/architectures. On Windows for example, you might have a mingw73_32 and a msvc2017 folder to choose.)
As already mentioned in the comments, a project is no CMake target. CMake targets are either libraries (add_library), executables (add_executable) or custom targets (add_custom_target); the project is not. If you want to set the AUTOMOC property target wise, that's ok and even suggested by CMake, but you can also set it globally by using:
set(CMAKE_AUTOMOC ON)

How do I use cmake to build external libraries as well as my own application?

I am trying to build a cross platform OpenGL application, which means building and including multiple libraries (glfw, glbinding, glm, etc.) Because my application is cross platform, it makes sense to use cmake to generate all the build scripts and not have to muck about with them myself. I am attempting to target Windows and Linux specifically.
A main feature that I need is that the libraries I need are not installed on the host system. Furthermore, they cannot be installed (due to administrative reasons). What I need is to build these libraries and then build my application.
I am mostly working on Windows using Visual Studio 2017, which has cmake support included. Currently, I have attempted to build these libraries myself, however I am having many issues getting find_package to do the right thing.
My directory structure looks like this:
project/
|-src/
|- my sources for my application
|-include/
|- my header files
|-external/
|-glfw-3.2.1/
|-glbinding-2.1.4/
|-glfw-build/
|-glbinidng-build/
So I am attempting to build the external libraries and use them in my application. I am also attempting to follow cmake best practices. My CMakeLists.txt currently looks like this:
cmake_minimum_required(VERSION 3.5)
project(glTestProj)
set(CMAKE_PREFIX_PATH "external/")
find_package(glfw3 3.2 REQUIRED)
find_package(glbinding REQUIRED)
add_executable(glTest src/main.cpp)
target_compile_features(glTest PRIVATE cxx_std_17)
target_compile_options(glTest PRIVATE -Wall -Wextra)
target_link_libraries(
glTest
glfw
glbinding::glbinding
)
The libraries in question (glfw and glbinding) both have instructions on including them via cmake, however I am running into this issue:
CMake Error at CMakeLists.txt:6 (find_package):
By not providing "Findglfw3.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "glfw3", but
CMake did not find one.
Could not find a package configuration file provided by "glfw3" (requested
version 3.2) with any of the following names:
glfw3Config.cmake
glfw3-config.cmake
Add the installation prefix of "glfw3" to CMAKE_PREFIX_PATH or set
"glfw3_DIR" to a directory containing one of the above files. If "glfw3"
provides a separate development package or SDK, be sure it has been
installed.

CMake find_package for FindLibXml2

I'm trying to create a CMake file that will detect the location of libxml2. From what see in examples and CMake documentation the find_package simply works. I'm running CLion on Ubuntu, the libxml2 is installed using apt-get, the FindLibXml2.cmake is located under CMake's modules. However CMake returns cryptic message:
Could not find a package configuration file provided by "FindLibXml2"
with any of the following names:
FindLibXml2Config.cmake
findlibxml2-config.cmake
Add the installation prefix of "FindLibXml2" to CMAKE_PREFIX_PATH or
set "FindLibXml2_DIR" to a directory containing one of the above
files. If "FindLibXml2" provides a separate development package or
SDK, be sure it has been installed.
Why it is trying to find this -config file? what I'm doing wrong?
CMake snippet
find_package(FindLibXml2 CONFIG REQUIRED)
I've also tried
find_package(FindLibXml2 REQUIRED)
Not sure which one to use
You should not have the Find in FindLibXml2; do:
find_package(LibXml2 REQUIRED)
As explained in the documentation:
CMake searches for a file called Find<package>.cmake

ROS hydro opencv2 linking error during 'catkin_make'

I have little problem with my ROS hydro distro. I need to use it for one project so can't change to Indiko.
Problem is that I have used catkin_create_pkg packname opencv2 ... for creating my project package. But when I try to invoke catkin_make I get following errors:
CMake Error at /opt/ros/hydro/share/catkin/cmake/catkinConfig.cmake:75
(find_package): Could not find a package configuration file provided
by "opencv2" with any of the following names:
opencv2Config.cmake
opencv2-config.cmake
Add the installation prefix of "opencv2" to CMAKE_PREFIX_PATH or set
"opencv2_DIR" to a directory containing one of the above files. If
"opencv2" provides a separate development package or SDK, be sure it
has been installed.
I know that opencv2 is installed, because I can find it with rospack find opencv2 and I can use it in other projects not related to ROS.
I have following lines in CMakeLists.txt and package.xml
CMakeLists.txt:
find_package(catkin REQUIRED COMPONENTS opencv2)
include_directories(
${catkin_INCLUDE_DIRS}
${opencv2_INCLUDE_DIRS} )
target_link_libraries(BasicObstDetect_node
${catkin_LIBRARIES}
${opencv2_LIBRARIES} )
package.xml:
<build_depend>opencv2</build_depend>
<run_depend>opencv2</run_depend>
I have tried to use OpenCV instead of opencv2 but that didn't make any difference. Any advices?
I'm not sure, but this might work: edit your CMakeLists to add
find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS})
and
target_link_libraries(follower ${OpenCV_LIBRARIES})