From 67c4e4081cb6027122d02dabab4171298c2bd4e5 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Fri, 16 Dec 2022 14:38:30 -0800 Subject: [PATCH] Add `ENABLE_WERROR` option for use on CI (#4381) Defaults to `OFF`. Downstream packagers are advised against enabling it as we can't guarantee it working on every possible configuration. Added the actual compile flag in the GTK client subdirectory and not the top-level CMakeLists.txt file due to other subprojects not being ready. Fixed the only GTK client warning reported by Clang on Mac. --- .github/workflows/actions.yml | 6 ++++++ CMakeLists.txt | 1 + gtk/CMakeLists.txt | 3 +++ gtk/PathButton.cc | 6 +++--- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 1c5de1a14..10f5c09ae 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -210,6 +210,7 @@ jobs: -DENABLE_TESTS=OFF \ -DENABLE_UTILS=${{ (needs.what-to-make.outputs.make-utils == 'true') && 'ON' || 'OFF' }} \ -DENABLE_WEB=OFF \ + -DENABLE_WERROR=ON \ -DRUN_CLANG_TIDY=OFF - name: Make run: cmake --build obj --config RelWithDebInfo @@ -284,6 +285,7 @@ jobs: -DENABLE_TESTS=OFF \ -DENABLE_UTILS=${{ (needs.what-to-make.outputs.make-utils == 'true') && 'ON' || 'OFF' }} \ -DENABLE_WEB=OFF \ + -DENABLE_WERROR=ON \ -DRUN_CLANG_TIDY=OFF - name: Make run: cmake --build obj --config RelWithDebInfo @@ -375,6 +377,7 @@ jobs: -DENABLE_TESTS=ON ` -DENABLE_UTILS=${{ (needs.what-to-make.outputs.make-dist == 'true' || needs.what-to-make.outputs.make-utils == 'true') && 'ON' || 'OFF' }} ` -DENABLE_WEB=OFF ` + -DENABLE_WERROR=ON ` -DRUN_CLANG_TIDY=OFF - name: Make run: | @@ -478,6 +481,7 @@ jobs: -DENABLE_TESTS=${{ (needs.what-to-make.outputs.make-tests == 'true') && 'ON' || 'OFF' }} \ -DENABLE_UTILS=${{ (needs.what-to-make.outputs.make-utils == 'true') && 'ON' || 'OFF' }} \ -DENABLE_WEB=OFF \ + -DENABLE_WERROR=ON \ -DRUN_CLANG_TIDY=OFF - name: Make run: cmake --build obj --config RelWithDebInfo @@ -553,6 +557,7 @@ jobs: -DENABLE_TESTS=${{ (needs.what-to-make.outputs.make-tests == 'true') && 'ON' || 'OFF' }} \ -DENABLE_UTILS=${{ (needs.what-to-make.outputs.make-utils == 'true') && 'ON' || 'OFF' }} \ -DENABLE_WEB=OFF \ + -DENABLE_WERROR=ON \ -DRUN_CLANG_TIDY=OFF - name: Build run: cmake --build obj --config RelWithDebInfo @@ -625,6 +630,7 @@ jobs: -DENABLE_TESTS=${{ (needs.what-to-make.outputs.make-tests == 'true') && 'ON' || 'OFF' }} \ -DENABLE_UTILS=${{ (needs.what-to-make.outputs.make-utils == 'true') && 'ON' || 'OFF' }} \ -DENABLE_WEB=OFF \ + -DENABLE_WERROR=ON \ -DRUN_CLANG_TIDY=OFF - name: Build run: cmake --build obj --config RelWithDebInfo diff --git a/CMakeLists.txt b/CMakeLists.txt index 0267368e3..1bee0603b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ tr_auto_option(ENABLE_MAC "Build Mac client" AUTO) option(ENABLE_TESTS "Build unit tests" ON) option(ENABLE_LIGHTWEIGHT "Optimize libtransmission for low-resource systems: smaller cache size, prefer unencrypted peer connections, etc." OFF) option(ENABLE_UTP "Build µTP support" ON) + option(ENABLE_WERROR "Treat warnings as errors" OFF) option(ENABLE_NLS "Enable native language support" ON) option(INSTALL_DOC "Build/install documentation" ON) option(INSTALL_LIB "Install the library" OFF) diff --git a/gtk/CMakeLists.txt b/gtk/CMakeLists.txt index 634c05a9c..b8c57881f 100644 --- a/gtk/CMakeLists.txt +++ b/gtk/CMakeLists.txt @@ -1,6 +1,9 @@ project(trgtk) add_compile_options(${C_WARNING_FLAGS}) +if(ENABLE_WERROR) + add_compile_options($,/WX,-Werror>) +endif() execute_process( COMMAND diff --git a/gtk/PathButton.cc b/gtk/PathButton.cc index c2005e845..7c7e6d6df 100644 --- a/gtk/PathButton.cc +++ b/gtk/PathButton.cc @@ -41,9 +41,9 @@ private: #endif private: +#if GTKMM_CHECK_VERSION(4, 0, 0) PathButton& widget_; -#if GTKMM_CHECK_VERSION(4, 0, 0) Glib::Property action_; Glib::Property title_; @@ -59,9 +59,9 @@ private: #endif }; -PathButton::Impl::Impl(PathButton& widget) - : widget_(widget) +PathButton::Impl::Impl([[maybe_unused]] PathButton& widget) #if GTKMM_CHECK_VERSION(4, 0, 0) + : widget_(widget) , action_(widget, "action", Gtk::FileChooser::Action::OPEN) , title_(widget, "title", {}) , image_(Gtk::make_managed())