nanoant / CMakePCHCompiler

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

Failed to compile the PCH #1

Closed AmineKhaldi closed 9 years ago

AmineKhaldi commented 9 years ago

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.

AmineKhaldi commented 9 years ago

I tested the latest revision and the problem still occurs.

nanoant commented 9 years ago

It should be fixed by acd3166fa78bb6495f4f3a52000340ac10696d04

AmineKhaldi commented 9 years ago

Now it's:

FAILED: E:\RosBE\i386\bin\g++.exe   -DDBG=1 -DKDBG=1 -DUSE_COMPILER_EXCEPTIONS -DWINVER=0x502 -D_DLL -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__USE_CRTIMP -D__i386__ -D_inline=__inline -Di386 -Dnetshell_EXPORTS -pipe -fms-extensions -fno-strict-aliasing -mstackrealign -fno-rtti -fno-exceptions -fdebug-prefix-map="e:\reactos-vanilla"=ReactOS -gdwarf-2 -gstrict-dwarf -femit-struct-debug-detailed=none -feliminate-unused-debug-symbols -march=pentium -mtune=i686 -Werror -Wall -Wpointer-arith -Wno-char-subscripts -Wno-multichar -Wno-unused-value -Wno-maybe-uninitialized -Wno-error=unused-but-set-variable -Wno-error=type-limits -O1 -fno-optimize-sibling-calls -fno-omit-frame-pointer -mpreferred-stack-boundary=3 -fno-set-stack-executable -Winvalid-pch -Werror=invalid-pch -std=c++11 -g -Idll/shellext/netshell -Ie:/reactos-vanilla/dll/shellext/netshell -Ie:/reactos-vanilla/include -Ie:/reactos-vanilla/include/psdk -Ie:/reactos-vanilla/include/dxsdk -Iinclude -Iinclude/psdk -Iinclude/dxsdk -Iinclude/reactos -Ie:/reactos-vanilla/include/crt -Ie:/reactos-vanilla/include/ddk -Ie:/reactos-vanilla/include/ndk -Ie:/reactos-vanilla/include/reactos -Ie:/reactos-vanilla/include/reactos/libs    -include E:/testing_new_pch/reactos/CMakeFiles/netshell.pch.dir/precomp.h -MMD -MT dll/shellext/netshell/CMakeFiles/netshell.dir/lanconnectui.cpp.obj -MF dll/shellext/netshell/CMakeFiles/netshell.dir/lanconnectui.cpp.obj.d -o dll/shellext/netshell/CMakeFiles/netshell.dir/lanconnectui.cpp.obj -c e:/reactos-vanilla/dll/shellext/netshell/lanconnectui.cpp
cc1plus.exe: fatal error: E:/testing_new_pch/reactos/CMakeFiles/netshell.pch.dir/precomp.h: No such file or directory
compilation terminated.

The "-include" should pass something like E:/testing_new_pch/reactos/dll/shellext/netshell/CMakeFiles/netshell.pch.dir/precomp.h instead of E:/testing_new_pch/reactos/CMakeFiles/netshell.pch.dir/precomp.h.

nanoant commented 9 years ago

Should be addressed by 9c6e030155656a648f1c7351961153f66d076e5d

