diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2796c42..efc58fd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -55,38 +55,26 @@ jobs: run: build/test_c && build/test_cpp use-action-with-specified-compiler: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: matrix: - lang: [C, CXX] + os: [windows-latest, ubuntu-latest, macos-latest] 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' }} + targets: test_c test_cpp + generator: Ninja + c-compiler: clang + cxx-compiler: clang++ + args: -D CHECK_USING_CLANG=ON - name: Run build result - run: build/${{ matrix.lang == 'C' && 'hello_world_c' || 'hello_world' }} + run: build/test_c && build/test_cpp use-action-with-specified-generator: runs-on: ${{ matrix.os }} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 617b4f1..1e108b3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,16 +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(CHECK_USING_CLANG "check if target is compiled using Clang" OFF) -if(BUILD_C) - add_executable(hello_world_c hello_world.c) -endif() +add_executable(hello_world hello_world.cpp) -if(BUILD_CXX) - add_executable(hello_world hello_world.cpp) -endif() - -add_executable(test_c EXCLUDE_FROM_ALL test.c) -add_executable(test_cpp EXCLUDE_FROM_ALL test.cpp) +list(APPEND LANGS c cpp) +foreach(LANG ${LANGS}) + configure_file(test.in ${CMAKE_CURRENT_BINARY_DIR}/test.${LANG}) + add_executable(test_${LANG} EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/test.${LANG}) + target_compile_definitions( + test_${LANG} PRIVATE + $<$:IS_C> + $<$:CHECK_USING_CLANG> + ) +endforeach() diff --git a/test/hello_world.c b/test/hello_world.c deleted file mode 100644 index 7791fbb..0000000 --- a/test/hello_world.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main() { - printf("Hello world!\n"); - return 0; -} diff --git a/test/test.c b/test/test.c deleted file mode 100644 index e9a0a23..0000000 --- a/test/test.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main() { - printf("all ok\n"); - return 0; -} diff --git a/test/test.cpp b/test/test.cpp deleted file mode 100644 index c36cbb6..0000000 --- a/test/test.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main() { - std::cout << "all ok" << std::endl; - return 0; -} diff --git a/test/test.in b/test/test.in new file mode 100644 index 0000000..6a4eb5f --- /dev/null +++ b/test/test.in @@ -0,0 +1,16 @@ +#ifdef IS_C +#include +#define PRINT(STR) printf(STR); printf("\n") +#else +#include +#define PRINT(STR) std::cout << STR << std::endl +#endif + +int main() { +#if defined(CHECK_USING_CLANG) && !defined(__clang__) + PRINT("compiler is not clang"); + return 1; +#endif + PRINT("all ok"); + return 0; +}