CMake execute_process命令如何运行? [英] How are CMake execute_process commands run?

查看:1028
本文介绍了CMake execute_process命令如何运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的CMakeLists.txt文件中包含以下几行.我在Windows 7上运行CMake 3.5.2,并将Visual Studio 12 2013用作生成器,并在gui中选中了使用默认本机编译器".

I've got the following lines in my CMakeLists.txt file. I'm running CMake 3.5.2 on Windows 7, and using Visual Studio 12 2013 as the generator with "Use default native compilers" checked in the gui.

find_path(FORTRAN_DIR NAMES cdll.cpp fdll.f90 Makefile PATHS ../source)
execute_process(COMMAND make
                WORKING_DIRECTORY ${FORTRAN_DIR})

这很好.

但是它是如何运行的呢?在Windows上!

But exactly how is it being run?? It's on Windows!

以前我已经在Windows上通过MSYS2(MinGW)编译了Makefile,但是如果CMake使用的是Makefile,那么我不确定它是怎么知道的.

I've compiled the Makefile via MSYS2 (MinGW) on Windows before, but if that's what CMake is using, then I'm not sure how it knows to do that.

我将execute_process(COMMAND uname -a)放入CMakeLists.txt文件,并得到MSYS_NT-6.1 MYCOMPUTERNAMEHERE 2.5.2(0.297/5/3) 2016-07-15 08:31 x86_64 Msys.所以我想这是通过MSYS运行的答案...但是CMake怎么知道这样做呢?

I put execute_process(COMMAND uname -a) into the CMakeLists.txt file and got MSYS_NT-6.1 MYCOMPUTERNAMEHERE 2.5.2(0.297/5/3) 2016-07-15 08:31 x86_64 Msys. So I guess that answers that it's being run through MSYS... but how does CMake know to do this?

文档说:

"CMake直接使用操作系统API执行子进程.所有参数都通过VERBATIM传递给子进程.不使用中间shell,因此将诸如>之类的shell运算符视为普通参数."

"CMake executes the child process using operating system APIs directly. All arguments are passed VERBATIM to the child process. No intermediate shell is used, so shell operators such as > are treated as normal arguments."

但是我不明白这意味着什么,特别是考虑到如果我使用以下行,我将得到/usr/bin/make作为输出:

But I don't understand what that means, especially considering that if I use the following line, I get /usr/bin/make as the output:

execute_process(COMMAND which make)

正在发生什么,和/或无论如何在这些环境/shell/中运行这些命令,我​​如何知道?

What is happening, and/or how can I figure out what environment/shell/whatever these commands are being run in?

推荐答案

CMake带有Kitware的操作系统抽象/检测库kwsys:

CMake comes with Kitware's OS abstraction/detection library kwsys:

KWSys为许多常见系统提供了独立于平台的API 在每个平台上实现不同的功能.

KWSys provides a platform-independent API to many common system features that are implemented differently on every platform.

execute_process()魔术发生在 ProcessWin32.c 使用CreateProcessW() ProcessUNIX.c 使用execvp()取决于您使用的CMake版本.

The execute_process() magic is happening in ProcessWin32.c using CreateProcessW() or ProcessUNIX.c using execvp() depending of which version of CMake you are using.

所以-正如@Tsyvarev所评论的-您的行为可能是PATH环境中的MinGW/MSYS的CMake的Win32/64版本(查找给定的Unix特定命令)或MinGW32/64 CMake版本从MSYS运行.

So - as @Tsyvarev has commented - your behavior could either be the Win32/64 version of CMake with MinGW/MSYS in the PATH environment (finding the Unix specific commands given) or the MinGW32/64 version of CMake run from MSYS.

您也可以考虑使用 FindUnixCommands 获取有关Unix工具的绝对路径.

Also you may consider the use of something like the FindUnixCommands to get absolute paths to the Unix tools in question.

参考

这篇关于CMake execute_process命令如何运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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