<legend id='pb2eJ'><style id='pb2eJ'><dir id='pb2eJ'><q id='pb2eJ'></q></dir></style></legend>
      <i id='pb2eJ'><tr id='pb2eJ'><dt id='pb2eJ'><q id='pb2eJ'><span id='pb2eJ'><b id='pb2eJ'><form id='pb2eJ'><ins id='pb2eJ'></ins><ul id='pb2eJ'></ul><sub id='pb2eJ'></sub></form><legend id='pb2eJ'></legend><bdo id='pb2eJ'><pre id='pb2eJ'><center id='pb2eJ'></center></pre></bdo></b><th id='pb2eJ'></th></span></q></dt></tr></i><div id='pb2eJ'><tfoot id='pb2eJ'></tfoot><dl id='pb2eJ'><fieldset id='pb2eJ'></fieldset></dl></div>

    1. <tfoot id='pb2eJ'></tfoot>
        <bdo id='pb2eJ'></bdo><ul id='pb2eJ'></ul>

    2. <small id='pb2eJ'></small><noframes id='pb2eJ'>

    3. 如何在 CMake 中正确创建目标之间的依赖关系?

      How do I correctly create dependencies between targets in CMake?(如何在 CMake 中正确创建目标之间的依赖关系?)
          <tbody id='kCHhq'></tbody>

              <bdo id='kCHhq'></bdo><ul id='kCHhq'></ul>
              <legend id='kCHhq'><style id='kCHhq'><dir id='kCHhq'><q id='kCHhq'></q></dir></style></legend>
            • <small id='kCHhq'></small><noframes id='kCHhq'>

              1. <tfoot id='kCHhq'></tfoot>

                <i id='kCHhq'><tr id='kCHhq'><dt id='kCHhq'><q id='kCHhq'><span id='kCHhq'><b id='kCHhq'><form id='kCHhq'><ins id='kCHhq'></ins><ul id='kCHhq'></ul><sub id='kCHhq'></sub></form><legend id='kCHhq'></legend><bdo id='kCHhq'><pre id='kCHhq'><center id='kCHhq'></center></pre></bdo></b><th id='kCHhq'></th></span></q></dt></tr></i><div id='kCHhq'><tfoot id='kCHhq'></tfoot><dl id='kCHhq'><fieldset id='kCHhq'></fieldset></dl></div>
                本文介绍了如何在 CMake 中正确创建目标之间的依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试使用 CMake 在 C++ 项目与其使用的库之间设置一些简单的依赖关系.

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

                设置如下

                • 项目
                  • 依赖

                  项目本身包含的源文件包含来自 Dependency 的头文件,并且在构建可执行文件时,它需要链接到 Dependency 的静态库.

                  Project itself contains source files that include headers from Dependency and when the executable is built it needs to be linked against Dependency's static library.

                  到目前为止我可以让它工作,但我必须在ProjectCMakeLists.txt文件中指定Dependency的包含目录> 手动.我希望它被自动拉出,并且我已经探索了使用 find_package() 命令这样做的选项,但成功率有限,并使事情变得更加复杂.

                  So far I can get this to work, but I have to specify the include directories of Dependency in the CMakeLists.txt file for Project manually. I want this to be pulled out automatically, and I have explored the option of using the find_package() command to do so with limited success and making things much more complicated.

                  我想要做的就是在 Project 之前构建 Dependency 并具有针对库的 Project 链接及其包含目录.有没有简单简洁的方法来实现这一点?

                  All I want to do is have Dependency built before Project and have Project link against the library and have its include directories. Is there a simple concise way of achieving this?

                  我当前的 CMake 文件:

                  My current CMake files:

                  项目,文件CMakeLists.txt:

                  cmake_minimum_required (VERSION 2.6)
                  project (Project)
                  include_directories ("${PROJECT_SOURCE_DIR}/Project")
                  add_subdirectory (Dependency)
                  add_executable (Project main.cpp)
                  target_link_libraries (Project Dependency)
                  add_dependencies(Project Dependency)
                  

                  依赖,文件CMakeLists.txt:

                  project(Dependency)
                  add_library(Dependency SomethingToCompile.cpp)
                  target_link_libraries(Dependency)
                  

                  推荐答案

                  CMake 2.8.11 开始,您可以使用 target_include_directories.只需在您的 DEPENDENCY 项目中添加此功能并填写您希望在主项目中看到的包含目录即可.CMake 会关心其余的.

                  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.

                  项目,CMakeLists.txt:

                  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)
                  

                  依赖,CMakeLists.txt

                  DEPENDENCY, CMakeLists.txt

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

                  这篇关于如何在 CMake 中正确创建目标之间的依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                Delay Loading DLLs(延迟加载 DLL)
                Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                Loading a dll from a dll?(从 dll 加载 dll?)
              2. <small id='Ofsuh'></small><noframes id='Ofsuh'>

              3. <tfoot id='Ofsuh'></tfoot>
                  <tbody id='Ofsuh'></tbody>

                <i id='Ofsuh'><tr id='Ofsuh'><dt id='Ofsuh'><q id='Ofsuh'><span id='Ofsuh'><b id='Ofsuh'><form id='Ofsuh'><ins id='Ofsuh'></ins><ul id='Ofsuh'></ul><sub id='Ofsuh'></sub></form><legend id='Ofsuh'></legend><bdo id='Ofsuh'><pre id='Ofsuh'><center id='Ofsuh'></center></pre></bdo></b><th id='Ofsuh'></th></span></q></dt></tr></i><div id='Ofsuh'><tfoot id='Ofsuh'></tfoot><dl id='Ofsuh'><fieldset id='Ofsuh'></fieldset></dl></div>

                    <legend id='Ofsuh'><style id='Ofsuh'><dir id='Ofsuh'><q id='Ofsuh'></q></dir></style></legend>

                      • <bdo id='Ofsuh'></bdo><ul id='Ofsuh'></ul>