Linux cmake在文件(GLOB)命令中停留了几个小时

时间:2019-11-27 05:41:59

标签: linux cmake bitbake

当我运行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的错误吗?我搜索了Google,没有找到有关此“错误”的描述。但是在旧/新版本之间的行为确实有所不同。

1 个答案:

答案 0 :(得分:0)

当此代码在Linux上运行时,由于file()命令卡在路径(x86)的括号中,CMake执行挂起。当bash遇到括号而不用单引号引起来时,它将引发错误:

bash: syntax error near unexpected token `('

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

较新版本的CMake通过将此CMake代码块包含在Windows中来避免了该问题。查看最新代码here

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()