Configure and build CMake projects on GitHub Actions
Go to file
Alfi Maulana 4427f0f36d
feat: remove support for auto-install Ninja (#258)
* feat: remove support for auto-installing Ninja

* ci: add step for setting up Ninja in `test-action-with-custom-tools` job

* docs: update readme related to auto-install Ninja support removal
2024-03-22 18:14:44 +08:00
.github feat: remove support for auto-install Ninja (#258) 2024-03-22 18:14:44 +08:00
dist feat: remove support for auto-install Ninja (#258) 2024-03-22 18:14:44 +08:00
src feat: remove support for auto-install Ninja (#258) 2024-03-22 18:14:44 +08:00
test docs: improve wordings in the CMakeLists.txt 2023-06-29 14:24:25 +07:00
.env.yarn test: reimplement unit testing (#229) 2024-03-08 21:20:32 +07:00
.eslintrc.json test: modify lint command to only process src dir (#236) 2024-03-10 17:00:02 +07:00
.gitattributes build: adjust source files structures (#136) 2023-12-14 19:20:50 +08:00
.gitignore test: reimplement unit testing (#229) 2024-03-08 21:20:32 +07:00
action.yml feat: remove support for testing CMake projects (#256) 2024-03-22 17:06:56 +08:00
jest.config.json test: reimplement unit testing (#229) 2024-03-08 21:20:32 +07:00
LICENSE chore: bump copyright year to 2024 (#152) 2024-01-07 23:59:23 +08:00
package.json feat: remove support for auto-install Ninja (#258) 2024-03-22 18:14:44 +08:00
README.md feat: remove support for auto-install Ninja (#258) 2024-03-22 18:14:44 +08:00
tsconfig.json build: build distribution files directly from TypeScript files (#221) 2024-03-04 21:16:05 +08:00
yarn.lock feat: remove support for auto-install Ninja (#258) 2024-03-22 18:14:44 +08:00

CMake Action

Configure and build your CMake project using GitHub Actions. This action simplifies the workflow for configuring the build environment of a CMake project. It can also be optionally specified to build a CMake project using the cmake --build command.

Features

  • Configures a CMake project using the cmake command.
  • Optionally builds a CMake project using the cmake --build command.
  • 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.

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.

Outputs

Name Value Type Description
build-dir Path The build directory of the CMake project.

Examples

name: Build
on:
  push:
jobs:
  build-project:
    name: Build Project
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4.1.2

      - name: Configure Project
        uses: threeal/cmake-action@v1.3.0

      - name: Build Project
        runs: cmake --build build

Note

: You can replace v1.3.0 with any version you prefer. See this.

Configure and Build in the Same Step

- name: Configure and Build Project
  uses: threeal/cmake-action@v1.3.0
  with:
    run-build: true

Specify the Source and Build Directories

- name: Configure Project
  uses: threeal/cmake-action@v1.3.0
  with:
    source-dir: submodules
    build-dir: submodules/out

Using Ninja as the Generator and Clang as the Compiler

- name: Setup Ninja
  uses: seanmiddleditch/gha-setup-ninja@v4

- name: Configure Project
  uses: threeal/cmake-action@v1.3.0
  with:
    generator: Ninja
    c-compiler: clang
    cxx-compiler: clang++

License

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

Copyright © 2023-2024 Alfi Maulana