From 1615d1b12a9bfd4a99662b96ccaa5a5bcf8936ef Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 11 Jan 2023 21:07:29 +0700 Subject: [PATCH] add option to check if using clang for `test_c` and `test_cpp` targets --- test/CMakeLists.txt | 5 +++++ test/test.c | 4 ++++ test/test.cpp | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 617b4f1..a166a0c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 $<$:CHECK_USING_CLANG>) + add_executable(test_cpp EXCLUDE_FROM_ALL test.cpp) +target_compile_definitions(test_cpp PRIVATE $<$:CHECK_USING_CLANG>) diff --git a/test/test.c b/test/test.c index e9a0a23..325c6c7 100644 --- a/test/test.c +++ b/test/test.c @@ -1,6 +1,10 @@ #include int main() { +#if defined(CHECK_USING_CLANG) && !defined(__clang__) + printf("compiler is not clang\n"); + return 1; +#endif printf("all ok\n"); return 0; } diff --git a/test/test.cpp b/test/test.cpp index c36cbb6..b3c6941 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,6 +1,10 @@ #include 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; }