I have a series of boilerplate cpp files that are created using configure_file. The files created are in my build directory, get built and included into my library. However, I noticed that in the depend.make file that the only dependency for the boilerplate .o file was its .cpp file. There were no other dependencies. These boilerplate files include several headers file which include many more.
Before when the boilerplate files were part of the source the depend.make had the full dependencies. Though I searched, I am not savvy enough to know if I have missed something or if there is a bug. I will wager the former.
Also, it is possible to add a dependency with the CMakeList.txt file so that if the implementation file changes all of the boilerplate files are recreated?
CMake gathers this information during the build. As a side effect of compiling (which must happen at least once to get the object file anyways), the set of included headers is generated (via something like
-MD) and then stored for the build system to use in the future. Then, if the source file itself or any of those included change, the object file will be remade.
Thanks for the reply Ben. That makes sense but I am not able to understand is why the dependencies did not get generated for the boilerplate files while they did for all the other cpp files. The only difference is that the boilerplate files were initially generated via CMake.
Previously the boilerplate files were part of the repo and the dependencies were generated.
I am unable to reproduce your problem. For me, regardless how the file is produced (source or generated with
configure_file()), dependencies are correctly generated.
Can you publish a snippet showing the issue?
Here is basic loop that I use to create all of my boilerplate cpp files.
SET(OPERATORS Boilerplate )
SET(SHAPES Seg Tri Quad )
foreach(OPERATOR IN LISTS OPERATORS)
foreach(SHAPE IN LISTS SHAPES)
# Create the cpp file from the implementation file.
# Add the respective header and cpp file.
Previously when these files were part of the normal source I did the following which worked fine:
Everything else in my CMakeLists.txt is the same. The only real different is that the .cpp files now reside on the “build” side rather than the “source” side (I do out of source builds).
the depend.make has the following:
However, the original depend.make has that and many many more including:
Similar for the other two, seg and quad. So there is only one dependency but there should be many more.
This does not help. As I said, I am not able to reproduce your problem. A complete usable
CMakeLists.txt must be provided.
By the way, what is your environment?
- OS type and version
- CMake version
Did you try with the latest version? For the most current compilers, dependencies are now directly computed by the compiler…
Thanks for looking at the issue. As you asked for a snippet, I thought the above would be enough details.
I am using cmake 3.19.5 built from source built on OS X 11.2 (XCode tools 12.4) using Apple clang version 12.0.0 (clang-122.214.171.124).
I just tried with cmake 3.22.3 and see substantial difference. 3.19 creates a single large depend.make for all dependencies. Whereas 3.22 there are smaller individual dependency files *.cpp.o.d. Looking at one of them they do have the full set of dependencies.
Nutshell, bug in 3.19, now fixed in 3.22