更改CMake的文件的标准位置 [英] Changing CMake files standard location
问题描述
我有一个叫做幽灵-DIR /文件夹中的源目录,我把所有生成的文件,我不需要。我希望把所有生成的文件由本的CMake幻影目录中(连同其它生成和丑陋的文件)。
I have a source directory with a folder called "phantom-dir/" where I put all generated files I don't need. I want to put all generated files by CMake inside this phantom directory (together with other generated and "ugly" files).
一个小例子:
$ mkdir cmake-test
$ cd cmake-test
$ echo 'message("Hello World!")' > CMakeLists.txt
$ cmake . | grep "Hello"
Hello World!
$ tree
.
├── CMakeCache.txt
├── CMakeFiles
│ ├── CMakeCCompiler.cmake
│ ├── cmake.check_cache
│ ├── CMakeCXXCompiler.cmake
│ ├── CMakeDetermineCompilerABI_C.bin
│ ├── CMakeDetermineCompilerABI_CXX.bin
│ ├── CMakeDirectoryInformation.cmake
│ ├── CMakeOutput.log
│ ├── CMakeSystem.cmake
│ ├── CMakeTmp
│ ├── CompilerIdC
│ │ ├── a.out
│ │ └── CMakeCCompilerId.c
│ ├── CompilerIdCXX
│ │ ├── a.out
│ │ └── CMakeCXXCompilerId.cpp
│ ├── Makefile2
│ ├── Makefile.cmake
│ ├── progress.marks
│ └── TargetDirectories.txt
├── cmake_install.cmake
├── CMakeLists.txt
└── Makefile
4 directories, 20 files
在默认情况下,所有文件的CMake(CMakeCache.txt,cmake_install.cmake,Makefile文件,CMakeFiles)被写入工作目录。但是,我想是这样的:
By default, all CMake files (CMakeCache.txt, cmake_install.cmake, Makefile, CMakeFiles) are written in the working directory. But, I want something like that:
$ mkdir cmake-test
$ cd cmake-test
$ mkdir phantom-dir
$ echo 'message("Hello World!")' > CMakeLists.txt
$ // editing CMakeLists.txt to set some cmake variables.
$ cmake . | grep "Hello"
Hello World!
$ tree
.
├── phantom-dir
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ │ ├── CMakeCCompiler.cmake
│ │ ├── cmake.check_cache
│ │ ├── CMakeCXXCompiler.cmake
│ │ ├── CMakeDetermineCompilerABI_C.bin
│ │ ├── CMakeDetermineCompilerABI_CXX.bin
│ │ ├── CMakeDirectoryInformation.cmake
│ │ ├── CMakeOutput.log
│ │ ├── CMakeSystem.cmake
│ │ ├── CMakeTmp
│ │ ├── CompilerIdC
│ │ │ ├── a.out
│ │ │ └── CMakeCCompilerId.c
│ │ ├── CompilerIdCXX
│ │ │ ├── a.out
│ │ │ └── CMakeCXXCompilerId.cpp
│ │ ├── Makefile2
│ │ ├── Makefile.cmake
│ │ ├── progress.marks
│ │ └── TargetDirectories.txt
│ ├── cmake_install.cmake
├── CMakeLists.txt
└── Makefile
4 directories, 20 files
这意味着:在Makefile在当前目录(。cmake的&功放;&放大器;使之作,),但幽灵目录中剩余的生成的文件
That means: the Makefile in the current directory (to make, "cmake . && make"), but the remaining generated files inside the "phantom" directory.
我知道我可以使它:
$ cd phantom-dir/
$ cmake ../
但它是一个有点无聊,我要我要重新编译或翻拍CMake的,最重要的是考虑到我修改很多次我的CMakeLists.txt每次都做到这一点。
But it's a little tiresome for me to do it each time I want to re-compiling or remake cmake, above all taking into account that I'm modifying many times my CMakeLists.txt.
我有哪些变量中的CMakeLists.txt文件来设置,以实现呢?
Which variables I have to set in the CMakeLists.txt file in order to achieve it?
推荐答案
您可以利用的无证CMake的选项 -H
和 -B
来避免留下您的源代码目录。 -H
指定的路径,主要的CMakeLists.txt文件, -B
指定所需的build目录的路径
You could make use of the undocumented CMake options -H
and -B
to avoid leaving your source dir. -H
specifies the path to the main CMakeLists.txt file, and -B
specifies the path to your desired build directory.
cmake -H. -Bphantom-dir
请注意,这些都是无证,所以我想可以在任何时候Kitware人感觉改变。
Note that these are undocumented and so I suppose could change at any time the Kitware guys feel like.
要生成项目不离开你的源代码目录,你可以使用(官方)选项的 - 建立
这是一个跨平台的方式来调用您所选择的构建工具,你可以通过你想这个工具的任何标志。例如。
To build your project without leaving your source dir, you can make use of the (official) option --build
This is a cross-platform way to invoke your chosen build tool, and you can pass whatever flags you want to this tool. e.g.
cmake --build phantom-dir -- -j3
这篇关于更改CMake的文件的标准位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!