CMake execute_process 命令如何 运行?

How are CMake execute_process commands run?

我的 CMakeLists.txt 文件中有以下行。我在 Windows 7 上 运行ning CMake 3.5.2,并使用 Visual Studio 12 2013 作为生成器,并在 gui 中检查了 "Use default native compilers"。

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

这个运行很好。

但具体情况如何 运行?在 Windows!

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

编辑:我将 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 是怎么知道这样做的?

The documentation 说:

"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 作为输出:

execute_process(COMMAND which make)

发生了什么,and/or 我怎么才能弄清楚 environment/shell/whatever 这些命令在 运行 中?

CMake 附带了 Kitware 的 OS abstraction/detection 库 kwsys:

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

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

所以 - 正如@Tsyvarev 评论的那样 - 你的行为可能是 Win32/64 版本的 CMake MinGW/MSYSPATH 环境中(找到给出了 Unix 特定命令)或来自 MSYS.

的 MinGW32/64 CMake 运行 版本

您也可以考虑使用 FindUnixCommands 之类的东西来获取相关 Unix 工具的绝对路径。

参考