CMake mailing list question

a guest Oct 3rd, 2012 35 Never
  1. Hi,
  3. I'm having issues with the way CMake scans for dependencies.  It's causing unpredictable rebuilds of my project which means I need to run 'make' multiple times (until nothing rebuilds) before I can 'sudo make install'.
  5. The project incorporates a code generator.  It parses all C++ header files and produces .h and .cpp files, which are then built into the main program.  The codegen and program both depend on a set of common utility files, which contain lines like this:
  7. #ifndef CODEGEN
  8.   #include "GeneratedFile.h"
  9. #endif
  11. From a compile standpoint, there is no problem -- the codegen is built with -DCODEGEN so it won't include the generated file, which of course wouldn't even exist on the first pass.  But since CMake doesn't preprocess headers, it creates a circular dependency situation, where the code generator "depends" on files which it generates.  This causes unnecessary rebuilds, since the code generator gets rebuilt after every time it regenerates files.
  13. I thought I could create a dummy "GeneratedFile.h" in the directory containing the codegen files, and put this into the CMakeLists.txt in that directory:
  14. include_directories(
  15.   BEFORE
  16.   ${PROJECT_SOURCE_DIR}/src/codegen
  17. )
  19. That seemed to work the first time -- if I looked at the codegen's depend.make file I saw lines like "SomeUtilityFile.cpp.o: ..../codegen/GeneratedFile.h" -- the dummy version of the file.
  21. The problem is that CMake seems to have a global dependency cache, so once SomeUtilityFile.cpp gets built for the program, the dependency globally changes to the real GeneratedFile.h.
  23. Any ideas to make this work, or other ways I can work around the problem?
  25. Thank you
  27. -dan
RAW Paste Data