随着CMake的,你会怎么禁用源建立? [英] With cmake, how would you disable in-source builds?

查看:309
本文介绍了随着CMake的,你会怎么禁用源建立?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要塞满我们的源代码树生成CMake的文件禁止人... ...,更重要的是,加强对现有不让他们的Makefile 不在的一部分我们使用CMake的为同一个构建过程。 (最好不要问)

I want to disallow people from cluttering our source tree with generated CMake files... and, more importantly, disallow them from stepping on existing Makefiles that are not part of the same build process we're using CMake for. (best not to ask)

我已经拿出来做到这一点的方法是让在顶部我的的CMakeLists.txt ,如下几行:

The way I have come up with to do this is to have a few lines at the top of my CMakeLists.txt, as follows:

if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
   message(SEND_ERROR "In-source builds are not allowed.")
endif("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")

不过,做这种方式似乎过于冗长。此外,如果我尝试了在源构建它仍然创建了 CMakeFiles / 目录,而 CMakeCache.txt 在源树文件是抛出错误之前。

However, doing it this way seems too verbose. Additionally, if I try an in-source build it still creates the the CMakeFiles/ directory, and the CMakeCache.txt file in the source tree before the error is thrown.

我缺少一个更好的方式来做到这一点?

Am I missing a better way to do this?

推荐答案

我觉得我喜欢你的方式。 CMake的邮件列表做得很好,在回答这些类型的问题。

I think I like your way. The cmake mailing list does a good job at answering these types of questions.

作为一个方面说明:您可以创建在失败目录下的CMake的可执行文件。根据是否不是。在他们的路径(在Linux上)。你甚至可以符号链接/斌/假的。

As a side note: you could create a "cmake" executable file in the directory which fails. Depending on whether or not "." is in their path (on linux). You could even symlink /bin/false.

在窗口,我不知道,如果在当前目录中的文件被发现,第一次还是不行。

In windows, I am not sure if a file in your current directory is found first or not.

这篇关于随着CMake的,你会怎么禁用源建立?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