CMake add_custom_command/_target in different directories for cross-compilation

后端 未结 2 1560
礼貌的吻别
礼貌的吻别 2020-12-16 23:20

In CMake, I\'m trying to build a project that includes libraries for multiple different processor architectures, compiled by different toolchains. For each architecture, st

相关标签:
2条回答
  • 2020-12-16 23:50

    Spot On!

    add_dependencies allowed me to create the final dependency 'link' between add_custom_target created targets, and add_custom_target generates the targets needed to get add_custom_command to create real content in the makefile, i.e., My add_custom_command wouldn't generate output to the makefiles unless the OUTPUT's from the add_custom_command were specified as dependencies in the add_custom_target command.

    Then to get the add_custom_command's to execute in the correct order, I had to use the target names defined in the add_custom_target's as dependencies in the add_dependencies. NOTE: The OUTPUT's specified in the add_custom_command and add_custom_target commands had to be specified in separate quoted paths, i.e.:

    add_custom_command(OUTPUT "out1 out2 out3" ...)  # WRONG!
    add_custom_target(CUSTOMTARG1 "out1 out2 out3")  # WRONG!
    
    add_custom_command(OUTPUT "out1" "out2" "out3" ...)  # RIGHT!
    add_custom_target(CUSTOMTARG1 "out1" "out2" "out3")  # RIGHT!
    

    If I didn't have them in separate quoted paths, the makefile built the outputs every time regardless of whether they existed or not!

    0 讨论(0)
  • 2020-12-16 23:58

    I presume you need to use add_dependencies to define dependencies between targets defined using add_custom_target. The DEPENDS option is used to specify file-level dependencies in custom rules but not target-level dependencies.

    For example, command generating .obj file as output uses DEPENDS to specify it depends on .cpp file. Also, a target can be dependant on a single file, not only on other targets. So, for file-level dependendies, use DEPENDS option, but add_dependencies for target-level.

    0 讨论(0)
提交回复
热议问题