[CMake] Cmake Dependency Generation with Compiler Specific Plugins

Russell Harmon rharmon at apple.com
Tue Jul 27 18:48:16 EDT 2010


We're looking to use cmake on a project which has some dependencies which are not properly picked up by cmake's dependency scanner. I'm not looking to fix the scanner, because I feel the scanner is fundamentally broken:

In order to properly scan a file for dependencies, you need to either use the compiler specific dependency scanner [1][2], or implement a fully featured c preprocessor. You can't do a partial job like the current dependency scanner does. I'd encourage you to read "Recursive Make Considered Harmful" [3] which discusses the importance of creating correct dependency graphs (with neither missing, nor erroneous dependencies). I'll provide a few examples of where cmake's method is lacking:

1. #define ARCH x86
   #define ASM_INCLUDE <ARCH/asm.h>
   #include ASM_INCLUDE
   cmake adds a dependency on ASM_INCLUDE instead of x86/asm.h

2. #ifdef DEBUG
   #include <debug_config.h>
   #else
   #include <config.h>
   #endif
   cmake adds a dependency on both debug_config.h and config.h
   In a worst-case scenario here (one which our project has), this could generate circular dependencies which cause the build to fail.

3. #if 0
   #include <nonexistantfile.h>
   #endif
   cmake adds a dependency on nonexistantfile.h when it shouldn't have

My suggestion for a solution to this problem is to use the compiler specific dependency generation methods. This could be done cleanly by converting dependency generation into a plugin based system with plugins for all the supported compilers.

I would have (tried to) made these changes to cmake already, but since this is both a non-trivial change and an architectural change, I felt it necessary to get an ok from you before I changed anything. I'm not really willing to do the work if it won't be accepted upstream (and I'm not willing to use cmake if this doesn't get fixed).

Thanks for your time
Russell Harmon

[1] http://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Preprocessor-Options.html#index-dependencies_002c-make-867
[2] http://msdn.microsoft.com/en-us/library/hdkef6tk.aspx
[3] http://aegis.sourceforge.net/auug97.pdf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100727/0ffdd3be/attachment-0001.htm>


More information about the CMake mailing list