Build Qt project with CMake problem

  • this is a copy of the question on stackoverflow here

    here is a doc about that, but it doesn't look correct for me ,
    so I've copied cmake instructions into my cmakelists.txt and it doesn't work.
    it's clear why it doesn't work - because there is no one instruction how to search qt:

    I suppose two cases:

    • some additional cmake instructions requires to set
    • some environment variables should be set

    but nothing about that.

    the instruction :


    refers to extra cmake script from qt kit , isn't it?
    I see the directory with that name (annd contains *.cmake scripts but another names) but there is no the script with this name

    these are the only .cmake files with qt in names in cmake 3.6 :



    C:\dev\tools\CLion.RC\bin\cmake\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug
    -G "CodeBlocks - MinGW Makefiles" C:\dev\workspace\algolist.v2 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:


    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.

    CMake Error at CMakeLists.txt:20 (target_link_libraries): Cannot
    specify link libraries for target "helloworld" which is not built by
    this project.

    -- Configuring incomplete, errors occurred! See also "C:/dev/workspace/algolist.v2/cmake-build-debug/CMakeFiles/CMakeOutput.log".

    seems it found Qt5Widgets, but absolutely not clear how it does this...
    so it looks for cmake files inside Qt5Widgets folder, in Qt kit.
    I can add this folder to the path but I don't think this is a valid way,
    because there is a lot of subfolders with cmake files

    Qt5.8 beta, built with MinGW, Win10, cmake 3.6

  • Lifetime Qt Champion


    You need to use CMAKE_PREFIX_PATH

    For example:

    cmake.exe -DCMAKE_PREFIX_PATH="C:/path/to/Qt/5.X/compiler/lib/cmake"

Log in to reply