Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
terminal

GitHub Action

CMake Action

v1.2.0

CMake Action

terminal

CMake Action

Configure and build CMake projects

Installation

Copy and paste the following snippet into your .yml file.

              

- name: CMake Action

uses: threeal/cmake-action@v1.2.0

Learn more about this action in threeal/cmake-action

Choose a version

CMake Action

Latest Version License Test Status

Configure, build, and test your CMake project using GitHub Actions. This action simplifies the workflow for your CMake project. It configures the build environment using the cmake command, and optionally builds the project using the cmake --build command and tests the project using the ctest command.

Features

  • Configures a project using the cmake command.
  • Option to build a project using the cmake --build command.
  • Option to test a project using the ctest command.
  • Auto-detects and installs required dependencies.
  • Supports specifying multiple CMake options directly from the Action inputs.

Usage

For more information, refer to action.yml and the GitHub Actions guide.

Inputs

Name Value Type Description
source-dir Path The source directory of the CMake project. It defaults to the current directory.
build-dir Path The build directory of the CMake project. It defaults to the build directory inside the source directory.
generator String The build system generator for the CMake project. It appends the CMake configuration arguments with -G [val].
c-compiler String The preferred executable for compiling C language files. It appends the CMake configuration arguments with -D CMAKE_C_COMPILER=[val].
cxx-compiler String The preferred executable for compiling C++ language files. It appends the CMake configuration arguments with -D CMAKE_CXX_COMPILER=[val].
c-flags Multiple strings Additional flags to pass when compiling C language files. It appends the CMake configuration arguments with -D CMAKE_C_FLAGS=[vals].
cxx-flags Multiple strings Additional flags to pass when compiling C++ language files. It appends the CMake configuration arguments with -D CMAKE_CXX_FLAGS=[vals].
options Multiple strings Additional options to pass during the CMake configuration. It appends the CMake configuration arguments with each of -D [val].
args Multiple strings Additional arguments to pass during the CMake configuration.
run-build true or false If enabled, it builds the project using CMake. It defaults to false.
build-args Multiple strings Additional arguments to pass during the CMake build.
run-test true or false If enabled, it runs testing using CTest. It defaults to false.
test-args Multiple strings Additional arguments to pass during the CTest run.

Note: Multiple strings mean that the input can be specified with more than one value. Separate each value with a space or a new line.

Note: All inputs are optional.

Examples

name: Build
on:
  push:
jobs:
  build-project:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the repository
        uses: actions/checkout@v3.5.3

      - name: Configure the project
        uses: threeal/cmake-action@main

      - name: Build the project
        runs: cmake --build build

      - name: Test the project
        runs: ctest --test-dir build

Note: You can replace @main with any version you prefer. See this.

Specify the Source and Build Directories

- name: Configure the project
  uses: threeal/cmake-action@main
  with:
    source-dir: submodules
    build-dir: submodules/out

Configure, Build, and Test in the Same Step

- name: Configure, build, and test the project
  uses: threeal/cmake-action@main
  with:
    options: BUILD_TESTING=ON
    run-build: true
    run-test: true

Using Ninja as the Generator and Clang as the Compiler

- name: Configure and build the project
  uses: threeal/cmake-action@main
  with:
    generator: Ninja
    c-compiler: clang
    cxx-compiler: clang++

License

This project is licensed under the terms of the MIT License.

Copyright © 2023 Alfi Maulana