英文:
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'
...
...在功能上是相同的(顺序略有不同,但所有变量都完全相同)。
我不确定问题出在哪里,是在bash
、docker
、cmake
还是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'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 "${_variableName}=${${_variableName}}")
endforeach()
The diff:
< -- 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>
---
> -- CMAKE_CXX_ARCHIVE_FINISH_IPO="/usr/bin/gcc-ranlib" <TARGET>
48,49c47,48
< -- 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
< -- 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
---
> -- CMAKE_CXX_COMPILER_AR=/usr/bin/gcc-ar
> -- CMAKE_CXX_COMPILER_AR=/usr/bin/gcc-ar
315,316c314,315
< -- 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
< -- 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
---
> -- CMAKE_CXX_COMPILER_RANLIB=/usr/bin/gcc-ranlib
> -- CMAKE_CXX_COMPILER_RANLIB=/usr/bin/gcc-ranlib
333c332
< -- CMAKE_CXX_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
---
> -- CMAKE_CXX_FLAGS=-O2 -pipe -g -feliminate-unused-debug-types
366d364
< -- CMAKE_C_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
396,400d393
< -- 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
< -- CMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY
< -- CMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY
< -- CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY
< -- CMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
419d411
< -- CMAKE_LDFLAGS_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
423,424c415,416
< -- CMAKE_LINKER=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld
< -- CMAKE_LINKER=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld
---
> -- CMAKE_LINKER=/usr/bin/ld
> -- CMAKE_LINKER=/usr/bin/ld
444,446c436,438
< -- CMAKE_NM=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-nm
< -- CMAKE_OBJCOPY=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-objcopy
< -- CMAKE_OBJDUMP=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-objdump
---
> -- CMAKE_NM=/usr/bin/nm
> -- CMAKE_OBJCOPY=/usr/bin/objcopy
> -- CMAKE_OBJDUMP=/usr/bin/objdump
454,455c446,447
< -- CMAKE_RANLIB=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ranlib
< -- CMAKE_RANLIB=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ranlib
---
> -- CMAKE_RANLIB=/usr/bin/ranlib
> -- CMAKE_RANLIB=/usr/bin/ranlib
511,512c503,504
< -- CMAKE_STRIP=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-strip
< -- CMAKE_SYSTEM=Linux
---
> -- CMAKE_STRIP=/usr/bin/strip
> -- CMAKE_SYSTEM=Linux-5.15.0-56-generic
519c511
< -- CMAKE_SYSTEM_PROCESSOR=aarch64
---
> -- CMAKE_SYSTEM_PROCESSOR=x86_64
522,523c514
< -- CMAKE_SYSTEM_VERSION=
< -- CMAKE_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake
---
> -- CMAKE_SYSTEM_VERSION=5.15.0-56-generic
528d518
< -- COMPILER_BASENAME=aarch64-poky-linux-g++
531d520
< -- INCLUDE_CMAKE_TOOLCHAIN_FILE_IF_REQUIRED=include("/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake")
533,534c522
< -- OE_QMAKE_PATH_EXTERNAL_HOST_BINS=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin
< -- PRESET_CMAKE_SYSTEM_NAME=TRUE
---
> -- PRESET_CMAKE_SYSTEM_NAME=FALSE
549d536
< -- _CMAKE_TOOLCHAIN_PREFIX=aarch64-poky-linux-
552d538
< -- _INCLUDED_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake
564d549
< -- config=
575d559
< -- 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 "cmake /src"
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 "cmake /src"
不等同于 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 "cmake -DCMAKE_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake'"
。
英文:
The reason /bin/bash -c "cmake /src"
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 "cmake -DCMAKE_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake'"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论