Giter VIP home page Giter VIP logo

cmakepchcompiler's People

Contributors

cdglove avatar drizt avatar embeddedteam103 avatar gjasny avatar nanoant avatar thewtex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cmakepchcompiler's Issues

CMakePCHCompiler doesnt check for header dependency updates

hi,

I use CMakePCHCompiler to generate a pch file from a header file which points to a number of sub header files. One problem I've been facing is that when I update one of my subheaders, cmake doesn't seem to know that it needs to recompile the main header file into pch. as a result I will frequently deal with compilation issues unless I do a make clean.

If there are any already built-in features which i am not aware of that will cause the main pch file to recompile after some manually speciified file changes, please let me know.

Thanks in advance.

Improve documentation about auto-include "pch.h"

Atm it's not obviously that precompiled header will be autoincluded with -include compilation flag. I found it's in README but first I inserted #include "pch.h" in all my project files. So please add in Example section also main.cpp and pch.h files to show how it exactly works. Or maybe new example dir in repo with full example which everyone can compile and learn.

-iframework flag is not applied for pch target

Problem. Compilation error on macOS

pch compilation command:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++  -DHAVE_QT5 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_CAST_FROM_ASCII -DQT_WIDGETS_LIB -I/Users/taurus/devel/torrent-file-editor -I/Users/taurus/devel/torrent-file-editor/test -I/Library/Frameworks/Sparkle.framework/Headers -isystem /usr/local/Qt/5.5/clang_64/lib/QtCore.framework -isystem /usr/local/Qt/5.5/clang_64/lib/QtCore.framework/Headers -isystem /usr/local/Qt/5.5/clang_64/./mkspecs/macx-clang -isystem /usr/local/Qt/5.5/clang_64/lib/QtGui.framework -isystem /usr/local/Qt/5.5/clang_64/lib/QtGui.framework/Headers -isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/OpenGL.framework/Headers -isystem /usr/local/Qt/5.5/clang_64/lib/QtWidgets.framework -isystem /usr/local/Qt/5.5/clang_64/lib/QtWidgets.framework/Headers  -stdlib=libc++ -Wall -Wextra -pedantic -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7   -std=gnu++11 -fPIC -x c++-header -o CMakeFiles/torrent-file-editor.pch.dir/pch.h.pch -c /Users/taurus/devel/torrent-file-editor/pch.h

But must be something link

clang++  -DHAVE_QT5 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_CAST_FROM_ASCII -DQT_WIDGETS_LIB -I../ -I. -I/Library/Frameworks/Sparkle.framework/Headers -iframework /usr/local/Qt/5.5/clang_64/lib -isystem /usr/local/Qt/5.5/clang_64/lib/QtCore.framework/Headers -isystem /usr/local/Qt/5.5/clang_64/./mkspecs/macx-clang -isystem /usr/local/Qt/5.5/clang_64/lib/QtGui.framework/Headers -isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/OpenGL.framework/Headers -isystem /usr/local/Qt/5.5/clang_64/lib/QtWidgets.framework/Headers -stdlib=libc++ -Wall -Wextra -pedantic -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7   -F/Library/Frameworks  -include /Users/taurus/devel/torrent-file-editor/pch.h -fPIC -std=gnu++11 -MD -MT CMakeFiles/torrent-file-editor.dir/datewidget.cpp.o -MF CMakeFiles/torrent-file-editor.dir/datewidget.cpp.o.d -o CMakeFiles/torrent-file-editor.dir/datewidget.cpp.o -c ../datewidget.cpp

Second command has -iframework /usr/local/Qt/5.5/clang_64/lib. In first command this flag is missing. You can look error on Travis.

CMake generator has complex rules to make includes flags. CMake sources. CMake generator loop over includes dirs and tries to find directory where frameworks are placed. So if it see /usr/local/Qt/5.5/clang_64/lib/QtGui.framework it drop last path part i.e. new string will be /usr/local/Qt/5.5/clang_64/lib then prepend it with -iframework.

On /usr/local/Qt/5.5/clang_64/lib/QtGui.framework input.
Output will be: -iframework /usr/local/Qt/5.5/clang_64/lib.

I don't know why such transformation is not applied for pch target.

Static libraries not supported

It is impossible to create a static library with a PCH today due to cyclic dependency.
The following fails at configure time:

