Stamp file generated during CMake configuration not detected by Ninja generator
Dear All,
I'm trying to understand a pretty involved issue in our configuration. One which I was able to reproduce with a simplified project momentarily yesterday, but then couldn't reproduce it any more. But let me elaborate...
During the build of the ATLAS offline software we build "converter libraries" out of source code that gets generated during the CMake configuration/build. ("Converters" for C++ classes that we wrote explicitly by hand.) As you can imagine, the generation of the source files is done through a combination of add_custom_command
and add_custom_target
calls.
Recently we discovered that certain operations can break our incremental CI builds. Namely, when a class, for which previously a converter was generated, is removed from the repository. In this case CMake re-generates the dependency rules for the source files of the converter, but since all that changed was that the source files now depend on fewer header files, during the build the converter sources are not re-generated. And we end up with a compilation error, as the previously generated source file is now looking for a header that's no longer available.
To work around this, I had to introduce some manual logic into our CMake configuration that generates a "stamp file" during the CMake configuration using file(WRITE ...)
, and makes the generation of the converter sources depend on this stamp file. So that we could force re-generating those sources when necessary.
You can find all of this code here:
- https://gitlab.cern.ch/atlas/atlasexternals/blob/master/Build/AtlasCMake/modules/AtlasLibraryFunctions.cmake#L542-575
- https://gitlab.cern.ch/atlas/atlasexternals/blob/master/Build/AtlasCMake/modules/AtlasLibraryFunctions.cmake#L674-692
- Plus a few more instances where
${_stampFile}
is referenced by that same function.
Now, when we generate the build configuration for Ninja, we get warnings like:
-- Generating done
CMake Warning (dev):
Policy CMP0058 is not set: Ninja requires custom command byproducts to be
explicit. Run "cmake --help-policy CMP0058" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
This project specifies custom command DEPENDS on files in the build tree
that are not specified as the OUTPUT or BYPRODUCTS of any
add_custom_command or add_custom_target:
Control/DataModelAthenaPool/CMakeFiles/DataModelAthenaPoolPoolCnv.stamp.txt
Database/IOVDbAthenaPool/CMakeFiles/IOVDbAthenaPoolPoolCnv.stamp.txt
Database/PersistentDataModelAthenaPool/CMakeFiles/PersistentDataModelAthenaPoolPoolCnv.stamp.txt
Event/EventAthenaPool/CMakeFiles/EventAthenaPoolPoolCnv.stamp.txt
Event/xAOD/xAODAssociationsAthenaPool/CMakeFiles/xAODAssociationsAthenaPoolPoolCnv.stamp.txt
Event/xAOD/xAODBTaggingAthenaPool/CMakeFiles/xAODBTaggingAthenaPoolPoolCnv.stamp.txt
Event/xAOD/xAODCaloEventAthenaPool/CMakeFiles/xAODCaloEventAthenaPoolPoolCnv.stamp.txt
Event/xAOD/xAODCaloRingsAthenaPool/CMakeFiles/xAODCaloRingsAthenaPoolPoolCnv.stamp.txt
Event/xAOD/xAODCoreAthenaPool/CMakeFiles/xAODCoreAthenaPoolPoolCnv.stamp.txt
Event/xAOD/xAODCutFlowAthenaPool/CMakeFiles/xAODCutFlowAthenaPoolPoolCnv.stamp.txt
For compatibility with versions of CMake that did not have the BYPRODUCTS
option, CMake is generating phony rules for such files to convince 'ninja'
to build.
Project authors should add the missing BYPRODUCTS or OUTPUT options to the
custom commands that produce these files.
This warning is for project developers. Use -Wno-dev to suppress it.
-- Build files have been written to: /home/krasznaa/projects/ninja/build
When looking for the files in question, right after I get back the prompt, they are all in the place pointed at by these printouts. (In the build/binary directory.)
As I started, I tried to produce a simple, standalone reproducer for this issue. And at first it seemed like I succeeded. I was getting the same sort of warning from an educational example on macOS. But after a few attempts the warning went away... Which makes me very suspicious whether this whole thing is due to cmake
not recognising some filesystem updates quickly enough. In some cases...
Any hints at how I could solve this, without touching CMP0058
, would be very helpful. (I don't want to turn off the warnings about non-declared byproducts globally.)
Cheers, Attila