From cfcd28affd6c32528ba54f31af5f588954d36526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cs=C3=A1sz=C3=A1r=20M=C3=A1ty=C3=A1s=20=5BVader=5D?= Date: Wed, 26 Jul 2023 21:08:37 +0200 Subject: [PATCH] Add wish_werror --- README.md | 12 +++++++++++- cmake/wish/wish_configuration.cmake | 2 +- cmake/wish/wish_flags.cmake | 14 ++++++++++++++ sandbox/versions/main.cpp | 2 ++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 362ca84..4a0624e 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ TODO: Format, place TODO: Auto self update the wish.cmake script (not just the wish/ folder) - v5.4.4 + - Feature: Add wish_werror - Improvement: Hide package_* target for non-package build types - v5.4.3 - Improvement: Add PLUGIN support for wish_generator @@ -112,7 +113,7 @@ wish_configurations wish_configurations(DEFAULT ...) # Example -wish_configurations(DEFAULT Release Dev Debug) +wish_configurations(debug dev DEFAULT release package) ``` wish_force_colored_output @@ -133,6 +134,15 @@ option(MY_PROJECT_SKIP_EXTERNAL_CONFIGURES "Do not configure external projects o wish_skip_external_configures(${MY_PROJECT_SKIP_EXTERNAL_CONFIGURES}) ``` +wish_werror +``` +wish_werror() + +# Example +option(MY_PROJECT_WERROR "Specify whether to treat warnings on compile as errors." FALSE) +wish_werror(${MY_PROJECT_WERROR}) +``` + wish_alternative_linker ``` wish_alternative_linker() diff --git a/cmake/wish/wish_configuration.cmake b/cmake/wish/wish_configuration.cmake index 16b4fbd..85ba84c 100644 --- a/cmake/wish/wish_configuration.cmake +++ b/cmake/wish/wish_configuration.cmake @@ -31,8 +31,8 @@ macro(wish_configurations) foreach (build_type IN LISTS arg_UNPARSED_ARGUMENTS arg_DEFAULT) string(TOLOWER ${build_type} build_type_lower) + string(TOUPPER ${build_type} build_type_upper) if (CMAKE_BUILD_TYPE STREQUAL build_type_lower) - string(TOUPPER ${build_type} build_type_upper) set(WISH_BUILD_TYPE_IS_${build_type_lower} TRUE) set(WISH_BUILD_TYPE_IS_${build_type_upper} TRUE) else () diff --git a/cmake/wish/wish_flags.cmake b/cmake/wish/wish_flags.cmake index eca1b38..db5630f 100644 --- a/cmake/wish/wish_flags.cmake +++ b/cmake/wish/wish_flags.cmake @@ -135,3 +135,17 @@ macro(wish_optimization_flags) endmacro() # ------------------------------------------------------------------------------------------------- + +function(wish_werror enable) + # It seams like there is an issue with CMAKE_COMPILE_WARNING_AS_ERROR, use the flags for now + # set(CMAKE_COMPILE_WARNING_AS_ERROR ${enable}) + if (enable) + wish_compiler_flags( + MSVC /Wx + Clang -Werror + GNU -Werror + ) + endif () +endfunction() + +# ------------------------------------------------------------------------------------------------- diff --git a/sandbox/versions/main.cpp b/sandbox/versions/main.cpp index 7348c19..784b90f 100644 --- a/sandbox/versions/main.cpp +++ b/sandbox/versions/main.cpp @@ -33,6 +33,8 @@ int main(int argc, char** argv) { wish::change_current_path(argc, argv); + int i = 0; + foo(); std::cout << "argv[0]: " << argv[0] << std::endl; std::cout << "version_number: " << build.version_number << std::endl;