find_package failed to generate project (in Qt) with Cmake

Asked

Viewed 91 times

4

I’m trying to generate the build configuration of a simple Qt example using Cmake. The code of the example is this:

#include <QApplication>
#include <QTextEdit>

int main(int argc, char** argv)
{
    QApplication app(argc, argv);

    QTextEdit textEdit;
    textEdit.setText("Olá mundo!");
    textEdit.show();

    return app.exec();
}

And the Cmake configuration file is this:

cmake_minimum_required(VERSION 2.8.11)

project (teste)

# Configuracao do Qt
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Core)
find_package(Qt5Widgets)

# Configuracao especifica para o gcc
if(NOT WIN32)
    set(CMAKE_C_FLAGS "-Wall -g")
endif()

# Adiciona todos os fontes na variavel SRCS
file(GLOB SRCS *.cpp *.h)

# Nome do executavel
if(WIN32)
    add_executable(teste WIN32 ${SRCS})
else()
    add_executable(teste ${SRCS})
endif()

# Usa os modulos do Qt 5
target_link_libraries(teste Qt5::Core)
target_link_libraries(teste Qt5::Widgets)

When I Gero the configuration in Windows (v.10, 64bits), it goes well. However, when I do the same on Ubuntu (v.14.04, 32bits), Cmake produces the following error message:

Cmake Warning at Cmakelists.txt:8 (find_package): By not providing "Findqt5core.cmake" in CMAKE_MODULE_PATH this project has Asked Cmake to find a package Configuration file provided by "Qt5core", but Cmake Did not find one.

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.

Some additional information:

  • Qt 5.5.1 is correctly installed on Ubuntu (in the local folder /home/luiz/Qt5.5.1).
  • Running the command apt-file search Qt5CoreConfig.cmake, i get the following path: qtbase5-dev: /usr/lib/i386-linux-gnu/cmake/Qt5Core/Qt5CoreConfig.cmake. So I’ve tried to add /usr/lib/i386-linux-gnu/cmake/ the environment variable CMAKE_PREFIX_PATH (as directed the documentation in the fifth paragraph of Getting Started), but the error continues.
  • I just didn’t try to define individually the variables Qt5<Module>_DIR because I believe that this approach will only take more work than necessary (and maybe there is some other wrong configuration).

Does anyone know where I might be going wrong?

  • @Guilhermenascimento It was normal. Really does not have in apt, the installation tutorial uses the site download directly. So I think it was installed in the local folder (but I didn’t imagine that this would possibly be a problem). About the rest, yes, I was wrong in the question. I will correct. :)

  • @Guilhermenascimento No. I installed the 5.5.1 same. : ) (the installation tutorial is a little older rs). Only in windows that I installed the 5.6 (but because of a dependency on VS 2015 - there is working well).

  • Has tried this http://askubuntu.com/q/4755/181632 ?

  • @Guilhermenascimento I had already seen this question (by the way, I found the tip of apt-file there). But I admit that the answer accepted is a little confusing for me. I even tried to change the names of the packages in the find_package as it suggests (in the "Qt*5-dev" pattern), but if so, it didn’t work here either.

  • @Guilhermenascimento I tried too (thinking the same thing you). Only then it gives the same error in Widgets. :/

  • He even reinstalled the Cmake apt-get remove cmake & apt-get install cmake? Maybe something is missing since apt-search finds but cmake does not.

  • @No, I did not. I will now after lunch.

  • @Guilhermenascimento I just reinstalled Cmake, and the error continues. :/

  • @Guilhermenascimento, thank you for your help. But I managed to resolve it (see my reply).

Show 4 more comments

1 answer

2


I managed to solve with help of that other thread. There were two problems:

  1. Instead of setting the path in a variable CMAKE_PREFIX_PATH environment, it seems that the "most correct" is to do as a variable within the Cmake script.
  2. The correct path is even the installation of Qt, but including the compiler specification (in the case of Ubuntu, gcc).

So I just added the following snippet to my Cmake script, before calling the find_package:

if(WIN32)
    set (CMAKE_PREFIX_PATH "C:\\Qt\\Qt5.6.0\\5.6\\msvc2015\\")
elseif(UNIX)
    set (CMAKE_PREFIX_PATH $ENV{HOME}/Qt5.5.1/5.5/gcc/)
endif()

The definition of the variable CMAKE_PREFIX_PATH was not required on my Windows environment earlier because the Qt path was added to the Path. Thus, to avoid this specific configuration within the Cmake script file, the most appropriate is to add the Qt installation path to the variable PATH environment (both on Windows and Linux) and not using the variable CMAKE_PREFIX_PATH.

  • 1

    I imagined something like this, only the problem is that for different "people" it won’t compile right? But as I do not know exactly what your goal seems to me that meets your current need +1 ;)

  • Yes, but at least someone with the similar problem will get some more objective hint of how to proceed (since the documentation is not very clear). :)

  • Got it, a curiosity, if you’re using QT because you don’t use the file .pro? For example create the project and create a . bat and bash inside the project folder, which would run the following command qmake and make && make install? I know Cmake is more about "preparing" the environment, but in your case it seems like an attempt to compile, I’m wrong?

  • @Guilhermenascimento Good curiosity. : ) I used the .pro this way (I even have a cool script that is both batch and bash to generate VS files on Windows and Makefile on Ubuntu). It turns out that recently I needed to use Cmake because of some additional dependencies. Briefly, the .pro makes my life easier in the case of Qt, but it has not made it easier in the case of Opencv and other dependencies.

  • @Guilhermenascimento This is such a nice script. : ) https://github.com/luigivieira/F3/blob/master/fat/update_projects.cmd

  • ah understand, but do you compile Openvc together with QT? Or do you pre-compile Openvc and then "link" in your project? Because it could do two separate things maybe, is that QT is very annoying sometimes to install and also live having difficulties on Linux due to this. So I always stay in qmake. I’ll take a look at your project.

  • Oh understood, you compile some things by MSVC direct, so I wondered, is that I use only the same QT and do not use the . sln, in case it is the . even pro (I usually use the same QT IDE).

  • 1

    @Guilhermenascimento Yes, I had the impression that Cmake might help with these future difficulties (especially with the new dependencies that will enter now). But let’s see. In practice I’m learning to use it myself. But I’ll keep the qmake by hand in the same way. Thanks! :)

  • @Guilhermenascimento Yes, in Windows I use MSVC directly. Usual issue. rs

  • @Guilhermenascimento I edited the answer, because just add the Qt path to the path so you don’t need the variable CMAKE_PREFIX_PATH. :)

  • 1

    You know I thought that, so I had asked how you did the installation, I find it strange that the installer of QT did not make this process for you.

  • @Guilhermenascimento So it is. I only found out when I went to run qmake and did not find in the path. :/

Show 7 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.