How to stop CMake force include precompiled headers

35 Views Asked by At

I am working on a c++ project using CMake (g++ linux, Manjaro KDE to be specific). I have a precompiled header file called cupch.h which I setup like:

target_precompile_headers(Copper-Engine PRIVATE ${PROJECT_SOURCE_DIR}/Copper-Engine/src/cupch.h)

However this add these compiler flags:

-Winvalid-pch -include /home/jakub/programming/Copper-Engine/CMake/Debug/Copper-Engine/CMakeFiles/Copper-Engine.dir/cmake_pch.hxx

Which for whatever reason seem to be causing massive issues. I don't know why but my project won't compile a UUID library that is using SIMD instructions when these flags are present, I am getting errors from inside the SIMD implementation for my OS (files like avxintrin.h, smmintrin.h, etc). The moment I remove adding cupch.h as a precompiled header to cmake, these flags are gone, and suddenly my project compiles okay.

Upon further digging I found out that the culprit is the -include flag specifically, that to my knowledge only force includes the precompiled header so that my source files don't have to #include "cupch.h" at the top. However I am already doing that as I need to do it for MSVC (I am building this project on Linux but I want it to be buildable on Windows and VS as well).

How can I get rid of the -include flag but keep the precompiled header? I have tried searching online but only found ways how to disable precompiled headers on certain files, but I still want to use the precompiled header in (almost) all my files, just get rid of the -include flag and manually #include "cupch.h" in every .cpp file.

0

There are 0 best solutions below