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.

I'm using CMake 3.13.4 on GNU/Linux with GCC C++ and Makefile
generators (we also will have support for MSVC but I'm not worried
about that here).

I have a function to deal with PCH generation:

  function(add_precompiled_header _target _header)
    ...
      # This is the actual command that does the precompiling
      add_custom_command(
          OUTPUT "${_pch_file}"
          COMMAND "${CMAKE_COMMAND}" -E make_directory "${_pch_dir}"
          COMMAND "${CMAKE_CXX_COMPILER}" "${_flags}" -x c++-header -o
"${_pch_file}" "${_header}"
          COMMAND_EXPAND_LISTS
          IMPLICIT_DEPENDS CXX "${_header}"
          COMMENT "Precompiling ${_header} for ${_target} (C++)")
    ...
      get_property(_sources TARGET ${_target} PROPERTY SOURCES)
      foreach(_source ${_sources})
    ...
          set_property(SOURCE ${_source} APPEND PROPERTY
              OBJECT_DEPENDS "${_pch_file}")
    ...
      endforeach()

Obviously there're a lot of other things here I'm leaving out, but
basically there's a custom command that compiles the header into a PCH
and lists the header as an IMPLICIT_DEPENDS, and adds that PCH as an
OBJECT_DEPENDS to the source files.

When I change the PCH file, the source files are rebuilt so that works.

If I change the header the PCH file is rebuilt so that works too.

But if I change a header file that the PCH includes, the PCH is NOT
rebuilt.  Not only that but if I use "make -d" I can see that the PCH
target never even considers any of the included files when determining
out-of-date-ness of the PCH file.

It seems like IMPLICIT_DEPENDS is behaving identically to DEPENDS here:
only listing the header as a dependency but not trying to determine
what it, itself, depends on.

What am I doing wrong?  Is there some subtlety to IMPLICIT_DEPENDS that
I'm missing?

-- 

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

Reply via email to