lukka / run-cmake

GitHub Action to build C++ applications with CMake (CMakePresets.json), Ninja and vcpkg on GitHub.
MIT License
173 stars 19 forks source link

[Question] How to force Release build? #75

Closed illia-bilinskyi closed 1 year ago

illia-bilinskyi commented 2 years ago

Hi, I'm trying to use your routine for building my stuff in GH actions. I want to build Release, and I succeed with it on my PC without any additional flags. But the routine keeps producing Debug. It also links to debug libraries, including MSVCRT, and I have liker issues. How to explicitly configure to build Release?

Here is my presets:

{
  "version": 3,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 22,
    "patch": 0
  },
  "configurePresets": [
    {
      "name": "default",
      "displayName": "Default Config",
      "description": "Default build",
      "binaryDir": "${sourceDir}/build",
      "cacheVariables": {
        "VCPKG_LOCATION": "${sourceDir}/vcpkg",
        "CMAKE_BUILD_TYPE": "Release",
        "CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS": true
      },
      "toolchainFile": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake"
    }
  ],
  "buildPresets": [
    {
      "name": "default",
      "configurePreset": "default"
    }
  ],
  "testPresets": [
    {
      "name": "default",
      "configurePreset": "default",
      "output": {"outputOnFailure": true},
      "execution": {"noTestsAction": "error", "stopOnFailure": true}
    }
  ]
}

And my yaml config:

name: CMake_vcpkg_autocache

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

env:
  BUILD_TYPE: Release

jobs:
  build:
    name: ${{ matrix.os }}-${{ github.workflow }},
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest]
        include:
          - os: windows-latest
            triplet: x64-windows-release
          - os: ubuntu-latest
            triplet: x64-linux-release

    env:
      VCPKG_DEFAULT_TRIPLET: ${{ matrix.triplet }}

    steps:
      - name: Checkout repository and submodules
        uses: actions/checkout@v2
        with:
          submodules: recursive

      - name: Install dependencies for Linux
        if: ${{ matrix.os == 'ubuntu-latest' }}
        run: sudo apt install curl clang make libboost-all-dev libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libglfw3 libglfw3-dev libxi-dev libtbb-dev

      - name: Restore artifacts, or setup vcpkg for building artifacts
        uses: lukka/run-vcpkg@main
        id: runvcpkg

      - name: List $RUNNER_WORKSPACE before build
        run: find $RUNNER_WORKSPACE
        shell: bash
      - name: Prints output of run-vcpkg's action.
        run: echo "root='${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_ROOT_OUT }}', triplet='${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_DEFAULT_TRIPLET_OUT }}' "

      - name: Run CMake+vcpkg
        uses: lukka/run-cmake@v10
        id: runcmake
        with:
          cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt'
          configurePreset: 'default'
          buildPreset: 'default'
          testPreset: 'default'

      - name: List $RUNNER_WORKSPACE after build
        run: find $RUNNER_WORKSPACE
        shell: bash
lukka commented 2 years ago

@illia-bilinskyi my guess is that depends on the generator that CMake is going to pick up at run time in the configure phase. Since you did not specify it, if CMake picks a multi-configuration generator, the CMAKE_BUILD_TYPE is ignored.

I think you just need to ensure you are using a single-configuration CMake generator, e.g. add to the configure section: "generator": "Ninja",

If this does not help, could you please add a link to the workflow run so that the output can be inspected in detail?

lukka commented 1 year ago

@illia-bilinskyi let me know if you solved the problem already, do not hesitate if you have questions or feedback, thanks!