【问题标题】:Build Qt/cmake based project in GitHub Actions在 GitHub Actions 中构建基于 Qt/cmake 的项目
【发布时间】:2021-11-05 13:02:30
【问题描述】:

我在我的项目中使用 Qt 5.12.11。由于我想在 linux 和 win 上都使用该软件,所以我选择了 gcc 编译器(我使用 MSYS2,所以 gcc 是 10.3.0)。对于 linux 和 win,本地构建都可以,但是通过 GitHub Actions 构建时找不到 qt(无论我是否设置了 CMAKE_PREFIX_PATH 或 Qt5_DIR)。

所以这是我被困了一段时间的地方。有没有人遇到过这样的问题或者有什么想法?

github 动作看起来像

name: Build

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

env:
  BUILD_TYPE: Release

jobs:
  build:
    runs-on: windows-latest
    defaults:
        run:
            shell: msys2 {0}

    steps:
      - uses: msys2/setup-msys2@v2
        with:
            install: mingw-w64-x86_64-toolchain
            msystem: mingw64
            release: false

      - name: Install Qt
        uses: jurplel/install-qt-action@v2
        with:
          version: '5.12.11'
          host: 'windows'
          target: 'desktop'
          arch: 'win64_mingw73'
          dir: '${{github.workspace}}/qt/'
          install-deps: 'true'

      - name: List files in Qt
        run: find ${{env.Qt5_Dir}}

      - uses: actions/checkout@v2

      - name: Configure CMake
        run: cmake -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_PREFIX_PATH="${{env.Qt5_Dir}}/lib/cmake/" -DQt5_DIR=${{env.Qt5_Dir}}/lib/cmake/Qt5/ -G "CodeBlocks - MinGW Makefiles" -B '${{github.workspace}}'/build

      - name: Build
        run: cmake --build '${{github.workspace}}'/build --target RePr

我也尝试过-DCMAKE_PREFIX_PATH="${{env.Qt5_Dir}}/lib/cmake/Qt5/",但没有帮助。 :( 如果我直接从 cmakelists 设置 CMAKE_PREFIX_PATH 我观察到相同的行为。

它失败的CMakeLists非常简单和常见(它是一个使用qt的嵌套包,所以不要混淆不同的cmakelists项目和构建目标)

cmake_minimum_required(VERSION 3.14)
project(RePr_controller)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(QT_VERSION 5)
set(REQUIRED_LIBS Core Gui Widgets)
set(REQUIRED_LIBS_QUALIFIED Qt5::Core Qt5::Gui Qt5::Widgets)

add_library(${PROJECT_NAME} main_window.cpp main_window.h main_window.ui resources/resources.qrc)
add_dependencies(${PROJECT_NAME} FacadeLib)
target_link_libraries(${PROJECT_NAME} FacadeLib Utils)

find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED)
target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED})

直接从 cmakelists 返回消息传递 CMAKE_PREFIX_PATH

D:/a/RePr/RePr/qt/Qt/5.12.11/mingw73_64/lib/cmake/

qt5 来了

D:/a/RePr/RePr/qt/Qt/5.12.11/mingw73_64/lib/cmake/Qt5/Qt5Config.cmake

最后,我从配置步骤中得到了这条消息

cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="D:/a/RePr/RePr/qt/Qt/5.12.11/mingw73_64/lib/cmake/" -DQt5_DIR=D:/a/RePr/RePr/qt/Qt/5.12.11/mingw73_64/lib/cmake/Qt5/ -G "CodeBlocks - MinGW Makefiles" -B 'D:\a\RePr\RePr'/build
  shell: D:\a\_temp\msys\msys2.CMD {0}
  env:
    BUILD_TYPE: Release
    MSYSTEM: MINGW64
    pythonLocation: C:\hostedtoolcache\windows\Python\3.9.6\x64
    Qt5_Dir: D:/a/RePr/RePr/qt/Qt/5.12.11/mingw73_64
    QT_PLUGIN_PATH: D:/a/RePr/RePr/qt/Qt/5.12.11/mingw73_64/plugins
    QML2_IMPORT_PATH: D:/a/RePr/RePr/qt/Qt/5.12.11/mingw73_64/qml
-- The C compiler identification is GNU 10.3.0
-- The CXX compiler identification is GNU 10.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done

CMake Error at Controller/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
-- Configuring incomplete, errors occurred!
See also "D:/a/RePr/RePr/build/CMakeFiles/CMakeOutput.log".
  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.


Error: Process completed with exit code 1.

【问题讨论】:

标签: c++ qt cmake github-actions msys2


【解决方案1】:

将 CMAKE_PREFIX_PATH 设置为 Qt5_Dir:

- name: Configure CMake
  env:
    CMAKE_PREFIX_PATH: ${{env.Qt5_Dir}}
  run: cmake -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -G "CodeBlocks - MinGW Makefiles" -B '${{github.workspace}}'/build

【讨论】:

  • 谢谢,但这没有帮助。我现在怀疑这是可能的。仍然是同样的错误。变量现在可见 ``` CMAKE_PREFIX_PATH: D:/a/RePr/RePr/qt/Qt/5.12.11/mingw73_64 ```
  • @Ali-G178 它对我有用,请参阅我的测试仓库:github.com/eyllanesc/69108420
  • 哇,我明白了。那让我玩一下吧..再次感谢:)
  • @eyllanesc 好的,查看提交历史对我来说一切都变得清晰了。结帐操作应该是第一个,因为它清除(不确定,但似乎是)已经安装了 qt 的工作区。这就是配置步骤失败的原因。感谢您的调查!
猜你喜欢
  • 2020-01-08
  • 2017-04-10
  • 2022-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-11
  • 1970-01-01
  • 2018-02-01
相关资源
最近更新 更多