CMAKE_PREFIX_PATH does not work as expected
-
I'm compiling the same Qt/QML application on Windows, Linux, MacOS, WebAssembly, iOS, and Android.
So far, I found that detection of Qt's components only works on Windows, regardless whether I'm using it to compile a Windows version or cross-compiling to Android. It doesn't work neither on MacOS nor on Linux.
I tried pointing CMAKE_PREFIX_PATH to Qt's installation prefix (~/Qt/5.15.0/wasm_32/), but it keeps on complaining about QtConfig.cmake. The only alternative I found to work was passing -DQt5_DIR for QtConfig.cmake to be found, but then it would keep on asking for at least 10 more .cmake files which I need to pass their paths one by one using _DIR variables. This way I would always end with a huge command and it's a major source of annoyance.
Note that I do not want to install Qt using apt or any other package manager. I only want to use Qt's installer since it gives me the flexibility of having multiple versions targeting multiple frameworks.Is it a problem in Qt? CMake? Ubuntu?
Qt: 5.15.0
CMake: 3.18.0
Ubuntu: 20.04 -
I could solve the problem by adding this to the beginning of my CMake script:
list(APPEND CMAKE_PREFIX_PATH "~/Qt/5.15.0/wasm_32")
Neither passing it as a command-line parameter nor as an env variable worked.Now I'm sure that I found it:
The toolchains had this:
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)It doesn't look like setting CMAKE_PREFIX_PATH was enough. I had to do this also:
list(APPEND CMAKE_FIND_ROOT_PATH "~/Qt/5.15.0/wasm_32") -
Hi,
I usually point it to the Qt/<version>/<name>/lib/cmake subfolder of the Qt version I want to use.
-
Tried doing it like this:
cmake -DCMAKE_TOOLCHAIN_FILE=~/Documents/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_PREFIX_PATH=~/Qt/5.15.0/wasm_32/lib/cmake ~/Documents/cpp/basic_qml
Still had the same error:
CMake Error at CMakeLists.txt:10 (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. -- Configuring incomplete, errors occurred!
-
@Ahmed-Yarub-Hani-Al-Nuaimi On linux, add QT_DIR/bin to PATH and QT_DIR/lib to LD_LIBRARY_PATH and cmake is able to find it. For example: QT_DIR=/opt/thirdParties/Qt-5.14/5.14.0/gcc_64/
-
@JoeCFD said in CMAKE_PREFIX_PATH does not work as expected:
LD_LIBRARY_PATH
export PATH=~/Qt/5.15.0/wasm_32/bin/:$PATH which qmake ~/Qt/5.15.0/wasm_32/bin//qmake export LD_LIBRARY_PATH=~/Qt/5.15.0/wasm_32/lib/
Still had the error.
It does mention here https://doc.qt.io/qt-5.15/cmake-get-started.html clearly:Set your CMAKE_PREFIX_PATH environment variable to the Qt 5 installation prefix. This is the recommended way.
Still, I could not find anybody who could get it working using this variable on Linux!
-
I could solve the problem by adding this to the beginning of my CMake script:
list(APPEND CMAKE_PREFIX_PATH "~/Qt/5.15.0/wasm_32")
Neither passing it as a command-line parameter nor as an env variable worked.Now I'm sure that I found it:
The toolchains had this:
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)It doesn't look like setting CMAKE_PREFIX_PATH was enough. I had to do this also:
list(APPEND CMAKE_FIND_ROOT_PATH "~/Qt/5.15.0/wasm_32") -
@Ahmed-Yarub-Hani-Al-Nuaimi you can find cmake is inside lib dir of qt installation: /opt/thirdParties/Qt-5.14/5.14.0/gcc_64/lib/cmake. Therefore, add QT_DIR/bin to PATH and
QT_DIR/lib to LD_LIBRARY_PATHif you can not make it manually, use cmake-gui to add it manually. It can detected it automatically from Qt lib path setting. When you install cmake, there is an option to add cmake-gui which is very useful for you to install packages.
-
@Ahmed-Yarub-Hani-Al-Nuaimi show me your CMakeLists.txt
show me the output of
echo $PATH
echo $LD_LIBRARY_PATH -
-
@Ahmed-Yarub-Hani-Al-Nuaimi Try to use full path of ~/Qt/5.15.0/wasm_32 to set PATH and LD_LIBRARY_PATH
-
@JoeCFD
echo $PATH
/home/fifothekid/Downloads/cmake-3.18.0-Linux-x86_64/bin:/home/fifothekid/Qt/5.15.0/wasm_32/bin/:/home/fifothekid/.wasmer/bin:/home/fifothekid/.wasienv/bin:/home/fifothekid/Documents/emsdk:/home/fifothekid/Documents/emsdk/upstream/emscripten:/home/fifothekid/Documents/emsdk/node/12.18.1_64bit/bin:/home/fifothekid/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/fifothekid/.wasmer/globals/wapm_packages/.binecho $LD_LIBRARY_PATH
/home/fifothekid/Qt/5.15.0/wasm_32/lib/and then tried /home/fifothekid/Qt/5.15.0/wasm_32
-
@Ahmed-Yarub-Hani-Al-Nuaimi type
which qmakethis is the only line in my cmake file to find Qt 5
find_package(Qt5 REQUIRED Core Gui Widgets Svg Xml Network DBus OpenGL Multimedia WebEngineWidgets) -
which qmake
/home/fifothekid/Qt/5.15.0/wasm_32/bin//qmake -
@Ahmed-Yarub-Hani-Al-Nuaimi
I tried this
cmake_minimum_required(VERSION 3.10)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
project(basic_qml)set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)set(CMAKE_CXX_STANDARD 17)
set (Qt5_FOUND false)
find_package(Qt5 COMPONENTS Core
Gui
Svg
Xml
Qml
Quick
QuickControls2 REQUIRED)if(Qt5_FOUND)
message("QT5 framework found")
else(Qt5_FOUND)
message(FATAL_ERROR "No QT5 framework found")
endif(Qt5_FOUND)==========================================================
the output:
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
QT5 framework found
-- Configuring done
-- Generating done
-- Build files have been written to: -
Are you cross-compiling for wasm32?
-
@Ahmed-Yarub-Hani-Al-Nuaimi this is only on linux ubuntu
-
I know. It does work if you are building for Ubuntu on Ubuntu. It's cross-compilation that doesn't work. According to official documentations, setting CMAKE_PREFIX_PATH should be enough, but it's not.
I had the same problem compiling for Android on Ubuntu and Windows, for iOS on MacOS, and for WebAssembly on Ubuntu. -
@Ahmed-Yarub-Hani-Al-Nuaimi
cmake -DCMAKE_PREFIX_PATH=$QT_DIR/lib/cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
QT5 framework found
-- Configuring done
-- Generating done
-- Build files have been written to:works as well without PATH and LIB settings. But this does not set qmake path. It is safe to set path and lib manually. Sure it is not needed if you install qt under root.
-
Can you try compiling for wasm32?