mirror of
https://github.com/threeal/cmake-action.git
synced 2025-04-20 02:31:20 +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
|
||||
|
||||
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 }}
|
||||
|
@ -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
|
||||
$<$<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