And please wrap compiler output with markdowns ~~~ or ```. Thanks for testing :)

AmineKhaldi commented 9 years ago

Nice! didn't know about this ;)

AmineKhaldi commented 9 years ago

Now we get:

build dll/shellext/netshell/CMakeFiles/netshell.dir/precomp.h.gch: CXXPCH_COMPILER e$:/reactos-vanilla/dll/shellext/netshell/precomp.h || cmake_order_depends_target_netshell
  DEFINES = -DDBG=1 -DKDBG=1 -DUSE_COMPILER_EXCEPTIONS -DWINVER=0x502 -D_DLL -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__USE_CRTIMP -D__i386__ -D_inline=__inline -Di386 -Dnetshell_EXPORTS
  DEP_FILE = dll/shellext/netshell/CMakeFiles/netshell.dir/precomp.h.gch.d
  FLAGS = -pipe -fms-extensions -fno-strict-aliasing -mstackrealign -fno-rtti -fno-exceptions -fdebug-prefix-map="e:
eactos-vanilla"=ReactOS -gdwarf-2 -gstrict-dwarf -femit-struct-debug-detailed=none -feliminate-unused-debug-symbols -march=pentium -mtune=i686 -Werror -Wall -Wpointer-arith -Wno-char-subscripts -Wno-multichar -Wno-unused-value -Wno-maybe-uninitialized -Wno-error=unused-but-set-variable -Wno-error=type-limits -O1 -fno-optimize-sibling-calls -fno-omit-frame-pointer -mpreferred-stack-boundary=3 -fno-set-stack-executable -Winvalid-pch -Werror=invalid-pch -std=c++11 -g -Idll/shellext/netshell -Ie:/reactos-vanilla/dll/shellext/netshell -Ie:/reactos-vanilla/include -Ie:/reactos-vanilla/include/psdk -Ie:/reactos-vanilla/include/dxsdk -Iinclude -Iinclude/psdk -Iinclude/dxsdk -Iinclude/reactos -Ie:/reactos-vanilla/include/crt -Ie:/reactos-vanilla/include/ddk -Ie:/reactos-vanilla/include/ndk -Ie:/reactos-vanilla/include/reactos -Ie:/reactos-vanilla/include/reactos/libs    -include E:/testing_new_pch/reactos/dll/shellext/netshell/CMakeFiles/netshell.pch.dir/precomp.h -x c++-header

Notice that it's two lines instead of one, because

 -fdebug-prefix-map="e:\reactos-vanilla"=ReactOS

In normal source files rules, is in this PCH case:

-fdebug-prefix-map="e:
eactos-vanilla"=ReactOS

Meaning the \r wasn't escaped properly and led to a new line.

nanoant commented 9 years ago

Seems like some CMake bug (or fancy behavior), anyways applied a fix at 596f28e6e27ebe5c3eb1c9e50f90a905abbca9f1

AmineKhaldi commented 9 years ago

Now:

FAILED: E:\RosBE\i386\bin\g++.exe   -DDBG=1 -DKDBG=1 -DUSE_COMPILER_EXCEPTIONS -DWINVER=0x502 -D_DLL -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__USE_CRTIMP -D__i386__ -D_inline=__inline -Di386 -Dnetshell_EXPORTS -pipe -fms-extensions -fno-strict-aliasing -mstackrealign -fno-rtti -fno-exceptions -fdebug-prefix-map="e:\reactos-vanilla"=ReactOS -gdwarf-2 -gstrict-dwarf -femit-struct-debug-detailed=none -feliminate-unused-debug-symbols -march=pentium -mtune=i686 -Werror -Wall -Wpointer-arith -Wno-char-subscripts -Wno-multichar -Wno-unused-value -Wno-maybe-uninitialized -Wno-error=unused-but-set-variable -Wno-error=type-limits -O1 -fno-optimize-sibling-calls -fno-omit-frame-pointer -mpreferred-stack-boundary=3 -fno-set-stack-executable -Winvalid-pch -Werror=invalid-pch -std=c++11 -g -Idll/shellext/netshell -Ie:/reactos-vanilla/dll/shellext/netshell -Ie:/reactos-vanilla/include -Ie:/reactos-vanilla/include/psdk -Ie:/reactos-vanilla/include/dxsdk -Iinclude -Iinclude/psdk -Iinclude/dxsdk -Iinclude/reactos -Ie:/reactos-vanilla/include/crt -Ie:/reactos-vanilla/include/ddk -Ie:/reactos-vanilla/include/ndk -Ie:/reactos-vanilla/include/reactos -Ie:/reactos-vanilla/include/reactos/libs    -include E:/testing_new_pch/reactos/dll/shellext/netshell/CMakeFiles/netshell.pch.dir/precomp.h -MMD -MT dll/shellext/netshell/CMakeFiles/netshell.dir/netshell.cpp.obj -MF dll/shellext/netshell/CMakeFiles/netshell.dir/netshell.cpp.obj.d -o dll/shellext/netshell/CMakeFiles/netshell.dir/netshell.cpp.obj -c e:/reactos-vanilla/dll/shellext/netshell/netshell.cpp
cc1plus.exe: error: E:/testing_new_pch/reactos/dll/shellext/netshell/CMakeFiles/netshell.pch.dir/precomp.h.gch: not used because `_DLL' is defined [-Werror=invalid-pch]

