Merge pull request #11 from threeal/add-compiler-inputs

Add Compiler Input Option
This commit is contained in:
Alfi Maulana 2023-01-08 13:55:29 +07:00 committed by GitHub
commit 0a276cb8d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 3 deletions

View File

@ -53,6 +53,40 @@ jobs:
- name: Check if default build directory is not exist
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:
runs-on: ubuntu-latest
steps:

View File

@ -13,6 +13,12 @@ inputs:
description: The build directory of CMake project
required: false
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:
description: Additional arguments passed during CMake configuration
required: false
@ -24,11 +30,17 @@ runs:
run: |
CONFIGURE_ARGS="${{ inputs.source-dir }} -B ${{ 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
CONFIGURE_ARGS="$CONFIGURE_ARGS ${{ inputs.args }}"
fi
echo "CMAKE_CONFIGURE_ARGS=$CONFIGURE_ARGS" >> $GITHUB_ENV
echo "CMAKE_BUILD_ARGS=$BUILD_ARGS" >> $GITHUB_ENV
echo "CMAKE_CONFIGURE_ARGS=${CONFIGURE_ARGS//[$'\t\r\n']}" >> $GITHUB_ENV
echo "CMAKE_BUILD_ARGS=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_ENV
- name: Configure CMake
shell: bash

View File

@ -1,9 +1,17 @@
cmake_minimum_required(VERSION 3.0)
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)
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)
add_custom_target(

6
test/hello_world.c Normal file
View File

@ -0,0 +1,6 @@
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}