为什么cmake在我的构建目录中创建一个'source'目录?

时间:2022-05-28 16:56:15

I am getting kind of frustrated with cmake, as I am trying to learn it and use it properly.

我对cmake感到很沮丧,因为我正在努力学习并正确使用它。

Here is my setup:

这是我的设置:

I have a directory called ~/project. In this directory, I have:

我有一个名为〜/ project的目录。在这个目录中,我有:

  • build directory
  • source directory
  • includes directory.
  • CMakeLists.txt file.

The contents of this CMakeLists.txt file is:

此CMakeLists.txt文件的内容是:

cmake_minimum_required(VERSION 2.8)
project(myProject)
subdirs(source)

I also have another CMakeLists.txt in ~/project/source, and its content is:

我在〜/ project / source中还有另一个CMakeLists.txt,其内容是:

cmake_minimum_required(VERSION 2.8)
include_directories("~/project/includes")
add_executable(exec entry.cpp)

Now, I go into the build directory which is empty, and do cmake ... This works fine. However I then see a 'source' directory get created as shown here.

现在,我进入构建目录,这是空的,并做cmake ...这很好。然而,我然后看到如此处所示创建的“源”目录。

Why is this being created? I do not know what is going on. As I understand it, it should not be doing this, it should give me everything I see here, except for the 'source' directory.

为什么要创建这个?我不知道发生了什么事。据我了解,它不应该这样做,它应该给我我在这里看到的一切,除了'源'目录。

Thanks.

1 个解决方案

#1


1  

Inside your build directory, CMake re-creates the whole directory structure of your project. The rational is, to keep the project structure. Image a bigger project with several levels of subfolders and sources, libraries and tests scattered in a meaningful way. To run a test, you follow the structure where the test's source is located, just in the build directory instead of the source directory.

在构建目录中,CMake重新创建项目的整个目录结构。理性是,保持项目结构。想象一个更大的项目,包含几个级别的子文件夹和源,库和测试以有意义的方式分散。要运行测试,请遵循测试源所在的结构,只需在构建目录而不是源目录中。

As your project, at least as far as CMake knows it, is only the source subdirectory, only this folder is created.

作为你的项目,至少就CMake所知,它只是源子目录,只创建了这个文件夹。

If you really have just the source project, I am not sure whether would be better to place the CMake project just inside source.

如果你真的只有源项目,我不确定将CMake项目置于源代码内是否更好。

#1


1  

Inside your build directory, CMake re-creates the whole directory structure of your project. The rational is, to keep the project structure. Image a bigger project with several levels of subfolders and sources, libraries and tests scattered in a meaningful way. To run a test, you follow the structure where the test's source is located, just in the build directory instead of the source directory.

在构建目录中,CMake重新创建项目的整个目录结构。理性是,保持项目结构。想象一个更大的项目,包含几个级别的子文件夹和源,库和测试以有意义的方式分散。要运行测试,请遵循测试源所在的结构,只需在构建目录而不是源目录中。

As your project, at least as far as CMake knows it, is only the source subdirectory, only this folder is created.

作为你的项目,至少就CMake所知,它只是源子目录,只创建了这个文件夹。

If you really have just the source project, I am not sure whether would be better to place the CMake project just inside source.

如果你真的只有源项目,我不确定将CMake项目置于源代码内是否更好。