How do I correctly create dependencies between targets in CMake?

后端 未结 2 1898
旧巷少年郎
旧巷少年郎 2020-12-13 18:06

I am trying to use CMake to set up some simple dependencies between a C++ project and the libraries that it uses.

The set up is as follows

  • Project
2条回答
  •  独厮守ぢ
    2020-12-13 18:51

    It is not exactly clear what you want to do, and why Project and Dependency have to be build separately.

    My first though on your example would be

    1. In PROJECT's CMakeLists.txt:

      • Remove add_dependencies(Project Dependency) There is no need to specify dependency, target_link_libraries() already does that.
    2. In DEPENDENCY's CMakeLists.txt:

      • Remove project(Dependency) It builds a library, so why to have own project?
      • Remove target_link_libraries(Dependency) Because it does nothing

提交回复
热议问题