2

Why CMake doesn't see my system variable?

if (NOT DEFINED $ENV{QT_LIBS_DIR}) message(FATAL "You need to have system-wide variable with path to Qt libs") set(QT_CMAKE_MODULES_FOUND FALSE) elseif(NOT DEFINED $ENV{QT_LIBS_DIR}) set(QT_CMAKE_MODULES "$ENV{QT_LIBS_DIR}/lib/cmake" CACHE PATH "CMake's modules which provided by Qt itself for Qt bindings") set(QT_CMAKE_MODULES_FOUND TRUE) endif(NOT DEFINED $ENV{QT_LIBS_DIR}) 

I got fatal error. Please help me to investigate. Btw for:

$ echo $QT_LIBS_DIR 

output is: /home/drew/Qt/5.5/gcc_64

1 Answer 1

3

For checking environment variables I use if ("$ENV{QT_LIBS_DIR}" STREQUAL "") to see if the environment variable is defined. So your example becomes:

if ("$ENV{QT_LIBS_DIR}" STREQUAL "") message(FATAL "You need to have system-wide variable with path to Qt libs") set(QT_CMAKE_MODULES_FOUND FALSE) elseif() set(QT_CMAKE_MODULES "$ENV{QT_LIBS_DIR}/lib/cmake" CACHE PATH "CMake's modules which provided by Qt itself for Qt bindings") set(QT_CMAKE_MODULES_FOUND TRUE) endif() 

But for what it is worth, I believe that find_package for qt gets the path for qt according to the qmake executable that it finds first in your path. This way you do not really need to use an environment variable. This applies to qt4; see How specify Qt version/location? for details.

For QT5, the Qt5/CMake manual says "In order for find_package to be successful, Qt 5 must be found below the CMAKE_PREFIX_PATH, or the Qt5_DIR must be set in the CMake cache to the location of the Qt5WidgetsConfig.cmake file. The easiest way to use CMake is to set the CMAKE_PREFIX_PATH environment variable to the install prefix of Qt 5."

Sign up to request clarification or add additional context in comments.

2 Comments

My thanks @Phil. About your remark: I don't have qt installed through package manager. So even whereis qmake leads me to empty output.
Qt does not need to be installed. You can have multiple versions of qt in many different locations. Unless you have stripped the file set to a minimum, you should have bin/qmake somewhere. For qt4 just put that in your PATH and find_package should set the cmake variables for qt correctly. For Qt5, simply add -DQt5_DIR to your command line for your cmake configure step, and find_package should work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.