cmake_minimum_required(VERSION 3.0)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/CMakePCHCompiler)

project(pchtest CXX CXXPCH)

add_library(engine src/engine.cpp src/library.cpp)
target_precompiled_header(engine src/prefix.h)

add_executable(demo src/demo.cpp)
target_link_libraries(demo engine)
target_precompiled_header(demo src/prefix.h REUSE engine)

The only difference to the readme example is removing the SHARED from the definition of engine.

Why is the cyclic dependency even required?

OpenGL::GL causes build failure

For some reason, using target_link_libraries(... OpenGL::GL) causes -isystem /usr/include to be added to the PCH build, which apparently causes breakage:

/usr/include/c++/8.3.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
 #include_next <stdlib.h>
               ^~~~~~~~~~
compilation terminated.

This doesn't seem to be added to the actual build (e.g., does not occur in compile_commands.json).

Minimal example

Minimal CMakeLists.txt example reproducing bug or showing requested feature:

cmake_minimum_required(VERSION 3.11)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/CMakePCHCompiler)

project(test CXX CXXPCH)

find_package(OpenGL REQUIRED COMPONENTS OpenGL)

add_executable(demo demo.cpp)
target_link_libraries(demo PRIVATE
  OpenGL::GL
  )

target_precompiled_header(demo prefix.h)

Of course, one must have some minimal prefix.h:

#include <cstdlib>

This is the only difference:

$ /usr/bin/g++   -isystem /usr/include  -O3 -DNDEBUG   -x c++-header -o CMakeFiles/demo.pch.dir/prefix.h.gch -c /home/rpav/tmp/test/prefix.h


In file included from /home/rpav/tmp/test/prefix.h:1:
/usr/include/c++/8.3.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
 #include_next <stdlib.h>
               ^~~~~~~~~~
compilation terminated.
$ /usr/bin/g++  -O3 -DNDEBUG   -x c++-header -o CMakeFiles/demo.pch.dir/prefix.h.gch -c /home/rpav/tmp/test/prefix.h
$

Additional information

  • OS: Linux (Arch, current)
  • CMake version 3.14.4
  • Compiler type and version: gcc-8.3 (also clang-8.0)
  • Additional Libraries used: Platform GL (nvidia)

no linux clang support?

Will the Linux-GNU-CXXPCH work with clang or is there a reason you didn't create a file for clang on linux?

Investigate and clarify better /Z7 necessity for MSVC 2010 and higher when using PCH

I think the new note on the /Z7 flag gives the impression that this is solution aimed at supporting 2010 (at the expense of newer editions) whereas it's really a problem that begins with 2010 and so far (at least) has no end. I.e. it applies equally to likely the most recent version of Visual Studio, whatever it is.

I spent a lot of time trying to put the PDB file in a different location, and link to it. But from what I can recall, the XML files that the compiler uses to save project information has inconsistent escaping both in Visual Studio and in CMake also. So it seemed like an intractable problem, which just magically goes away with /Z7. Even when I would make ground on the problems, and new one would always emerge. Until I think I was left with nowhere to go but to think outside the box.

EDITED: I seem to recall a problem with sharing PDB files between build-targets also. Which went beyond their early deletion. I think that the deletion is so draconian BTW because it's a foregone conclusion that sharing, and therefore referencing an external PDB is not even a possibility. Unfortunately, I cannot remember a lot of the details. I did speak on some of these things in the Kitware issue-tracker at the time, but only inadvertently.

TYPE is c++-header? What is this for anyway?

I was just reading the README. I think it should also say that the default for TYPE is c-header under C.

But, I also wonder what changing this can achieve, and if that should be explained by the README file?

get_target_property() called with non-existent target "NOTFOUND".

I'm porting a rather large code base CMake and shopping around for a precompiled header solution. Yours seems like the cleanest, but I've had no luck getting it to work.

When I attempt to add a precompiled header to any of my targets, I get the following two errors repeated for several thousand lines. CMake version 3.2.3. Since the stack isn't real, I don't know how to start debugging the issue. Any assistance would be appreciated.

CMake Error at cmake/CMakePCHCompiler/CMakePCHCompiler.cmake:229 (get_target_property):
  get_target_property() called with non-existent target "NOTFOUND".