cc1plus.exe: error: one or more PCH files were found, but they were invalid

cc1plus.exe: fatal error: E:/testing_new_pch/reactos/dll/shellext/netshell/CMakeFiles/netshell.pch.dir/precomp.h: No such file or directory

cc1plus.exe: all warnings being treated as errors

compilation terminated.

ninja: build stopped: subcommand failed.

It seems like you're missing the addition of target COMPILE_DEFINITIONS property? because that's where we add _DLL and __USE_CRTIMP in some specific cases.

nanoant commented 9 years ago

Well, I know the reason of this one. PCH is simply in different target suffixed with .pch and it does not inherit COMPILE_DEFINITIONS property from its originating main target.

I cannot either put pch in the main target, since then it will try to link damn pch file, and there is no way to prevent that.

So I need to think of it more. Maybe tomorrow I find some solution.

AmineKhaldi commented 9 years ago

Hmm, can't you simply use the target name that we input to target_precompiled_header() in order to get this property from this target, and apply it to the pch target?

This target idea btw means in ReactOS for example there will be extra 900+ targets. Is there a better way? The current PCH solution (from Peter) doesn't involve any additional targets, only two properties added to CMake (code).

nanoant commented 9 years ago

Okay I think I managed to solve it with 9f3102e5924449d14231b4463262459c9a10d0f6

Let me know how it works for you now.

Hmm, can't you simply use the target name that we input to target_precompiled_header() in order to get this property from this target, and apply it to the pch target?

See: https://github.com/nanoant/CMakePCHCompiler#how-does-it-work

AmineKhaldi commented 9 years ago

Now:

CMake Error at cmake/CMakePCHCompiler.cmake:224 (set_target_properties):
  set_target_properties called with incorrect number of arguments.
Call Stack (most recent call first):
  Some weird path:9999 (__watch_pch_last_hook)
nanoant commented 9 years ago

Wrrr.... okay I made little mistake in property checking. Fixed in 8df5ad56a87401ddf26d6f688be2511eaae86877. Please try again.

AmineKhaldi commented 9 years ago

Tons and tons of

CMake Warning (dev) at cmake/CMakePCHCompiler.cmake:217 (get_target_property):
  Policy CMP0045 is not set: Error on non-existent target in
  get_target_property.  Run "cmake --help-policy CMP0045" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  get_target_property() called with non-existent target "NOTFOUND".
Call Stack (most recent call first):
  Some weird path:9999 (__watch_pch_last_hook)
This warning is for project developers.  Use -Wno-dev to suppress it.
nanoant commented 9 years ago

Can you tell me which CMake version you are using?

AmineKhaldi commented 9 years ago

cmake version 3.1

nanoant commented 9 years ago

Okie, this seems like you fault as you are passing "NOTFOUND" target as parameter. I have added check a7ec70e94d0be5d9d9e5d0bebae6dcae13d61745 that should make cmake fail with more reasonable message.

AmineKhaldi commented 9 years ago

I'm doing: target_precompiled_header(netshell precomp.h) What NOTFOUND ?

Also the issue persists with the latest revision.

nanoant commented 9 years ago

I am sorry, you are right, I was running last step hook unconditionally, now fixed with 3329f661c2c8b822c67fcac969847e7d49fc2008

Please re-test.

AmineKhaldi commented 9 years ago

The line became cmake/CMakePCHCompiler.cmake:228

paul-michalik commented 8 years ago

I also ran into the same problem. Why is this issue marked as fixed?

m-7761 commented 7 years ago

Here is a fix for this problem in my case: https://github.com/nanoant/CMakePCHCompiler/pull/11