mirror of
https://github.com/threeal/cmake-action.git
synced 2025-06-09 02:31:21 +00:00
Merge pull request #11 from threeal/add-compiler-inputs
Add Compiler Input Option
This commit is contained in:
commit
0a276cb8d8
34
.github/workflows/test.yml
vendored
34
.github/workflows/test.yml
vendored
@ -53,6 +53,40 @@ jobs:
|
|||||||
- name: Check if default build directory is not exist
|
- name: Check if default build directory is not exist
|
||||||
run: test ! -d build
|
run: test ! -d build
|
||||||
|
|
||||||
|
use-action-with-specified-compiler:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
lang: [C, CXX]
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3.3.0
|
||||||
|
|
||||||
|
- name: Use this action with specified invalid compiler
|
||||||
|
id: failed_step
|
||||||
|
continue-on-error: true
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
source-dir: test
|
||||||
|
c-compiler: ${{ matrix.lang == 'C' && 'invalid' || '' }}
|
||||||
|
cxx-compiler: ${{ matrix.lang == 'CXX' && 'invalid' || '' }}
|
||||||
|
|
||||||
|
- name: Check if previous step is failing
|
||||||
|
run: ${{ steps.failed_step.outcome == 'failure' && 'true' || 'false' }}
|
||||||
|
|
||||||
|
- name: Use this action with specified compiler
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
source-dir: test
|
||||||
|
c-compiler: ${{ matrix.lang == 'C' && 'clang' || '' }}
|
||||||
|
cxx-compiler: ${{ matrix.lang == 'CXX' && 'clang++' || '' }}
|
||||||
|
args: |
|
||||||
|
-D BUILD_C=${{ matrix.lang == 'C' && 'ON' || 'OFF' }}
|
||||||
|
-D BUILD_CXX=${{ matrix.lang == 'CXX' && 'ON' || 'OFF' }}
|
||||||
|
|
||||||
|
- name: Run build result
|
||||||
|
run: build/${{ matrix.lang == 'C' && 'hello_world_c' || 'hello_world' }}
|
||||||
|
|
||||||
use-action-with-additional-args:
|
use-action-with-additional-args:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
16
action.yml
16
action.yml
@ -13,6 +13,12 @@ inputs:
|
|||||||
description: The build directory of CMake project
|
description: The build directory of CMake project
|
||||||
required: false
|
required: false
|
||||||
default: build
|
default: build
|
||||||
|
c-compiler:
|
||||||
|
description: The preferred executable for compiling C language files
|
||||||
|
required: false
|
||||||
|
cxx-compiler:
|
||||||
|
description: The preferred executable for compiling CXX language files
|
||||||
|
required: false
|
||||||
args:
|
args:
|
||||||
description: Additional arguments passed during CMake configuration
|
description: Additional arguments passed during CMake configuration
|
||||||
required: false
|
required: false
|
||||||
@ -24,11 +30,17 @@ runs:
|
|||||||
run: |
|
run: |
|
||||||
CONFIGURE_ARGS="${{ inputs.source-dir }} -B ${{ inputs.build-dir }}"
|
CONFIGURE_ARGS="${{ inputs.source-dir }} -B ${{ inputs.build-dir }}"
|
||||||
BUILD_ARGS="--build ${{ inputs.build-dir }}"
|
BUILD_ARGS="--build ${{ inputs.build-dir }}"
|
||||||
|
if [ -n '${{ inputs.c-compiler }}' ]; then
|
||||||
|
CONFIGURE_ARGS="$CONFIGURE_ARGS -D CMAKE_C_COMPILER=${{ inputs.c-compiler }}"
|
||||||
|
fi
|
||||||
|
if [ -n '${{ inputs.cxx-compiler }}' ]; then
|
||||||
|
CONFIGURE_ARGS="$CONFIGURE_ARGS -D CMAKE_CXX_COMPILER=${{ inputs.cxx-compiler }}"
|
||||||
|
fi
|
||||||
if [ -n '${{ inputs.args }}' ]; then
|
if [ -n '${{ inputs.args }}' ]; then
|
||||||
CONFIGURE_ARGS="$CONFIGURE_ARGS ${{ inputs.args }}"
|
CONFIGURE_ARGS="$CONFIGURE_ARGS ${{ inputs.args }}"
|
||||||
fi
|
fi
|
||||||
echo "CMAKE_CONFIGURE_ARGS=$CONFIGURE_ARGS" >> $GITHUB_ENV
|
echo "CMAKE_CONFIGURE_ARGS=${CONFIGURE_ARGS//[$'\t\r\n']}" >> $GITHUB_ENV
|
||||||
echo "CMAKE_BUILD_ARGS=$BUILD_ARGS" >> $GITHUB_ENV
|
echo "CMAKE_BUILD_ARGS=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Configure CMake
|
- name: Configure CMake
|
||||||
shell: bash
|
shell: bash
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 3.0)
|
||||||
project(test)
|
project(test)
|
||||||
|
|
||||||
|
option(BUILD_C "build hello world in C Language" OFF)
|
||||||
|
option(BUILD_CXX "build hello world in CXX Language" ON)
|
||||||
option(BUILD_TXT "build hello world txt file" OFF)
|
option(BUILD_TXT "build hello world txt file" OFF)
|
||||||
|
|
||||||
add_executable(hello_world hello_world.cpp)
|
if(BUILD_C)
|
||||||
|
add_executable(hello_world_c hello_world.c)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(BUILD_CXX)
|
||||||
|
add_executable(hello_world hello_world.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(BUILD_TXT)
|
if(BUILD_TXT)
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
|
6
test/hello_world.c
Normal file
6
test/hello_world.c
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
printf("Hello world!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user