Call Stack (most recent call first):
  Some weird path:9999 (__watch_pch_last_hook)


CMake Error at cmake/CMakePCHCompiler/CMakePCHCompiler.cmake:236 (set_target_properties):
  set_target_properties Can not find target to add properties to:
  NOTFOUND.pch
Call Stack (most recent call first):
  Some weird path:9999 (__watch_pch_last_hook)

PCH breaks clang code model in Qt Creator.

It's not CMakePCHCompiler problem. It's common. Qt Creator uses clang to have good syntax higlighting. This option is optional but by default it's enabled. This means Qt Creator compiles each file with clang with compile options which set by CMake project + plus something set in Qt Creator settings. For example. I use such command to compile my file

g++ -g -O2 -DFOO=bar -Wall -include CMakeFiles/pch.dir/pch.h -o main.cpp.o -c main.cpp

Qt Creator based on this command use such command to parse main.cpp

clang++ -g -O2 -DFOO=bar -Wall -include CMakeFiles/pch.dir/pch.h -pedantic -o main.cpp.o -c main.cpp

This command fails due gcc pch format is not compatible with clang pch format. So Qt Creator can't parse main.cpp and colorize source code. I opened QTCREATORBUG-22427. Also I found a workaround for this. Need to put pch.h near with pch.h.gch and compile sources with -Wno-invalid-pch

Can't find PCH file during build.

I am testing this module out with our software but I can't get it to compile. After calling add_library(), I call target_precompiled_header(${target} ${pch_path}) to add the PCH to it. CMake will run successfully if I use the absolute or relative path to the .pch file but when I try to compile the code I get one of the following errors:

(relative path)
cc1plus: fatal error: /home/smcmich1/repo/visionworkbench/build/src/vw/Core/CMakeFiles/VwCore.pch.dir/../stdafx.h: No such file or directory

(absolute path)
cc1plus: fatal error: /home/smcmich1/repo/visionworkbench/build/src/vw/Core/CMakeFiles/VwCore.pch.dir//home/smcmich1/repo/visionworkbench/src/vw/stdafx.h: No such file or directory

Do you know what could be going wrong? The PCH file is located at /home/smcmich1/repo/visionworkbench/src/vw/stdafx.h. CMake is being called from the "build" subfolder and the code is located in the "src" subfolder. The project line is:
project (VisionWorkbench C CXX CXXPCH CPCH)

This is on Red Hat 6, with CMake 3.5.2, and GCC 4.9.3.

Thanks,
Scott

Alternative to separate CXXPCH compiler definition

In project README

CMake does not allow to insert source file to existing target once it has been defined.

But source can be insert before add_executable/library.

Even if it was possible, we could not ensure precompiled header is built first in main target, but adding it as subtarget we can.

It's possible with OBJECT_DEPENDS property on source files.

We cannot prevent header.pch, which is output of CPCH/CXXPCH compiler from being linked when it is in part of main target, but if we put it into OBJECT library, then by definition we skip linking process. Also we take the result object to be a recompiled header for main target.

Output can be changed witho dummy .o file without code.

project(pchtest CXX)
set(CMAKE_VERBOSE_MAKEFILE ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

add_executable(${PROJECT_NAME} "main.cpp" "pch.cpp" "pch.h" "pch_dummy.cpp")
add_compile_options(${PROJECT_NAME} PUBLIC -Wall -Werror -Winvalid-pch)

set_source_files_properties(pch.cpp PROPERTIES COMPILE_OPTIONS "-x;c++-header" OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/pchtest.dir/pch_dummy.cpp.o)

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/pch.h.gch
    COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/pchtest.dir/pch.cpp.o ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/pch.h.gch
    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/pchtest.dir/pch_dummy.cpp.o ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/pchtest.dir/pch.cpp.o
    COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/pch.h.gch

    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/pchtest.dir/pch.cpp.o
    COMMENT "Copy PCH"
)

set_source_files_properties(main.cpp PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/pch.h.gch COMPILE_OPTIONS "-include;${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/pch.h")

Full example here.

Works with CMake 3.14.3, gcc 8.3.1 and Makefile generator. Ninja generator doesn't works but it seems a CMake bug. I opened an issue here.

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

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.

Does not work with cmake 3.1 compatibility level

Hello,

