CMake子目录

发布于 2024-09-18 05:10:02 字数 633 浏览 2 评论 0原文

我正在使用 CMake,我想尝试制作它,所以我有一个它的子目录,而不是分散在我的项目或其根目录中的文件。

我的目录布局为 project/cmake/CMakeLists.txtproject/binproject/source,因此人们可以轻松删除 CMake如果他们愿意的话。我唯一的问题是可能有一种我不知道的方法可以做到这一点。目前它会生成一堆垃圾,包括一个 project/cmake/bin/obtap.dir/home/jookia/Programming/obtap/source 文件夹。

cmake_minimum_required(VERSION 2.6)
project(obtap)
add_definitions(-g -Wall)
add_executable(../bin/obtap ../source/main.cpp)

它编译得很好,它输出正确的目录。但我的问题是这样的: 有没有办法删除 project/cmake/bin 目录,并且可选,有没有办法不拥有所有 CMake 内容,而只是生成一个 makefile,这样我就有两个文件:CMakeLists.txt 和 Makefile ?

I'm using CMake and I want to try and make it so I have a subdirectory for it rather than files scattered through my project or the root of it.

I have a directory layout of project/cmake/CMakeLists.txt and project/bin and project/source, so people can easily remove the CMake stuff if they want to. My only problem is that there probably is a way to do this that I don't know of. Currently it generates a bunch of rubbish including a project/cmake/bin/obtap.dir/home/jookia/Programming/obtap/source folder.

cmake_minimum_required(VERSION 2.6)
project(obtap)
add_definitions(-g -Wall)
add_executable(../bin/obtap ../source/main.cpp)

It compiles fine, it outputs the right directories. But my problems are this:
Is there a way to remove project/cmake/bin directory and optionally, is there a way to not have all the CMake stuff and instead just generate a makefile so I have two files, CMakeLists.txt and Makefile?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠檬色的秋千 2024-09-25 05:10:03

正如 CMake 常见问题解答中指定的,生成的 Makefile 包含库的完整路径和源代码,因此没有简单的方法来分发 CMake 生成的构建树。

As specified in the CMake FAQ, the generated Makefiles contains full path to libraries and source code, so there is no easy way to distribute a build tree generated by CMake.

蓝眸 2024-09-25 05:10:03

我相信你想要的应该是所谓的out of source build,可以通过在专用目录中运行cmake在单独的目录中生成中间文件来实现,根据您的情况,您可以尝试以下命令:

mkdir -p project/bld/
cd project/bld/
cmake project/cmake

现在您将获得在 project/bld 目录中生成的所有 CMake 内容,并且每当您想要删除所有这些内容时,只需运行:

rm -fr project/bld/

您甚至可以获得几个不同的配置文件通过设置不同的构建树。

如果您想控制生成的可执行文件输出路径,使其不隐藏在深度嵌套的 cmake 中间二叉树中,则可能会出现一个问题;答案是你可以设置变量CMAKE_CURRENT_BINARY_DIR来自定义可执行输出的绝对路径,或者只使用cmake -Eadd_custom_command命令来复制可执行输出。

I believe what you want should be the so called out of source build, which can be achieved by generating intermediate files in a separate directory by running cmake in a dedicated directory, for your case, you can try below commands:

mkdir -p project/bld/
cd project/bld/
cmake project/cmake

Now you get all the CMake stuffs generated in the project/bld directory and whenever you want to remove all those things, just run:

rm -fr project/bld/

You can even get several different profiles by setting up different build trees.

One issue may arise if you want to control the generated executable output path such that it's not hidden in the deeply nested cmake intermediate binary tree; the answer is you can set the variable CMAKE_CURRENT_BINARY_DIR to customise the executable output absolute path, or just use cmake -E and add_custom_command command to copy the executable out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文