From 98b40bce3ed3fb6687a34c526730b3adeac653be Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sat, 14 Jan 2023 17:59:14 +0700 Subject: [PATCH] add option in test target to check if it could surpass a compiler warning --- test/CMakeLists.txt | 5 +++++ test/test.in | 3 +++ 2 files changed, 8 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1e108b3..f240946 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 $<$:IS_C> $<$:CHECK_USING_CLANG> + $<$:CHECK_SURPASS_WARNING> ) endforeach() diff --git a/test/test.in b/test/test.in index 6a4eb5f..4098a34 100644 --- a/test/test.in +++ b/test/test.in @@ -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;