diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 04d05be..1e108b3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -5,8 +5,13 @@ option(CHECK_USING_CLANG "check if target is compiled using Clang" OFF) add_executable(hello_world hello_world.cpp) -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>) +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/test.c b/test/test.c deleted file mode 100644 index 325c6c7..0000000 --- a/test/test.c +++ /dev/null @@ -1,10 +0,0 @@ -#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 deleted file mode 100644 index b3c6941..0000000 --- a/test/test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#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; -} 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; +}