nanoant / CMakePCHCompiler

CMake precompiled header support via custom PCH compiler extension
MIT License
103 stars 20 forks source link

wrong -isystem /usr/include in pch.h compilations flags #33

Closed drizt closed 5 years ago

drizt commented 5 years ago

OS Fedora 29

I can set manually C++ standard. But in this case I got another error.

[taurus@lix debug]$ make 
/usr/bin/cmake -S/home/taurus/tmp/pchtest -B/home/taurus/tmp/pchtest/debug --check-build-system CMakeFiles/Makefile.cmake 0
-- Configuring done
CMake Debug Log at CMakeLists.txt:16 (target_link_libraries):
  Used includes for target pchtest:

   * /usr/include/qt5
   * /usr/include/qt5/QtCore
   * /usr/lib64/qt5/mkspecs/linux-g++

CMake Debug Log at CMakeLists.txt:16 (target_link_libraries):
  Used includes for target pchtest:

   * /usr/include/qt5/QtGui
   * /usr/include

CMake Debug Log at cmake/CMakePCHCompiler/CMakePCHCompiler.cmake:110 (set_target_properties):
  Used includes for target pchtest.pch:

   * /usr/include/qt5
   * /usr/include/qt5/QtCore
   * /usr/lib64/qt5/mkspecs/linux-g++

Call Stack (most recent call first):
  CMakeLists.txt:17 (target_precompiled_header)

CMake Debug Log at cmake/CMakePCHCompiler/CMakePCHCompiler.cmake:110 (set_target_properties):
  Used includes for target pchtest.pch:

   * /usr/include/qt5/QtGui
   * /usr/include

Call Stack (most recent call first):
  CMakeLists.txt:17 (target_precompiled_header)

-- Generating done
-- Build files have been written to: /home/taurus/tmp/pchtest/debug
/usr/bin/cmake -E cmake_progress_start /home/taurus/tmp/pchtest/debug/CMakeFiles /home/taurus/tmp/pchtest/debug/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/taurus/tmp/pchtest/debug'
make -f CMakeFiles/pchtest.pch_autogen.dir/build.make CMakeFiles/pchtest.pch_autogen.dir/depend
make[2]: Entering directory '/home/taurus/tmp/pchtest/debug'
cd /home/taurus/tmp/pchtest/debug && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/taurus/tmp/pchtest /home/taurus/tmp/pchtest /home/taurus/tmp/pchtest/debug /home/taurus/tmp/pchtest/debug /home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.pch_autogen.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/taurus/tmp/pchtest/debug'
make -f CMakeFiles/pchtest.pch_autogen.dir/build.make CMakeFiles/pchtest.pch_autogen.dir/build
make[2]: Entering directory '/home/taurus/tmp/pchtest/debug'
[ 14%] Automatic MOC for target pchtest.pch
/usr/bin/cmake -E cmake_autogen /home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.pch_autogen.dir/AutogenInfo.cmake Debug
make[2]: Leaving directory '/home/taurus/tmp/pchtest/debug'
[ 14%] Built target pchtest.pch_autogen
make -f CMakeFiles/pchtest.pch.dir/build.make CMakeFiles/pchtest.pch.dir/depend
make[2]: Entering directory '/home/taurus/tmp/pchtest/debug'
cd /home/taurus/tmp/pchtest/debug && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/taurus/tmp/pchtest /home/taurus/tmp/pchtest /home/taurus/tmp/pchtest/debug /home/taurus/tmp/pchtest/debug /home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.pch.dir/DependInfo.cmake --color=
Scanning dependencies of target pchtest.pch
make[2]: Leaving directory '/home/taurus/tmp/pchtest/debug'
make -f CMakeFiles/pchtest.pch.dir/build.make CMakeFiles/pchtest.pch.dir/build
make[2]: Entering directory '/home/taurus/tmp/pchtest/debug'
[ 28%] Building CXX object CMakeFiles/pchtest.pch.dir/pchtest.pch_autogen/mocs_compilation.cpp.o
/usr/lib64/ccache/c++  -DQT_CORE_LIB -DQT_GUI_LIB -I/home/taurus/tmp/pchtest/debug -I/home/taurus/tmp/pchtest -I/home/taurus/tmp/pchtest/debug/pchtest.pch_autogen/include -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtCore -isystem /usr/lib64/qt5/mkspecs/linux-g++ -isystem /usr/include/qt5/QtGui  -g   -std=gnu++11 -fPIC -std=gnu++11 -o CMakeFiles/pchtest.pch.dir/pchtest.pch_autogen/mocs_compilation.cpp.o -c /home/taurus/tmp/pchtest/debug/pchtest.pch_autogen/mocs_compilation.cpp
[ 42%] Building CXXPCH object CMakeFiles/pchtest.pch.dir/pch.h.gch
/usr/lib64/ccache/c++  -DQT_CORE_LIB -DQT_GUI_LIB -I/home/taurus/tmp/pchtest/debug -I/home/taurus/tmp/pchtest -I/home/taurus/tmp/pchtest/debug/pchtest.pch_autogen/include -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtCore -isystem /usr/lib64/qt5/mkspecs/linux-g++ -isystem /usr/include/qt5/QtGui -isystem /usr/include  -g   -std=gnu++11 -fPIC -x c++-header -o CMakeFiles/pchtest.pch.dir/pch.h.gch -c /home/taurus/tmp/pchtest/pch.h
In file included from /usr/include/c++/8/bits/stl_algo.h:59,
                 from /usr/include/c++/8/algorithm:62,
                 from /usr/include/qt5/QtCore/qglobal.h:142,
                 from /usr/include/qt5/QtCore/qcoreapplication.h:43,
                 from /usr/include/qt5/QtCore/QCoreApplication:1,
                 from /home/taurus/tmp/pchtest/pch.h:1:
