I am working on a project with many .cpp
files on vs2013
, and using a precompiled header for them. I am using CMake to build my project.
But I have one .c
file (let's call it xyz.c
) for which I want to disable precompiled header.
I tried several methods, but if I enable precompiled headers to all .cpp
file, it automatically turns on for the .c
file as well. This is what I tried:
set_source_files_properties (xyz.c
PROPERTIES COMPILE_FLAGS /Y-xyz.c )
Assuming that /Yu
is on for all files, I just try to turn off this option for xyz.c
.
If any one knows any method, please let me know.
To turn off precompiled headersSelect the Configuration properties > C/C++ > Precompiled Headers property page. In the property list, select the drop-down for the Precompiled Header property, and then choose Not Using Precompiled Headers. Choose OK to save your changes.
Precompiled headers were invented for one purpose: to make compiling faster. Rather than parsing the same header files over and over, these files get parsed once, ahead of time. Speed is important! The faster you compile, the faster you can complete the feedback loop to see if recent changes were successful.
Usage of precompiled headers may significantly reduce compilation time, especially when applied to large header files, header files that include many other header files, or header files that are included in many translation units.
The precompiled header is compiled only when it, or any files it includes, are modified. If you only make changes in your project source code, the build will skip compilation for the precompiled header. The compiler options for precompiled headers are /Y .
Starting from cmake 3.16 setting /Y-
compiler option will not work. Correct way to disable precompiled headers for individual file is like this:
set_source_files_properties(non-pch.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
Documentation: https://cmake.org/cmake/help/v3.16/prop_sf/SKIP_PRECOMPILE_HEADERS.html
(Not so useful anyway)
/Y-
doesn't take arguments. Try:
set_source_files_properties(xyz.c
PROPERTIES COMPILE_FLAGS /Y-)
Alternatively, instead of using /Yu
on all files and disable it only for your .c
file, you can use the opposite approach and only use /Yu
for the .cpp
files. Given your .cpp
files are listed in a variable SOURCES
and my_pch.h
is your precompiled header:
set_source_files_properties(${SOURCES}
PROPERTIES COMPILE_FLAGS /Yumy_pch.h)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With