无法在使用Yocto工具链时,从子shell中使用`cmake`构建Qt项目。

huangapple go评论114阅读模式
英文:

Cannot `cmake` a Qt project from a subshell when using the Yocto toolchain

问题

  1. 我有一个项目,其配置步骤如下:

cmake /src

  1. 这个项目正在一个Ubuntu 20.04Docker容器中构建,该容器只包含了我的镜像的Yocto工具链,并且$HOME/.bashrc的最后一行是`source /opt/my-distro/2.5.3/environment-setup-aarch64-poky-linux`
  2. 如果我按照以下方式加载Docker容器...

(宿主机)$ docker run --rm -it -v /home/me/my-source:/src mybuildenv:latest
(Docker内部)$ mkdir /build
(Docker内部)$ cd /build
(Docker内部)$ cmake /src
-- CXX编译器标识为GNU 7.3.0
-- 检查工作中的CXX编译器:/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++
-- 检查工作中的CXX编译器:/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++ -- 已通过
-- 检测CXX编译器ABI信息
-- 检测CXX编译器ABI信息 - 完成
-- 检测CXX编译特性
-- 检测CXX编译特性 - 完成
-- 配置完成
-- 生成完成
-- 构建文件已写入:/build

  1. 如果我在子shell中执行相同的cmake命令,我会得到:

(宿主机)$ docker run --rm -it -v /home/me/my-source:/src mybuildenv:latest
(Docker内部)$ mkdir /build
(Docker内部)$ cd /build
(Docker内部)$ /bin/bash -c 'cmake /src'
-- CXX编译器标识为GNU 7.3.0
-- 检查工作中的CXX编译器:/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++
-- 检查工作中的CXX编译器:/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++ -- 已通过
-- 检测CXX编译器ABI信息
-- 检测CXX编译器ABI信息 - 完成
-- 检测CXX编译特性
-- 检测CXX编译特性 - 完成
CMake错误,位于application/CMakeLists.txt:17(find_package):
由于未在CMAKE_MODULE_PATH中提供“FindQt5.cmake”,该项目已要求CMake查找由“Qt5”提供的包配置文件,但CMake没有找到。

无法在以下名称之一提供“Qt5”的包配置文件:

  1. Qt5Config.cmake
  2. qt5-config.cmake

将“Qt5”的安装前缀添加到CMAKE_PREFIX_PATH,或将“Qt5_DIR”设置为包含上述任何文件之一的目录。如果“Qt5”提供了单独的开发包或SDK,请确保已安装。

-- 配置不完整,出现错误!
请参阅“/build/CMakeFiles/CMakeOutput.log”。

我希望它能工作,因为父shell和子shell的环境...

(Docker内部)$ env
...
(Docker内部)$ /bin/bash -c 'env'
...

...在功能上是相同的(顺序略有不同,但所有变量都完全相同)。

我不确定问题出在哪里,是在bashdockercmake还是yocto。这是一个问题,因为我正在Microsoft Azure流水线中运行此构建环境,它正在docker exec下生成一个子shell,并在这种情况下,我无法构建我的应用程序。


编辑

我看了一下CMake文件中使用的变量,使用了这个片段:

  1. get_cmake_property(_variableNames VARIABLES)
  2. list (SORT _variableNames)
  3. foreach (_variableName ${_variableNames})
  4. message(STATUS "${_variableName}=${${_variableName}}")
  5. endforeach()

差异:

  1. < -- CMAKE_AR=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ar
  2. < -- CMAKE_AR=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ar
  3. < -- CMAKE_ASM_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
  4. ---
  5. > -- CMAKE_AR=/usr/bin/ar
  6. > -- CMAKE_AR=/usr/bin/ar
  7. 18c17
  8. < -- CMAKE_CROSSCOMPILING=TRUE
  9. ---
  10. > -- CMAKE_CROSSCOMPILING=FALSE
  11. 39c38
  12. < -- CMAKE_CXX_ARCHIVE_APPEND_IPO="/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ar" r <TARGET> <LINK_FLAGS> <OBJECTS>
  13. ---
  14. > -- CMAKE_CXX_ARCHIVE_APPEND_IPO="/usr/bin/gcc-ar" r <TARGET> <LINK_FLAGS> <OBJECTS>
  15. 41c40
  16. < -- CMAKE_CXX_ARCHIVE_CREATE_IPO="/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ar" cr <TARGET> <LINK_FLAGS> <OBJECTS>
  17. ---
  18. > -- CMAKE_CXX_ARCHIVE_CREATE_IPO="/usr/bin/gcc-ar" cr <TARGET> <LINK_FLAGS> <OBJECTS>
  19. 43c42
  20. < -- CMAKE_CXX_ARCHIVE_FINISH_IPO="/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ranlib" <TARGET>
  21. ---
  22. >
  23. <details>
  24. <summary>英文:</summary>
  25. I have a project whose configuration steps are as follows:

