在GitHub Actions中构建基于Qt/cmake的项目。

7
我在我的项目中使用Qt 5.12.11。由于我想在Linux和Windows上都使用该软件,我选择了gcc编译器(我使用MSYS2,因此gcc是10.3.0)。本地构建在Linux和Windows上都没有问题,但是通过GitHub Actions构建时找不到qt(无论我是否设置了CMAKE_PREFIX_PATH或Qt5_DIR)。
所以这就是我陷入困境的地方。是否有人遇到过这样的问题或者有任何想法呢?
GitHub Action看起来像:
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.

1个回答

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
@Ali-G178 它对我有效,见我的测试仓库:https://github.com/eyllanesc/69108420 - eyllanesc
哇,我明白了。那我试着操作一下好了.. 再次感谢 :) - Ali-G178
1
@eyllanesc 好的,通过查看提交历史记录,我已经完全明白了。检出操作应该是第一个,因为它清除了(不确定,但似乎是)已经安装了Qt的工作区。这就是配置步骤失败的原因。感谢您的调查! - Ali-G178

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接