1

I have a fairly special setup here and I have not enough knowledge about CMake to find out what is wrong.

I am on Ubuntu 12.04. I installed Qt5 from apt-add-repository ppa:ubuntu-sdk-team/ppa and CMake 2.8.11.2 from apt-add-repository ppa:kalakris/cmake (https://launchpad.net/~kalakris/+archive/ubuntu/cmake).

Here is the complete, minimal test-case:

daniel@omni-travis-test:~/projects/qtcmaketest$ ls
blubb.cpp  CMakeLists.txt

daniel@omni-travis-test:~/projects/qtcmaketest$ cat CMakeLists.txt

cmake_minimum_required(VERSION 2.8.11)
project (qtcmaketest)
find_package (Qt5Widgets REQUIRED)
add_executable(qtcmaketest blubb.cpp)
target_link_libraries (qtcmaketest Qt5::Widgets)

daniel@omni-travis-test:~/projects/qtcmaketest$ cat blubb.cpp
#include <QWidget>
#include <QApplication>

int main (int argc, char * argv[])
{
    QApplication app (argc, argv);
    QWidget foo;
    foo.show ();
}
daniel@omni-travis-test:~/projects/qtcmaketest$ cmake . && make
-- The C compiler identification is GNU 4.8.1
-- The CXX compiler identification is GNU 4.8.1
-- 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
-- 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
-- Configuring done
-- Generating done
-- Build files have been written to: /home/daniel/projects/qtcmaketest
Scanning dependencies of target qtcmaketest
[100%] Building CXX object CMakeFiles/qtcmaketest.dir/blubb.cpp.o
/home/daniel/projects/qtcmaketest/blubb.cpp:1:19: fatal error: QWidget: No such file or directory
#include <QWidget>
                   ^
compilation terminated.
make[2]: *** [CMakeFiles/qtcmaketest.dir/blubb.cpp.o] Error 1
make[1]: *** [CMakeFiles/qtcmaketest.dir/all] Error 2
make: *** [all] Error 2

Why is the include directory missing when find_package was successful?

I was using this guide: http://qt-project.org/doc/qt-5/cmake-manual.html

I just noticed that, when following the instructions from the chapter "Using Qt 5 with CMake older than 2.8.9", compilation works. I added the following lines:

include_directories(${Qt5Widgets_INCLUDE_DIRS})
add_definitions(${Qt5Widgets_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")

I know that this should work without those lines, since it runs on an Ubuntu 14.04 box (which includes the appropriate Qt and CMake versions by default). I don't expected to get a solution to this problem, but I could need some pointers on where to look for the problem.

4
  • The minimal test case is important. It tells us whether the problem is in your code or not. What happens with the posted CMakeLists.txt if blubb.cpp contains a QWidget include? Commented Dec 1, 2014 at 19:22
  • Thanks for feedback @steveire, added a minimal test-case and a bit more information. Commented Dec 2, 2014 at 4:34
  • Try 'make VERBOSE=1' instead of 'make'. What version of Qt 5 is this? Commented Dec 2, 2014 at 8:34
  • Using VERBOSE=1 I noticed that there is no include path to Qt 5 given on the command line to gcc. I think maybe the version of the FindQt5 is old and does not support setting the includes automatically, yet. I might try to figure that out more exactly and set the additional flags depending on the Qt5 version in my CMakeLists.txt to stay compatible on all versions... Commented Dec 4, 2014 at 18:08

2 Answers 2

1

I'm pretty sure that the problem lies in the version of Qt. I think that this early Qt 5 version does not include the CMake scripts to properly work with find_package alone.

On newer distros with newer Qt 5, it works as expected. Looks like you have to add special version checks to include or exclude the lines I mentioned as a workaround.

Additional info: Since Ubuntu 12.04 is really old, I decided not to support it as a target build platform for my project. My initial reason was that Travis CI uses 12.04, but since it is so much trouble, I will hold my travis builds until they upgrade to 14.04, which seems to be quite a problem. Travis tweeted to me, on December, 12th 2014:

Travis CI: We are working on it. Most pieces are there, but there is a critical issue with infrastructure. Thanks for your patience.

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

Comments

0

Here I recently had the same problem and found the following solution to install newer Qt5 versions which enables cmake to proceed properly:

 sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu trusty universe"
 sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu trusty main"
 sudo add-apt-repository --yes ppa:kalakris/cmake
 sudo apt-get update -qq
 sudo apt-get install cmake
 sudo apt-get install qdbus qmlscene qt5-default qt5-qmake qtbase5-dev-tools qtchooser qtdeclarative5-dev xbitmaps xterm libqt5svg5-dev qttools5-dev qtscript5-dev qtdeclarative5-folderlistmodel-plugin qtdeclarative5-controls-plugin -y

In the end I ended up using the following .travis.yml file to get things going:

https://github.com/hzdr/qutselect/blob/master/.travis.yml

Hope that also solves your problems.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.