/usr/include/c++/8/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
 #include_next <stdlib.h>
               ^~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/pchtest.pch.dir/build.make:79: CMakeFiles/pchtest.pch.dir/pch.h.gch] Error 1
make[2]: Leaving directory '/home/taurus/tmp/pchtest/debug'
make[1]: *** [CMakeFiles/Makefile2:114: CMakeFiles/pchtest.pch.dir/all] Error 2
make[1]: Leaving directory '/home/taurus/tmp/pchtest/debug'
make: *** [Makefile:87: all] Error 2
[taurus@lix debug]$ cd ..
[taurus@lix pchtest]$ ll
total 32
drwxrwxr-x 3 taurus taurus 4096 Apr 29 21:41 cmake
-rw-rw-r-- 1 taurus taurus  568 Apr 29 22:54 CMakeLists.txt
-rw-rw-r-- 1 taurus taurus 9922 Apr 29 22:06 CMakeLists.txt.user
drwxrwxr-x 5 taurus taurus 4096 Apr 29 22:53 debug
-rw-rw-r-- 1 taurus taurus  142 Apr 29 21:40 main.cpp
-rw-rw-r-- 1 taurus taurus   28 Apr 29 21:40 pch.h
[taurus@lix pchtest]$ cd cmake/
[taurus@lix cmake]$ rm -fr *
[taurus@lix cmake]$ cp -r ~/develop/CM
cmake/            CMakePCHCompiler/ cmoss/            
[taurus@lix cmake]$ cp -r ~/develop/CMak
cmake/            CMakePCHCompiler/ 
[taurus@lix cmake]$ cp -r ~/develop/CMakePCHCompiler .
[taurus@lix cmake]$ ll
total 4
drwxrwxr-x 4 taurus taurus 4096 Apr 29 22:54 CMakePCHCompiler
[taurus@lix cmake]$ cd ../debug/
[taurus@lix debug]$ make
/usr/bin/cmake -S/home/taurus/tmp/pchtest -B/home/taurus/tmp/pchtest/debug --check-build-system CMakeFiles/Makefile.cmake 0
-- Configuring done
CMake Debug Log at CMakeLists.txt:19 (target_link_libraries):
  Used includes for target pchtest:

   * /usr/include/qt5
   * /usr/include/qt5/QtCore
   * /usr/lib64/qt5/mkspecs/linux-g++