I added an example (08a3320) as proposed by the Readme.md but set the cmake compatibility to 3.1. Then I get:

-- 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
CMake Warning at /Users/gjasny/src/CMakePCHCompiler/CMakePCHCompiler.cmake:39 (message):
  Precompiled headers not supported for AppleClang
Call Stack (most recent call first):
  CMakeLists.txt:8 (target_precompiled_header)


CMake Warning at /Users/gjasny/src/CMakePCHCompiler/CMakePCHCompiler.cmake:39 (message):
  Precompiled headers not supported for AppleClang
Call Stack (most recent call first):
  CMakeLists.txt:12 (target_precompiled_header)


-- Configuring done
-- Generating done
-- Build files have been written to: /Users/gjasny/src/CMakePCHCompiler/example

I'm using CMake 3.1.3 with Xcode 6.1.1 on OSX Yosemite.

Thanks,
Gregor

Failed to compile the PCH

I tried this with a C++ module in ReactOS, but got:

FAILED: E:\RosBE\i386\bin\g++.exe   -DDBG=1 -DKDBG=1 -DUSE_COMPILER_EXCEPTIONS -DWINVER=0x502 -D_M_IX86 -D_NETSHELL_ -D_SEH_ENABLE_TRACE -D_SETUPAPI_VER=0x502 -D_USE_32BIT_TIME_T -D_USE_PSEH3=1 -D_WIN32_IE=0x600 -D_WIN32_WINDOWS=0x502 -D_WIN32_WINNT=0x600 -D_X86_ -D__REACTOS__ -D__i386__ -D_inline=__inline -Di386 -g dll/shellext/netshell e:/reactos-vanilla/dll/shellext/netshell e:/reactos-vanilla/include e:/reactos-vanilla/include/psdk e:/reactos-vanilla/include/dxsdk include include/psdk include/dxsdk include/reactos e:/reactos-vanilla/include/crt e:/reactos-vanilla/include/ddk e:/reactos-vanilla/include/ndk e:/reactos-vanilla/include/reactos e:/reactos-vanilla/include/reactos/libs -x c++-header -o dll/shellext/netshell/CMakeFiles/netshell.pch.dir/precomp.h.gch -c e:/reactos-vanilla/dll/shellext/netshell/precomp.h
e:/reactos-vanilla/dll/shellext/netshell/precomp.h:21:27: fatal error: shlguid_undoc.h: No such file or directory

Notice that header folders are not prefixed with -I for inclusions.

pch.h generates without c++ standard

My OS Fedora 29. I create console Qt application and tri to compile it with PCH support. So console output.

