cmake: struggling with add_custom_command dependencies

后端 未结 4 1016
面向向阳花
面向向阳花 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:43

    I don't think add_custom_target will work for what I want. According to the cmake documents, a custom target created by add_custom_target is always considered out of date and is always built.

    The problem is that I am trying to take the output from one add_custom_command, and feed it into the input of another add_custom_command in a different directory. I only want this to happen if the original source file is out of date - if I used add_custom_target, then the output would always be rebuilt even if the source file had not changed. Given that there are hundreds of these source files, this would make the build very slow.

    Here's what I am trying to do: I have a program which generates a .bc file (LLVM bitcode) given a source file. There are a lot of these source files, which create a lot of .bc files.

    A second program transforms all of the the .bc files into a single .obj (ELF object) file. So the transformation steps look like this:

       source file -> .bc     (via add_custom_command)
       .bc         -> .obj    (via add_custom_command)
       .obj        -> .exe    (via add_executable)
    

    The original source code files are in different directories because they are libraries of classes - I don't want to have to put all the code for every class library in the same directory.

提交回复
热议问题