[CMake] Prefix header for Makefiles

Andrew Shaitorov andrew.shaitorov at gmail.com
Wed Aug 26 05:48:58 EDT 2015


Hi All!

I have a very annoying problem with CMake Makefiles generator.

I'm using prefix header (see attached archive for minimized test).

There is one source file named Main.cpp and two header files: Prefix.h and
DependHeader.h. Prefix.h includes DependHeader.h and Main.cpp includes
Prefix.h by using prefix header compiler flag (-include for GCC/Clang and
/FI for MSVC):

set_source_files_properties(Main.cpp PROPERTIES
COMPILE_FLAGS "-include Prefix.h"
OBJECT_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/Prefix.h)

When I change Prefix.h, then make recompiles Main.cpp as needed. But when I
make a change in DependHeader.h, then no recompilation happens. Its clear
for me that I have to specify all depend files in OBJECT_DEPENDS option,
but in real project there may be a lot of depend files with nested
includes. And the most annoying thing is that the project compiles without
any errors and may just crash because of struct layout or other critical
changes in depend headers.

I seems like the following script have the same problem when using
FORCE_INCLUDE option:

https://github.com/larsch/cmake-precompiled-header/blob/master/PrecompiledHeader.cmake

I looked in CMake source code and didn't find a way to add Prefix.h in a
list for dependency scanning. Also I don't know how to run depend scanner
on Prefix.h in CMake script to generate a list of all depend files for
OBJECT_DEPENDS option.

Any advise?

Best,
Andrew.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150826/cae9d27e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CMakePrefixHeaderTest.zip
Type: application/zip
Size: 1028 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150826/cae9d27e/attachment.zip>


More information about the CMake mailing list