14

I just installed the Qt 5.1.1 for Windows 32-bit (MinGW 4.8, OpenGL) and tried to add it to my cmake. But CMake just does not want to find it and i dont know why. What am i missing? Do i need to set an environment variable or something?

Here is my cmake :

cmake_minimum_required( VERSION 2.8.11 )
PROJECT(Blemmer)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" ${CMAKE_MODULE_PATH})

set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
find_package(SFML REQUIRED system window graphics network audio)
# The QUIET option disables messages if the package cannot be found. 
FIND_PACKAGE(Qt5Widgets) 
add_subdirectory(Entity)
add_subdirectory(Engine)
add_subdirectory(Game)
add_executable(Blemmer main.cpp)

include_directories(${SFML_INCLUDE_DIR} ${PROJECT_SOURCE_DIR})
target_link_libraries(Blemmer ${SFML_LIBRARIES} Game Engine Qt5::Widgets)

and this is the output of cmake-gui :

CMake Warning at CMakeLists.txt:14 (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.
László Papp
  • 51,870
  • 39
  • 111
  • 135
Captain GouLash
  • 1,257
  • 3
  • 20
  • 33
  • 1
    Have you tried the steps at the bottom of you output "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." – drescherjm Sep 10 '13 at 17:03

3 Answers3

24

I successfully built my GUI on MacOSX 10.10 by exporting Linux environment variables

$ brew install qt5
$ ls /usr/local/opt/qt5/lib/cmake/Qt5Widgets/Qt5WidgetsConfig.cmake
$ /usr/local/opt/qt5/lib/cmake/Qt5Widgets/Qt5WidgetsConfig.cmake
$ export CMAKE_PREFIX_PATH=/usr/local/opt/qt5/
$ cd ./build
$ cmake ../CMakeLists.txt
$ make -j8

According to http://www.cmake.org/cmake/help/v3.0/variable/CMAKE_PREFIX_PATH.html, the cmake function FIND_LIBRARY() will appends /lib to each of the directories. So done.

micfan
  • 800
  • 8
  • 12
17

You need to set the CMAKE_PREFIX_PATH to the Qt installation.

See http://doc.qt.io/qt-5/cmake-manual.html

Community
  • 1
  • 1
László Papp
  • 51,870
  • 39
  • 111
  • 135
  • "you need to se this line qt5_use_modules(Blemmer Widgets), and remove that 'Qt5::Widgets' stuff from there" << This is incorrect. See the cmake manual in the Qt documentation. – steveire Nov 13 '14 at 17:47
  • Steveire, I am currently on vacation. Please feel free to improve the answer by suggesting an edit, otherwise I will have a look when I am back. Thank you for the feedback. – László Papp Nov 14 '14 at 13:35
  • lpapp, I tried, but my edit was rejected. Peter Krauss then apparently made an edit which did not fix the critical error. So, lpapp, please fix this yourself when you can. I have resubmitted my edit. – steveire Nov 18 '14 at 20:55
  • My edit was rejected again because it fixes the critical error. It is remarkable that having the wrong answer accepted with a critical error is desired. I thought SO was for collating good answers, not bad ones. This answer is marked as correct, but is definitely not. – steveire Nov 19 '14 at 22:52
  • 1
    @steveire, it is unfortunate that the reviewers rejected it. Unfortunately, SO is imperfect, but I appreciate your willingness to constructively contribute. I updated the post, thanks. Let me know if there is anything else that can be improved. – László Papp Nov 20 '14 at 07:54
6

Fixed it with the following in a CMakeLists.txt file:

set(CMAKE_PREFIX_PATH $ENV{HOME}/Qt5.5.0/5.5/gcc_64)

For me, the context ended up something like:

# Ubuntu 14.04 LTS, CMake 2.8.12.2
wget http://download.qt.io/official_releases/qt/5.5/5.5.0/qt-opensource-linux-x64-5.5.0.run
chmod u+x qt-opensource-linux-x64-5.5.0.run
./qt-opensource-linux-x64-5.5.0.run
# Follow GUI prompts, installed to default location
pzrq
  • 1,626
  • 1
  • 18
  • 24
  • 3
    For the record: This is misleading. `CMAKE_PREFIX_PATH` can be set as environment variable without further modifications to CMakeLists.txt. See the accepted answer. – kfunk May 22 '17 at 13:55
  • 2
    Thanks @kfunk you are correct that it is also possible to use the environment variable, the accepted answer doesn't actually make it clear that `CMAKE_PREFIX_PATH` can be an environment variable at this time, without consulting the documentation link and searching for it. – pzrq Jun 01 '17 at 13:07