How do I correctly create dependencies between targets in CMake?

后端 未结 2 1905
旧巷少年郎
旧巷少年郎 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 19:02

    Since CMake 2.8.11 you can use target_include_directories. Just simply add in your DEPENDENCY project this function and fill in include directories you want to see in the main project. CMake will care the rest.

    PROJECT, CMakeLists.txt:

    cmake_minimum_required (VERSION 2.8.11)
    project (Project)
    include_directories (Project)
    add_subdirectory (Dependency)
    add_executable (Project main.cpp)
    target_link_libraries (Project Dependency)
    

    DEPENDENCY, CMakeLists.txt

    project (Dependency)
    add_library (Dependency SomethingToCompile.cpp)
    target_include_directories (Dependency PUBLIC include)
    

提交回复
热议问题