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.