[taurus@lix debug]$ cmake -DCMAKE_BUILD_TYPE=Debug ..
-- The CXX compiler identification is GNU 8.3.1
-- Check for working CXX compiler: /usr/lib64/ccache/c++
-- Check for working CXX compiler: /usr/lib64/ccache/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/taurus/tmp/pchtest/debug
[taurus@lix debug]$ make VERBOSE=1
/usr/bin/cmake -S/home/taurus/tmp/pchtest -B/home/taurus/tmp/pchtest/debug --check-build-system CMakeFiles/Makefile.cmake 0
/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=
Dependee "/home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.pch_autogen.dir/DependInfo.cmake" is newer than depender "/home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.pch_autogen.dir/depend.internal".
Dependee "/home/taurus/tmp/pchtest/debug/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.pch_autogen.dir/depend.internal".
Scanning dependencies of target pchtest.pch_autogen
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
AutoMoc: Generating "moc_predefs.h" because it doesn't exist
AutoMoc: Running command:
/usr/lib64/ccache/c++ -dM -E -c /usr/share/cmake/Modules/CMakeCXXCompilerABI.cpp -I/home/taurus/tmp/pchtest/debug -I/home/taurus/tmp/pchtest -I/usr/include/qt5 -I/usr/include/qt5/QtCore -I/usr/lib64/qt5/mkspecs/linux-g++ -I/usr/include/c++/8 -I/usr/include/c++/8/x86_64-redhat-linux -I/usr/include/c++/8/backward -I/usr/lib/gcc/x86_64-redhat-linux/8/include -I/usr/local/include -I/usr/include -DQT_CORE_LIB
AutoMoc: Generating MOC compilation /home/taurus/tmp/pchtest/debug/pchtest.pch_autogen/mocs_compilation.cpp
AutoGen: Writing settings file "/home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.pch_autogen.dir/AutogenOldSettings.txt"
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=
Dependee "/home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.pch.dir/DependInfo.cmake" is newer than depender "/home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.pch.dir/depend.internal".
Dependee "/home/taurus/tmp/pchtest/debug/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.pch.dir/depend.internal".
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 -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++  -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 -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++  -g   -fPIC -x c++-header -o CMakeFiles/pchtest.pch.dir/pch.h.gch -c /home/taurus/tmp/pchtest/pch.h
make[2]: Leaving directory '/home/taurus/tmp/pchtest/debug'
[ 42%] Built target pchtest.pch
make -f CMakeFiles/pchtest_autogen.dir/build.make CMakeFiles/pchtest_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_autogen.dir/DependInfo.cmake --color=
Dependee "/home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest_autogen.dir/DependInfo.cmake" is newer than depender "/home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest_autogen.dir/depend.internal".
Dependee "/home/taurus/tmp/pchtest/debug/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest_autogen.dir/depend.internal".
Scanning dependencies of target pchtest_autogen
make[2]: Leaving directory '/home/taurus/tmp/pchtest/debug'
make -f CMakeFiles/pchtest_autogen.dir/build.make CMakeFiles/pchtest_autogen.dir/build
make[2]: Entering directory '/home/taurus/tmp/pchtest/debug'
[ 57%] Automatic MOC for target pchtest
/usr/bin/cmake -E cmake_autogen /home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest_autogen.dir/AutogenInfo.cmake Debug
AutoMoc: Generating "moc_predefs.h" because it doesn't exist
AutoMoc: Running command:
/usr/lib64/ccache/c++ -dM -E -c /usr/share/cmake/Modules/CMakeCXXCompilerABI.cpp -I/home/taurus/tmp/pchtest/debug -I/home/taurus/tmp/pchtest -I/usr/include/qt5 -I/usr/include/qt5/QtCore -I/usr/lib64/qt5/mkspecs/linux-g++ -I/usr/include/c++/8 -I/usr/include/c++/8/x86_64-redhat-linux -I/usr/include/c++/8/backward -I/usr/lib/gcc/x86_64-redhat-linux/8/include -I/usr/local/include -I/usr/include -DQT_CORE_LIB
AutoMoc: Generating MOC compilation /home/taurus/tmp/pchtest/debug/pchtest_autogen/mocs_compilation.cpp
AutoGen: Writing settings file "/home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest_autogen.dir/AutogenOldSettings.txt"
make[2]: Leaving directory '/home/taurus/tmp/pchtest/debug'
[ 57%] Built target pchtest_autogen
make -f CMakeFiles/pchtest.dir/build.make CMakeFiles/pchtest.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.dir/DependInfo.cmake --color=
Dependee "/home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.dir/DependInfo.cmake" is newer than depender "/home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.dir/depend.internal".
Dependee "/home/taurus/tmp/pchtest/debug/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.dir/depend.internal".
Scanning dependencies of target pchtest
make[2]: Leaving directory '/home/taurus/tmp/pchtest/debug'
make -f CMakeFiles/pchtest.dir/build.make CMakeFiles/pchtest.dir/build
make[2]: Entering directory '/home/taurus/tmp/pchtest/debug'
[ 71%] Building CXX object CMakeFiles/pchtest.dir/pchtest_autogen/mocs_compilation.cpp.o
/usr/lib64/ccache/c++  -DQT_CORE_LIB -I/home/taurus/tmp/pchtest/debug -I/home/taurus/tmp/pchtest -I/home/taurus/tmp/pchtest/debug/pchtest_autogen/include -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtCore -isystem /usr/lib64/qt5/mkspecs/linux-g++  -g   -include /home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.pch.dir/pch.h -fPIC -std=gnu++11 -o CMakeFiles/pchtest.dir/pchtest_autogen/mocs_compilation.cpp.o -c /home/taurus/tmp/pchtest/debug/pchtest_autogen/mocs_compilation.cpp
cc1plus: error: one or more PCH files were found, but they were invalid
cc1plus: error: use -Winvalid-pch for more information
cc1plus: fatal error: /home/taurus/tmp/pchtest/debug/CMakeFiles/pchtest.pch.dir/pch.h: No such file or directory
compilation terminated.
make[2]: *** [CMakeFiles/pchtest.dir/build.make:63: CMakeFiles/pchtest.dir/pchtest_autogen/mocs_compilation.cpp.o] Error 1
make[2]: Leaving directory '/home/taurus/tmp/pchtest/debug'
make[1]: *** [CMakeFiles/Makefile2:74: CMakeFiles/pchtest.dir/all] Error 2
make[1]: Leaving directory '/home/taurus/tmp/pchtest/debug'
make: *** [Makefile:84: all] Error 2

