CMake的输出/ build目录 [英] CMake output/build directory

查看:6718
本文介绍了CMake的输出/ build目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是pretty新CMake的,并阅读关于如何使用它的几个教程,并且为了使程序对3个不同的编译器写了一些复杂的50行CMake的脚本。这大概总结了我的CMake所有的知识。

现在我的问题是,我有一些源$ C ​​$ C,其文件夹我不想去碰/一塌糊涂,当我做节目。我想,所有cmake并作出输出文件和文件夹进入../Compile/,所以我在为CMake的脚本改变了一些变数,和它的工作了一段时间,当我做这样的事情在我的笔记本电脑:

 编译$ cmake的../src
编译$使

在哪里有,我有我的,现在我的文件夹中一个干净的输出,这正是我要找的。

现在我搬到另一台计算机,并重新编译CMake的2.8.11.2,我几乎又回到了起点!它总是编译成的东西在我的的CMakeLists.txt所在的src文件夹。

在这里我选择在我的CMake脚本的目录部分是这样的:

 套装(DIR $ {} CMAKE_CURRENT_SOURCE_DIR /../编译/)
集(EXECUTABLE_OUTPUT_PATH $ {}目录缓存路径建设目录FORCE)
集(LIBRARY_OUTPUT_PATH $ {}目录缓存路径建设目录FORCE)
集(CMAKE_RUNTIME_OUTPUT_DIRECTORY $ {DIR})
集(CMAKE_BUILD_FILES_DIRECTORY $ {DIR})
集(CMAKE_BUILD_DIRECTORY $ {DIR})
集(CMAKE_BINARY_DIR $ {DIR})
SET(EXECUTABLE_OUTPUT_PATH $ {DIR})
SET(LIBRARY_OUTPUT_PATH $ {}目录LIB)
SET(CMAKE_CACHEFILE_DIR $ {DIR})

和现在它总是以结尾:

   - 建立文件已被写入:/.../src

我缺少的东西吗?

感谢你的任何努力。


解决方案

(把我的意见变成一个答案)

有一点需要设置所有你设置的变量。 CMake的他们设置为合理的默认值。你一定要的的修改 CMAKE_BINARY_DIR CMAKE_CACHEFILE_DIR 。对待这些为只读。

只需删除所有的设置()命令,并做到:

  CD编译
室射频*
cmake的../src

只要你运行CMake的时候是源目录之外,也不会修改源目录中,除非你明确CMakeList告诉它。

一旦你有这方面的工作,你可以看看那里的CMake把事情在默认情况下,只有当你不满意默认位置(如 EXECUTABLE_OUTPUT_PATH ),这些你只需要修改。并尝试相对前preSS它们 CMAKE_BINARY_DIR CMAKE_CURRENT_BINARY_DIR PROJECT_BINARY_DIR 等。

如果你看一下CMake的文件,你会看到被分割成语义部分变量。除的非常的特殊情况下,你应该把所有只读内CMakeLists提供信息的变量中所列的。

I'm pretty new to cmake, and read a few tutorials on how to use it, and wrote some complicated 50 lines CMake script in order to make a program for 3 different compilers. This probably concludes all my knowledge in cmake.

Now my problem is that I have some source code, whose folder I don't want to touch/mess when I make the program. I want that all cmake and make output files and folders to go into ../Compile/, so I changed a few variables in my cmake script for that, and it worked for sometime when I did something like this on my laptop:

Compile$ cmake ../src
Compile$ make

Where with that I had a clean output in the folder I'm in right now, which is exactly what I'm looking for.

Now I moved to another computer, and recompiled CMake 2.8.11.2, and I'm almost back to square one! It always compiles the thing into the src folder where my CMakeLists.txt is located.

The part where I choose the directory in my cmake script is this:

set(dir ${CMAKE_CURRENT_SOURCE_DIR}/../Compile/)
set(EXECUTABLE_OUTPUT_PATH ${dir} CACHE PATH "Build directory" FORCE)
set(LIBRARY_OUTPUT_PATH ${dir} CACHE PATH "Build directory" FORCE)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${dir})
set(CMAKE_BUILD_FILES_DIRECTORY ${dir})
set(CMAKE_BUILD_DIRECTORY ${dir})
set(CMAKE_BINARY_DIR  ${dir})
SET(EXECUTABLE_OUTPUT_PATH ${dir})
SET(LIBRARY_OUTPUT_PATH ${dir}lib)
SET(CMAKE_CACHEFILE_DIR ${dir})

And now it always ends with:

-- Build files have been written to: /.../src

Am I missing something?

Thank you for any efforts.

解决方案

(Turning my comments into an answer)

There's little need to set all the variables you're setting. CMake sets them to reasonable defaults. You should definitely not modify CMAKE_BINARY_DIR or CMAKE_CACHEFILE_DIR. Treat these as read-only.

Simply remove all the set() commands and do:

cd Compile
rm -rf *
cmake ../src

As long as you're outside of the source directory when running CMake, it will not modify the source directory unless your CMakeList explicitly tells it to.

Once you have this working, you can look at where CMake puts things by default, and only if you're not satisfied with the default locations (such as the default value of EXECUTABLE_OUTPUT_PATH), modify only those you need. And try to express them relative to CMAKE_BINARY_DIR, CMAKE_CURRENT_BINARY_DIR, PROJECT_BINARY_DIR etc.

If you look at CMake documentation, you'll see variables partitioned into semantic sections. Except for very special circumstances, you should treat all those listed under "Variables that Provide Information" as read-only inside CMakeLists.

这篇关于CMake的输出/ build目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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