add option to check if using clang for test_c and test_cpp targets

This commit is contained in:
Alfi Maulana 2023-01-11 21:07:29 +07:00
parent 085f486acb
commit 1615d1b12a
No known key found for this signature in database
GPG Key ID: 2242A64C2A8DF5A4
3 changed files with 13 additions and 0 deletions

View File

@ -4,6 +4,8 @@ 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()
@ -13,4 +15,7 @@ if(BUILD_CXX)
endif()
add_executable(test_c EXCLUDE_FROM_ALL test.c)
target_compile_definitions(test_c PRIVATE $<$<BOOL:${CHECK_USING_CLANG}>:CHECK_USING_CLANG>)
add_executable(test_cpp EXCLUDE_FROM_ALL test.cpp)
target_compile_definitions(test_cpp PRIVATE $<$<BOOL:${CHECK_USING_CLANG}>:CHECK_USING_CLANG>)

View File

@ -1,6 +1,10 @@
#include <stdio.h>
int main() {
#if defined(CHECK_USING_CLANG) && !defined(__clang__)
printf("compiler is not clang\n");
return 1;
#endif
printf("all ok\n");
return 0;
}

View File

@ -1,6 +1,10 @@
#include <iostream>
int main() {
#if defined(CHECK_USING_CLANG) && !defined(__clang__)
std::cout << "compiler is not clang" << std::endl;
return 1;
#endif
std::cout << "all ok" << std::endl;
return 0;
}