1

I have a CMake project. For some reason (that I won't say here, but which I can provide upon request), I need some object files that are part of the same library to be compiled before others. Specifically:

  • FILES is a list of source files
  • file_a.c is a member of FILES
  • file_d.c is a member of FILES
  • file_a.o MUST exist on disk before file_d.c is compiled

This is what I have now:

 set_source_files_properties(
   file_a.c
   PROPERTIES
   OBJECT_OUTPUTS file_a.o
   )

 set_source_files_properties(
   file_d.c
   PROPERTIES
   OBJECT_DEPENDS file_a.o
   )

This works well for Makefiles, but it doesn't appear to play nice with Ninja; I get a circular dependency error and complaints about multiple rules.

xaav
  • 7,876
  • 9
  • 30
  • 47

1 Answers1

2

Don't try to declare dependencies between object files. If there are files that have a dependency, break them out into a separate library with add_library and then declare the dependency with add_dependencies and target_link_libraries. There is no extra cost for doing this.

Particularly, consider looking at Object Libraries.

xaav
  • 7,876
  • 9
  • 30
  • 47