add option in test target to check if it could surpass a compiler warning

This commit is contained in:
Alfi Maulana 2023-01-14 17:59:14 +07:00
parent 830ed408e9
commit 98b40bce3e
No known key found for this signature in database
GPG Key ID: 2242A64C2A8DF5A4
2 changed files with 8 additions and 0 deletions

View File

@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.0)
project(test)
option(CHECK_USING_CLANG "check if target is compiled using Clang" OFF)
option(CHECK_SURPASS_WARNING "check if target could surpass a compiler warning" OFF)
set(CMAKE_C_FLAGS "-Werror -Wunused-variable ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-Werror -Wunused-variable ${CMAKE_CXX_FLAGS}")
add_executable(hello_world hello_world.cpp)
@ -13,5 +17,6 @@ foreach(LANG ${LANGS})
test_${LANG} PRIVATE
$<$<STREQUAL:"${LANG}","c">:IS_C>
$<$<BOOL:${CHECK_USING_CLANG}>:CHECK_USING_CLANG>
$<$<BOOL:${CHECK_SURPASS_WARNING}>:CHECK_SURPASS_WARNING>
)
endforeach()

View File

@ -7,6 +7,9 @@
#endif
int main() {
#ifdef CHECK_SURPASS_WARNING
int unused;
#endif
#if defined(CHECK_USING_CLANG) && !defined(__clang__)
PRINT("compiler is not clang");
return 1;