mirror of
https://github.com/threeal/cmake-action.git
synced 2025-04-20 10:41:21 +00:00
Merge pull request #18 from threeal/use-clang-as-compiler
Test Specified Compiler With Clang on Multiple Platforms
This commit is contained in:
commit
04440066e8
28
.github/workflows/test.yml
vendored
28
.github/workflows/test.yml
vendored
@ -55,38 +55,26 @@ jobs:
|
|||||||
run: build/test_c && build/test_cpp
|
run: build/test_c && build/test_cpp
|
||||||
|
|
||||||
use-action-with-specified-compiler:
|
use-action-with-specified-compiler:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
lang: [C, CXX]
|
os: [windows-latest, ubuntu-latest, macos-latest]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3.3.0
|
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
|
- name: Use this action with specified compiler
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
source-dir: test
|
source-dir: test
|
||||||
c-compiler: ${{ matrix.lang == 'C' && 'clang' || '' }}
|
targets: test_c test_cpp
|
||||||
cxx-compiler: ${{ matrix.lang == 'CXX' && 'clang++' || '' }}
|
generator: Ninja
|
||||||
args: |
|
c-compiler: clang
|
||||||
-D BUILD_C=${{ matrix.lang == 'C' && 'ON' || 'OFF' }}
|
cxx-compiler: clang++
|
||||||
-D BUILD_CXX=${{ matrix.lang == 'CXX' && 'ON' || 'OFF' }}
|
args: -D CHECK_USING_CLANG=ON
|
||||||
|
|
||||||
- name: Run build result
|
- 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:
|
use-action-with-specified-generator:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
@ -1,16 +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(CHECK_USING_CLANG "check if target is compiled using Clang" OFF)
|
||||||
option(BUILD_CXX "build hello world in CXX Language" ON)
|
|
||||||
|
|
||||||
if(BUILD_C)
|
|
||||||
add_executable(hello_world_c hello_world.c)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(BUILD_CXX)
|
|
||||||
add_executable(hello_world hello_world.cpp)
|
add_executable(hello_world hello_world.cpp)
|
||||||
endif()
|
|
||||||
|
|
||||||
add_executable(test_c EXCLUDE_FROM_ALL test.c)
|
list(APPEND LANGS c cpp)
|
||||||
add_executable(test_cpp EXCLUDE_FROM_ALL test.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
|
||||||
|
$<$<STREQUAL:"${LANG}","c">:IS_C>
|
||||||
|
$<$<BOOL:${CHECK_USING_CLANG}>:CHECK_USING_CLANG>
|
||||||
|
)
|
||||||
|
endforeach()
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
printf("Hello world!\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
printf("all ok\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
std::cout << "all ok" << std::endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
16
test/test.in
Normal file
16
test/test.in
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifdef IS_C
|
||||||
|
#include <stdio.h>
|
||||||
|
#define PRINT(STR) printf(STR); printf("\n")
|
||||||
|
#else
|
||||||
|
#include <iostream>
|
||||||
|
#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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user