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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.