DEPFILE usage in add_custom_command(...)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

DEPFILE usage in add_custom_command(...)

Attila Krasznahorkay
Dear All,

I'm trying to use the DEPFILE argument of add_custom_command(...) to be able to tell Ninja exactly when it should re-run that custom command. But unfortunately I'm not able to get it to work as I'd like. :-(

I'm running a custom command that processes a header file through a custom executable. (It's a long story, see https://gitlab.kitware.com/cmake/cmake/issues/18695 and https://gitlab.kitware.com/cmake/cmake/issues/16830 for some more details.) I run that custom executable using a script file that I generate during the CMake configuration. In that script file I generate a dependency file using:

   set( cmd "${cmd}${CMAKE_CXX_COMPILER} -I\"$<JOIN:${incdirs},\" -I\">\"" )
   set( cmd "${cmd} -D$<JOIN:${definitions}, -D>" )
   if( CMAKE_OSX_SYSROOT )
      set( cmd "${cmd} -isysroot ${CMAKE_OSX_SYSROOT}" )
   endif()
   set( cmd "${cmd} -MM -MT ${rootmap_name} -MF ${dictname}.d ${ARG_HEADER}\n" )

This then results in a file like:

/Users/krasznaa/ATLAS/sw/projects/volatile/externals/build_test/DictionaryPackage/CMakeFiles/DictionaryPackageDict.dsomap: \
  /Users/krasznaa/ATLAS/sw/projects/volatile/externals/build_test/DictionaryPackage/CMakeFiles/DictionaryPackageDict.h \
  /Users/krasznaa/ATLAS/sw/projects/volatile/externals/CMakeDictionaryTests/DictionaryPackage/DictionaryPackage/MyClass.h \
  /Users/krasznaa/ATLAS/sw/projects/volatile/externals/CMakeDictionaryTests/DictionaryPackage/DictionaryPackage/HelperHeader.h \
  /Users/krasznaa/ATLAS/sw/projects/volatile/externals/CMakeDictionaryTests/DictionaryPackage/DictionaryPackage/MyOtherClass.h \
  /Users/krasznaa/ATLAS/sw/projects/volatile/externals/CMakeDictionaryTests/AthLinks/AthLinks/DataLink.h \
  /Users/krasznaa/ATLAS/sw/projects/volatile/externals/CMakeDictionaryTests/AthLinks/AthLinks/ElementLink.h \
  /Users/krasznaa/ATLAS/sw/projects/volatile/externals/CMakeDictionaryTests/AthLinks/AthLinks/ElementLinkVector.h \
  /Users/krasznaa/ATLAS/sw/projects/volatile/externals/CMakeDictionaryTests/AthContainers/AthContainers/tools/AuxTypeVectorFactory.h

Which looks correct to me. The generated Ninja file refers to this dependency file with:

#############################################
# Custom command for DictionaryPackage/CMakeFiles/DictionaryPackageDict.dsomap

build DictionaryPackage/CMakeFiles/DictionaryPackageDict.dsomap DictionaryPackage/CMakeFiles/DictionaryPackageDictReflexDict.cxx x86_64-mac1014-clang100-opt/lib/libDictionaryPackageDict_rdict.pcm: CUSTOM_COMMAND DictionaryPackage/CMakeFiles/DictionaryPackageDict.h /Users/krasznaa/ATLAS/sw/projects/volatile/externals/CMakeDictionaryTests/DictionaryPackage/DictionaryPackage/DictionaryPackageDict.h DictionaryPackage/CMakeFiles/selection.xml DictionaryPackage/CMakeFiles/DictionaryPackageDict.h /Users/krasznaa/ATLAS/sw/projects/volatile/externals/CMakeDictionaryTests/DictionaryPackage/DictionaryPackage/DictionaryPackageDict.h
  COMMAND = cd /Users/krasznaa/ATLAS/sw/projects/volatile/externals/build_test/DictionaryPackage/CMakeFiles && /Users/krasznaa/Software/CMake/3.11.4/bin/cmake -E make_directory /Users/krasznaa/ATLAS/sw/projects/volatile/externals/build_test/x86_64-mac1014-clang100-opt/lib && sh /Users/krasznaa/ATLAS/sw/projects/volatile/externals/build_test/DictionaryPackage/CMakeFiles/makeDictionaryPackageDictReflexDict.sh
  DESC = Generating DictionaryPackageDictReflexDict.cxx
  depfile = /Users/krasznaa/ATLAS/sw/projects/volatile/externals/build_test/DictionaryPackage/CMakeFiles/DictionaryPackageDictReflexDict.d
  restat = 1

Which again, looks correct to me. But... This setup results in Ninja *always* re-running this command on every re-build. Even when I didn't modify any of the files referenced in that dependency file. :-(

Does anyone have an idea what I'm doing wrong? Unfortunately I didn't manage to find examples of using DEPFILE that would've helped me further than this... Any help would be very much appreciated.

Cheers,
         Attila

--

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 | Threaded
Open this post in threaded view
|

Re: DEPFILE usage in add_custom_command(...)

Ed Branch

The target name in the depfile does not match the target name on the
ninja build line due to absolute vs relative path mismatch. Even though
they refer to the same file, the target names must match exactly.
--

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