Ninja equivalent of Make's “build from this directory down” feature (with CMake)?

前端 未结 3 2259
小蘑菇
小蘑菇 2021-02-15 14:12

When building a project using CMake and Make, you can execute make from a subdirectory of your build tree (i.e. from a directory below whatever directory contains y

3条回答
  •  梦谈多话
    2021-02-15 14:52

    Good question. I would like to know the answer if you find it. I am just in the process of transitioning to cmake+ninja myself.

    I found that I could not create targets with the same name at different levels (if there is a way I would be interested to know). So I adopted a naming convention for different targets E.g. name - builds program or library test.name - runs tests for the named program or library doxygen.name - build doxygen for the named program or library

    For deeper hierarchies you can do something like: doxygen.subproject doxygen.subproject.name

    Using this pattern you can control precisely what is built but you have to issue the command from the top-level build directory. I think after I get used to this I will find it more productive as there is no need to change directory before you build or run something and though there is sometimes a little extra typing required the shell history generally has it covered.

    This is implemented under the hood by using add_custom_target() and adding appropriate dependencies. I use a macro to do this automatically so that a macro "add_doxygen()" will add the doxygen target for the program and make the doxygen target at each higher level depend on it using add_dependencies().

提交回复
热议问题