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

      <small id='CQX1x'></small><noframes id='CQX1x'>

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

        带有包含和源路径的 CMake - 基本设置

        时间:2023-08-26

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

                <tbody id='WH6HL'></tbody>

                1. <legend id='WH6HL'><style id='WH6HL'><dir id='WH6HL'><q id='WH6HL'></q></dir></style></legend>
                2. 本文介绍了带有包含和源路径的 CMake - 基本设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试建立一个看起来像我自己的项目的测试项目,只是为了让事情先运行起来,它看起来像这样:

                  I'm trying to set up a test project looking like my own project just to get things working first and it looks like this:

                  /MainProject/inc/main.h
                  /MainProject/src/main.cpp
                  /LibProject/inc/test.h
                  /LibProject/src/test.cpp
                  

                  我找到了一些教程,但是当我有 inc 和 src 文件夹时,我无法找到如何设置它?CMakeLists.txt 文件看起来如何?我会在/中有一个,每个项目文件夹中有一个吗?好像我不需要在 inc 和 src 文件夹中有一个?

                  I've found some tutorials, but I cant find out how to set up this when I have the inc and src folder? How would the CMakeLists.txt files look? Would I have one in /, one in each of the project folders? It seems like I dont need to have one in the inc and src folders?

                  推荐答案

                  对于每个源子目录,您都需要一个 CMakeLists.txt.您的结构应如下所示:

                  You need a CMakeLists.txt for each source subdirectory. Your structure should look something like this:

                  root
                  |-MainProject
                  | |-inc
                  | | '-main.h
                  | |-src
                  | | |-main.cpp
                  | | '-CMakeLists.txt
                  | '-CMakeLists.txt 
                  |-LibProject
                  | |-inc
                  | | '-test.h
                  | |-src
                  | | |-test.cpp
                  | | '-CMakeLists.txt
                  | '-CMakeLists.txt
                  '-CMakeLists.txt
                  

                  root/CMakeLists.txt 的内容:

                  project(MyProject)
                  add_subdirectory(MainProject)
                  add_subdirectory(LibProject)
                  

                  LibProject/CMakeLists.txtMainProject/CMakeLists.txt 的内容:

                  add_subdirectory(src)
                  

                  LibProject/src/CMakeLists.txt的内容:

                  # Notice name prefix of this variable, set by CMake according
                  # to value given with "project()" in the root CMakeLists.txt.
                  include_directories(${MyProject_SOURCE_DIR}/LibProject/inc)
                  add_library(LibProject test.cpp)
                  

                  MainProject/src/CMakeLists.txt的内容:

                  include_directories(${MyProject_SOURCE_DIR}/MainProject/inc)
                  # I assume you want to use LibProject as a library in MainProject.
                  include_directories(${MyProject_SOURCE_DIR}/LibProject/inc)
                  link_directories(${MyProject_SOURCE_DIR}/LibProject/src)
                  add_executable(MainProject main.cpp)
                  target_link_libraries(MainProject LibProject)
                  

                  然后配置和构建:

                  $ cd root
                  $ mkdir build
                  $ cd build
                  $ cmake ..
                  $ make
                  

                  这篇关于带有包含和源路径的 CMake - 基本设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:无法使用 CMake 找到 Eigen3 下一篇:在 CMake 中使用预编译的头文件

                  相关文章

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

                    1. <tfoot id='tNzGb'></tfoot>
                    2. <small id='tNzGb'></small><noframes id='tNzGb'>

                        <bdo id='tNzGb'></bdo><ul id='tNzGb'></ul>