CMake Workflow
This action runs a complete CMake workflow from source files.
This is usually the next step in your workflow after setting up a C++ compiler and fetching dependencies with Install Packages.
A workflow is composed of the following steps:
-
Configure
-
Build
-
Test
-
Install
The action also sets up the environment for the workflow:
-
It validates the CMake version installed in the system,
-
Updates CMake if the library has a different minimum version,
-
Identifies what features the current CMake version supports, and
-
Runs a complete cmake workflow
The action will adjusts the parameters as needed according to the features that CMake version supports. For instance,
-
If the CMake version does not support the
-S … -B …syntax, the action will create the build directory and run the configuration step from there. -
If the specified or default generator is multi-config,
CMAKE_CONFIGURATION_TYPESwill be used instead ofCMAKE_BUILD_TYPE, since the later is ignored by these generators. -
If the CMake version does not support the
cmake --installsyntax, thecmake --build --target installwill be use instead. -
If the CMake version does not support multiple targets in the
cmake --buildsyntax, the action will run the build step once for each target.
The action also creates GitHub annotations when warnings or errors are emitted at any of these steps. This includes annotations for CMake errors at the configure step and build errors emitted from the compiler at the build step.
Next steps
After running the a complete CMake workflow for your project, the next step in your workflow should usually be
the generation of reports, with tools such as the Create Flamegraph (when matrix.time-trace) and
Create Changelog (usually in another workflow job). You can also include customs steps to
upload coverage reports (when matrix.coverage).
If your project provides CMake installation and configuration scripts, it is also usual to include multiple CMake workflow steps as integration tests for CMake.
Example
steps:
- name: CMake Workflow
uses: alandefreitas/cpp-actions/cmake-workflow@v1.6.1
with:
cmake-version: '>=3.20'
source-dir: tests
generator: ${{ matrix.generator }}
toolchain: ${{ steps.package-install.outputs.vcpkg-toolchain }}
build-type: ${{ matrix.build-type }}
run-tests: true
install-prefix: $GITHUB_WORKSPACE/.local
cxxstd: ${{ matrix.cxxstd }}
cc: ${{ steps.setup-cpp.outputs.cc || matrix.cc }}
ccflags: ${{ matrix.ccflags }}
cxx: ${{ steps.setup-cpp.outputs.cxx || matrix.cxx }}
cxxflags: ${{ matrix.cxxflags }}
shared: ${{ matrix.shared }}
extra-args: ${{ ( !matrix.no-deps && format('-D BOOST_SRC_DIR="{0}"', steps.boost-clone.outputs.boost-dir)
) || '' }} ${{ ( matrix.no-deps && '-D CPP_ACTIONS_NO_DEPS=ON' ) || '' }}
export-compile-commands: ${{ matrix.time-trace }}
package: true
package-artifact: ${{ matrix.is-main }}
ref-source-dir: .
Input Parameters
Parameter |
Description |
Default |
|
The cmake executable. |
|
|
A semver range string with the cmake versions supported by this workflow. If the existing version in the environment does not satisfy this requirement, the action install the min CMake version that satisfies it. This should usually match the |
|
|
Directory for the source files. |
|
|
Directory for the binaries relative to the source directory. |
|
|
Path to C compiler. |
|
|
Flags to be used with the C compiler. |
|
|
Path to C++ compiler. |
|
|
List of standards with which cmake will build and test the program. |
|
|
Flags to be used with the C++ compiler. |
|
|
Determines if add_library should create shared libraries ( |
|
|
Path to toolchain. |
|
|
Generator name. |
|
|
Build type. |
|
|
Targets to build instead of the default target. |
|
|
Path where the library should be installed. |
|
|
Extra arguments to cmake configure command. |
|
|
Set CMAKE_EXPORT_COMPILE_COMMANDS=ON. |
|
|
Whether we should run tests. |
|
|
Whether we should install the library. The library is only installed once in the The latest std version described in |
|
|
Run cpack with the specified generators after the install step. |
|
|
The name of the package (or application). If not specified, it defaults to the project name. |
|
|
The directory in which the packages are generated by cpack. If it is not set then this will default to the build dir. The CPACK_PACKAGE_DIRECTORY may be defined in CMakeLists.txt, a CPack config file or from the cpack command line option -B. If set, the command line option overrides the value found in the config file. |
|
|
Override/define CPACK_PACKAGE_VENDOR. |
|
|
A semicolon-separated list of generator names used by cpack. If this variable is not set, the action will attempt to generate the package with all cpack generators available to CMake. |
|
|
Whether the packages generated with cpack should be stored as action artifacts. |
|
|
Create github annotations on errors. |
|
|
A reference source directory for annotations. Any annotation filename will be relative to this directory. This is typically useful when the repository being tested is not the current directory, in which we need to make annotations relative to some other directory. In most cases, the default option should be enough. |
|
|
Trace commands executed by the workflow. |
|