Skip to content

Commit 1524843

Browse files
committed
feat(setup-cmake): an action to setup cmake
1 parent 3017df4 commit 1524843

30 files changed

+21310
-427
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ jobs:
111111
- name: CMake Workflow
112112
uses: ./cmake-workflow
113113
with:
114-
cmake-version: '>=3.8'
115-
cmake-min-version: ${{ matrix.container && '3.8' }}
114+
cmake-version: '>=3.20'
116115
source-dir: tests
117116
generator: ${{ matrix.generator }}
118117
toolchain: ${{ steps.package-install.outputs.vcpkg-toolchain }}

README.adoc

Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ NOTE: READ THE DOCS: https://alandefreitas.github.io/cpp-actions/
3030
- <<boost-clone>>
3131
- <<b2-workflow>>
3232
- <<create-changelog>>
33+
- <<setup-cmake>>
3334

3435
=== Install dependencies [[package-install]]
3536
:reftext: Install dependencies
@@ -155,7 +156,7 @@ steps:
155156
- name: CMake Workflow
156157
uses: alandefreitas/cpp-actions/cmake-workflow@master
157158
with:
158-
cmake-version: '>=3.8'
159+
cmake-version: '>=3.20'
159160
source-dir: tests
160161
toolchain: ${{ steps.package-install.outputs.vcpkg-toolchain }}
161162
run-tests: 'true'
@@ -167,36 +168,15 @@ steps:
167168
ref-source-dir: .
168169
----
169170

170-
Example 2 (`cmake-min-version`):
171+
Example 2 (`build-type`, `generator`):
171172

172173
[source,yml]
173174
----
174175
steps:
175176
- name: CMake Workflow
176177
uses: alandefreitas/cpp-actions/cmake-workflow@master
177178
with:
178-
cmake-version: '>=3.8'
179-
cmake-min-version: '3.8'
180-
source-dir: tests
181-
toolchain: ${{ steps.package-install.outputs.vcpkg-toolchain }}
182-
run-tests: 'true'
183-
install-prefix: $GITHUB_WORKSPACE/.local
184-
cxxstd: '11'
185-
cxx: g++-4.8
186-
cc: gcc-4.8
187-
extra-args: -D BOOST_SRC_DIR=$GITHUB_WORKSPACE/boost-root
188-
ref-source-dir: .
189-
----
190-
191-
Example 3 (`build-type`, `generator`):
192-
193-
[source,yml]
194-
----
195-
steps:
196-
- name: CMake Workflow
197-
uses: alandefreitas/cpp-actions/cmake-workflow@master
198-
with:
199-
cmake-version: '>=3.8'
179+
cmake-version: '>=3.20'
200180
source-dir: tests
201181
generator: Unix Makefiles
202182
toolchain: ${{ steps.package-install.outputs.vcpkg-toolchain }}
@@ -207,15 +187,15 @@ steps:
207187
ref-source-dir: .
208188
----
209189

210-
Example 4 (`cxxflags`):
190+
Example 3 (`cxxflags`):
211191

212192
[source,yml]
213193
----
214194
steps:
215195
- name: CMake Workflow
216196
uses: alandefreitas/cpp-actions/cmake-workflow@master
217197
with:
218-
cmake-version: '>=3.8'
198+
cmake-version: '>=3.20'
219199
source-dir: tests
220200
toolchain: ${{ steps.package-install.outputs.vcpkg-toolchain }}
221201
run-tests: 'true'
@@ -232,29 +212,14 @@ steps:
232212

233213
|===
234214
|Parameter |Description |Default
235-
|`cmake-exec` |The cmake executable. |`cmake`
215+
|`cmake-path` |The cmake executable. |`cmake`
236216
|`cmake-version` |A semver range string with the cmake versions supported by this workflow.
237217

238-
If the existing version in the environment does not satisfy this requirement, the action attempts
239-
to install or update CMake using cmake-min-version.
240-
241-
If this input is undefined, the version ">= cmake-min-version" is considered.
218+
If the existing version in the environment does not satisfy this requirement, the action install
219+
the min CMake version that satisfies it.
242220

