Linux cmake 卡在 file(GLOB) 命令中几个小时



当我运行bitbake时,它卡在包的do_configure任务中。通过打印调试,我发现它卡住了 https://github.com/Kitware/CMake/blame/ae5f98a5e36da8cf3c75625ffb9a1d34aa2407cb/Modules/FindDoxygen.cmake,正是这一行:

file(GLOB _Doxygen_GRAPHVIZ_BIN_DIRS
"$ENV{ProgramFiles}/Graphviz*/bin"
"$ENV{ProgramFiles${_x86}}/Graphviz*/bin"
)

然后我写了这个CMakeLists.txt文件:

set(_x86 "(x86)")
message(STATUS "Will run file GLOB...")
file(GLOB _Doxygen_GRAPHVIZ_BIN_DIRS
"$ENV{ProgramFiles}/Graphviz*/bin"
"$ENV{ProgramFiles${_x86}}/Graphviz*/bin"
)
unset(_x86)
message(STATUS "file GLOB end")

在 RedHat Linux 上运行较旧的 cmake 版本:

$ cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.5 (Santiago)
$ cmake --version
cmake version 3.6.1
$ cmake .
-- The C compiler identification is GNU 4.4.7
-- The CXX compiler identification is GNU 4.4.7
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Will run file GLOB...
# stuck for several hours...

在 Ubuntu 18.04.1 LTS 上运行较新的 cmake 版本:

$ cmake --version
cmake version 3.10.2
$ cmake .
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Will run file GLOB...
-- file GLOB end
...
-- Build files have been written to: xxx
# Finished in less than 1min.

那么file(GLOB)是旧cmake版本中的错误吗?我搜索了谷歌,没有找到关于这个"错误"的描述。但它在旧/新版本之间的行为确实不同。

当此代码在 Linux 上运行时,CMake 执行挂起,因为file()命令卡在路径(x86)的括号上。当bash遇到括号,没有被单引号包围时,它会抛出错误:

bash: syntax error near unexpected token `('

因此,在旧版本的 CMake 上,file()命令永远不会返回,因为它使用bash来执行特定操作。

较新版本的 CMake 通过检查 Windows 来绕过此 CMake 代码块来避免此问题。在此处查看最新代码:

if(WIN32)
set(_x86 "(x86)")
file(
GLOB _Doxygen_GRAPHVIZ_BIN_DIRS
"$ENV{ProgramFiles}/Graphviz*/bin"
"$ENV{ProgramFiles${_x86}}/Graphviz*/bin"
)
unset(_x86)
else()
set(_Doxygen_GRAPHVIZ_BIN_DIRS "")
endif()

最新更新