cmake 将中间文件放置到某个目录
我对 cmake 还很陌生,想知道如何使用 cmake 来做到这一点。我想将所有中间文件(如 .o 文件)放置在某个目录(例如“build”)中,然后一旦构建完成,我想复制我需要的某些文件(例如,.exe、. dll 就像最终产品一样)从构建目录到“stage”目录。如何指定这两个目录(构建和阶段)的路径? Cmake 还将检查 build/stage 目录是否存在。如果不存在,它将为我创建目录。
任何帮助将不胜感激。
I am pretty new to cmake and wonder how I can do this is cmake. I want to place all the intermediate files (like the .o files) to be placed in a certain directory (say "build") and then once the build is done I want copy certain files I need (e.g., the .exe, .dll like the end product) from build directory to "stage" directory. how can I specify the path to these two directories (build and stage)? Cmake will also check if the build/stage directory exists or not. If does not exist, it will create the directories for me.
Any help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您问的是最常见的 CMake 用例。
要使整个构建过程发生在任意目录中,您应该从该目录运行
cmake /path/to/your/project
(或使用 cmake-gui)。在您明确告诉 CMake 在那里输出一些文件之前,您的源目录将保持不变。
至于第 2 点:
您应该将
install()
调用放入 CMakeLists.txt(请参阅有关install()
的文档)并将 CMAKE_INSTALL_PREFIX 设置为您希望文件所在的目录被复制。之后,您可以从构建目录运行make install
或cmake -P cmake_install.cmake
来安装这些文件。What are you asking is the most often CMake use case.
To make whole build process to occur in arbitary dir, you should run
cmake /path/to/your/project
from that dir (or use cmake-gui).Your source dir would be untouched until you explicitly tell CMake to output some files there.
As for point 2:
You should place
install()
invocations into your CMakeLists.txt (see documentation oninstall()
) and set CMAKE_INSTALL_PREFIX to the dir where you wish files to be copied. After that you can runmake install
orcmake -P cmake_install.cmake
from your build dir to install these files.我建议采用另一种方法。
或者改为选择步骤 2 时,您还可以提供一个安装例程,其中所需的可执行文件安装在给定路径中。 参见此处
I would suggest another approach.
Or instead of choosing step 2 you also can provide an install routine where the needed executables are installed in a give path. see here