Updated Qt library; cannot build anymore - c++

I have a previously working Qt5/cmake project which built fine. I then updated Qt from 5.6 to 5.8. Now cmake cannot find Qt anymore.
This is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.0)
project(TEST)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "/opt/Qt/Qt5.8.0")
set(QT_QMAKE_EXECUTABLE ${CMAKE_PREFIX_PATH}/5.8/clang_64/bin/qmake)
find_package(Qt5Widgets)
...
This is the error message I get:
CMake Warning at CMakeLists.txt:56 (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.
I followed what written in Qt documentation, so I do not understand what is wrong.
Version details:
- cmake 3.9.0
- Qt 5.8.0
- QMake 3.1
- Mac OS X 10.9.5

Did you check CMake version that is compatible with QT? Also did you check that everything is ok with qmake? Because this is what causes the problems most of the times. Check QT_QMAKE_EXECUTABLE to be pointing in the new QT version, i get problems with new versions of QT all the time.

Fixed setting the following system variables:
QTDIR=/opt/Qt/Qt5.8.0/5.8/clang_64
PATH=$PATH:/opt/Qt/Qt5.8.0/5.8/clang_64/bin
and removing:
set(CMAKE_PREFIX_PATH "/opt/Qt/Qt5.8.0")
from CMakeLists.txt.

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)

cmake Could not find a package configuration file provided by "glfw3"

I am trying to add glfw to my c++ project. I am using cmake and CLion. I am getting the error:
CMake Error at CMakeLists.txt:11 (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.3) 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.
I downloaded glfw using homebrew (brew install glfw) and put the downloaded contents in my project. My project structure looks like this
project structure
my CMakeLists.txt looks like this
cmake_minimum_required(VERSION 3.20)
project(open_gl)
set(CMAKE_CXX_STANDARD 14)
add_executable(open_gl src/Application.cpp)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
# glfw
find_package(glfw3 3.3 REQUIRED)
target_link_libraries(open_gl glfw)
Does anybody know what I am doing wrong? Might just be making some beginner mistake but I have been at this for way too long now.

How to find (configure) Qt for cmake project of iOS?

I install Qt via online installer on my macOS (Qt for iOS and macOS).
And qmake project works just fine, now I need compile with cmake Qt project:
cmake_minimum_required(VERSION 3.5)
project(demo LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Core Quick REQUIRED)
And I can not find Qt.
Direct build configuration:
cmake .. -GXcode -DQt5_DIR=/Users/user/Qt/5.14.1/clang_64/lib/cmake/Qt5
...
-- Configuring done
-- Generating done
-- Build files have been written to:
Cross-compiling for iOS:
cmake .. -GXcode -DCMAKE_SYSTEM_NAME=iOS -DQt5_DIR=/Users/user/Qt/5.14.1/ios/lib/cmake/Qt5
...
CMake Error at /Users/user/Qt/5.14.1/ios/lib/cmake/Qt5/Qt5Config.cmake:28 (find_package):
Could not find a package configuration file provided by "Qt5Core" with any
of the following names:
Qt5CoreConfig.cmake
qt5core-config.cmake
Add the installation prefix of "Qt5Core" to CMAKE_PREFIX_PATH or set
"Qt5Core_DIR" to a directory containing one of the above files. If
"Qt5Core" provides a separate development package or SDK, be sure it has
been installed.
Obviously Qt5CoreConfig.cmake is just fine and it is in relatively the same place as for "direct" compilation, but for some reason cmake can not find it
$ find /Users/user/Qt/5.14.1/ios/lib/cmake/ -name Qt5CoreConfig.cmake
/Users/user/Qt/5.14.1/ios/lib/cmake//Qt5Core/Qt5CoreConfig.cmake
How can I fix this?
When building for iOS CMAKE_SYSROOT is set to iPhoneOS.sdk path.
find_package:
The CMAKE_SYSROOT variable can also be used to specify exactly one directory to use as a prefix. Setting CMAKE_SYSROOT also has other effects. See the documentation for that variable for more.
These variables are especially useful when cross-compiling to point to the root directory of the target environment and CMake will search there too. By default at first the directories listed in CMAKE_FIND_ROOT_PATH are searched, then the CMAKE_SYSROOT directory is searched, and then the non-rooted directories will be searched.
So, adding the option -DCMAKE_FIND_ROOT_PATH=/Users/user/Qt/5.14.1/ios will help.

Include cpp-netlib with CLion and Make on macOS

I'm very new to CLion, CMake and macOS at all so I need a little bit of help while trying to include cppnetlib into my CLion project.
I started out with creating an new CLion project which gave me a new CMakeLists.txt which I edited so that it would include boost as well:
CMAKE_MINIMUM_REQUIRED(VERSION 3.7)
PROJECT(myapp)
SET(CMAKE_CXX_STANDARD 11)
SET(SOURCE_FILES main.cpp)
ADD_EXECUTABLE(myapp ${SOURCE_FILES})
FIND_PACKAGE(Boost 1.63.0 REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(dxcheck ${Boost_LIBRARIES})
I've installed boost through homebrew, but I did not find a package for cppnetlib with homebrew so I downloaded cppnetlib and placed it in /usr/local/Cellar/cpp-netlib. Now, when I follow the tutorial on their page and put
set (CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} /usr/local/Cellar/cpp-netlib)
find_package (cppnetlib 0.12.0 REQUIRED)
include_directories (${CPPNETLIB_INCLUDE_DIRS})
target_link_libraries (myapp ${CPPNETLIB_LIBRARIES})
into the CMakeLists.txt, I get the following output:
-- Boost version: 1.63.0
CMake Error at CMakeLists.txt:14 (find_package):
By not providing "Findcppnetlib.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"cppnetlib", but CMake did not find one.
Could not find a package configuration file provided by "cppnetlib"
(requested version 0.11.0) with any of the following names:
cppnetlibConfig.cmake
cppnetlib-config.cmake
Add the installation prefix of "cppnetlib" to CMAKE_PREFIX_PATH or set
"cppnetlib_DIR" to a directory containing one of the above files. If
"cppnetlib" provides a separate development package or SDK, be sure it has
been installed.
I've already done some research about finding packages but all I could achieve was that I was able to include cppnetlib by manually adding the include path to the CMakeLists.txt but then I got an error saying that the compiler could not find the headers which are located inside the "deps" folder in cpp-netlib.
I know want to know how to include a package like cppnetlib properly into my CLion project using CMake. I am using CLion 2017.1, macOS Sierra and I think CLion is using CMake 3.7.