|
1 | 1 | # CMake Action |
2 | 2 |
|
3 | | -[](https://github.com/threeal/cmake-action/releases/) |
4 | | -[](./LICENSE) |
5 | | -[](https://github.com/threeal/cmake-action/actions/workflows/test.yml) |
| 3 | +[](https://github.com/threeal/cmake-action/releases/) |
| 4 | +[](./LICENSE) |
| 5 | +[](https://github.com/threeal/cmake-action/actions/workflows/test.yml) |
6 | 6 |
|
7 | | -Configure, build, and test a [CMake](https://cmake.org/) project on [GitHub Actions](https://github.com/features/actions). |
8 | | -Use this action to simplify the workflow run of your CMake project. |
9 | | -This action will configure a build environment for your project using the `cmake` command, |
10 | | - then it will build your project by running a `cmake --build` command, |
11 | | - and last it could test your project using the `ctest` command. |
| 7 | +Configure, build, and test your [CMake](https://cmake.org/) project using [GitHub Actions](https://github.com/features/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. |
12 | 8 |
|
13 | 9 | ## Features |
14 | 10 |
|
15 | | -- Configure and build a project using the [cmake](https://cmake.org/cmake/help/latest/manual/cmake.1.html) command. |
16 | | -- Optionally test a project using the [ctest](https://cmake.org/cmake/help/latest/manual/ctest.1.html) command. |
17 | | -- Auto-detect and install required dependencies. |
18 | | -- Specify multiple CMake options directly from the Action inputs. |
| 11 | +- Configures a project using the [`cmake`](https://cmake.org/cmake/help/latest/manual/cmake.1.html) command. |
| 12 | +- Option to build a project using the `cmake --build` command. |
| 13 | +- Option to test a project using the [`ctest`](https://cmake.org/cmake/help/latest/manual/ctest.1.html) command. |
| 14 | +- Auto-detects and installs required dependencies. |
| 15 | +- Supports specifying multiple CMake options directly from the Action inputs. |
19 | 16 |
|
20 | 17 | ## Usage |
21 | 18 |
|
22 | | -For more information, see [action.yml](./action.yml) and [GitHub Actions guide](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions). |
| 19 | +For more information, refer to [action.yml](./action.yml) and the [GitHub Actions guide](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions). |
23 | 20 |
|
24 | 21 | ### Inputs |
25 | 22 |
|
26 | 23 | | Name | Value Type | Description | |
27 | 24 | | --- | --- | --- | |
28 | | -| `source-dir` | Path | Source directory of the CMake project. Defaults to current directory. | |
29 | | -| `build-dir` | Path | Build directory of the CMake project. Defaults to `build` directory inside the source directory. | |
30 | | -| `targets` | Multiple strings | List of build targets. | |
31 | | -| `run-test` | `true` or `false` | If enabled, run testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. | |
32 | | -| `generator` | String | Build system generator of the CMake project. | |
33 | | -| `c-compiler` | String | Preferred executable for compiling C language files. | |
34 | | -| `cxx-compiler` | String | Preferred executable for compiling C++ language files. | |
35 | | -| `c-flags` | Multiple strings | Additional flags passed when compiling C language files. | |
36 | | -| `cxx-flags` | Multiple strings | Additional flags passed when compiling C++ language files. | |
37 | | -| `args` | Multiple strings | Additional arguments passed during the CMake configuration. | |
38 | | -| `test-args` | Multiple strings | Additional arguments passed during the CTest run. | |
39 | | - |
40 | | -> Note: Multiple strings mean that the input could be specified with more than one value. Separate each value with a space or a new line. |
41 | | -
|
42 | | -> Note: All inputs are optional. |
| 25 | +| `source-dir` | Path | The source directory of the CMake project. It defaults to the current directory. | |
| 26 | +| `build-dir` | Path | The build directory of the CMake project. It defaults to the `build` directory inside the source directory. | |
| 27 | +| `generator` | String | The build system generator for the CMake project. It appends the CMake configuration arguments with `-G [val]`. | |
| 28 | +| `c-compiler` | String | The preferred executable for compiling C language files. It appends the CMake configuration arguments with `-D CMAKE_C_COMPILER=[val]`. | |
| 29 | +| `cxx-compiler` | String | The preferred executable for compiling C++ language files. It appends the CMake configuration arguments with `-D CMAKE_CXX_COMPILER=[val]`. | |
| 30 | +| `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]`. | |
| 31 | +| `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]`. | |
| 32 | +| `options` | Multiple strings | Additional options to pass during the CMake configuration. It appends the CMake configuration arguments with each of `-D [val]`. | |
| 33 | +| `args` | Multiple strings | Additional arguments to pass during the CMake configuration. | |
| 34 | +| `run-build` | `true` or `false` | If enabled, it builds the project using CMake. It defaults to `false`. | |
| 35 | +| `build-args` | Multiple strings | Additional arguments to pass during the CMake build. | |
| 36 | +| `run-test` | `true` or `false` | If enabled, it runs testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). It defaults to `false`. | |
| 37 | +| `test-args` | Multiple strings | Additional arguments to pass during the CTest run. | |
| 38 | + |
| 39 | +> **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. |
| 40 | +
|
| 41 | +> **Note**: All inputs are optional. |
43 | 42 |
|
44 | 43 | ### Examples |
45 | 44 |
|
46 | 45 | ```yaml |
47 | | -name: build |
| 46 | +name: Build |
48 | 47 | on: |
49 | 48 | push: |
50 | 49 | jobs: |
51 | 50 | build-project: |
52 | 51 | runs-on: ubuntu-latest |
53 | 52 | steps: |
54 | | - - name: Check out this repository |
55 | | - uses: actions/checkout@v3.3.0 |
| 53 | + - name: Checkout the repository |
| 54 | + uses: actions/checkout@v3.5.3 |
56 | 55 |
|
57 | | - - name: Configure and build this project |
58 | | - uses: threeal/cmake-action@latest |
| 56 | + - name: Configure the project |
| 57 | + uses: threeal/cmake-action@main |
| 58 | + |
| 59 | + - name: Build the project |
| 60 | + runs: cmake --build build |
| 61 | + |
| 62 | + - name: Test the project |
| 63 | + runs: ctest --test-dir build |
59 | 64 | ``` |
60 | 65 |
|
61 | | -> Note: You can replace `@latest` with any version you like. See [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses). |
| 66 | +> **Note**: You can replace `@main` with any version you prefer. See [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses). |
62 | 67 |
|
63 | | -#### Specify the Source and the Build Directories |
| 68 | +#### Specify the Source and Build Directories |
64 | 69 |
|
65 | 70 | ```yaml |
66 | | -- name: Configure and build this project |
67 | | - uses: threeal/cmake-action@latest |
| 71 | +- name: Configure the project |
| 72 | + uses: threeal/cmake-action@main |
68 | 73 | with: |
69 | 74 | source-dir: submodules |
70 | 75 | build-dir: submodules/out |
71 | 76 | ``` |
72 | 77 |
|
73 | | -#### Specify the Build Targets |
74 | | - |
75 | | -```yaml |
76 | | -- name: Configure and build this project |
77 | | - uses: threeal/cmake-action@latest |
78 | | - with: |
79 | | - targets: hello_mars hello_sun |
80 | | -``` |
81 | | - |
82 | | -#### Run Unit Tests After Build |
| 78 | +#### Configure, Build, and Test in the Same Step |
83 | 79 |
|
84 | 80 | ```yaml |
85 | | -- name: Configure, build, and test this project |
86 | | - uses: threeal/cmake-action@latest |
| 81 | +- name: Configure, build, and test the project |
| 82 | + uses: threeal/cmake-action@main |
87 | 83 | with: |
88 | | - args: -DBUILD_TESTING=ON |
| 84 | + options: BUILD_TESTING=ON |
| 85 | + run-build: true |
89 | 86 | run-test: true |
90 | 87 | ``` |
91 | 88 |
|
92 | 89 | #### Using Ninja as the Generator and Clang as the Compiler |
93 | 90 |
|
94 | 91 | ```yaml |
95 | | -- name: Configure and build this project |
96 | | - uses: threeal/cmake-action@latest |
| 92 | +- name: Configure and build the project |
| 93 | + uses: threeal/cmake-action@main |
97 | 94 | with: |
98 | 95 | generator: Ninja |
99 | 96 | c-compiler: clang |
|
0 commit comments