cmake /src

  1. This is being built in an Ubuntu 20.04 docker container where the only contents are the Yocto toolchain for my image and last line of $HOME/.bashrc is `source /opt/my-distro/2.5.3/environment-setup-aarch64-poky-linux`
  2. If I load up the docker container as follows...

(host) $ docker run --rm -it -v /home/me/my-source:/src mybuildenv:latest
(docker) $ mkdir /build
(docker) $ cd /build
(docker) $ cmake /src
-- The CXX compiler identification is GNU 7.3.0
-- Check for working CXX compiler: /opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++
-- Check for working CXX compiler: /opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /build

  1. If I load up the container and do the same cmake command in a subshell, I get

(host) $ docker run --rm -it -v /home/me/my-source:/src mybuildenv:latest
(docker) $ mkdir /build
(docker) $ cd /build
(docker) $ /bin/bash -c 'cmake /src'
-- The CXX compiler identification is GNU 7.3.0
-- Check for working CXX compiler: /opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++
-- Check for working CXX compiler: /opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at application/CMakeLists.txt:17 (find_package):
By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5", but
CMake did not find one.

Could not find a package configuration file provided by "Qt5" with any of
the following names:

  1. Qt5Config.cmake
  2. qt5-config.cmake

Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
to a directory containing one of the above files. If "Qt5" provides a
separate development package or SDK, be sure it has been installed.

-- Configuring incomplete, errors occurred!
See also "/build/CMakeFiles/CMakeOutput.log".

  1. I expect this to work since both the parent and subshells environments...

