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

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

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

问题

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

cmake /src


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

如果我按照以下方式加载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


如果我在子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”的包配置文件:

Qt5Config.cmake
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文件中使用的变量,使用了这个片段:

get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
    message(STATUS "${_variableName}=${${_variableName}}")
endforeach()

差异:

< -- CMAKE_AR=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ar
< -- CMAKE_AR=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ar
< -- CMAKE_ASM_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
---
> -- CMAKE_AR=/usr/bin/ar
> -- CMAKE_AR=/usr/bin/ar
18c17
< -- CMAKE_CROSSCOMPILING=TRUE
---
> -- CMAKE_CROSSCOMPILING=FALSE
39c38
< -- 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>
---
> -- CMAKE_CXX_ARCHIVE_APPEND_IPO="/usr/bin/gcc-ar" r <TARGET> <LINK_FLAGS> <OBJECTS>
41c40
< -- 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>
---
> -- CMAKE_CXX_ARCHIVE_CREATE_IPO="/usr/bin/gcc-ar" cr <TARGET> <LINK_FLAGS> <OBJECTS>
43c42
< -- 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>
---
>

<details>
<summary>英文:</summary>

I have a project whose configuration steps are as follows:

cmake /src


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`

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


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:

Qt5Config.cmake
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".


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

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


... are functionally identical (ordering slightly different but all variables are the exact same).

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.

----

# EDIT

One other thing I looked at was the variables define in the CMake files using this snippet:

``` cmake
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
    message(STATUS &quot;${_variableName}=${${_variableName}}&quot;)
endforeach()

The diff:

&lt; -- CMAKE_AR=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ar
&lt; -- CMAKE_AR=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ar
&lt; -- CMAKE_ASM_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
---
&gt; -- CMAKE_AR=/usr/bin/ar
&gt; -- CMAKE_AR=/usr/bin/ar
18c17
&lt; -- CMAKE_CROSSCOMPILING=TRUE
---
&gt; -- CMAKE_CROSSCOMPILING=FALSE
39c38
&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;
---
&gt; -- CMAKE_CXX_ARCHIVE_APPEND_IPO=&quot;/usr/bin/gcc-ar&quot; r &lt;TARGET&gt; &lt;LINK_FLAGS&gt; &lt;OBJECTS&gt;
41c40
&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;
---
&gt; -- CMAKE_CXX_ARCHIVE_CREATE_IPO=&quot;/usr/bin/gcc-ar&quot; cr &lt;TARGET&gt; &lt;LINK_FLAGS&gt; &lt;OBJECTS&gt;
43c42
&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;
---
&gt; -- CMAKE_CXX_ARCHIVE_FINISH_IPO=&quot;/usr/bin/gcc-ranlib&quot; &lt;TARGET&gt;
48,49c47,48
&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
&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
---
&gt; -- CMAKE_CXX_COMPILER_AR=/usr/bin/gcc-ar
&gt; -- CMAKE_CXX_COMPILER_AR=/usr/bin/gcc-ar
315,316c314,315
&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
&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
---
&gt; -- CMAKE_CXX_COMPILER_RANLIB=/usr/bin/gcc-ranlib
&gt; -- CMAKE_CXX_COMPILER_RANLIB=/usr/bin/gcc-ranlib
333c332
&lt; -- CMAKE_CXX_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
---
&gt; -- CMAKE_CXX_FLAGS=-O2 -pipe -g -feliminate-unused-debug-types
366d364
&lt; -- CMAKE_C_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
396,400d393
&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
&lt; -- CMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY
&lt; -- CMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY
&lt; -- CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY
&lt; -- CMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
419d411
&lt; -- CMAKE_LDFLAGS_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
423,424c415,416
&lt; -- CMAKE_LINKER=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld
&lt; -- CMAKE_LINKER=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld
---
&gt; -- CMAKE_LINKER=/usr/bin/ld
&gt; -- CMAKE_LINKER=/usr/bin/ld
444,446c436,438
&lt; -- CMAKE_NM=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-nm
&lt; -- CMAKE_OBJCOPY=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-objcopy
&lt; -- CMAKE_OBJDUMP=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-objdump
---
&gt; -- CMAKE_NM=/usr/bin/nm
&gt; -- CMAKE_OBJCOPY=/usr/bin/objcopy
&gt; -- CMAKE_OBJDUMP=/usr/bin/objdump
454,455c446,447
&lt; -- CMAKE_RANLIB=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ranlib
&lt; -- CMAKE_RANLIB=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ranlib
---
&gt; -- CMAKE_RANLIB=/usr/bin/ranlib
&gt; -- CMAKE_RANLIB=/usr/bin/ranlib
511,512c503,504
&lt; -- CMAKE_STRIP=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-strip
&lt; -- CMAKE_SYSTEM=Linux
---
&gt; -- CMAKE_STRIP=/usr/bin/strip
&gt; -- CMAKE_SYSTEM=Linux-5.15.0-56-generic
519c511
&lt; -- CMAKE_SYSTEM_PROCESSOR=aarch64
---
&gt; -- CMAKE_SYSTEM_PROCESSOR=x86_64
522,523c514
&lt; -- CMAKE_SYSTEM_VERSION=
&lt; -- CMAKE_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake
---
&gt; -- CMAKE_SYSTEM_VERSION=5.15.0-56-generic
528d518
&lt; -- COMPILER_BASENAME=aarch64-poky-linux-g++
531d520
&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;)
533,534c522
&lt; -- OE_QMAKE_PATH_EXTERNAL_HOST_BINS=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin
&lt; -- PRESET_CMAKE_SYSTEM_NAME=TRUE
---
&gt; -- PRESET_CMAKE_SYSTEM_NAME=FALSE
549d536
&lt; -- _CMAKE_TOOLCHAIN_PREFIX=aarch64-poky-linux-
552d538
&lt; -- _INCLUDED_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake
564d549
&lt; -- config=
575d559
&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:

确定