merge file and configuration for test_c and test_cpp

This commit is contained in:
Alfi Maulana 2023-01-12 14:32:06 +07:00
parent 0971b49fe1
commit ab9af67ec9
No known key found for this signature in database
GPG Key ID: 2242A64C2A8DF5A4
4 changed files with 26 additions and 25 deletions

View File

@ -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 $<$<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>)
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()

View File

@ -1,10 +0,0 @@
#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,10 +0,0 @@
#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;
}

16
test/test.in Normal file
View 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;
}