Then I tried to drop -std=gnu++11 from latest compilation command and hit enter. And then compiled without problems.

Error when compiling with Clang on OSX

Hello,

When compiling the example (08a3320) I get the following error:

$ make VERBOSE=1
/usr/local/Cellar/cmake/3.1.3/bin/cmake -H/Users/gjasny/src/CMakePCHCompiler/example -B/Users/gjasny/src/CMakePCHCompiler/example --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.1.3/bin/cmake -E cmake_progress_start /Users/gjasny/src/CMakePCHCompiler/example/CMakeFiles /Users/gjasny/src/CMakePCHCompiler/example/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/engine.pch.dir/build.make CMakeFiles/engine.pch.dir/depend
cd /Users/gjasny/src/CMakePCHCompiler/example && /usr/local/Cellar/cmake/3.1.3/bin/cmake -E cmake_depends "Unix Makefiles" /Users/gjasny/src/CMakePCHCompiler/example /Users/gjasny/src/CMakePCHCompiler/example /Users/gjasny/src/CMakePCHCompiler/example /Users/gjasny/src/CMakePCHCompiler/example /Users/gjasny/src/CMakePCHCompiler/example/CMakeFiles/engine.pch.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/engine.pch.dir/build.make CMakeFiles/engine.pch.dir/build
make[2]: Nothing to be done for `CMakeFiles/engine.pch.dir/build'.
/usr/local/Cellar/cmake/3.1.3/bin/cmake -E cmake_progress_report /Users/gjasny/src/CMakePCHCompiler/example/CMakeFiles  5
[ 20%] Built target engine.pch
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/engine.dir/build.make CMakeFiles/engine.dir/depend
cd /Users/gjasny/src/CMakePCHCompiler/example && /usr/local/Cellar/cmake/3.1.3/bin/cmake -E cmake_depends "Unix Makefiles" /Users/gjasny/src/CMakePCHCompiler/example /Users/gjasny/src/CMakePCHCompiler/example /Users/gjasny/src/CMakePCHCompiler/example /Users/gjasny/src/CMakePCHCompiler/example /Users/gjasny/src/CMakePCHCompiler/example/CMakeFiles/engine.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/engine.dir/build.make CMakeFiles/engine.dir/build
Linking CXX shared library libengine.dylib
/usr/local/Cellar/cmake/3.1.3/bin/cmake -E cmake_link_script CMakeFiles/engine.dir/link.txt --verbose=1
/usr/bin/c++   -dynamiclib -Wl,-headerpad_max_install_names  -o libengine.dylib -install_name /Users/gjasny/src/CMakePCHCompiler/example/libengine.dylib CMakeFiles/engine.dir/src/engine.cpp.o CMakeFiles/engine.dir/src/library.cpp.o CMakeFiles/engine.dir/src/prefix.h.pch 
error: invalid value 'precompiled-header' in '-x precompiled-header'
make[2]: *** [libengine.dylib] Error 1
make[1]: *** [CMakeFiles/engine.dir/all] Error 2
make: *** [all] Error 2

I'm using CMake 3.1.3 with Xcode 6.1.1 on OSX Yosemite.

Thanks,
Gregor

clang from llvm does not seem to work on osx

-- The CXX compiler identification is Clang 6.0.1
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at cmake/CMakePCHCompiler/Platform/Darwin-Clang-CXXPCH.cmake:1 (include):
  include could not find load file:

    Platform/Darwin-Clang
Call Stack (most recent call first):
  cmake/CMakePCHCompiler/CMakePCHCompiler.cmake:156 (include)
  cmake/CMakePCHCompiler/CMakeCXXPCHInformation.cmake:11 (__define_pch_compiler)
  CMakeLists.txt:12 (project)


CMake Error at cmake/CMakePCHCompiler/Platform/Darwin-Clang-CXXPCH.cmake:2 (__darwin_compiler_clang):
  Unknown CMake command "__darwin_compiler_clang".
Call Stack (most recent call first):
  cmake/CMakePCHCompiler/CMakePCHCompiler.cmake:156 (include)
  cmake/CMakePCHCompiler/CMakeCXXPCHInformation.cmake:11 (__define_pch_compiler)
  CMakeLists.txt:12 (project)


-- Configuring incomplete, errors occurred!

Doesn't work on linux cmake 3.10.2

-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Could not determine Eclipse version, assuming at least 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong.
-- 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
-- Detecting C compile features
-- Detecting C compile features - 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
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at build/cmake/CMakePCHCompiler/CMakePCHCompiler.cmake:39 (message):
Precompiled headers not supported for
Call Stack (most recent call first):
src/librender/CMakeLists.txt:9 (target_precompiled_header)
-- Generating done

Looking at the source it is missing CMAKE_PCH_COMPILER_LANGUAGE

If I set CMAKE_PCH_COMPILER_LANGUAGE to CXX the following error comes up:

CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_CXXPCH_COMPILE_OBJECT

Setting CMAKE_CXX_STANDARD leads to error

Setting CMAKE_CXX_STANDARD leads to error

Minimal CMakeLists.txt example reproducing bug or showing requested feature:

cmake_minimum_required(VERSION 3.0)

# Choose C++ standard
set(CMAKE_CXX_STANDARD 17)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/CMakePCHCompiler)

project(pchtest CXX CXXPCH)

add_library(engine src/engine.cpp src/library.cpp)
target_precompiled_header(engine src/prefix.h)

add_executable(demo src/demo.cpp)
target_link_libraries(demo engine)
target_precompiled_header(demo src/prefix.h REUSE engine)

Leads to error:

CMake Error at /home/user/workspace/CMakePCHCompiler/CMakePCHCompiler.cmake:116 (add_library):
  CXXPCH_STANDARD is set to invalid value '17'
Call Stack (most recent call first):
  CMakeLists.txt:10 (target_precompiled_header)

Additional information

  • OS [Ubuntu]
  • CMake version [3.14.1]
  • Compiler type and version [GCC 7.2]

target_precompiled_header(Foo bar.h) creates both CMakeFiles/Foo.pch.dir/Bar.h.gch and CMakeFiles/Foo.dir/Bar.h.gch targets

I am trying to use this package under Ubuntu with gcc, and somehow I get the following:

  • The make rules for creating and using CMakeFiles/Foo.pch.dir/Bar.h.gch are done correctly - everything works
  • But there is also a make rule for creating CMakeFiles/Foo.dir/Bar.h.gch by compiling CMakeFiles/Foo.pch.dir/Bar.h (which fails as there is no such .h)... I could not figure out where it is coming from...

Doesn't work with multiple language targets.

It doesn't work when target mixes multiple languages (C, C++, Objective-C, ObjectiveC++). target_precompiled_header should generate a separate header for each language, or use the pch only for the language it was compiled for.

Visual Studio deletes common precompiled headers :(

I've made many improvements to this module (I need to apply it to a real world project) only to in the final moment be thwarted seemingly by VS itself:

https://developercommunity.visualstudio.com/content/problem/15171/shared-precompiled-header-gots-deleted-during-buil.html

This is not my bug-report, but I've found a few of these around, and I think it's worth logging with this effort. I would make this "issue" under my fork, but GitHub either won't let me make an issue on my own repository or on forks.

It seems as if this issue has been around since VS2010. Going by accounts. To work around it the REUSE feature can't be used, and some other strategy will be required.

From the link: (Shared precompiled header gots deleted during build.)[sic]

I use shared static library project for building precompiled header, which is shared among most of other projects. When dependant projects start build the referenced .pch file got deleted due to lines 249-250 in Microsoft.CppCommon.targets file, which are trying to prevent compile warnings. But in my I case I would prefer disable certain warnings instead of loosing ability to use common pch. To reproduce the issue I attached a simple solution with such configuration. How can I workaround this issue, without disabling debug info in my projects?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.