CMake Debug Log at CMakeLists.txt:19 (target_link_libraries):
  Used includes for target pchtest:

   * /usr/include/qt5/QtGui
   * /usr/include

CMake Debug Log at cmake/CMakePCHCompiler/CMakePCHCompiler.cmake:110 (set_target_properties):
  Used includes for target pchtest.pch:

   * /usr/include/qt5
   * /usr/include/qt5/QtCore
   * /usr/lib64/qt5/mkspecs/linux-g++

Call Stack (most recent call first):
  CMakeLists.txt:20 (target_precompiled_header)

CMake Debug Log at cmake/CMakePCHCompiler/CMakePCHCompiler.cmake:110 (set_target_properties):
  Used includes for target pchtest.pch:

   * /usr/include/qt5/QtGui
   * /usr/include

Call Stack (most recent call first):
  CMakeLists.txt:20 (target_precompiled_header)

-- Generating done
-- Build files have been written to: /home/taurus/tmp/pchtest/debug
/usr/bin/cmake -E cmake_progress_start /home/taurus/tmp/pchtest/debug/CMakeFiles /home/taurus/tmp/pchtest/debug/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/taurus/tmp/pchtest/debug'
make -f CMakeFiles/pchtest.pch_autogen.dir/build.make CMakeFiles/pchtest.pch_autogen.dir/depend
make[2]: Entering directory '/home/taurus/tmp/pchtest/debug'
cd /home/taurus/tmp/pchtest/debug && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/taurus/tmp/pchtest /home/taurus/tmp/pchtest /home/taurus/tmp/pchtest/debug /home/taurus/tmp/pchtest/debug /home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.pch_autogen.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/taurus/tmp/pchtest/debug'
make -f CMakeFiles/pchtest.pch_autogen.dir/build.make CMakeFiles/pchtest.pch_autogen.dir/build
make[2]: Entering directory '/home/taurus/tmp/pchtest/debug'
[ 14%] Automatic MOC for target pchtest.pch
/usr/bin/cmake -E cmake_autogen /home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.pch_autogen.dir/AutogenInfo.cmake Debug
make[2]: Leaving directory '/home/taurus/tmp/pchtest/debug'
[ 14%] Built target pchtest.pch_autogen
make -f CMakeFiles/pchtest.pch.dir/build.make CMakeFiles/pchtest.pch.dir/depend
make[2]: Entering directory '/home/taurus/tmp/pchtest/debug'
cd /home/taurus/tmp/pchtest/debug && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/taurus/tmp/pchtest /home/taurus/tmp/pchtest /home/taurus/tmp/pchtest/debug /home/taurus/tmp/pchtest/debug /home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.pch.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/taurus/tmp/pchtest/debug'
make -f CMakeFiles/pchtest.pch.dir/build.make CMakeFiles/pchtest.pch.dir/build
make[2]: Entering directory '/home/taurus/tmp/pchtest/debug'
[ 28%] Building CXX object CMakeFiles/pchtest.pch.dir/pchtest.pch_autogen/mocs_compilation.cpp.o
/usr/lib64/ccache/c++  -DQT_CORE_LIB -DQT_GUI_LIB -I/home/taurus/tmp/pchtest/debug -I/home/taurus/tmp/pchtest -I/home/taurus/tmp/pchtest/debug/pchtest.pch_autogen/include -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtCore -isystem /usr/lib64/qt5/mkspecs/linux-g++ -isystem /usr/include/qt5/QtGui  -std=c++11 -g   -fPIC -std=gnu++11 -o CMakeFiles/pchtest.pch.dir/pchtest.pch_autogen/mocs_compilation.cpp.o -c /home/taurus/tmp/pchtest/debug/pchtest.pch_autogen/mocs_compilation.cpp
[ 42%] Building CXXPCH object CMakeFiles/pchtest.pch.dir/pch.h.gch
/usr/lib64/ccache/c++  -DQT_CORE_LIB -DQT_GUI_LIB -I/home/taurus/tmp/pchtest/debug -I/home/taurus/tmp/pchtest -I/home/taurus/tmp/pchtest/debug/pchtest.pch_autogen/include -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtCore -isystem /usr/lib64/qt5/mkspecs/linux-g++ -isystem /usr/include/qt5/QtGui -isystem /usr/include  -std=c++11 -g   -fPIC -x c++-header -o CMakeFiles/pchtest.pch.dir/pch.h.gch -c /home/taurus/tmp/pchtest/pch.h
In file included from /usr/include/c++/8/bits/stl_algo.h:59,
                 from /usr/include/c++/8/algorithm:62,
                 from /usr/include/qt5/QtCore/qglobal.h:142,
                 from /usr/include/qt5/QtCore/qcoreapplication.h:43,
                 from /usr/include/qt5/QtCore/QCoreApplication:1,
                 from /home/taurus/tmp/pchtest/pch.h:1:
/usr/include/c++/8/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
 #include_next <stdlib.h>
               ^~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/pchtest.pch.dir/build.make:79: CMakeFiles/pchtest.pch.dir/pch.h.gch] Error 1
make[2]: Leaving directory '/home/taurus/tmp/pchtest/debug'
make[1]: *** [CMakeFiles/Makefile2:114: CMakeFiles/pchtest.pch.dir/all] Error 2
make[1]: Leaving directory '/home/taurus/tmp/pchtest/debug'
make: *** [Makefile:87: all] Error 2

PCH adds -isystem /usr/include which missing in normal compilation process. This flag comes from Qt5::Gui library.

drizt commented 5 years ago

I dump all properties for Qt5::Gui and one from them:

Qt5::Gui INTERFACE_INCLUDE_DIRECTORIES = /usr/include/qt5/;/usr/include/qt5/QtGui;/usr/include

Also I opened CMake sources. They exclude /usr/include. https://github.com/Kitware/CMake/blob/master/Source/cmLocalGenerator.cxx#L964

nanoant commented 5 years ago

@drizt Hi, thanks for the root cause analysis. Can you please let me know if removing /usr/include from Qt's INTERFACE_INCLUDE_DIRECTORIES fixes the problem? If yes, I believe it is Qt to be blamed not CMakePCHCompiler. Apparently CMake there at https://github.com/Kitware/CMake/blob/master/Source/cmLocalGenerator.cxx#L964 hardcodes some bugfix, which is obviously not affecting CXXPCH & CPCH derived PCH languages.

drizt commented 5 years ago

Yes. For Qt5 I use such workaround:

  get_target_property(Qt5GuiIncDirs Qt5::Gui INTERFACE_INCLUDE_DIRECTORIES)
  list(REMOVE_ITEM Qt5GuiIncDirs "/usr/include")
  set_target_properties(Qt5::Gui PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Qt5GuiIncDirs}")

And this for Qt4:

  get_target_property(Qt4GuiIncDirs Qt4::QtGui INTERFACE_INCLUDE_DIRECTORIES)
  list(REMOVE_ITEM Qt4GuiIncDirs "/usr/include")
  set_target_properties(Qt4::QtGui PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Qt4GuiIncDirs}")

  get_target_property(Qt4CoreIncDirs Qt4::QtCore INTERFACE_INCLUDE_DIRECTORIES)
  list(REMOVE_ITEM Qt4CoreIncDirs "/usr/include")
  set_target_properties(Qt4::QtCore PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Qt4CoreIncDirs}")

  list(REMOVE_ITEM QT_INCLUDE_DIR "/usr/include")
drizt commented 5 years ago

You use non-standard lang for pch header. It's very rare case. I think this problem can happens in other cases not only mine. Maybe this information should be add to README or there is a way to workaround it in your CMakePCHCompiler?

drizt commented 5 years ago

Open an issue on Qt bugtracker.

nanoant commented 5 years ago

Okay, thanks for the update. Do you think we should keep this issue open or we can close it now?

nanoant commented 5 years ago

This was very likely fixed by fa975ba71ae3a2f664b60ed2b718dc2c5d26c38f and looks similar to #36, anyways the example in Tests/Issue36_QTFramework now works.