On Fri, 2019-04-26 at 17:26 -0400, Paul Smith wrote: > We're trying to implement precompiled headers (yes, I've seen all the > various github projects around this). As part of this we need to make > sure the precompiled header is rebuilt whenever any of the headers that > it includes changes: this seems like exactly the job for > add_custom_command's IMPLICIT_DEPENDS. > > But, it doesn't seem to be doing anything at all for me so I wonder > what I'm doing wrong.
OK, I figured out the issue. The problem is a combination of the way I was testing and a sort of bizarre "feature" of the CMake Makefile generator: The Makefile generator only generates prerequisite information when a CMake target is completely built. It doesn't generate the information when an individual object file is built. I was testing (to allow faster turnaround) by simply running: cmake ... make foo.cpp.o touch header.h make foo.cpp.o and the PCH file was not being rebuilt even though it included header.h. After MUCH tearing of hair and groping around in the generated makefiles, I realized that unless I built the full target and not just the individual object file, no prerequisite information was created. I had to run: cmake ... make footarget touch header.h make foo.cpp.o The first make would build foo.cpp.o and also generate all the prerequisite information as a side-effect of creating footarget. Then the second make would correctly update the PCH file in addition to rebuilding the object file. Note this is not related to PCH at all: you can reproduce this with the simplest of CMake configurations. That is definitely a subtlety of the makefile generator that was unexpected: maybe it will help someone else trying to do similar testing. -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake