View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000944CMakepublic2004-06-22 10:212006-08-29 09:11
ReporterBradley Lowekamp 
Assigned ToBrad King 
PrioritylowSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000944: Incorrect dependencies for generated header files
DescriptionOriginal CMake Mailing list post:

I am needed to use a script to generate some source and header files in my project. I was able to get the generation of the source code to work well and all of the dependencies to be correct with the SET_SOURCE_FILES_PROPERTIES and the GENERATED option.
    However with generated header files I can not seem to get the dependencies to work correctly. The SET_SOURCE_FILES_PROPERTIES with the GENERATED option appears to have no affect. When CMake tries to make the dependencies for the source files, the header files do not exist and so they are not implicitly added as dependent for anything, so they will not get generated. I had to resort to adding them as a dependency to all source files, which results in an unacceptable amount of building needing to be done when any generated header file is modified, but it does work. (I have what I am doing at the end of this e-mail.) So how can I get the dependencies to work correctly for the header files?
    I just had a thought as I was righting up this e-mail. If I could add a dependency to the make_depends or what ever target it is, I could some how make the make depends target dependent on the generated header files or something? Any suggestions about how to get this to work would be good and very much appreciated I am actually not sure what versions of CMake I have tried these things with.

Thanks!
Brad


And this was also happening with recent 1.9+, 2.0 version of CMake.

I have here a basic CMakeLists.txt file what would produce the problem if, gen.h.in exists, and main.c includes gen.h and has a basic main function. It should also be noted that marking gen.h as GENERATED doesn't seem to actually do anything.

ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/gen.h
  COMMAND ${CMAKE_COMMAND}
  ARGS copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/gen.h.in ${CMAKE_CU
RRENT_BINARY_DIR}/gen.h
  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gen.h.in
  )

SET_SOURCE_FILES_PROPERTIES(
  ${CMAKE_CURRENT_BINARY_DIR}/gen.h
  PROPERTIES GENERATED 1)

ADD_EXECUTABLE(test main.c)
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0001209)
Bill Hoffman (manager)
2004-06-22 10:41

The following seems to do what you want:
(The trick is to use the OBJECT_DEPENDS
property on main.c) I tested this on cmake 2.0.2.


ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/gen.h
  COMMAND ${CMAKE_COMMAND}
  ARGS -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/gen.h.in ${CMAKE_CURRENT_BINARY_DIR}/gen.h
  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gen.h.in
  )

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})

SET_SOURCE_FILES_PROPERTIES(
  ${CMAKE_CURRENT_BINARY_DIR}/gen.h
  PROPERTIES GENERATED 1)

SET_SOURCE_FILES_PROPERTIES(main.c OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/gen.h)

ADD_EXECUTABLE(test main.c)
(0001210)
Bill Hoffman (manager)
2004-06-22 10:49

I just checked your original post, and see that the OBJECT_DEPEND was not what you wanted. I guess what you want is the make depend part of cmake to realize that there is a generated file involved, and add the depend information from the include. I guess we could make a virtual file that the cmake depend step would find and add to the depend. So if a file includes a generated file, cmake depend would find it. The change would be in here:

 cmMakeDepend::FullPath(const char* fname, const char *extraPath)

It would some how have to get at all the generated files, and check them as well as the disk.

-Bill

(0002638)
Bill Hoffman (manager)
2005-07-13 09:14

Brad is this fixed by the new generator?
(0002640)
Brad King (manager)
2005-07-13 09:22

This has not been fixed. It is a very hard problem. Somehow the dependency scanner (which no longer runs with knowledge of the list files) would need to know about all the generated headers that will exist but may not yet. Then it would have to add this dependency to the object file. When the object file is built make will first see the dependency on the header file and run the rule to generate it.

After the first build finishes, we would have to make sure that the next build causes dependencies to be scanned again for the object file to add any dependencies pulled in through the generated header (that may include other headers). The new dependencies would have to be written in a way that does not cause the object file to be rebuilt if nothing changed.
(0004761)
Alex Neundorf (developer)
2006-08-27 10:34

Can this be closed with cmake 2.4.3 ?
Deps of generated files are handled now by adding them to the list of source files for the target.
(0004787)
Brad King (manager)
2006-08-29 09:11

Yes, you are correct. By listing the output of the custom command as a source file in the target that needs it the generated build system will automatically pick up the dependency. Further, the output will be generated whether or not any source actually includes the header.

 Issue History
Date Modified Username Field Change


Copyright © 2000 - 2018 MantisBT Team