(docker) $ env
...
(docker) $ /bin/bash -c 'env'
...

  1. ... are functionally identical (ordering slightly different but all variables are the exact same).
  2. I am unsure where the problems lies, if it&#39;s in `bash`, `docker`, `cmake`, or `yocto`. This is a problem since the Microsoft Azure pipeline I am running this build environment in is spawning a sub shell under `docker exec` and under this circumstance I cannot built my application.
  3. ----
  4. # EDIT
  5. One other thing I looked at was the variables define in the CMake files using this snippet:
  6. ``` cmake
  7. get_cmake_property(_variableNames VARIABLES)
  8. list (SORT _variableNames)
  9. foreach (_variableName ${_variableNames})
  10. message(STATUS &quot;${_variableName}=${${_variableName}}&quot;)
  11. endforeach()

The diff:

  1. &lt; -- CMAKE_AR=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ar
  2. &lt; -- CMAKE_AR=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ar
  3. &lt; -- CMAKE_ASM_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
  4. ---
  5. &gt; -- CMAKE_AR=/usr/bin/ar
  6. &gt; -- CMAKE_AR=/usr/bin/ar
  7. 18c17
  8. &lt; -- CMAKE_CROSSCOMPILING=TRUE
  9. ---
  10. &gt; -- CMAKE_CROSSCOMPILING=FALSE
  11. 39c38
  12. &lt; -- CMAKE_CXX_ARCHIVE_APPEND_IPO=&quot;/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ar&quot; r &lt;TARGET&gt; &lt;LINK_FLAGS&gt; &lt;OBJECTS&gt;
  13. ---
  14. &gt; -- CMAKE_CXX_ARCHIVE_APPEND_IPO=&quot;/usr/bin/gcc-ar&quot; r &lt;TARGET&gt; &lt;LINK_FLAGS&gt; &lt;OBJECTS&gt;
  15. 41c40
  16. &lt; -- CMAKE_CXX_ARCHIVE_CREATE_IPO=&quot;/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ar&quot; cr &lt;TARGET&gt; &lt;LINK_FLAGS&gt; &lt;OBJECTS&gt;
  17. ---
  18. &gt; -- CMAKE_CXX_ARCHIVE_CREATE_IPO=&quot;/usr/bin/gcc-ar&quot; cr &lt;TARGET&gt; &lt;LINK_FLAGS&gt; &lt;OBJECTS&gt;
  19. 43c42
  20. &lt; -- CMAKE_CXX_ARCHIVE_FINISH_IPO=&quot;/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ranlib&quot; &lt;TARGET&gt;
  21. ---
  22. &gt; -- CMAKE_CXX_ARCHIVE_FINISH_IPO=&quot;/usr/bin/gcc-ranlib&quot; &lt;TARGET&gt;
  23. 48,49c47,48
  24. &lt; -- CMAKE_CXX_COMPILER_AR=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ar
  25. &lt; -- CMAKE_CXX_COMPILER_AR=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ar
  26. ---
  27. &gt; -- CMAKE_CXX_COMPILER_AR=/usr/bin/gcc-ar
  28. &gt; -- CMAKE_CXX_COMPILER_AR=/usr/bin/gcc-ar
  29. 315,316c314,315
  30. &lt; -- CMAKE_CXX_COMPILER_RANLIB=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ranlib
  31. &lt; -- CMAKE_CXX_COMPILER_RANLIB=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ranlib
  32. ---
  33. &gt; -- CMAKE_CXX_COMPILER_RANLIB=/usr/bin/gcc-ranlib
  34. &gt; -- CMAKE_CXX_COMPILER_RANLIB=/usr/bin/gcc-ranlib
  35. 333c332
  36. &lt; -- CMAKE_CXX_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
  37. ---
  38. &gt; -- CMAKE_CXX_FLAGS=-O2 -pipe -g -feliminate-unused-debug-types
  39. 366d364
  40. &lt; -- CMAKE_C_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
  41. 396,400d393
  42. &lt; -- CMAKE_FIND_ROOT_PATH=/opt/my-distro/2.5.3/sysroots/aarch64-poky-linux;/opt/b9-core-5/2.5.3/sysroots/x86_64-pokysdk-linux
  43. &lt; -- CMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY
  44. &lt; -- CMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY
  45. &lt; -- CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY
  46. &lt; -- CMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
  47. 419d411
  48. &lt; -- CMAKE_LDFLAGS_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
  49. 423,424c415,416
  50. &lt; -- CMAKE_LINKER=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld
  51. &lt; -- CMAKE_LINKER=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld
  52. ---
  53. &gt; -- CMAKE_LINKER=/usr/bin/ld
  54. &gt; -- CMAKE_LINKER=/usr/bin/ld
  55. 444,446c436,438
  56. &lt; -- CMAKE_NM=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-nm
  57. &lt; -- CMAKE_OBJCOPY=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-objcopy
  58. &lt; -- CMAKE_OBJDUMP=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-objdump
  59. ---
  60. &gt; -- CMAKE_NM=/usr/bin/nm
  61. &gt; -- CMAKE_OBJCOPY=/usr/bin/objcopy
  62. &gt; -- CMAKE_OBJDUMP=/usr/bin/objdump
  63. 454,455c446,447
  64. &lt; -- CMAKE_RANLIB=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ranlib
  65. &lt; -- CMAKE_RANLIB=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ranlib
  66. ---
  67. &gt; -- CMAKE_RANLIB=/usr/bin/ranlib
  68. &gt; -- CMAKE_RANLIB=/usr/bin/ranlib
  69. 511,512c503,504
  70. &lt; -- CMAKE_STRIP=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-strip
  71. &lt; -- CMAKE_SYSTEM=Linux
  72. ---
  73. &gt; -- CMAKE_STRIP=/usr/bin/strip
  74. &gt; -- CMAKE_SYSTEM=Linux-5.15.0-56-generic
  75. 519c511
  76. &lt; -- CMAKE_SYSTEM_PROCESSOR=aarch64
  77. ---
  78. &gt; -- CMAKE_SYSTEM_PROCESSOR=x86_64
  79. 522,523c514
  80. &lt; -- CMAKE_SYSTEM_VERSION=
  81. &lt; -- CMAKE_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake
  82. ---
  83. &gt; -- CMAKE_SYSTEM_VERSION=5.15.0-56-generic
  84. 528d518
  85. &lt; -- COMPILER_BASENAME=aarch64-poky-linux-g++
  86. 531d520
  87. &lt; -- INCLUDE_CMAKE_TOOLCHAIN_FILE_IF_REQUIRED=include(&quot;/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake&quot;)
  88. 533,534c522
  89. &lt; -- OE_QMAKE_PATH_EXTERNAL_HOST_BINS=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin
  90. &lt; -- PRESET_CMAKE_SYSTEM_NAME=TRUE
  91. ---
  92. &gt; -- PRESET_CMAKE_SYSTEM_NAME=FALSE
  93. 549d536
  94. &lt; -- _CMAKE_TOOLCHAIN_PREFIX=aarch64-poky-linux-
  95. 552d538
  96. &lt; -- _INCLUDED_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake
  97. 564d549
  98. &lt; -- config=
  99. 575d559
  100. &lt; -- toolchain_config_files=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake.d/OEQt5Toolchain.cmake

So, as seen when I run /bin/bash -c &quot;cmake /src&quot; no toolchain related variables are populated, while when I run cmake /src there are. Is there any reason this would be the case when the bash environments are the same? Is there something I can do to make sure the variables carry over? I don't seem to have this problem with qmake.

答案1

得分: 0

原因是 /bin/bash -c &quot;cmake /src&quot; 不等同于 cmake /src 是因为 cmake 是一个别名,指向 cmake -DCMAKE_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake,而别名不会被子shell继承

解决方案是使用 /bin/bash -c &quot;cmake -DCMAKE_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake&#39;&quot;

英文:

The reason /bin/bash -c &quot;cmake /src&quot; is not equivalent to cmake /src is because cmake was an alias for cmake -DCMAKE_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake and aliases are not inherited by subshells.

The solution is to use /bin/bash -c &quot;cmake -DCMAKE_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake&#39;&quot;

huangapple
  • 本文由 发表于 2023年2月18日 03:02:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75488338.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定