243221
This should usually match the `cmake_minimum_required` defined in your CMakeLists.txt file.
244222
. |
245-
|`cmake-min-version` |Set the minimum cmake version for this workflow when the cmake-version requirement is not satisfied.
246-
247-
If the existing version in the environment does not satisfy this cmake-version requirement,
248-
the action attempts to install or update CMake using this cmake-min-version.
249-
250-
If cmake-version is not set, this option overrides the `cmake-version` input as `>= cmake-min-version`.
251-
252-
If cmake-min-version is not defined, the action attempts to extract the cmake-min-version
253-
from CMakeLists.txt.
254-
255-
If a minimum version cannot be found in CMakeLists.txt, the lastest CMake version is considered
256-
the minimum version.
257-
. |
258223
|`source-dir` |Directory for the source files. |`.`
259224
|`build-dir` |Directory for the binaries relative to the source directory. |`build`
260225
|`cc` |Path to C compiler. |
@@ -540,6 +505,64 @@ This constraint does not apply to the current and latest commit.
540505
|`trace-commands` |Trace commands executed by the workflow. |`false`
541506
|===
542507

508+
=== Setup CMake [[setup-cmake]]
509+
:reftext: Setup CMake
510+
:navtitle: Setup CMake Action
511+
// This setup-cmake.adoc file is automatically generated.
512+
// Edit parse_actions.py instead.
513+
514+
Set up a specific version of a CMake compiler and add it to the PATH.
515+
516+
This action will also set-up any dependencies required by CMake.
517+
518+
In most workflows, this is used as an auxiliary action for the cmake-workflow action.
519+
520+
521+
==== Input Parameters
522+
523+
|===
524+
|Parameter |Description |Default
525+
|`version` |Version range or exact version of CMake to use, using SemVer's version range syntax.
526+
527+
Reads from `cmake-file` input if unset.
528+
529+
By default, it uses any version available in the environment.
530+
. |`*`
531+
|`cmake-file` |File containing the CMake version to use in a cmake_minimum_required command.
532+
533+
Example: A CMakeLists.txt file containing a call to cmake_minimum_required."
534+
. |`CMakeLists.txt`
535+
|`cmake-path` |The cmake executable. We attempt to find cmake at this path first. |`cmake`
536+
|`cache` |Used to specify whether the CMake installation should be cached in the case CMake needs to be downloaded."
537+
. |`True`
538+
|`architecture` |The target architecture (x86, x64). By default, this value is inferred.
539+
. |
540+
|`check-latest` |By default, when CMake is not available, this action will install the minimum version in the version spec.
541+
This ensures the code respects its contract in terms of what minimum CMake version is supported.
542+
543+
Set this option if you want the action to check for the latest available version that satisfies the version spec
544+
instead.
545+
. |
546+
|`update-environment` |Set this option if you want the action to update environment variables. |`True`
547+
|`trace-commands` |Trace commands executed by the workflow. |`false`
548+
|===
549+
550+
==== Outputs
551+
552+
|===
553+
|Output |Description
554+
|`version` |The installed CMake version. Useful when given a version range as input.
555+
|`version-major` |The installed CMake version major. Useful when given a version range as input.
556+
|`version-minor` |The installed CMake version minor. Useful when given a version range as input.
557+
|`version-patch` |The installed CMake version patch. Useful when given a version range as input.
558+
|`cache-hit` |A boolean value to indicate a cache entry was found
559+
|`path` |The absolute path to the CMake executable.
560+
|`dir` |The absolute path to the CMake directory.
561+
|`supports-path-to-build` |Whether CMake supports the -B <path-to-build> syntax
562+
|`supports-parallel-build` |Whether CMake supports the -j <threads> syntax
563+
|`supports-build-multiple-targets` |Whether CMake supports the --target with multiple targets
564+
|`supports-cmake-install` |Whether CMake supports the cmake --install
565+
|===
543566

544567

545568
== Contributions

0 commit comments

Comments
 (0)