cmake: struggling with add_custom_command dependencies

后端 未结 4 1020
面向向阳花
面向向阳花 2021-02-12 23:06

I\'m trying to get a file produced by an add_custom_command in one directory to be a dependency of an add_custom_command in another directory.

In the first directory (li

4条回答
  •  你的背包
    2021-02-12 23:25

    The cmake documentation says the following about the DEPENDS parameter:

    The DEPENDS option specifies files on which the command depends. If any dependency is an OUTPUT of another custom command in the same directory (CMakeLists.txt file) CMake automatically brings the other custom command into the target in which this command is built. If DEPENDS specifies any target (created by an ADD_* command) a target-level dependency is created to make sure the target is built before any target using this custom command.

    Therefore I think you will have to define a target using add_custom_target and depend on this.

    The documentation for add_custom_target says:

    Dependencies listed with the DEPENDS argument may reference files and outputs of custom commands created with add_custom_command() in the same directory (CMakeLists.txt file).

    So you will have to use add_custom_command and add_custom_target as follows:

    1. In the first directory generating the bc file you do

      add_custom_command(OUTPUT libcore.bc ... ) # just as in your question add_custom_target (LibCoreBC DEPENDS libcore.bc)

    2. In the second directory you do

      add_custom_command (OUT ${OBJ_FILE} DEPENDS LibCoreBC ....)

提交回复
热议问题